Jump to content
  • Advertisement
Sign in to follow this  
hello_there

inaccuracy problem

This topic is 5171 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!