• Advertisement
Sign in to follow this  

Lesson 10 is all MODELVIEW. How can i change?

This topic is 2403 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 was very proud to get lesson 10 working in LWJGL and its now working as presented. I'm now trying to learn how to place objects in the world and rotate them individually and independently from the world.

Based on what I've read with openGL. That is what the distinction between MODELVIEW and PROJECTION matrix modes is for.

Lesson 10 seems to rotate the entire world as one big model with MODELVIEW. So what i'm confused about is if I was to attempt to add a quad to the middle of the level and then rotate it with glRotatef that would rotate not only the quad but all of the walls, floors and everything else that is part of the scene. Not just the quad like I would like to try and do.

Since the heading and looking angle appear to be taken care of only by the below two lines:


GL11.glRotatef(lookupdown, 1.0f, 0, 0);
GL11.glRotatef(sceneroty, 0, 1.0f, 0);

I thought a good solution would be to change them to this:

GL11.glMatrixMode(GL11.GL_PROJECTION);


GL11.glRotatef(lookupdown, 1.0f, 0, 0);
GL11.glRotatef(sceneroty, 0, 1.0f, 0);
GL11.glMatrixMode(GL11.GL_MODELVIEW);

However this causes the level to look normal at first but if I try to do anything that involves rotating it makes the level start spinning out of control.

Any idea how I can conquer this one? Thanks a lot I do appreciate the help.

Share this post


Link to post
Share on other sites
Advertisement
[quote name='docpunk' timestamp='1308387613' post='4824752']
I was very proud to get lesson 10 working in LWJGL and its now working as presented. I'm now trying to learn how to place objects in the world and rotate them individually and independently from the world.

Based on what I've read with openGL. That is what the distinction between MODELVIEW and PROJECTION matrix modes is for.

Lesson 10 seems to rotate the entire world as one big model with MODELVIEW. So what i'm confused about is if I was to attempt to add a quad to the middle of the level and then rotate it with glRotatef that would rotate not only the quad but all of the walls, floors and everything else that is part of the scene. Not just the quad like I would like to try and do.

Since the heading and looking angle appear to be taken care of only by the below two lines:


GL11.glRotatef(lookupdown, 1.0f, 0, 0);
GL11.glRotatef(sceneroty, 0, 1.0f, 0);

I thought a good solution would be to change them to this:

GL11.glMatrixMode(GL11.GL_PROJECTION);


GL11.glRotatef(lookupdown, 1.0f, 0, 0);
GL11.glRotatef(sceneroty, 0, 1.0f, 0);
GL11.glMatrixMode(GL11.GL_MODELVIEW);

However this causes the level to look normal at first but if I try to do anything that involves rotating it makes the level start spinning out of control.

Any idea how I can conquer this one? Thanks a lot I do appreciate the help.
[/quote]

Don't you have to do glPushMatrix() and glPopMatrix() whenever you do any rotations, translations, or scaling?

So it'd be

[code]
glPushMatrix();
GL11.glRotatef(lookupdown, 1.0f, 0, 0);
GL11.glRotatef(sceneroty, 0, 1.0f, 0);
glPopMatrix();
[/code]


Also, after looking at lesson 10, it looks like you rotate everything to move around...that isn't going to be very good once you have a lot of things...
I learned to use gluLookAt(), which sets up a camera pretty much..

Share this post


Link to post
Share on other sites
The main problem your having is that for the MODELVIEW matrix you normally call glLoadIdentety at the begining which resets the matrix to 0.
But this is normally not done for the PROJECTION matrix so in your case this means that for every frame you rotate it a little bit more, but it doesn't reset so it just keeps adding and adding resulting in the spinning out of control effect.

Now it really doesn't matter where you do the rotations since in the end both the modelview and projection matrices are multiplied with each other.
It also doesn't matter how you do this, where you place this code or how many times since the amount of time it takes to do this is insignificant, especially since you should be fill rate limited.
So in your case to fix this try

GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
GL11.glRotatef(lookupdown, 1.0f, 0, 0);
GL11.glRotatef(sceneroty, 0, 1.0f, 0);
GL11.glMatrixMode(GL11.GL_MODELVIEW);

[quote name='lildragon555' timestamp='1308409697' post='4824810']
Don't you have to do glPushMatrix() and glPopMatrix() whenever you do any rotations, translations, or scaling?

So it'd be

[code]
glPushMatrix();
GL11.glRotatef(lookupdown, 1.0f, 0, 0);
GL11.glRotatef(sceneroty, 0, 1.0f, 0);
glPopMatrix();
[/code]
[/quote]
no.

Share this post


Link to post
Share on other sites
[quote name='lc_overlord' timestamp='1308422445' post='4824852']
no.
[/quote]

Well I'm sorry for trying to help...it seems like this forum is dead so I thought it'd be okay to try and help with the little knowledge I have

Share this post


Link to post
Share on other sites
[quote name='lildragon555' timestamp='1308432451' post='4824891']
[quote name='lc_overlord' timestamp='1308422445' post='4824852']
no.
[/quote]

Well I'm sorry for trying to help...it seems like this forum is dead so I thought it'd be okay to try and help with the little knowledge I have
[/quote]

Thanks mate you were helpful. I hadn't even considered gluLookat and I think it will solve a lot of my other problems.

Overlord thanks mate. You answered my question and taught me some very valuable stuff.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement