Sign in to follow this  
cedricmobile

About Backface Culling

Recommended Posts

I have read the following post and have some problems that I would like to ask. http://www.gamedev.net/reference/articles/article1088.asp int i; Vector normal, // the polygon normal camera(0,0,0), // the camera at 0,0,0 cv; // the camera vector (or view vector) // Loop through all the polygons for(i = 0; i < faces; i++) { // Transform our normal to view space... // This example assumes you've already precalculated the normal and // so all you must do is rotate it into world space by your matrix. // See my vector tutorial on how to calculate a polygon normal. normal = *face[i].normal; normal = normal * to_world_space; // Now calculate a vector from the camera to any point on the polygon cv.set(camera, world_space[ face[i].vertex[0] ] ); // Now calculate the dot product of the normal and the camera vector if((cv.dot(&normal) > 0)) { // draw the polygon here, it's visible } } I wonder how can I get the "to_world_space"? and world_space[ face[i].vertex[0] ] )? ( how to change the face's vertex to world space?) Can you give me some example? And how can I change the points of a Mesh that I read from .obj or .off to World Space? Actually, I am not very familiar with transforming something to World space and then to Camera space. Can you give me some example as well. Thanks.

Share this post


Link to post
Share on other sites
you need to transform vertices from model space to world space, and then to view space (also called Camera Space). In order to do that, you need to multiply each vertex by a transformation matrix (More Information here). In the example code that you gave, to_world_space is a world matrix by which you need to multiply the vertices and normals.
To create transformation matrices you need to use some formulas.
You can find these formulas by searching for "Transformation Matrices".
You can also look here.

Share this post


Link to post
Share on other sites
The world matrix causes a vertex to be transformed from the model space into world space.
If you have a model of a ball, the position of each vertex will be obviously relative to the center of the ball; or in other words, the point (0, 0, 0) will be assumed as the center of the ball. However, when you put this ball in the world, along with other models, the ball won't be at the point (0, 0, 0) of the whole world. For example, if you decide to put the ball at point (0, 0, 5), each vertex of it will be moved +5 in the Z-Axis accordingly. The world matrix causes each vertex to be transformed into the correct position in the big world. This matrix usually consists of 2 basic transformations: Translation (moving the object) and Rotation.
Other transformations include Scaling, Mirroring, Shadowing...

To create the world matrix you need to decide about how your model will be located in the world (position, rotation, ...). Then you fill in the 4X4 matrix with values according to the formulas in the 2nd link I gave you in the first reply. After that, you multiply each vertex with this matrix and your whole model will appear the same it was, just in a different place and rotated (if you rotated it).
*If you are using Direct3D then you can easily find function to create all the Transformation matrices for you.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this