# Simple Distance Measuring - wrong system?

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

## Recommended Posts

Hi there! I am currently trying to get into collision detection and I worked out a small example where I can move in 3D-Space (like in an Ego-Shooter, so no movement on y-axis right now). Now I have a small triangle set in Space: CVector3 vtx0 (-2.0, 1.0, -2.0); CVector3 vtx1 (-2.0, 0.0, -2.0); CVector3 vtx2 (-0.3, 0.0, -2.0); CVector3 vPolygon[] = {vtx0, vtx1, vtx2}; I am moving the camera via gluLookAt( eyeposx, eyeposy, eyeposz, eyeposx + x_add, eyeposy, eyeposz + z_add, 0.0f, 1.0f, 0.0f); so the origin of the ray intersecting the plane of the triangle is (eyeposx, eyeposy, eyeposz). I am using the 3DMath-Library from DigiBen on gametutorials.com. My first task is to get the distance of my position to the plane where the triangle is situated in. Therefore I get the normal of the plane first via a function. Next, I pass the normal and my current position to the PlaneDistance() method which returns a distance. That's all fine and it is working. But: the distance is wrong because the plane is not situated where the triangle is, but in the origin (0,0,0). While moving around the correct distance to this plane is calculated, but not to the one of the triangle (which is at z=-2). Because the library is working, I wonder if I am using the wrong kind of "system" to move around in Space, because the PlaneDistance() method obviously doesn't take the coordinates of the triangle into consideration. I hope I could express my problem quite clearly :I I would be pleased if anyone has suggestions for standard movement implementation in 3D-Space (e.g. moving myself, moving objects around,...). Thanks a lot! Andy

##### Share on other sites
What equation are you using for your plane?
The standard form is Ax + By + Cz + D = 0
(A,B,C) is the normal of the plane, and D is the negative distance to the origin. So you may have to adjust your plane equation if the triangle doesn't pass through the origin. This is quite easy to calculate:
D = -(Ax + By + Cz), where (x,y,z) is any point on the plane.

What does the PlaneDistance function look like?

##### Share on other sites
If the equation of the plane is Ax + By + Cz + D = 0, then the distance from the plane to the a point [x y z] along the normal of the plane is Ax + By + Cz + D.

You didn't say why you need to know the distance from the camera to the plane, so it is difficult to give you any more help than that.

##### Share on other sites
Hi,

the PlaneDistance-Function looks like this, it is using the right formula for a plane:

float PlaneDistance (CVector3 Normal, CVector3 Point) {
float distance = 0;
// Use the plane equation to find the distance
// (Ax + By + Cz + D = 0) We want to find D.
// So, we come up with D = -(Ax + By + Cz)

distance = -((Normal.x * Point.x) + (Normal.y * Point.y) +
(Normal.z * Point.z));

return distance;
}

What I want to do is basic collision detection. Because I can follow the calculations of this math library I wonder if my system of moving in 3D-Space is appropriate. What is common practice? Is the "player" fixed to the origin and the world is translated according to the movement of the player or is the world static and the player moves (like in my example) ?

Thanks!

##### Share on other sites
Your function PlaneDistance computes the distance from the plane to the origin given the normal and a point on the plane.

The player should move through the world. Don't keep him at the origin and move the world around him.

The camera follows the player around. It is easier if you keep these things separate. You move the player around the world and it collides with things. The camera follows the player (for a FPS, it would be in the player's head).

##### Share on other sites
I got the interpretation of "origin" within the function wrong. Because I am thinking of the player being the origin for the line of sight I must have mixed that up.

Thanks!

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 11
• 13
• 90
• 11
• 10
• ### Forum Statistics

• Total Topics
632973
• Total Posts
3009620
• ### Who's Online (See full list)

There are no registered users currently online

×