MAJOR issues, Please help me.

Just a couple minor little problems with your code and comments… I put my additional comments in italics for emphasis. There’s only one spot with a real code flaw, but some of the comments are a bit misleading.

void display(void)
{

glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Let clear things for a freash start

You seem to imply that you were using the
GL_PROJECTION matrix with the 2nd line here
if so, you just wiped it out. Flip these two
lines around so you are clearing the GL_MODELVIEW

glLoadIdentity(); // Look at it like clearing the matrix.
glMatrixMode(GL_MODELVIEW); // We are working now with objects.

// The following is changing the base matrix
// I use this to move my view(camara) around
// Yes we are rotation the world, but just as if you picked up a map of your world on paper. And moved the paper around, your places on the map stay the same just now the map could be upside down.

glRotatef(WrotateX, 1.0f, 0.0f, 0.0f);
glRotatef(WrotateY, 0.0f, 1.0f, 0.0f);
glRotatef(WrotateZ, 0.0f, 0.0f, 1.0f);
glTranslatef( 0,0, Worldz); //move forward/backward
// Now everything after this will be effected by these change.
// Here is where push/pop matrix comes into play.
// If we where just to draw our box here, it would be drawn using the last matrix changes.

// Draw box
glPushMatrix(); // Lets take to old matrix and save it.
// We now are starting with a new matrix and past matrix changes do not effect it now.
Not true. You still have the old matrix, and
other transforms below will MULTIPLY to the current
matrix, which is still the old matrix.
This is ok, as it’s what you want.

glTranslatef( 10, 10, 5); // move the BOX to it location in our world.
glRotatef( 15, 1, 0, 0); // Rotate box only

Draw_box(); // code would be here to draw box

glPopMatrix(); // Let’s combine past matrix and new matrix.
glPopMatrix doesn’t combine the two matrices,
if it did, you wouldn’t get the results you want.
Instead, what it does is restores the matrix to the
state it was in before you did the glPushMatrix.
This essentially cancels out any transformations
you did after the glPushMatrix.

[This message has been edited by Deiussum (edited 08-06-2002).]

Ok i think i got it, DAMN my head is as thick as a concreate wall.

But there is one more tiny thing i dont get.

I move the camera, then i draw my objects if they are visable. (and simply move them ‘physicaly’) by actualy manipulating the xyz components. Example. I have a box on a wall. I want to move the box along the wall 5 units closer to the left, in the ACTUAL world. So I do not call glTranslate because that would just change the view of the object. I would actualy change the x coords by -5 for each vertex, to PHYSICALY move the box 5 units to the left.

My one remaining question is this. Why would I need to use glTranslate, or glRotate on each object?? If i have moved my camera with it, this create my view point. All the objects will simply be drawn from that view with WORLD coords. So anytime i need to move something i would simply PHYSICALY move it by way of manipulating the actualy vertex data. So calling glTranslate and glRotate would simply change the view of the object, but If i simply MOVE the object wo the correct location, there would be no need to change the view of it, because it would already be where it needs to be viewed correct???

If in your code to move the objects you are actually updating each vertex, than you’re right, you don’t need to use glTranslate and glRotate on each object.

BUT if instead you keep all the vertices at values as if the object was at 0,0,0, and also keep separate variables for the object’s current position and orientation, then you don’t need to update every vertex and can just use glTranslate and glRotate instead.

To be more clear, there are two ways you could potentially do the object’s move method. It sounds like you are doing something like so…

void Object::Move()
{
for each vertex
{
vertex.x = newX;
vertex.y = newY;
vertex.z = newZ;
}
}

The following is the way I like to do things as it requires fewer calculations.

void Object::Move()
{
this->Position = newPosition;

// Individual vertices are left alone
}

OK. I GET IT, HALLALOOYA, (heavens part, and a light ray is cast down apon the ignorant one)…LOL

Any who, one final question, and im done, is changing each vertex physcialy, alot more computationaly heavy?? or would it be ok to do?? OR could i desing my own matrix, to ACTUALY change the data, similarly to how opengl changes the view from the data?? Im just curious about performace issues now. What would be faster, and is there going to be a HUGE diffrence from doing one to the other??

I just wanted you all to know, that this is my first post that ever became a flaming post. Im so proud of my ignorance. LOL. Thank you all for you help.

In most cases changing all the vertex data is going to be quite a bit more computationally expensive than just updating the object positions. For collision detection, you may still have to do the calculations of transformed vertices, but there are usually ways to keep from having to do those calculations on ALL the vertices. And with certain collision detection routines, you may not have to do those calculations at all. (Simple sphere bounding for example.)

So, in an engine like Quake 3 for instance, do the players, and items, ACTUALY move, or are there possisions simply updated each step??, because i could see the updating the posision, and view each time becoming quite confusing to reset data each time.

Just to maybe help…
Here is a little program, it uses GLUT, mouse functions, glutIdleFunc, Keyboard, lighting, object maping via an array.

Over view of program…
Use the mouse to move your view and a triangle in your front view. Multiple triangle move in the back ground.
right/left mouse click moves you along the z-axis

ESC key exits the program.

Could use some commenting of the code…

#include <GL/glut.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include “mystuff.h”

static int xsides = 0, rotateX = 0, rotateY = 0, rotateZ = 0;
static int WrotateX = 0, WrotateY = 0, WrotateZ = 0;
static float Worldz = 0,Worldzdir = 0.1, Mouse_x, Mouse_y, Win_x, Win_y;
static float xscale = 1, wscale = 1;
static int demo_state = 0;

GLfloat LightAmbient= { 0.5f, 0.5f, 0.5f, 1.0f };
GLfloat LightDiffuse= { 0.5f, 0.5f, 0.5f, 1.0f };
GLfloat LightPosition= { 0.0f, 0.0f, -5.0f, 1.0f };
GLfloat mat_specular = { 1.0, 1.0, 1.0, 1.0 };

static Point3F pryamida[21] = {{0.0f,1.0f,0.0f},{-1.0f,-1.0f,1.0f},{1.0f,-1.0f,1.0f},{0.0f,1.0f,0.0f},
{0.0f,1.0f,0.0f},{1.0f,-1.0f,1.0f},{1.0f,-1.0f,-1.0f},{0.0f,1.0f,0.0f},
{0.0f,1.0f,0.0f},{1.0f,-1.0f,-1.0f},{-1.0f,-1.0f,-1.0f},{0.0f,1.0f,0.0f},
{0.0f,1.0f,0.0f},{-1.0f,-1.0f,-1.0f},{-1.0f,-1.0f,1.0f},{0.0f,1.0f,0.0f},
{-1.0f,-1.0f,1.0f},{1.0f,-1.0f,1.0f},{1.0f,-1.0f,-1.0f},{-1.0f,-1.0f,-1.0f},{-1.0f,-1.0f,1.0f}};

static Point3F pryamid[18] = {{0.0f,1.0f,0.0f},{-1.0f,-1.0f,1.0f},{1.0f,-1.0f,1.0f},
{0.0f,1.0f,0.0f},{1.0f,-1.0f,1.0f},{1.0f,-1.0f,-1.0f},
{0.0f,1.0f,0.0f},{1.0f,-1.0f,-1.0f},{-1.0f,-1.0f,-1.0f},
{0.0f,1.0f,0.0f},{-1.0f,-1.0f,-1.0f},{-1.0f,-1.0f,1.0f},
{-1.0f,-1.0f,1.0f},{1.0f,-1.0f,1.0f},{1.0f,-1.0f,-1.0f},
{1.0f,-1.0f,-1.0f},{-1.0f,-1.0f,-1.0f},{-1.0f,-1.0f,1.0f}};

static Point3F pryamidc[18] = {{1.0f,1.0f,1.0f},{1.0f,1.0f,1.0f},{1.0f,1.0f,1.0f},
{0.5f,1.0f,0.5f},{0.5f,1.0f,0.5f},{0.5f,1.0f,0.5f},
{0.5f,0.5f,0.5f},{0.5f,0.5f,0.5f},{0.5f,0.5f,0.5f},
{0.0f,1.0f,0.0f},{0.0f,1.0f,0.0f},{0.0f,1.0f,0.0f},
{1.0f,0.0f,1.0f},{1.0f,0.0f,1.0f},{1.0f,0.0f,1.0f},
{1.0f,1.0f,0.0f},{1.0f,1.0f,0.0f},{1.0f,1.0f,0.0f}};

static Object_data My_Object[1001];

static void TimeEvent(int te)
{
int timent;
int i;

Worldz = Worldz + Worldzdir;
if (( Worldz > 25) | | (Worldz < 0)) Worldzdir = Worldzdir * -1;

if (My_Object[0].Ticks > My_Object[0].Ticks_per_frame)
{
if (demo_state == 0)
{
My_Object[0].Rotation_x = My_Object[0].Rotation_x + 5;
if (My_Object[0].Rotation_x > 360) My_Object[0].Rotation_x =0;
My_Object[0].Rotation_y = My_Object[0].Rotation_y + 5;
if (My_Object[0].Rotation_y > 360) My_Object[0].Rotation_y =0;
My_Object[0].Rotation_z = My_Object[0].Rotation_z + 5;
if (My_Object[0].Rotation_z > 360) My_Object[0].Rotation_z =0;

  My_Object[0].Curent_point.xyz[0] = My_Object[0].Curent_point.xyz[0] + (0.1 * (My_Object[0].Curent_point.xyz[0] < My_Object[0].Int_point.xyz[0])) + (-0.1 * (My_Object[0].Curent_point.xyz[0] > My_Object[0].Int_point.xyz[0]));
  My_Object[0].Curent_point.xyz[1] = My_Object[0].Curent_point.xyz[1] + (0.1 * (My_Object[0].Curent_point.xyz[1] < My_Object[0].Int_point.xyz[1])) + (-0.1 * (My_Object[0].Curent_point.xyz[1] > My_Object[0].Int_point.xyz[1]));
  My_Object[0].Curent_point.xyz[2] = My_Object[0].Curent_point.xyz[2] + (0.1 * (My_Object[0].Curent_point.xyz[2] < My_Object[0].Int_point.xyz[2])) + (-0.1 * (My_Object[0].Curent_point.xyz[2] > My_Object[0].Int_point.xyz[2]));

 for(i=1; i < 1000; i++)
    {

  	My_Object[i].Rotation_x = My_Object[i-1].Rotation_x;
      My_Object[i].Rotation_y = My_Object[i-1].Rotation_y;
      My_Object[i].Rotation_z = My_Object[i-1].Rotation_z;

  	My_Object[i].Curent_point.xyz[0] = My_Object[i].Curent_point.xyz[0] + (0.1 * (My_Object[i].Curent_point.xyz[0] < My_Object[i].Int_point.xyz[0])) + (-0.1 * (My_Object[i].Curent_point.xyz[0] > My_Object[i].Int_point.xyz[0]));
  	My_Object[i].Curent_point.xyz[1] = My_Object[i].Curent_point.xyz[1] + (0.1 * (My_Object[i].Curent_point.xyz[1] < My_Object[i].Int_point.xyz[1])) + (-0.1 * (My_Object[i].Curent_point.xyz[1] > My_Object[i].Int_point.xyz[1]));
  	My_Object[i].Curent_point.xyz[2] = My_Object[i].Curent_point.xyz[2] + (0.1 * (My_Object[i].Curent_point.xyz[2] < My_Object[i].Int_point.xyz[2])) + (-0.1 * (My_Object[i].Curent_point.xyz[2] > My_Object[i].Int_point.xyz[2]));
     }

   }

 if( demo_state ==1 )
     {

        	My_Object[0].Rotation_x = My_Object[0].Rotation_x + 5;
          if (My_Object[0].Rotation_x > 360) My_Object[0].Rotation_x =0;
          My_Object[0].Rotation_y = My_Object[0].Rotation_y + 5;
          if (My_Object[0].Rotation_y > 360) My_Object[0].Rotation_y =0;
          My_Object[0].Rotation_z = My_Object[0].Rotation_z + 5;
          if (My_Object[0].Rotation_z > 360) My_Object[0].Rotation_z =0;
  		for(i=1000; i > 0; i--)
  			{
              My_Object[i].Rotation_x = My_Object[i-11].Rotation_x;
              My_Object[i].Rotation_y = My_Object[i-1].Rotation_y;
              My_Object[i].Rotation_z = My_Object[i-1].Rotation_z;
  		    }

       }
My_Object[0].Ticks = 0;
 }else My_Object[0].Ticks++;

glutPostRedisplay();
glutTimerFunc( 10, TimeEvent, 1);
}

void buildquad( int sides, Point3F polygon)
{
float angle, xangle;
float x, y, z;
float r;
int i;

r = 2.0f;
xangle = 3.1415927f / sides;

for (i=0; i <= sides; i++)
{
angle = xangle * i * 2;
polygon[i].xyz[0] = r * cos( angle ); // X
polygon[i].xyz[1] = r * sin( angle ); // Y
polygon[i].xyz[2] = 0.0f; // Z
}
polygon[i] = polygon[0];
//polygon[i].xyz[1] = polygon[0].xyz[1];
//polygon[i].xyz[2] = polygon[0].xyz[2];

}

void init(void)
{
int ix,iy,iz;
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_SMOOTH);
glLightfv(GL_LIGHT1 ,GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT1 ,GL_DIFFUSE, LightDiffuse);
glLightfv(GL_LIGHT1 ,GL_POSITION, LightPosition);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT1);
glEnable(GL_DEPTH_TEST);
My_Object[0].Ticks_per_frame = 1;
My_Object[0].Ticks = 0;

