Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Gladiator

3D Solid Cube

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there again! I''m writing a DOS32 progam that rotates a 3D solid cube, and I''m having some problems with backface culling and hidden surface removal. If anyone can help me out to get it working, I''ll be grateful. (I''m a beginner at 3D graphics) Thank you! ..-=gLaDiAtOr=-..

Share this post


Link to post
Share on other sites
Advertisement
Backface culling is really quite easy. What you want to check is wether the triangle's normal is facing the camera or not. You do this like so:

d = DotProduct(TriangleVertex - CameraPosition, Normal);
if( d >= 0 )
// The camera is behind the triangle
else
// The camera is in front of the triangle

-

The dot product of two vectors, U and V, is calculated as

DotProduct = U.x*V.x + U.y*V.y + U.z*V.z;

The mathematical formula for the dot product is

DotProduct = LengthOf(U)*LengthOf(V)*cos(SmallestAngle(U,V))

This will have the effect that if the vectors are perpendicular to each other the dotproduct is 0, if they are facing in the same general direction (angle < 90 degrees) the dotproduct is positive and negative if facing away from each other (angle > 90 degrees).

-

You can also do the test after 3D to 2D projection by computing the signed area of the triangle:

Area = (U.x*V.y - U.y*V.x)/2;
if( Area < 0 )
// The triangle is invisible
else
// The triangle is visible

The formula for the signed area is derived from the cross product (But that is not relevant to your question).

WitchLord

Edited by - WitchLord on 4/18/00 4:01:38 PM

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!