All I'm trying to do is determine how far away the player is from objects in the world, but no matter where I actually am in the world I am getting the same values. I have done out everything manually so you wouldn't have to rely on my overloaded operators and operators. What am I doing wrong here exactly? I'll show you my code and the values I'm getting in the text file (really strange stuff)
Note the whole thing about checking for the time, that's so it only writes to the text file once a second (otherwise massively huge text file)
Code:
//object - campos to get vector from object to camera position
//costheta = A dot B / ||A|| ||B||
char dist[128];
char x[128];
float length;
Vector ObjectToCamera;
ObjectToCamera.x = Position.x - Player1->Position.x;
ObjectToCamera.y = Position.y - Player1->Position.y;
ObjectToCamera.z = Position.z - Player1->Position.z;
length = sqrt((ObjectToCamera.x * ObjectToCamera.x) + (ObjectToCamera.y * ObjectToCamera.y) +
(ObjectToCamera.z * ObjectToCamera.z));
if( (GameController->CurrentTime - GameController->LastTime) >= 1000)
test << ObjectToCamera.x << " " << ObjectToCamera.y << " " << ObjectToCamera.z << " " << length << "\n";
sprintf(dist, "distance: %d", (int)length);
SetWindowText(hWnd, dist);
return true;
Here are the resulting values, note these are produced despite the fact that I am constantly moving closer and farther away from the object...weird!
That is the x, y, and z of the vector from the object and the player's position, and the last value is the length of that vector (the distance jebroni)
-4.31602e+008 -4.31602e+008 -4.31602e+008 7.47557e+008
-4.31602e+008 -4.31602e+008 -4.31602e+008 7.47557e+008
-4.31603e+008 -4.31602e+008 -4.31603e+008 7.47558e+008
-4.31603e+008 -4.31602e+008 -4.31603e+008 7.47558e+008
-4.31603e+008 -4.31602e+008 -4.31604e+008 7.47559e+008