for(iz=0; iz < 10; iz++)
{
for(iy=0; iy < 10; iy++)
{
for(ix=0; ix < 10; ix++)
{
My_Object[iz100+iy10+ix].Int_point.xyz[0] = ix * 2 - 9;
My_Object[iz100+iy10+ix].Int_point.xyz[1] = iy * 2 - 9;
My_Object[iz100+iy10+ix].Int_point.xyz[2] = iz * 2 - 34;
My_Object[iz100+iy10+ix].Curent_point.xyz[0] = 0;
My_Object[iz100+iy10+ix].Curent_point.xyz[1] = 0;
My_Object[iz100+iy10+ix].Curent_point.xyz[2] = -24;
My_Object[iz100+iy10+ix].Rotation_x = 0;
My_Object[iz100+iy10+ix].Rotation_y = 0;
My_Object[iz100+iy10+ix].Rotation_z = 0;

  		}
  	}
  }

}

void display(void)
{
float i,j;

glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glLoadIdentity();
glMatrixMode(GL_MODELVIEW);

glPushMatrix();

glTranslatef( Mouse_x, Mouse_y, -15.0);
//glRotatef(270, 1.0, 0.0, 0.0);
glColorMaterial(GL_FRONT, GL_EMISSION);
glEnable(GL_COLOR_MATERIAL);

glColor3f(0.0, 1.0, 0.0);

glBegin(GL_LINE_LOOP);

for(i=0;i <= 17;i++)
{

   //glColor4f( pryamidc[(int)i].xyz[0], pryamidc[(int)i].xyz[1],pryamidc[(int)i].xyz[2], 0.2);
 glNormal3fv(  &pryamid[(int)i] );
 glVertex3fv(  &pryamid[(int)i] );
   }

glEnd();

glPopMatrix();

glRotatef(WrotateX, 1.0f, 0.0f, 0.0f);
glRotatef(WrotateY, 0.0f, 1.0f, 0.0f);
glRotatef(WrotateZ, 0.0f, 0.0f, 1.0f);
glTranslatef( 0,0, Worldz);

for(j=0; j < 1000; j++ )
{
glPushMatrix();

glColorMaterial(GL_FRONT, GL_DIFFUSE);
glColor3f(0.0, 1.0, 0.0);

glTranslatef(My_Object[(int)j].Curent_point.xyz[0], My_Object[(int)j].Curent_point.xyz[1], My_Object[(int)j].Curent_point.xyz[2]);

glRotatef(My_Object[(int)j].Rotation_x, 1.0f, 0.0f, 0.0f);
glRotatef(My_Object[(int)j].Rotation_y, 0.0f, 1.0f, 0.0f);
glRotatef(My_Object[(int)j].Rotation_z, 0.0f, 0.0f, 1.0f);
glScalef(xscale, xscale, xscale);
glBegin(GL_LINE_LOOP);

for(i=0;i <= 17;i++)
{

   //glColor3f( pryamidc[(int)i].xyz[0], pryamidc[(int)i].xyz[1],pryamidc[(int)i].xyz[2]);
 glNormal3fv(  &pryamid[(int)i] );
 glVertex3fv(  &pryamid[(int)i] );
   }

glEnd();
glPopMatrix();
}

glutSwapBuffers();
}

