• Advertisement

Archived

This topic is now archived and is closed to further replies.

Model space vs. world space

This topic is 6039 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
it sounds like you dont have depth testing enabled

http://members.xoom.com/myBollux

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Well you have it enabled but are you clearing it every frame?
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

-SirKnight

Share this post


Link to post
Share on other sites
Yes, I have that line of code at the top of my DrawScene() function, exactly as you have it there.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Backface culling is depending on the order of the vertices. Clockwise or the other way and you can set which one to use.

Share this post


Link to post
Share on other sites
Did you remember to specify a depth buffer when you initialized?

If you are using glut, you need GLUT_DEPTH in glutInitDisplayMode()

-Blackstream

Will you, won''t you, will you, won''t you, won''t you take my virus?

-The Mad Hacker

Blackstream''s Webpage

Share this post


Link to post
Share on other sites
Call me crazy but it actually sounds to me like an incomplete model.

If the front shows through with culling disabled, and you see nothing with culling enabled then it is not a depth buffer issue. The front of the model would be completely ignored with culling enabled as far as the depth buffer is concerned.

Well. The only other thing that I can think of is maybe it is a clipping issue. How far away is your model when you view it?

It is possible that when you rotate it you are bringing the model closer than your near clipping plane and it is simply shearing off the back polygons.

Try setting your near clipping distance to 0.001 or something like that. Or try translating your model a little ways along the depth axis.

Seeya
Krippy

Share this post


Link to post
Share on other sites
I''ve solved the problem, finally. Thanks for everyone''s help. I had missed a couple lines of code in the drawModel() function, where I was using a modelview matrix to do some calculations. After removing that line, it works fine. Thanks again.

Share this post


Link to post
Share on other sites

  • Advertisement