Jump to content

  • Log In with Google      Sign In   
  • Create Account

Model space vs. world space


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
12 replies to this topic

#1 october121   Members   -  Reputation: 122

Like
Likes
Like

Posted 04 July 2001 - 12:13 AM

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?

Sponsor:

#2 zedzeek   Members   -  Reputation: 528

Like
Likes
Like

Posted 04 July 2001 - 11:19 AM

it sounds like you dont have depth testing enabled

http://members.xoom.com/myBollux

#3 october121   Members   -  Reputation: 122

Like
Likes
Like

Posted 04 July 2001 - 01:03 PM

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?

#4 SirKnight   Members   -  Reputation: 316

Like
Likes
Like

Posted 04 July 2001 - 01:51 PM

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

-SirKnight

#5 october121   Members   -  Reputation: 122

Like
Likes
Like

Posted 04 July 2001 - 04:56 PM

Yes, I have that line of code at the top of my DrawScene() function, exactly as you have it there.

#6 outRider   Members   -  Reputation: 852

Like
Likes
Like

Posted 05 July 2001 - 12:31 PM

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

#7 Dobbs   Members   -  Reputation: 164

Like
Likes
Like

Posted 05 July 2001 - 02:22 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

#8 october121   Members   -  Reputation: 122

Like
Likes
Like

Posted 05 July 2001 - 04:02 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?

#9 Ionut Costica   Members   -  Reputation: 122

Like
Likes
Like

Posted 06 July 2001 - 01:29 PM

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.

#10 Obelix   Members   -  Reputation: 122

Like
Likes
Like

Posted 07 July 2001 - 02:05 PM

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

#11 Blackstream   Members   -  Reputation: 122

Like
Likes
Like

Posted 09 July 2001 - 06:41 PM

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

#12 Krippy2k   Members   -  Reputation: 134

Like
Likes
Like

Posted 10 July 2001 - 05:34 AM

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

#13 october121   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 July 2001 - 08:20 AM

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.




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