Not logged in, Join Here! or Log In Below:  
News Articles Search    

 Home / 3D Theory & Graphics / Help with depth and hidden surface removal Account Manager
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
Ben Jackson

August 14, 1999, 07:16 PM

I've just started doing a software 3dEngine and am doing something wrong when it comes
to computing both the depth of a certain polygon and whether a poly is facing the eye.

I have my eye set up so that it is storing its position, X, Y, and Z unit orientation vecors, and two angles in radians also indicating its orientation. Points are oriented to eye space by translating by the negative eye coords, and projecting onto each of the x, y, and z unit vecotors of the eye. The normal of the polygon is translated by projecting onto to the x,y,and z vecors as well.

I project a point onto the uv plane by
u = x/z * zoom + X_SCREEN
v = y/z * zoom

Now as far as determining the the visibilty of a polygon, I calculate D as

D = CurPos.x * CurNormal.x + CurPos.y * CurNormal.y + CurPos.z * CurNormal.z;

where CurPos is the point on the plane, and CurNoraml is the normal, both relative
to the eye. This is the dot product of the two vectors, and therefor, if D>=0 then
the plane should not be visible because the parallel component of the dot product is
oriented in the same direction as the position vector. So I have the condition:

if (D >= 0)
visible = FALSE;

However this has wacky behavior when I attempt to run the engine: the faces disapear and
reapper at odd angles.

I also use d in the calculation of the distance of a point on the poly plane from the eye.
at U, V I calculate the depth as (SCREEN_X is half the distance accross the screen, v doesn't need correcting)

depth = D/(line->Parent->CurNormal.x * (u - SCREEN_X) / zoom +
line->Parent->CurNormal.y * v / zoom +

Is there something wrong with my theory, or do I just have some coding error somewhere?

Ben Jackson

August 15, 1999, 02:40 PM

Ben Jackson wrote:

As an addendum,

It the depth/hiddensurface removal seems to work fine if I keep the cameral aligned with the
world axis and just translate it.

Ben Jackson

August 15, 1999, 07:06 PM

Found the problem. Wasn't remembering to project the poly's position onto
the eye's orientation.

This thread contains 3 messages.
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.