**Started by aldur on utilitybase****aldur** Member

Posted: 2005-Feb-13 03:48:37

the distance between two 3d points A and B where both have the values x,y & z is as follows A(3,4,5), B(10,11,12)

/pesudo code

Dx = Ax-Bx; //(= -7)

Dy = Ay-By; //(= -7)

Dz = Az-Bz; //(= -7)

distance = SquareRoot ((Dx*Dx)+(Dy*Dy)+(Dz*Dz));

Distance = SquareRoot ((-7*-7)+(-7*-7)+(-7*-7));

Distance = SquareRoot (49+49+49);

Distance = SquareRoot (147);

yes i'm bored

**nicomen**Humble Servant

Posted: 2005-Feb-13 04:30:57

Noted for my next killer demo

**aldur** Member

Posted: 2005-Feb-13 05:48:25

you can do perspective with this as well take point middle of your screen (viewpoint) vp(0,0,0) running ahead of you say 10000 pixels

if you have a cube of four points you can work out the distance of each one from Vp(0,0,0) then modify eah in turn giving you objects getting smaller, worked this out about five years ago was bored then too ;-)

can't remember the perspecitive formula at the minute but I know it worked.

**nicomen**Humble Servant

Posted: 2005-Feb-13 06:10:17

pythagoras rocks

**Rogue** Member

Posted: 2005-Feb-13 11:43:08

yes i'm bored

Depending on application, you should use squared distances to save the square root. For example, if you're raytracing you can store the squared radius of a sphere instead of the real one, that makes hit tests faster :-)

**aldur** Member

Posted: 2005-Feb-15 22:07:54 ยท Edited by: aldur

@Rogue

so you could use your self as the center of the sphere and work out if points are outside the visible sphere?

What values would you recommend for

A. field of view? (degrees)

B. Distance an object has to be before invisible.

**Rogue** Member

Posted: 2005-Feb-16 09:05:51

so you could use your self as the center of the sphere and work out if points are outside the visible sphere?

Yes, for a simple inside/outside test you can use the squared radius of the sphere against the squared distance between the center and the "test point". The sqrt function is quite calculation-intensive.

A. field of view? (degrees)

Quake et alia normally use 90 degrees. That seems reasonable. I think Halo uses a smaller FOV with the result that it looks "zoomed". You can try the effect in Quake (IIRC the variable is "fov").

B. Distance an object has to be before invisible.

That greatly depends on your scale, and the complexity of your engine. Ideally, you would degrade the distance progressively if the frame rate drops too low, and increase it when your framerate increases as well.