basic rotating and moving problem

maybe someone here could help me?

http://puppygames.net/forums/viewtopic.php?t=591&sid=deca9f44332c3fd813e1f47f2b4f0d0f

Hi there !

You should use glPushMatrix() and glPopMatrix() like that :


public static void movefirkant()
{
   GL11.glPushMatrix();
   GL11.glRotatef(firkantz,0.0f,0.0f,0.2f); 
   GL11.glTranslatef(400.0f,400.0f,0.0f);
   GL11.glPopMatrix();
}

This should work…

Chman

Hi thank you

It now works almost, with this code:


public static void firkant(){       
       movefirkant();       
 }
 public static void movefirkant(){
       
       GL11.glPushMatrix();
       GL11.glTranslatef(200.0f,400.0f,0.0f);
       GL11.glRotatef(firkantz,0.0f,0.0f,1.0f);
renderfirkant();
       GL11.glPopMatrix();
  }
 public static void renderfirkant(){
       
       GL11.glBegin(GL11.GL_QUADS);
       GL11.glVertex3f(0.0f, 0.0f, 0.0f);
       GL11.glVertex3f(40.0f, 0.0f, 0.0f);
       GL11.glVertex3f(40.0f, 40.0f, 0.0f);
       GL11.glVertex3f(0.0f, 40.0f, 0.0f);
       GL11.glEnd();
 }

It rotates the quad around the first vertex wherever
i put it on the screen but still not around the center of the quad. Maybe its because the quad isnt placed around 0.0? its to the right of 0.0

When moving a model should you change the drawing coordinates in renderfirkant() or move it with
the glTranslatef method?

I also tried to place the renderfirkant() call after the
movefirkant call in firkant() but that didnt work.

You should place the glRotatef() before the glTranslatef() and it should work…

Chman

then it rotates around the bottom left side of the screen…

I dont understand this

Build the quad around 0/0… that makes it easier. In general - you should build everything around that total zero, because rotations are always relative to that (in addition you won’t need to remember the width and height, because they just don’t matter).

thank you both for answering, think i got it now.

How will this work when you load models created in f.ex. in milkshape?

Well, locate em (in your favorite 3d application) around the origin (0/0/0) or let 'em stand on it. Eg for a human “stand on” would be nicer (usually) and for let’s say a space ship you would use “around”. This way roations and the like are a no brainer. So either relative to the surface or relative to the center. Just pick the one wich makes more sense and you’ll avoid confusion.