Results 1 to 3 of 3

Thread: normalize vertices

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2011

    normalize vertices

    hi, i'm a noob to opengl but i have to do operations without openGL help. so far, i've made shapes, rotation/translation/scaling of my custom 3d shapes and now i need to do lighting and i am stuck at normalizing. i can tell that my lighting works because i added a glutSolidTeapot to my scene and it has some smooth lighting on it while my custom shapes are just all white.

    i have my vertices stored like this:

    verts[i][j][0] = some val for x equation
    verts[i][j][1] = some val for y equation
    verts[i][j][2] = some val for z equation
    verts[i][j][3] = 1 for homogenous

    and my shapes work. now, i don't know how to normalize them. i think i understand that you use the cross product and then normalize but i don't understand how to make the cross product for my vertices. i have them as "quads" not triangles if that means anything. any help on how to normalize with the way my vertices are stored would be appreciated

  2. #2
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    UK, London

    Re: normalize vertices

    You need to construct normals from your vertices. You then normalise the normals not the verticies.
    You can construct the normals from any triangle by using the 3 points to create a plane. By definition the normal is perpendicular to the plane. For a quad you simply have two triangles so you can pick which verticies you want when creating the plane.

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2011

    Re: normalize vertices

    i still cant get it to work. heres the code i have to calculate the normal of a shape (such as a cone, sphere, etc)

    Code :
    	while(i < 50){
    		while(j < 50){
    			calcCross(po->vertices[i][j], po->vertices[i][j+1], po->vertices[i+1][j+1], po->normals[i][j]);

    Code :
    void calcCross(GLfloat *a, GLfloat *b, GLfloat *c, GLfloat *n){
    	n[0] = (b[1] - a[1])*(c[2] - a[2]) - (b[2] - a[2])*(c[1] - a[1]);
    	n[1] = (b[2] - a[2])*(c[0] - a[0]) - (b[0] - a[0])*(c[2] - a[2]);
    	n[2] = (b[0] - a[0])*(c[1] - a[1]) - (b[1] - a[1])*(c[0] - a[0]);

    Code :
    void normalize(GLfloat *p){ 
    	GLfloat d = 0.0;
    	int i;
    	for(i=0; i<3; i++){
    	if(d > 0.0){
    		for(i=0; i<3; i++){
    			//printf("normal: %f\n", p[i]);

    with my shape on when i open the app i see

    if i turn mine off and turn on glutSolidTeapot i see

    anyone can tell me what i need to do to get mine to have the lighting?

Similar Threads

  1. Do we always need to normalize the normals
    By Lee_Jennifer_82 in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 01-24-2016, 02:03 PM
  2. normalize( float4 ) precision errors
    By DelicateFrenesie in forum OpenCL
    Replies: 2
    Last Post: 11-29-2011, 11:57 AM
  3. optimalization by textureCube instead of normalize
    By glAren in forum OpenGL: GLSL
    Replies: 5
    Last Post: 07-26-2006, 07:01 AM
  4. normalize
    By imported_Groovounet in forum OpenGL: GLSL
    Replies: 4
    Last Post: 01-17-2005, 06:45 PM
  5. normalize, textureXD textureXDProj
    By V-man in forum OpenGL: GLSL
    Replies: 3
    Last Post: 04-23-2004, 05:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean