Skip to main content
gamedev.net
🔒 Locked

3D Solid Cube

Started by Gladiator Apr 18, 2000 at 3:31 PM 1 replies 700+ views
Original Post
Gladiator
Gladiator
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=-..
WitchLord
WitchLord
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
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - <a href="http://www.angelcode.com/tower" rel
Gladiator
Gladiator
hehe, thank you very much WitchLord

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.