Jump to content

  • Log In with Google      Sign In   
  • Create Account


Problem with ... normals?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 TeTE   Members   -  Reputation: 122

Like
Likes
Like

Posted 21 June 2001 - 05:44 AM

Look the picture at http://www4.uji.es/~al024870/misc/cube.jpg and you will see what''s my problem. It''s a cube with light and a green texture. I use vertex arrays with the vertices, the texture coordinates and the normals. All is read from an OBJ file. And the models are made with Nendo. What''s wrong? May be the normals? I think they are per vertex normals. I have tried more complex objects (airplanes, buildings). All look similar and no one is smooth even with GL_SMOOTH enabled.

Sponsor:

#2 mittens   Moderators   -  Reputation: 1315

Like
Likes
Like

Posted 21 June 2001 - 09:22 AM

In order for GL_SMOOTH to take effect, you must calculate, and send the normals to OpenGL. Here is the function that I use to calculate a normal:


void ComputeNormal(VECTOR3D* v1, VECTOR3D* v2, VECTOR3D* v3)
{
VECTOR3D a(0.0f, 0.0f, 0.0f);
VECTOR3D b(0.0f, 0.0f, 0.0f);
VECTOR3D result(0.0f, 0.0f, 0.0f);
float length;

a.vertex[0]= v1->vertex[0] - v2->vertex[0];
a.vertex[1]= v1->vertex[1] - v2->vertex[1];
a.vertex[2]= v1->vertex[2] - v2->vertex[2];

b.vertex[0]= v1->vertex[0] - v3->vertex[0];
b.vertex[1]= v1->vertex[1] - v3->vertex[1];
b.vertex[2]= v1->vertex[2] - v3->vertex[2];

result.vertex[0]= (a.vertex[1]*b.vertex[2]) - (b.vertex[1]*a.vertex[2]);
result.vertex[1]= (b.vertex[0]*a.vertex[2]) - (a.vertex[0]*b.vertex[2]);
result.vertex[2]= (a.vertex[0]*b.vertex[1]) - (b.vertex[0]*a.vertex[1]);

//Calculate the length of the normal
length= (float)sqrt(SQUARE(result.vertex[0]) +
SQUARE(result.vertex[1]) +
SQUARE(result.vertex[2]));

//Normalize, and send to OpenGL
glNormal3f(result.vertex[0]/length, result.vertex[1]/length, result.vertex[2]/length);


Note that this function is *REALLY* a speed hazard. Especially the call to sqrt(...) . Owwww

------------------------------
Trent (ShiningKnight)
E-mail me
OpenGL Game Programming Tutorials

Edited by - ShiningKnight on June 21, 2001 4:26:55 PM

#3 TeTE   Members   -  Reputation: 122

Like
Likes
Like

Posted 21 June 2001 - 12:06 PM

I know that I have to send the normals. I read them from the file.

But I don''t know why, I get this strange image. May be the program has a "bug" and doesn''t saves them correctly.

#4 TeTE   Members   -  Reputation: 122

Like
Likes
Like

Posted 21 June 2001 - 12:08 PM

I know that I have to send the normals. I read them from the file.

But I don''t know why, I get this strange image. May be the program has a "bug" and doesn''t saves them correctly.

#5 newt   Members   -  Reputation: 122

Like
Likes
Like

Posted 22 June 2001 - 02:24 AM

Maybe you could draw the normals.

VECTOR3 a,b,c; // the points for a triangle
VECTOR3 m = (a + b + c) / 3.0; // center of the triangle
VECTOR3 e = m + normal * 10.0; // end of normal line

glBegin(GL_LINES);
glVertex3f(m.x, m.y, m.z);
glVertex3f(e.x, e.y, e.z);
glEnd();

But from the look of the cube i would guess the x and z (or other combination) coordinates are swaped...

#6 TeTE   Members   -  Reputation: 122

Like
Likes
Like

Posted 22 June 2001 - 11:49 AM

The problem was that Nendo saves the normals incorrectly, because when using a converter I get the expected results. Well, not exactly what I expected ...

Now I have another problem. All is tinted in blue!! I don''t use alpha and nor the light nor the materials have a great blue component. Any idea of what is the error?

Thanks for the tip of drawing the normals!!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS