# Thread: Normal question (well, kinda weird actualy)

1. ## Normal question (well, kinda weird actualy)

I wrote a program that can load and render .obj files with textures, but the .obj file does not have normals data, is there a way to calculate normals?

how can i draw an .obj with lighting?

thanks!

2. ## Re: Normal question (well, kinda weird actualy)

The normals is an equation to calculate it for each verticy, i don't know it. I use DirectX calls to calculate all my normals for me.

3. ## Re: Normal question (well, kinda weird actualy)

im trying to stick with opengl, is there a way to calculate normals in opengl?

4. ## Re: Normal question (well, kinda weird actualy)

See appendix E from the red book, also recommended to zix99 so he does not have to depend on some helper functions.
If you really do not want to make the effort is low level libraries like OpenGL and Direct3D not what you want.

You probably need to calculate the cross product. Here is two libraries with that function and others. http://plib.sourceforge.net/sg/ http://www-2.cs.cmu.edu/~ajw/doc/svl.html

Once you have the normals can you use the standard OpenGL lights.

5. ## Re: Normal question (well, kinda weird actualy)

the normal of a vertex is the normalized sum of the normal of the triangles that share the vertex.

for each triangle
normal[triangle.vertex[0]] += triangle.normal
normal[triangle.vertex[1]] += triangle.normal
normal[triangle.vertex[2]] += triangle.normal
end for

6. ## Re: Normal question (well, kinda weird actualy)

it's strange that there is not normals in obj file! i using maya's exported obj models and they contain normals data!
like this: vn 1 0 0

7. ## Re: Normal question (well, kinda weird actualy)

thanks some guy, i'll try not to use DX this time. Its a pain to use DX for just ONE call in my whole program.

8. ## Re: Normal question (well, kinda weird actualy)

simple math question, it says that the normal = [v1 - v2] × [v2 - v3].

How do you subtract 2 vectors? is it: (x1+y1+z1 - x2+y2+z2) or: (x1-x2 y1-y2 z1-z2)
i think its (x1-x2 y1-y2 z1-z2) because its the only one resulting in a vector, but imnot sure... and also, how do you muliply?

9. ## Re: Normal question (well, kinda weird actualy)

The cross product of 2 given vectors v1 and v2 is as follows:
v1 x v2 = ( v1.x*v1.z - v1.z*v2.y , v1.z*v2.x - v1.x*v2.z, v1.x*v2.y - v1.y*v2.x )

I think it would be better for you if you get a math book and take a look at vector math, so you can understand where this formula comes from.

10. ## Re: Normal question (well, kinda weird actualy)

Here is a description on how to calculate the cross product, its really very simple. http://www.lighthouse3d.com/opengl/m...3?crossproduct
Note that the x means cross pruduct and not multiplication.

If you need some reference material about matrices could perhaps the matrix FAQ be used. http://www.j3d.org/matrix_faq/

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•