Advertisement

OpenGL normal newB question

Started by July 10, 2002 10:53 AM
11 comments, last by TYBZ 22 years, 7 months ago
I all, first of all, i''m quite a newb in OpenGL and it''s my first post here, I''ve just start to learn ogl a week ago, but I really enjoy it... I have a little question... well I have many but let''s start somewhere... Now I know that the normal of a polygone is to detemine the UP face of a wall for exemple. The part that mess me up, is how it works ??? I mean where is the origin when we set normals, on the center of the polygone OR on the "actual" origin ??? a good example would be apreciated thanx in advance TYBZ
It''s only takes motivation!
I don''t think there is an ACTUAL origin for the normal. I''ve read three books on this, OpenGL Game Programming, OpenGL Programming Guide, and OpenGL SuperBible, and I didn''t hear anything about the normal being located at the center of the polygon. Maybe all you need to know is which direction is up for that polygon.
I don't have a signature
Advertisement
I agree, a normal is a direction vector so doesn''t really have an origin, just any point on the face of the poly.
yeah, I KNOW THAT... but the normal point is DEFINE in relation to WITCH POINT ?????

A) sometimes you define vertex in relation to the origin (0,0,0)
B) but sometimes you move your cursor to (2,0,0) and make the this point the "temp" origin for drawing your polygons

C) in case B the point (1,0,0) will be the same location as (3,0,0) in case A

my question is: is the normal is define by the polygon point of view OR the "world" point of view ???
It''s only takes motivation!
The polygon point of view. When you're dealing with normals, everything is relative to the polygon. You could translate the MODELVIEW matrix back -100 units, draw a polygon at points

(0.0f, 10.0f, 0.0f)
(10.0f, 0.0f, 0.0f)
(-10.0f, 0.0f, 0.0f)

and apply your normal vector to that polygon

It would be the same as staying at the ORIGINAL origin and drawing
your polygon at

(0.0f, 10.0f, -100.0f)
(10.0f, 0.0f, -100.0f)
(-10.0f, 0.0f, -100.0f)

and apply your normal.

In the first example you translate the modeling matrix, or world matrix back -100 units, draw you polygon and apply it's normals at that worlds origin.
The second example you stay at the original origin, and draw the triangle -100 units down the z-axis which is the same location in the first example.

So it deosn't matter if you move the modeling matrix back and draw at the origin, or stay at your original origin, and drawing the polygon several units down the z axis. Both triangles will have a normal that points down the -z axis, because of it's winding orientation.

I'm not sure if I explained that correctly. Sorry.


[edited by - Brian Jones on July 10, 2002 3:44:36 PM]
I don't have a signature
ok. a crucial point that you are missing is that vectors do not NEED an origin. think of a vector as (+x, +y, +z) instead of as a coordinate. a vector is just a direction. the vector (1,2,1) is exactly the same wherever in the universe of the world coordinate system you put it.

to visualize the (1,2,1) vector, move it anywhere in the coordinate system. The vector is drawn from the point you are at (x,y,z) to the point (x+1, y+2, z+1). a vector is a DIRECTION it is not a specific point in space.

a normal vector is the vector perpendicular to the plane on which your polygon/triangle exists.

to find a normal for a triangle with points P0(x0,y0,z0) P1(x1,y1,z1) and P2(x2,y2,z2) listed in counterclockwise order. you first find 2 vectors from those points:

v1(x1 - x0, y1 - y0, z1 - z0);
v2(x1 - x2, y1 - y2, z1 - z2);

then you take the crossProduct of those 2 vectors and the resulting vector is your normal vector. you should then normalize the vector to make openGL happy.

if it''s a planar polygon, just pick any 3 points and run the same equation.

anyway, this is all assuming tha you are going for polygonal shading (i.e. all vertices of the same polygon have the same normal). if you want a smoother shaded model you''ll want to do averaging of adjacent normals, but stick with the above until you understand vectors better.

in fact, i think you would be greatly helped by looking around on the web for 3D math tutorials so you can learn the fundimentals solidly. it''ll make 3D programmin a million times easier.

again remember VECTORS HAVE NO ABSOLUTE ORIGIN

-me
Advertisement
Hmm ok, I''ve understand the vector part, but in pratice, that just don''t work, my lightnings are cut by polygone... could you give me an exemple, like a square room, with 4 lights, tx. that would really help
It''s only takes motivation!
quote:
Original post by TYBZ
in pratice, that just don't work, my lightnings are cut by polygone



i don't understand what this sentance means.

but my guess is that you mean: "my objects are polygons, not triangles." and i gave you an example for a triangle but you want an example for a polygon.

anyway, take the example i gave for a triangle and make the normals for the polygons by selecting 3 of the many points you use in your polygon and pretend those are the P0, P1 and P2 of my example. everything else is exactly the same. remember to make sure that P0, P1 and P2 are listed in counter-clockwise order or your normals will point backwards. cool?

so if you have a polygon with 5 pts then just select the first 3 vertices and use those coords for the values of P0, P1, P2.

you only set the normals once. the number or lights you have doesn't matter. openGL uses the same normals for each light that it calculates.

-me

[edited by - Palidine on July 10, 2002 8:30:08 PM]
hmm, ok first you seem to say that I can calculate my normals with 3 points of my polygons... ?!?! I don''t understand that, if WE can calculate that with informations that we''ve already give to OpenGL, why ogl can''t calculate it itself ???

In my little project I made a room with 8 walls, I use quads, with 4 dirrerent color lights. That gives my cut off lighting, I mean one wall is ONLY red, then to other next to it is ONLY BLUE, etc.

For the exemple could give something like that:
// Front Face
glNormal3f( 0.0f, 0.0f, 1.0f);
glVertex3f(-1.0f, -1.0f, 1.0f);
glVertex3f( 1.0f, -1.0f, 1.0f);
glVertex3f( 1.0f, 1.0f, 1.0f);
glVertex3f(-1.0f, 1.0f, 1.0f);

Sorry for being dumb, I''m really a newb.
It''s only takes motivation!
quote:
Original post by TYBZ
hmm, ok first you seem to say that I can calculate my normals with 3 points of my polygons... ?!?! I don't understand that, if WE can calculate that with informations that we've already give to OpenGL, why ogl can't calculate it itself ???


well, the reason you don't want openGL to calculate that stuff for you is that when you get into more advanced lighting/shading stuff you'll want to have each vertex of each polygon have different normals so that the shading is smoother & 'rounder'. you could do that by averaging the normals of each vertex's adjacent polygons. or you could do that by applying some formula to figure out the normals. the bottom line is that there are too many ways that you might want to calculate your normals for that to be done by openGL for you.

the example i gave you will give each vertex of a polygon the SAME normal vector. that will result in models in which the polygons are very clearly visable. the reason i started you with that is b/c it is easy and will give you a better idea of what normal vectors are. stick with all vertices on the same polygon having the same normal till you feel comfortable with what normals are and what they are used for.

....

quote:
Original post by TYBZ
// Front Face
glNormal3f( 0.0f, 0.0f, 1.0f);
glVertex3f(-1.0f, -1.0f, 1.0f);
glVertex3f( 1.0f, -1.0f, 1.0f);
glVertex3f( 1.0f, 1.0f, 1.0f);
glVertex3f(-1.0f, 1.0f, 1.0f);



assuming that you have correctly calculated the normal for your polygon, the above code should work fine. (the above code has a correct normal vector if you want the outward face to be the side away from the origin)

as an aside, if you are not yet working on lighting, you don't need normals to sucessfully display your polygons. normals are used by openGL to determine the amount of light each vertex gets from each light source

i'd suggest that you look here and read about how openGL does lighting. it'll help you understand what's going on:
http://fly.cc.fer.hr/~unreal/theredbook/chapter06.html

quote:
Original post by TYBZ
Sorry for being dumb, I'm really a newb



whatever. you're not being dumb. this stuff IS actually confusing if you're new to it.

-me

[edited by - Palidine on July 11, 2002 3:28:03 PM]

This topic is closed to new replies.

Advertisement