Quote: "To solve this you need to render the scene so that the player is at the origin at all times"
Yes. That's exactly what I'm doing. The problem with doubles is that they loose accuracy around 10000 or so... Don't know why. I think its "precision" is in the places right of the decimal. I came up with a vector convention to handle the problem. I was hoping some one knew of a variable type I didn't.....
Here is the code I promissed:
struct INTVECTOR3{
INTVECTOR3(){}
INTVECTOR3(int x,int y,int z){ix=x;iy=y;iz=z;}
int ix,iy,iz;
INTVECTOR3 operator + ( CONST INTVECTOR3& other) const;
INTVECTOR3 operator - ( CONST INTVECTOR3& other) const;
INTVECTOR3 operator * ( CONST int& other) const;
INTVECTOR3 operator / ( CONST int& other) const;
INTVECTOR3& operator -= ( CONST INTVECTOR3& other);
INTVECTOR3& operator+=( CONST INTVECTOR3& other);
INTVECTOR3& operator/=( CONST int other);
INTVECTOR3& operator*=( CONST int other);
D3DXVECTOR3 Div(float m);
D3DXVECTOR3 Mul(float m);
};
INTVECTOR3 INTVECTOR3::operator*( CONST int& other) const{
return INTVECTOR3(ix*other,iy*other,iz*other);
}
INTVECTOR3 INTVECTOR3::operator/( CONST int& other) const{
return INTVECTOR3(ix/other,iy/other,iz/other);
}
INTVECTOR3 INTVECTOR3::operator+( CONST INTVECTOR3& other) const{
return INTVECTOR3(ix+other.ix,iy+other.iy,iz+other.iz);
}
INTVECTOR3 INTVECTOR3::operator-( CONST INTVECTOR3& other) const{
return INTVECTOR3(ix-other.ix,iy-other.iy,iz-other.iz);
}
INTVECTOR3& INTVECTOR3::operator-=( CONST INTVECTOR3& other){
this->ix-=other.ix;
this->iy-=other.iy;
this->iz-=other.iz;
return *this;
}
INTVECTOR3& INTVECTOR3::operator+=( CONST INTVECTOR3& other){
this->ix+=other.ix;
this->iy+=other.iy;
this->iz+=other.iz;
return *this;
}
INTVECTOR3& INTVECTOR3::operator/=( CONST int other){
this->ix/=other;
this->iy/=other;
this->iz/=other;
return *this;
}
INTVECTOR3& INTVECTOR3::operator*=( CONST int other){
this->ix*=other;
this->iy*=other;
this->iz*=other;
return *this;
}
D3DXVECTOR3 INTVECTOR3::Div(float m){
float x=float(ix);
float y=float(iy);
float z=float(iz);
x/=m;
y/=m;
z/=m;
ix=int(x);
iy=int(y);
iz=int(z);
D3DXVECTOR3 v;
v=D3DXVECTOR3(x-float(ix),y-float(iy),z-float(iz));
return v;
}
D3DXVECTOR3 INTVECTOR3::Mul(float m){
float x=float(ix);
float y=float(iy);
float z=float(iz);
x*=m;
y*=m;
z*=m;
ix=int(x);
iy=int(y);
iz=int(z);
D3DXVECTOR3 v;
v=D3DXVECTOR3(x-float(ix),y-float(iy),z-float(iz));
return v;
}
struct HUGEVECTOR3{
HUGEVECTOR3(){Sector=INTVECTOR3(0,0,0);Loc=D3DXVECTOR3(0,0,0);};
HUGEVECTOR3(INTVECTOR3 s,D3DXVECTOR3 l){Sector=s;Loc=l;}
HUGEVECTOR3(D3DXVECTOR3 l){Sector=INTVECTOR3(0,0,0);Loc=l;}
HUGEVECTOR3(INTVECTOR3 s){Sector=s;Loc=D3DXVECTOR3(0,0,0);}
HUGEVECTOR3 operator + ( CONST HUGEVECTOR3& other) const;
HUGEVECTOR3 operator - ( CONST HUGEVECTOR3& other) const;
HUGEVECTOR3& operator-=( CONST D3DXVECTOR3& other);
HUGEVECTOR3& operator+=( CONST D3DXVECTOR3& other);
HUGEVECTOR3& operator/=( CONST float other);
HUGEVECTOR3& operator*=( CONST float other);
INTVECTOR3 Sector;
D3DXVECTOR3 Loc;
float Length;
void CheckScale(void);
float GetLength(void);
D3DXVECTOR3 Normalize(void);
};
float HUGEVECTOR3::GetLength(){
D3DXVECTOR3 v=Loc+D3DXVECTOR3(float(Sector.ix*1000),float(Sector.iy*1000),float(Sector.iz*1000));
return D3DXVec3Length(&v);
}
D3DXVECTOR3 HUGEVECTOR3::Normalize(){
Length=GetLength();
float x=(Sector.ix*1000.0f/Length)+(Loc.x/Length);
float y=(Sector.iy*1000.0f/Length)+(Loc.y/Length);
float z=(Sector.iz*1000.0f/Length)+(Loc.z/Length);
return D3DXVECTOR3(x,y,z);
}
void HUGEVECTOR3::CheckScale(void){
if ((this->Loc.x>=1000.0f)||(this->Loc.x<0.0f)){
int x=int(this->Loc.x)-int(this->Loc.x)%1000;
this->Loc.x-=float(x);
this->Sector.ix+=(x)/1000;
}
if ((this->Loc.y>=1000.0f)||(this->Loc.y<0.0f)){
int y=int(this->Loc.y)-int(this->Loc.y)%1000;
this->Loc.y-=float(y);
this->Sector.iy+=(y)/1000;
}
if ((this->Loc.z>=1000.0f)||(this->Loc.z<0.0f)){
int z=int(this->Loc.z)-int(this->Loc.z)%1000;
this->Loc.z-=float(z);
this->Sector.iz+=(z)/1000;
}
}
HUGEVECTOR3& HUGEVECTOR3::operator+=( CONST D3DXVECTOR3& other){
this->Loc+=other;
CheckScale();
return *this;
}
HUGEVECTOR3& HUGEVECTOR3::operator-=( CONST D3DXVECTOR3& other){
this->Loc-=other;
CheckScale();
return *this;
}
HUGEVECTOR3 HUGEVECTOR3::operator+( CONST HUGEVECTOR3& other) const{
HUGEVECTOR3 tmp;
tmp.Loc=Loc+other.Loc;
tmp.Sector=Sector+other.Sector;
tmp.CheckScale();
return tmp;
}
HUGEVECTOR3 HUGEVECTOR3::operator-( CONST HUGEVECTOR3& other) const{
HUGEVECTOR3 tmp;
tmp.Loc=Loc-other.Loc;
tmp.Sector=Sector-other.Sector;
tmp.CheckScale();
return tmp;
}
HUGEVECTOR3& HUGEVECTOR3::operator *= ( CONST float other) {
this->Loc*=other;
this->Loc+=(this->Sector.Mul(other))*1000.0f;
this->CheckScale();
return *this;
}
HUGEVECTOR3& HUGEVECTOR3::operator /= ( CONST float other) {
this->Loc/=other;
this->Loc+=(this->Sector.Div(other))*1000.0f;
this->CheckScale();
return *this;
}
I guess most people don't use DirectX math, but I do. So some of the functions have D3DXVECTOR3 stuff in them. If you don't like using them, you can make your own or, for DGDK2.0 users, use the new vector structures.
It's messy, but it's mine!
BTW, I have stopped using GDK all together because of the numerous problems. Once DGDK2.0 is a complete package with all that was promissed when I bought it, I may take another look. Until then, I'll keep plugging away with DX.
The fastest code is the code never written.