Advertisement

normals and height terrain

Started by February 02, 2004 03:18 PM
14 comments, last by JagWire 21 years, 1 month ago
ok several questions 1. i understand that one needs 2 vectors from 2 points on the surface, now if im using triangle strips(where 2 form a quad) can i use the 2 vertices of the adjacent side going through the quad for both surfaces(2 triangle strips total). 1b. if this is the case, would i have to make 2 seperate calls to glNormal3f()? 2. In no relation to the topic of q1, when dealing with heightmaps do you have to calculate the normals manually and then pass them to glNormal3f()? 3. When calling glNormal3f(), where should the call be placed? i.e. before first 3 vertices and between each triangle? 4. How will light position affect a heightmap if its a flat plane( haven''t tried this yet but i have to get lighting to work first). 5. Is GL_NORMALIZE necessary for my situation? Thank you to all in advance that can help me with my questions If you wish to contact me, aim: XJagWire or JagWire on irc.coders-realm.org
1. Yes
1b. You have to call glNormal3f() before every vertex you draw. When you call the glNormal3f() function the normal is set to the one you pass, all vertices that you draw after that call will have that normal as their normal.
EDIT: So when you have enabled lighting or something else that needs normals you will need to call glNormal3f once for every vertex (if the previous passed normal isn't already the normal you want).

2. Yes, there is no OpenGL function for calculating normals

3. All vertex properties should be placed before the call to a vertex drawing function, for the drawn vertex, the last passed property values will be used when needed.

4. For every vertex the light intensity will be
distance*dotproduct(light to vertex normal,vertex normal)

5. GL_NORMALIZE is only neccesary if there is a chance the normals you pass using glNormal3f() aren't normalized (normalized means that the size of the normal is exactly 1.0) else you will get real bad lighting (or real strange).

[edited by - Tree Penguin on February 2, 2004 4:39:07 PM]
Advertisement
still can''t seem to get it to work, everytime i turn on lighting the terrain goes black.
Did you turn on any lights (glEnable(GL_LIGHT0))?

Enigma
yes LIGHT0
Can you post your normal calculation code?

Enigma
Advertisement
Have you enabled lighting (glEnable(GL_LIGHTING); ) ?

edit: ; ) instead of

[edited by - Tree Penguin on February 2, 2004 5:34:52 PM]
yes lighting is all set up and enabled, its code i used previously for something else. The normal calculation code is as follows:

void CrossProduct(float point1[3], float point2[3], float point3[4], float normal[3])
{

float vector1[3], vector2[3];

vector1[0] = point1[0] - point2[0];
vector1[1] = point1[1] - point2[1];
vector1[2] = point1[2] - point2[2];

vector2[0] = point2[0] - point3[0];
vector2[1] = point2[1] - point3[1];
vector2[2] = point2[2] - point3[2];

normal[0] = vector1[1]*vector2[2] - vector1[2]*vector2[1];
normal[1] = vector1[2]*vector2[0] - vector1[0]*vector2[2];
normal[2] = vector1[0]*vector2[1] - vector1[1]*vector2[0];
}
---------------------------------------
and then i pass the 3 normal values to glNormal3f() like so:

glNormal3f(normal[0], normal[1], normal[2]);
You''ll need to normalise your normal or enable GL_NORMALISE. You probably also want to use four points to calculate your normals:
+--a--+|\ |\ || \| \|b--x--c|\ |\ || \| \|+--d--+

such that vector1 = c - b and vector2 = d - a.

Enigma
One question on that, is using GL_NORMALIZE faster that normalizing the vector yourself ?

This topic is closed to new replies.

Advertisement