#### Archived

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

# 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.

## 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 on other sites
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 on other sites
hehe, thank you very much WitchLord

1. 1
2. 2
3. 3
Rutin
12
4. 4
5. 5

• 26
• 10
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633695
• Total Posts
3013382
×