Computing Face Normals (Updated with SCREENS)

Started by
12 comments, last by d h k 18 years, 6 months ago
Quote:Original post by d h k
Simple things first: I have no idea why that second image isn't showing up. I uploaded it to rapidshare just like I did with the first screen, and the first one works... Here is a new link that works!

Sorry, I should've been clearer. The link works, but the button 'free' in rapid share gives a missing/broken image symbol...

Quote:Original post by d h k
Here is more code, that you requested:
I initialize a light like this:

I notice two problems with the way you're using lighting. First, you don't use glMaterial to set the material properties, you use glColor. Although that is possible, it will only work if you call during your initialization:
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);glEnable(GL_COLOR_MATERIAL);

Furthermore, if you use white materials (glColor4f( 1.0f, 1.0f, 1.0f, 1.0f )) in combination with full out red ambient (ambient[] = { 1.0f, 0.0f, 0.0f, 1.0f };) everything will be fully red. I personally prefer debugging lighting with ambient set to black. Also, try setting specular or diffuse to black to find out which of the two causes the behaviour you're seeing. Check this page on my CG website to get more info on how the lighting calculation works.

Quote:Original post by d h k
Here is my object::draw ( ) function, that draws models from 3ds files:


I'm not sure if 3ds files guarantee a consistent CW or CCW triangle definition. There is a simple test to check if the models you use are:
1. disable culling if necessary (glDisable(GL_CULL_FACE);)
2. in your rendering function replace your glColor4f(1,1,1,1) call with:
const float red[] = {1,0,0,1};const float green[] = {0,1,0,1};glMaterialfv(GL_FRONT, GL_EMISSION, red);glMaterialfv(GL_BACK,  GL_EMISSION, green);

3. run your app and check the output:
If your models that are consistent CW or CCW will be either completely red OR green on the outside, where inconsistent objects will have green AND red triangles on the outside.

Tom
Advertisement
First of all a big thank you to you, Tom, you are helping me out big time. :)

So, first I added the "glColorMaterial ( ... );" and the "glEnable ( GL_COLOR_MATERIAL );" calls to my init function. Then I changed my ambient light color to ( 0, 0, 0, 1 ) or black.

But that didn't change the problem. It looks actually way better because I set the ambient light color to black, but the problem is still there.

Then I followed your further advice and added the red/green coloring based on triangle orientation to my models... and... everything is fine. All models were absolutely red on the outside and absolutely green on the inside.

Any more ideas?
Quote:Original post by d h k
First of all a big thank you to you, Tom, you are helping me out big time. :)

So, first I added the "glColorMaterial ( ... );" and the "glEnable ( GL_COLOR_MATERIAL );" calls to my init function. Then I changed my ambient light color to ( 0, 0, 0, 1 ) or black.

But that didn't change the problem. It looks actually way better because I set the ambient light color to black, but the problem is still there.

Then I followed your further advice and added the red/green coloring based on triangle orientation to my models... and... everything is fine. All models were absolutely red on the outside and absolutely green on the inside.

Any more ideas?


I checked your normal calculation code and it seems fine (although I must say that I found the second for loop in get_face_normal() function a bit hard to read (I suggest writing a vector class that contains all vector math functionality (or you can have my math headers if you want, just PM me)).

Did you check setting diffuse/specular to black to find out which of the two causes the trouble? If it is specular you might want to set the shininess value to something decent (e.g. 12). Anyway, good luck with it, I'm signing off and will be away for the weekend. If this doesn't solve your problem you may want to make a new post on the OpenGL forum with the current status and see if you can get more help there, as I believe the problem is OpenGL and not the math.

Tom
It's the diffuse color, that is causing the problem. Whenever I only use ambient and specular, the specularity doesn't seem to do anything. Wierd.

Thanks for your help and I'll probably start a new thread in the OpenGL area since you are right, this problem has become more of an OpenGL thing than a maths thing.

This topic is closed to new replies.

Advertisement