what am I doing wrong. Am I just a complete retard or something?

This is a discussion on what am I doing wrong. Am I just a complete retard or something? within the Game Programming forums, part of the General Programming Boards category; All I'm trying to do is determine how far away the player is from objects in the world, but no ...

  1. #1
    Banned
    Join Date
    Jan 2003
    Posts
    1,708

    what am I doing wrong. Am I just a complete retard or something?

    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

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Looking at those values, the distance does change. look at the last digit of the mantissa, it increases one every second calculation, so the objects distance increases with ~500 units per frame.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    it can't be changing at the appropriate rate. Would you like me to attach the project? I'm only going to if you'll look at it. I can be literally colliding with the object, but not having a distance of any less than like 7.47559e+008 ...that is totally strange and I have absolutely no clue why it is like that

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Did you notice the +008 in 7.47557e+008? The distance you have is 747557000, and a little difference in that number won't be too noticable. Also, since they are large floating point numbers, a little addition may not be registered due to its precision.
    Why do you have such huge coordinates anyway?
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  5. #5
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    i have no clue...I think its all wrong because the starting position of the player should be at the origin, i.e 0,0,0. this seemed simple

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 10:50 PM
  2. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 01:40 PM
  3. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  4. Hmm... Anything wrong with this?
    By jon_nc17 in forum C++ Programming
    Replies: 2
    Last Post: 12-01-2002, 08:33 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 02:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21