AVector glASC::GetNormal(AVector v1, AVector v2, AVector v3) {
AVector b1, b2;
AVector Normal;
b1.x = v1.x - v2.x;
b1.y = v1.y - v2.y;
b1.z = v1.z - v2.z;
b2.x = v3.x - v2.x;
b2.y = v3.y - v2.y;
b2.z = v3.z - v2.z;
Normal.x = ((b1.y * b2.z) - (b1.z * b2.y));
Normal.y = ((b1.z * b2.x) - (b1.x * b2.z));
Normal.z = ((b1.x * b2.y) - (b1.y * b2.x));
return Normal;
}
Probably very basic, and it works fine, except for the fact that all faces are flat shaded.
I'm very new to openGL, but shouldn't glShadeModel(GL_SMOOTH); take care of that ?
Or is there something wrong with the calculations.
the full source can be found here: http://home.junkshop.nu/panic/glASC/
Again, I'm just trying to lern, so you don't have to point me to any existing ASC readers
newbie2001
Edited by - panic on February 16, 2001 11:11:35 PM
Smooth shading with "your own" normals ?
Hey.
I've been messing with an .ASC reader just for lerning.
It's based on an .ASE reader by Philippe Kunzle wich I found in his files for his OOGL project.
I got it all working great, it can read ASC files and get all nessesary data to draw the object in openGL, but, since ASC files doesn't contain any normal data like ASE files I started messing with calculating the normals for each face in order to get the object affected by light.
The rutine I wrote for that is:
Hi,
Don''t you need to normalize your vectors ??
I think you calculate one vector for a plane, that''s why you have flat shading. You need to calculate the average on each vertex of all the plane normals that this vertex belongs to.
Then you will get a smooth shading.
success
Jan
Belgium
Don''t you need to normalize your vectors ??
I think you calculate one vector for a plane, that''s why you have flat shading. You need to calculate the average on each vertex of all the plane normals that this vertex belongs to.
Then you will get a smooth shading.
success
Jan
Belgium
GL_SMOOTH will work fine if you interpolate your normals...
to get the approximated normal for a vertex add the normals of all faces that share that vertex together and divide it by the number added normals..
another thing: normalize the normal vectors... (get them to unit length) otherwise you might get unexact results....
do not use GL_NORMALIZE cause it will renormalize them each frame, and normalizing involves an square root call, sooo...
hope that helped,
cya,
Phil
Visit Rarebyte!
and no!, there are NO kangaroos in Austria (I got this questions a few times over in the states
to get the approximated normal for a vertex add the normals of all faces that share that vertex together and divide it by the number added normals..
another thing: normalize the normal vectors... (get them to unit length) otherwise you might get unexact results....
do not use GL_NORMALIZE cause it will renormalize them each frame, and normalizing involves an square root call, sooo...
hope that helped,
cya,
Phil
Visit Rarebyte!
and no!, there are NO kangaroos in Austria (I got this questions a few times over in the states
Visit Rarebyte! and no!, there are NO kangaroos in Austria (I got this question a few times over in the states ;) )
LOL
hmmm, now I feel stupid.
I spent hours of writing a routine that would calculate the vector normal for each vertex of the imported model.
When I compiled and tested it all worked great, smooth shading was perfect! Then I saw that I didn't even use the calculations I had made, but I simply gave the vertices vector that I was about to draw as normal.
like this:
hmmm, now I feel stupid.
I spent hours of writing a routine that would calculate the vector normal for each vertex of the imported model.
When I compiled and tested it all worked great, smooth shading was perfect! Then I saw that I didn't even use the calculations I had made, but I simply gave the vertices vector that I was about to draw as normal.
like this:
glBegin(GL_TRIANGLES); glNormal3f(Vertices[Faces[\i].A].x /aScale, Vertices[Faces.A].y /aScale, Vertices[Faces.A].z /aScale);<br> glVertex3f(Vertices[Faces.A].x / aScale,Vertices[Faces.A].y / aScale,Vertices[Faces.A].z / aScale);<br> glNormal3f(Vertices[Faces.B].x /aScale, Vertices[Faces.B].y /aScale, Vertices[Faces.B].z /aScale);<br> glVertex3f(Vertices[Faces.B].x / aScale,Vertices[Faces.B].y / aScale,Vertices[Faces.B].z / aScale);<br> glNormal3f(Vertices[Faces.C].x /aScale, Vertices[Faces.C].y /aScale, Vertices[Faces.C].z /aScale);<br> glVertex3f(Vertices[Faces.C].x / aScale,Vertices[Faces.C].y / aScale,Vertices[Faces.C].z / aScale);<br>glEnd();<br> </pre> <br><br>When I tested with using my calculated normals it got all messed up <img src="smile.gif" width=15 height=15 align=middle> <br><br>I guess some things have an easier solution then you think of.. <img src="smile.gif" width=15 height=15 align=middle><br><br>edit:<br>aww, seems like it only worked for a sphere <img src="smile.gif" width=15 height=15 align=middle>, hmm, think I'll have to lern some more math before messing with this..<br><br><br><br><br>Edited by - panic on February 17, 2001 4:04:39 PM </i>
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement