A closer model that does not rotate when a farther model is rotated.

Started by josheirm, August 10, 2020, 15:57:30

Previous topic - Next topic

josheirm

I am trying to rotate a model and I want another model that is closer to me  to not rotate.  From my research I am thinking that we used to us glPushMatrix and glPopMatrix.  So, when we popped the stack with the unchanged matrix the model would not rotate too.  However, it just doesn't seem right to me.  I have found a modern way to do this, but how do I not rotate the model?  I enjoy LWJGL and am so happy that there is a forum!   8)

Thank you,

Josheirm

KaiHH

Quote from: josheirm on August 10, 2020, 15:57:30
From my research I am thinking that we used to us glPushMatrix and glPopMatrix.
The (legacy) OpenGL matrix stack can be used to model the transformations and renderings of your objects as a scene graph traversal. glPushMatrix() saves the current state of the matrix of the current matrix mode, whereas glPopMatrix() restores it to where it was before the most recent call to glPushMatrix().
If you want to use the (legacy) OpenGL matrix stack, then:
glMatrixMode(GL_MODELVIEW);
// setup view/camera matrix
// ...
// visit one object (here the one that is rotated)
{
  glPushMatrix();
  glTranslatef(...); // <- translate object to its position
  glRotatef(...); // <- rotate it
  // issue draw call for first object (glDraw* or glBegin/glEnd)
  glPopMatrix();
}
// visit the other object
{
  glTranslatef(...); // <- translate the other object to its respective position
  // issue draw call for first object (glDraw* or glBegin/glEnd)
  glPopMatrix();
}


If you don't want to use the (legacy) OpenGL matrix stack, then you simply have to mimic the effect of those (legacy) OpenGL matrix stack functions, that is: Upload a modelview matrix with translation and rotation before drawing the first object, and upload a new modelview matrix with just translation before drawing the second object.

Quote from: josheirm on August 10, 2020, 15:57:30
So, when we popped the stack with the unchanged matrix the model would not rotate too.
This sentence is too vague and unclear, what exactly you mean by that.

Quote from: josheirm on August 10, 2020, 15:57:30
However, it just doesn't seem right to me.
What exactly do you mean by that? You have not provided any context/code to interpret this statement of yours: Do you mean that your approach works but you don't think it should and it does not "feel" right? Or does anything not work? And if not, what exactly does not work?

Quote from: josheirm on August 10, 2020, 15:57:30
I have found a modern way to do this, but how do I not rotate the model?
It's also unclear what exactly you mean by "modern way" and what exactly you've found. Can you clarify?

josheirm

Oh, well when I said," it just doesn't feel right,"  I was scared of writing all this mimicking code and being wrong with my understanding.  When I said modern, it seems that everywhere I turn the new OpenGL is using the newer pipe line and it is said to be modern.

On the other hand, I have been trying to do this forever, and now I am understanding how it works, thanks for the reassurance!   8)

Josheirm