void reshape (int w, int h)
{
Win_x = w;
Win_y = h;
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective(60.0,(GLfloat) w/(GLfloat) h, 1.0, 50.0);
//gluLookAt (0.0, 0.0, wscale, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glMatrixMode(GL_MODELVIEW);
// glLoadIdentity();

}

void keyboard (unsigned char key, int x, int y)
{
switch (key) {
case ‘-’:
demo_state–;
if (demo_state < 0) demo_state = 0;
break;
case ‘+’:
demo_state++;
if (demo_state > 3) demo_state = 3;
break;
case ‘y’:
WrotateY = WrotateY + 15;
if (WrotateY > 360) WrotateY = 0;
glutPostRedisplay();
break;
case ‘Y’:
WrotateY = WrotateY - 15;
if (WrotateY < 0) WrotateY = 360;
glutPostRedisplay();
break;
case ‘x’:
WrotateX = WrotateX + 15;
if (WrotateX > 360) WrotateX = 0;
glutPostRedisplay();
break;
case ‘X’:
WrotateX = WrotateX - 15;
if (WrotateX < 0) WrotateX = 360;
glutPostRedisplay();
break;
case ‘z’:
WrotateZ = WrotateZ + 15;
if (WrotateZ > 360) WrotateZ = 0;
glutPostRedisplay();
break;
case ‘Z’:
WrotateZ = WrotateZ - 15;
if (WrotateZ < 0) WrotateZ = 360;
glutPostRedisplay();
break;
case ‘s’:
xscale = xscale -0.01f;
if (xscale < 0.01f ) xscale = 0.01f;
glutPostRedisplay();
break;
case ‘S’:
xscale = xscale + 0.01f;
if (xscale > 10) xscale = 10;
glutPostRedisplay();
break;
case ‘w’:
wscale = wscale - 0.01f;
if (wscale < 0.0f ) wscale = 10.0f;
glutPostRedisplay();
break;
case ‘W’:
wscale = wscale + 0.01f;
if (wscale > 10) wscale = 0;
glutPostRedisplay();
break;
case 27:
exit(0);
break;
default:
break;
}

}

void mouse(int button, int state, int x, int y)
{

if ((button == GLUT_RIGHT_BUTTON) && (state == GLUT_DOWN)) Worldz++;

if ((button == GLUT_LEFT_BUTTON) && (state == GLUT_DOWN)) Worldz–;

}

void mouse_passive( int x, int y)
{

Mouse_x = -5 + 10 * (x/Win_x);
Mouse_y = 5 - 10 * (y/Win_y);

if ((Mouse_x < -1) && (Mouse_y < -1))
{
WrotateX++;
WrotateY–;
}

if ((Mouse_x > 1) && (Mouse_y > 1))
{
WrotateX–;
WrotateY++;
}

if ((Mouse_x > 1) && (Mouse_y < -1))
{
WrotateX++;
WrotateY++;
}

if ((Mouse_x < -1) && (Mouse_y > 1))
{
WrotateX–;
WrotateY–;
}

if ((Mouse_x < -1) && (Mouse_y > -1) && (Mouse_y < 1))
{
WrotateY–;
}

if ((Mouse_x > 1) && (Mouse_y > -1) && (Mouse_y < 1))
{
WrotateY++;
}

}

int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (10, 10);
glutCreateWindow (argv[0]);
glutSetWindowTitle(“GLbase”);
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutPassiveMotionFunc(mouse_passive);
glutTimerFunc( 10, TimeEvent, 1);
glutMainLoop();
return 0;
}

/* Mystuff.h

by Eric Stringer

*/

typedef struct
{
GLfloat xyz[3];

}Point3F;

typedef struct
{
int Sides;
GLfloat x, y, z;
GLfloat Scale;
GLfloat Color3f[3];
Point3F* Vertex3f;
}Primitive3F;

typedef struct // this structure definded for the location of each pyramid
{
int object;
int sides;
Point3F Int_point;
Point3F Curent_point;
Point3F Target_point;
int Int_angle_x;
int Int_angle_y;
int Int_angle_z;
int Target_angle_x;
int Target_angle_y;
int Target_angle_z;
int Rotation_x;
int Rotation_y;
int Rotation_z;
int Rotation_rate_x;
int Rotation_rate_y;
int Rotation_rate_z;
int Speed_x;
int Speed_y;
int Speed_z;
int direction_x;
int direction_y;
int direction_z;
int Ticks_per_frame;
int Ticks;
}Object_data;

struct XYZ_BOUND
{
float ax;
float bx;
int timex;
float ay;
float by;
int timey;
float az;
float bz;
int timez;
};

You must think like an animator, when thinking how scenes are created.
You have heard the term FPS(Frame per second) in games like quake, that is how many times a scene can be redrawn per second.
That means redrawing each scene new each time like cells of an animated show, just chaning the view and location of moving objects each time…

I think people get confused, because they think once you load the objects you only need to move the carama around them. Which is not the case, you must redraw each scene with each object that is moving in a updated location.

See my example program in my other post, on tracking object position.

Originally posted by LostInTheWoods:
So, in an engine like Quake 3 for instance, do the players, and items, ACTUALY move, or are there possisions simply updated each step??, because i could see the updating the posision, and view each time becoming quite confusing to reset data each time.

Then is movement by glTranslate, and glRotate Cummulative. Or in other words. If I have an triangle, with verts V1,V2,V3.
And translate the verts.
glTranslate(0,5,0)

Internaly i end up with the triangle visualy moved 5 in the y direction.
V1 new = ModelView*V1; etc;
So now if the next frame i move the object again, by 5 more in the y direction, do the V1,V2,V3 values get moved in the y from there start possisions, or are they moved based on the V1 New, V2 New, V3 New??

Meaning, is the triangle now visably 10 units away from start, or mearly 5 again??

I ask this since im guess this is the way animations are formed. The engine NEVER, actualy moves the objects, physicaly, just the view of each object. Which is quite a hard thing to grasp.

Ok now i’m confused.

I had to make a bird fly around on a line. And have a camera view that would rotate around the whole track. This is what I did
I found where the bird was suppose to be next, then i would use push/pop_matrix and rotate/translate in the model space (is that the correct term?) to put the wings, head, tail in the correct spot. Does that make sense or am I totally off?

killercow, you’ve pretty much hit the solution on the head.

LostInTheWoods, I’m sorry, but I don’t know how I can make this any more clear. The engine DOES keep track of the object positions. It just doesn’t do so by changing EVERY vertex.

So… you have an object that starts at 0,0,0. Frame 1, you move it 5 units up. You now have to store it’s position as 0,5,0. You have to do that YOURSELF. glTranslate will not automatically set that for you.

Next frame, you move it 5 units up again… now it’s 0, 10, 0. Again, you have to update that position YOURSELF. And now when you display it you will use glTranslatef(0, 10, 0);

You still are a bit off on the idea…
In cartoon animation the camara does not move but the world drawn in front of it does.

Now about verts, you don’t rotate them one at a time, you make a object, say a triangle.

triangle = {{ 0,0,0 } ,{ -1,-1,0 }, { 1,1,0 }}; triangle with 3 points.

You rotate all verts at one time with glRotate, which does it in the matrix.

glRotate is cummulative when used one after another.

example:
glRotatef(15, 1, 0, 0); Rotate X by 15 degrees

glRotatef(15, 1, 0, 0); Rotate X by 15 Degrees.

draw_object(); it will be drawn rotated by 30 Degrees.

example 2

glRotatef(15, 1, 0, 0); Rotate X by 15

glPushMatrix();
glRotatef(15, 1, 0, 0); Rotate X by 15

draw_object(); Object is drawn rotate only 15 degrees

glPopMatrix();

Think about your object as a drag and drop item on the desk top. When you drag it, it is not one pixel at time but a whole icon.
In gl you draw the object then translate/rotate it to it location in the scene.
Just like a icon on the desk top, we don’t need to know what each pixel is located, we just move the whole thing to a new x,y location.

The same hold true to openGL, it is not your verts that change. but the location in which they are drawn. So here we have in the example a triangle made of verts, its values per my triangle variable never change, only its location.

glPushMatrix();
gltranslate(…); location to move object to
glrotate(…); Rotate of object.

draw_object(); Draw object made up of a bunch of verts.

glPopMatrix();

To move the object we change the values in the gltranslate.

So in your triangle problem, if we did not use glLoadIdentity each time display was called, we would have an accumative effect from the glRotate/Translate.

So if each time you draw your triangle, and you have glTranslatef fixed at (0,5,0), then there will be not change to the object position.
But if you add a variable call, V2.
The first time we call the display V2 = 5;
glTranslate(V1,V2,V3)
then the next time we call the display routine we add V2=V2+5.
The glTranslatef will now move the triangle to 0,10,0.

Originally posted by LostInTheWoods:
[b]Then is movement by glTranslate, and glRotate Cummulative. Or in other words. If I have an triangle, with verts V1,V2,V3.
And translate the verts.
glTranslate(0,5,0)

Internaly i end up with the triangle visualy moved 5 in the y direction.
V1 new = ModelView*V1; etc;
So now if the next frame i move the object again, by 5 more in the y direction, do the V1,V2,V3 values get moved in the y from there start possisions, or are they moved based on the V1 New, V2 New, V3 New??

Meaning, is the triangle now visably 10 units away from start, or mearly 5 again??

I ask this since im guess this is the way animations are formed. The engine NEVER, actualy moves the objects, physicaly, just the view of each object. Which is quite a hard thing to grasp.

[/b]

[This message has been edited by nexusone (edited 08-06-2002).]

[This message has been edited by nexusone (edited 08-06-2002).]

Sorry, I don’t mean to correct you again, but I think for your example 2you mean this instead…

example 2

glPushMatrix();
glRotatef(15, 1, 0, 0); Rotate X by 15
glPopMatrix();

glPushMatrix();
glRotatef(15, 1, 0, 0); Rotate X by 15

draw_object(); Object is drawn rotate only 15 degrees

glPopMatrix();

Yes it is more correct, as to what I ment.

glRotate… // rotate world

object 1
glPushMatrix…
glRoate… // Rotate object 1
draw_object
glPop…

object 2
glPushMatrix…
glRotate… // Rotate object 2
draw_object // Note object 2 is not change by the glrotate in object 1
glPopMatrix…

Now both objects are drawn without effecting each other, but they are both change by the glRotate before both where drawn.

Originally posted by Deiussum:
[b]Sorry, I don’t mean to correct you again, but I think for your example 2you mean this instead…

example 2

glPushMatrix();
glRotatef(15, 1, 0, 0); Rotate X by 15
glPopMatrix();

glPushMatrix();
glRotatef(15, 1, 0, 0); Rotate X by 15

draw_object(); Object is drawn rotate only 15 degrees

glPopMatrix();

[/b]

Ok I am going to simply track my models. By way of creating variables to hold the Distance traveled, and degrees turned from the original model. And simply call that with translate and rotate each time. (not sure how this will work with Key Frame animations, and bones and joints, but i will cross that bridge when i get there).

My new question is this. If the center of the object starts at 0,0,0 and i translate its view to 0,4,0, and i want to rotate it around the center, do i rotate it around the ACTUAL center at 0,0,0, or the ‘new’ images center at 0,4,0??

But thank you for all your help. I truly finaly get the concept of the translation, and rotation, i just need to track my objects movements each time. And use that new value added to the old value to get the actual move.

