inaccuracy problem

Started by
-1 comments, last by hello_there 19 years, 7 months ago
I have a problem with accuracy of a double. I have thsi code for when i detect a collision in my game. CVector3 Distances[4]; double Pos[3] = {XDrawPositions[TileData[MapData[Y+i][Z+j][X+t]].X], YDrawPositions[TileData[MapData[Y+i][Z+j][X+t]].Y], ZDrawPositions[TileData[MapData[Y+i][Z+j][X+t]].Z]}; Distances[0] = Obj->OldPosition - CVector3(Pos[0],Pos[1],Pos[2]-0.2); Distances[1] = Obj->OldPosition - CVector3(Pos[0]+0.2,Pos[1],Pos[2]); Distances[2] = Obj->OldPosition - CVector3(Pos[0],Pos[1],Pos[2]+0.2); Distances[3] = Obj->OldPosition - CVector3(Pos[0]+0.2,Pos[1],Pos[2]); LOG(LOG_VARIABLE, "%f Top", Distances[0].CheapLength()); LOG(LOG_VARIABLE, "%f Right", Distances[1].CheapLength()); LOG(LOG_VARIABLE, "%f Bottom", Distances[2].CheapLength()); LOG(LOG_VARIABLE, "%f Left", Distances[3].CheapLength()); // Index of the biggest value byte Smallest = 0; for(int w=0;w<4;w++) //if(Distances[w].CheapLength() != Distances[Smallest].CheapLength()) if(Distances[w].CheapLength() < Distances[Smallest].CheapLength()) Smallest = w; //else; else; //Smallest = 10; if(Smallest == 0) Obj->Position.z = ZDrawPositions[TileData[MapData[Y+i][Z+j][X+t]].Z]-0.2-Obj->GetSize(); else if(Smallest == 1) Obj->Position.x = XDrawPositions[TileData[MapData[Y+i][Z+j][X+t]].X]+0.2+Obj->GetSize(); else if(Smallest == 2) Obj->Position.z = ZDrawPositions[TileData[MapData[Y+i][Z+j][X+t]].Z]+0.2+Obj->GetSize(); else if(Smallest == 3) Obj->Position.x = XDrawPositions[TileData[MapData[Y+i][Z+j][X+t]].X]-0.2-Obj->GetSize(); CheapLength just gets the length without getting the square root. The DrawPositions arrays are the positions of the centre of the cube being collided with. The LOG is for my testing My problem is that when you hold down 2 movement keys at once the values outputed by the LOG function go from 6 d.p to 3 d.p anyone know why. everything there uses doubles.
____________________________________________________________How could hell be worse?

This topic is closed to new replies.

Advertisement