Sign in to follow this  

inaccuracy problem

This topic is 4868 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

This topic is 4868 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this