Public Group

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

## 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.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.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.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 on other sites
Moved to For Beginners.

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

but how can I get the world matrix ?

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

1. 1
2. 2
3. 3
Rutin
19
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633657
• Total Posts
3013200
×