Distance between 2 points on an arbitary axis

Started by
4 comments, last by The Bag 20 years ago
I''m working on a game where all the objects in the world are represented by a 4x4 Matrix which is made up of: - Right Vector (x) - Up Vector (y) - At Vector (z) - Pos Vector The first three give the object an it''s own axis system, the position vector gives the position of the object in the world coordinate space. I am trying to get the distance one object is behind the other (ie the camera and player) to keep them at a set distance. The camera and player have the same axes and I wish to know how far back along the z axis the camera is from the player. It sort of works using the z values from the Pos vector, but not consistantly (camera can get too close, it moves it and out whilst rotating), any ideas? Is there another way of calculating this?
Advertisement
So what''s the problem? How I see it: the two objects (person and cam) are using the same UVN orientation and only differ by position. So if you wanted to find the distance between the two you''d find the distance simple enough. But all you want is the displacement along the z-axis right? So even simpler, wouldn''t it just be the absolute value of the difference of the the z components from both positions?

z_dist = abs(cam.z - person.z); ???
"I study differential and integral calculus in my spare time." -- Karl Marx
Yeah, I''ve got it working now - distance between the two points and restricting changes to z for dist.

Still fucking up slightly with y, but that''s another problem (woohoo).
It''s not working properly.

When I rotate there are problems. If I use the z values from the Pos vector and compare them it doesn''t work, as these z values are tied to the world axes, not the object axes.

What I want is the distance along the object''s Z-axis, not the worlds. Is there a way of converting the points from the world axes to the object axes?
quote:Original post by The Bag
What I want is the distance along the object's Z-axis, not the worlds. Is there a way of converting the points from the world axes to the object axes?


yes, that´s what your rotation matrix actually does (don´t jump on me if it´s the inverse, that´s not important for my post) but you don´t need that.
Take the scalar product of your objects z-axis and the displacement vector between the object and the other one. The result is the distance in your object´s z-direction.

[edited by - Atheist on April 5, 2004 12:46:23 PM]
You''re probably already doing this but make sure your z vector stays normalized. If it''s not, you can divide the result by the magnitude of it and you''ll get the same thing. B/c A.B = |A||B|cos t.
"I study differential and integral calculus in my spare time." -- Karl Marx

This topic is closed to new replies.

Advertisement