Model space vs. world space

Started by
11 comments, last by october121 22 years, 9 months ago
I''m new to OpenGL, so this may be an easy question for those of you with more exerience. I have code that loads a model from an .ASE file and renders it in GL. It loads fine, and displays alright, until you rotate it 90 degrees. Once the "front" of the model is pointing away from the camera, strange visual artifacts appear, and it looks like the faces that were the original front are still being drawn last, and they''re overwriting the "back" faces, which should now be occluding them. I think what''s happening is that all of the drawing is still being done as if the model hadn''t been rotated. How do I tell GL to draw and light the model from the perspective of the camera, and not from the perspective of model space?
Advertisement
it sounds like you dont have depth testing enabled

http://members.xoom.com/myBollux
Hmm...I _think_ it''s enabled, but I might be doing it wrong. Here''s a snippet of code from My GLInit() function:

-------------------------------------------

glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);

glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);

--------------------------------------------

Any comments?
Well you have it enabled but are you clearing it every frame?
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

-SirKnight
Yes, I have that line of code at the top of my DrawScene() function, exactly as you have it there.
Are you rotating from 0 straight to 90 degrees, or in increments? If you're doing 0 to 90 then try rotating in increments and see what happens, might show you what the problem is. If you're doing it in increments and it only starts to happen when you hit 90 degrees then I'd guess your rotating it wrongly somehow, since everything else looks fine.

One more thing, maybe the back of your model is corrupt, maybe you're not reading it in properly, or perhaps the way you're using whichever OGL drawing function your using is incorrect.

Edited by - outRider on July 5, 2001 7:33:47 PM
Do you have back face culling enabled? If not, what happens when you turn it on? glEnable(GL_CULL_FACE);

Edited by - Dobbs on July 5, 2001 9:24:14 PM
When I enabled back face culling, it worked perfectly, except that it always culled the same faces....the ones that were the original, unrotated "back" of the model. So when I rotate it, the back half, as seen from the original camera perspective, isn''t there....if I''m rotating a sphere model, it''s just a hemishpere

In response to outRider, I''m rotating in increments, and the strangeness only appears when the original front of the model is facing more than 90 degrees away from the camera. I think I may be reading the model file incorrectly, but I''m not exactly sure where. Here''s the code where I rotate the view for drawing.

----------------------------------------------

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glLoadIdentity();

glTranslatef(0.0f, 0.0f, zoom);
glRotatef(xrot, 1.0f, 0.0f, 0.0f);
glRotatef(yrot, 0.0f, 1.0f, 0.0f);

drawModel(&theModel);

xrot += xspeed;
yrot += yspeed;

----------------------------------------------

xspeed and yspeed can be changed with the arrow keys, as can zoom. That''s basically the entire contents of my drawScene() function at the moment. Anything glaringly wrong?
Question: if you apply the transformation matrix for all the vertices and calculate face normals per scene, will the backface culling be ok? (i know it''s costly, but theoratically, if we had super-computers)

"Everything is relative." -- Even in the world of computers.
everything is relative. -- even in the world of computers... so PUSH BEYOND THE LIMITS OF SANITY!
Backface culling is depending on the order of the vertices. Clockwise or the other way and you can set which one to use.

This topic is closed to new replies.

Advertisement