Hi mister Lostinthewoods.

I have follow all this thread and if i understand well your problem i think i can contribute posting some info:

In the virtual 3d word there are mainly 3 kinds objects:

  • static object: this is the floor, mountais, houses, rocks, etc, everithing that in real world is not animated.

  • You main character: this is controled for the player and it can be moved through the virtual world.

  • NPC (Non Player Characters), others objects that are moved or animated in the world, like people, badguys, goodguys, etc.

If i understand you well, seem that when you want to move the player YOU ARE MOVING THE WHOLE SCENE (the virtual world) relative to the player…but what you have to do is move your CAMERA to the new position and then draw the static objects (the virtual world) as normal, not any coordinates need to be changed for statics objects.

You need to understand that in opengl you can do this:

GlMatrixMode(Gl_projection);
glpushmatrix;
//update the camera position.
gltranslate(x,y,z)…
glrotated(x,y,z)…

when the matrixmode is switched to “gl_projection” then next gltranslate and glscale will affect THE CAMERA ONLY, your virtual world is not affected.

You need to keep track your self the camera rotation & position and move/rotate the camera each frame using those values.

Now you need to switch to matrixmode to “gl_modelview” so now you are going to draw your static objects models.

GlMatrixMode(Gl_modelview);
glpushmatrix;
//draw all your statics objects.
draw_static_objects; //no need to translated or rotated anything here.

Now you draw your others objects that can be moved, for do that you can keep track your self the ABSOLUTES world cordinates for each object and draw them as normal, if you need to rotated them you will need to use gltranslate and glrotaed before drawing each object.

the whole seudocode is somthing like this:

GlMatrixMode(Gl_projection);
glpushmatrix;
//update the camera position.
gltranslate(x,y,z)…
glrotated(x,y,z)…
GlMatrixMode(Gl_modelview); //now draw objetcs.
glpushmatrix;
draw_static_objects;
//now draw objects than can be moved.
for k=1 to num_objects do
begin
glpushmatrix;
gltranslatef(x,y,z); //if neded
glrotatef(x,y,z); //if needed
draw_moved_object[k];
glpopmatrix
end;

glpopomatrix; //restore the matrix at the same state found before we started mesing with gltranslates and glrotates.
GlMatrixMode(Gl_projection);
glpopmatrix;


hope this help.

Turbo Pascal

Animation and joint’s are all handle in variables.

example one per draw data for movement:

robot[1].model[0] // data for robot standing
robot[1].model[1] // data for robot walking pose 1
robot[1].model[2] // data for robot walking pose 2

glPushMatrix(); Draw robot routine
glTranslate(…); Move robot
glRotate(…); Rotate robot.

Draw_object(robot[1].model[2]); // drawn robot in pose 2.
glPopMatrix();

Just like cell’s in a animation, you just cycle through the poses to make the robot walk. Quake I think uses this type of animation to make movement.

example two robot with joint variables:

robot[1].head // data on head position
robot[1].rightarm // data on right arm position
robot[1].leftarm // data on right arm position
repeat for any moving part.

glPushMatrix();
glTranslate(…) move robot
glRotate(…) rotate robot
glPushMatrix(); // Draw arm
glTranslate(…);// move arm to position
glRotate(…); rotate arm
Draw_arm(); // draw arm
glPopMatrix();
//repeat for each moving part of robot
glPopMatrix();

Originally posted by LostInTheWoods:
[b]Ok I am going to simply track my models. By way of creating variables to hold the Distance traveled, and degrees turned from the original model. And simply call that with translate and rotate each time. (not sure how this will work with Key Frame animations, and bones and joints, but i will cross that bridge when i get there).

My new question is this. If the center of the object starts at 0,0,0 and i translate its view to 0,4,0, and i want to rotate it around the center, do i rotate it around the ACTUAL center at 0,0,0, or the ‘new’ images center at 0,4,0??

But thank you for all your help. I truly finaly get the concept of the translation, and rotation, i just need to track my objects movements each time. And use that new value added to the old value to get the actual move.[/b]

[This message has been edited by nexusone (edited 08-06-2002).]