PDA

View Full Version : MAJOR issues, Please help me.



LostInTheWoods
08-05-2002, 06:46 AM
Ok I have 2 MAJOR questions. First, If I create a scene and within the scene I have an assortment of objects. I Do a simply test to see if the objects are visable, at the time of view. If not, then they are simply not drawn. BUT, if i dont draw them, then any subsequent movements of the observer (moving the screen around) are not passed to the object, there fore the object never moves when the scene moves. (If i understand this correctly). So is there a way to move an object without rendering it, so objects culled from the drawing field are also moved even though there not drawn??????

Secondly. I have a scene that i have created, that uses a set of vectors (similar to the normals, but not as many, this way I can cut out collisions that i know cant happen) To check for collisions within the scene. Now I am guessing that when the scene is rotated by the view of the player, that the Vectors for the collisions would also have to be rotated. Is that correct? Because of the whole model/view duality, that the camera dosnt move, the world does?? Right. So i would have to also rotate the vectors, but not translate them, because the are only stateing a direction. Or would i have to translate them also?? I am SOOO confused.

Edit:
Here is some psydo code to help.

for(int a=0; a<NumberOfItems; a++)
{
bool DrawItem;
DrawItem =ItemVisable(); //Check visablity

if(DrawItem == true)
{
glPushMatrix();
//rotations & translations here
//Draw Items here using vertex arrays
glPopMatrix();
}
}

But i need to be able to move the objects even if there not seen. And im not sure how to put the Items VERTS through the matrix without drawing them??

[This message has been edited by LostInTheWoods (edited 08-05-2002).]

Pops
08-05-2002, 07:35 AM
From your code, you do the test before you move the object anyway. Whether you draw the object or not should make no difference.

The way I implement view/camera is by having camera position variables (camera class in fact) and to move the camera I do

push matrix //camera
Translation cam.x, cam.y, cam.z
then
Rotation cam_rot.x, cam_rot.y, cam_rot.z

then draw objects
for i = 0 to num_objects
push matrix //object
draw object i
pop matrix //object
next I

pop matrix //camera

everything including normals will be rotated and you donít have worry about updating the normals yourself.


[This message has been edited by Pops (edited 08-05-2002).]

LostInTheWoods
08-05-2002, 07:43 AM
Ok i understand that just fine. My problem is this. Say i make 10 objects. Each of there data is held in a array of verts, normals, and texture coords.

I test to see if the object is within view. If it is not the object is simply NOT drawn. BUT i do need that object to be moved along with the scene in order for it to be drawn when it is visable.

So i need to know how to rotate, and translate the Objects information without physicaly drawing it to the screen.

like if I had this.

glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, &Verts);

glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, 0, &Normals);

how would i rotate and translate them, without having to draw them. Could i simply run the Verts array and normal array through the projection matrix, to move the objects without drawing them?? And if so how??? Does what im asking make sence? Or do i need to clarify???

nexusone
08-05-2002, 08:00 AM
Tracking objects:

Just use a variable:

\\ process all objects.

if (my_object[X].in_motion == TRUE ) Update_object(my_object[X]); \\ We need only update data if object has moved.

if (my_object[X].visiable == TRUE )draw_object(my_object[X]); Draw only if visiable to user.

Collision:


The object's direction of Travel should not be effected by the camara's rotation.

It will still have the same vector of travel, just your view of it has changed.

Just because you don't see an object hit another, you still need to know when and the direction of travel to see if it bouces back to the front of the viewer.


Hope this helps


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

Deiussum
08-05-2002, 08:05 AM
You seem to be confused about something. OpenGL itself has no concept of objects. "Running the vertices through the projection matrix" just does calculations to see how to display the vertices, it doesn't update the vertex positions for you. You have to do that yourself.

Typically, you will have vertices based on when your object is placed at 0,0,0. Then you store your objects current position and orientation with the object. You then use that position and orientation to do the appropriate rotates and translates, and then draw the object. To do movement, you simply update the position and orientation, not the individual vertices of the object. Updating the position and orientation is totally left up to you to do. It's not something OpenGL will do for you.

So, for your problem, even though the objects aren't visible, you should still be updating the position and orientation of those objects.

LostInTheWoods
08-05-2002, 08:05 AM
but dont i have to move the object whenever the player moves, since the world is moving around him, the whole world/eye view duality thing.

SO if the player steps forward, then in actuality the world is stepping towards him, so if an object isnt drawn that frame, the object isnt stepped with the world?? get it?? or am i thinking incorectly about how the world and player are drawn corresponding to one another??

nexusone
08-05-2002, 08:27 AM
Maybe a translation think.. or thinking wrong...???

As you say, a player step's forward, we in reality we move the world forward. But we have not change the location of the world but the player.

Say the player takes 5 steps forward, moving away from an object behind him.
Before the player was 10 units away from the object, he will now be 15 units away.
Now say the object was at point 0,0,0 in our world, that has not changed. Only our players position, is now 0,0,15

Maybe this will help.



Originally posted by LostInTheWoods:
but dont i have to move the object whenever the player moves, since the world is moving around him, the whole world/eye view duality thing.

SO if the player steps forward, then in actuality the world is stepping towards him, so if an object isnt drawn that frame, the object isnt stepped with the world?? get it?? or am i thinking incorectly about how the world and player are drawn corresponding to one another??

LostInTheWoods
08-05-2002, 09:18 AM
Ok. I understand if you move the player forward, then "only" the player moves. My Problem is this. When i update my 'camera'. I simply rotate, and translate the entire scene around, because there is no 'camera' in OpenGL. So when i Move my player around, like I would Move a camera. Does the worlds coords actualy change?? or does my view simply change??

Does this make sence??

//Step player forward..
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslate(0, 5, 0);

//Draw my world
DrawRoom();

//Draw my objects
for(int a=0; a<NumObjects; a++)
{
if(ObjectVisability == true)
{
DrawObject(a); //Select wich object to draw
}
}

..........
Now if i do this, and lets say 4 objects dont get drawn, and 1 does (because its in view). The other 4 objects dont get 'moved' along with the scene as it moves 'because the player is what seems to be moving, but the world is what is actualy moving?' or is this incorrect??
So if the 4 objects dont move with the scene, then i have to update them manualy correct??

coredump
08-05-2002, 09:46 AM
basically:

if an object (player or otherwise) is moving, update it's position. otherwise, leave it alone.
if an object is in view of the player, draw it. otherwise, don't.
to determine if an object is moving is up to you (or your engine)
to determine if an object is in the player's view is also up to you.

b

LostInTheWoods
08-05-2002, 09:51 AM
OK. But if the player is moving, dosnt that mean that 'everything' else is moving instead?? Because I call glTranslate, and glRotate, (negativly) to update the players possition. Thus does this mean that 'everything in the scene actualy moves' or not??. I think my hang up is, this, I cant figure out if moving the player actualy moves the player, or the ENTIRE world, and objects??

So by calling my tranlation and rotation for the player, is that changing the entire world?? Sorry to be so stupid. I just cant figure out this model/view connection.....

Deiussum
08-05-2002, 10:17 AM
I think you're taking the concept of moving the world a bit too far. Keep track of the location of everything in world coordinates, and then when you draw do something like so..

- Do "camera" transformations (inverse transformations on the world)
- For each object do appropriate world translations and draw

coredump
08-05-2002, 10:22 AM
this was hard for me to grasp initially also. since your tranlations and rotations are affecting the modelview matrix, all geometry drawn will be affected, whereas the "camera" will remain stationary. so effectively when the player moves forward, all your geometry moves backward, as far as OpenGL is concerned. but as far as your game engine is concerned most of that geometry (doors, walls, boxes, etc) is stationary. for example, in my FPS engine i keep track of the players look, right and up vectors as well as his position. each time through the loop i get my mouse/keyboard input, alter the vectors, apply the translations and rotations, then finally draw my geometry. at this point i could draw other game entities (weapons, items, monsters) each of which would have their own translation and rotation. hope this makes sense.

b

LostInTheWoods
08-05-2002, 10:28 AM
Ok i must be an idiot. Because i still have one more question.

Is moving the 'camera' exactly like moving the everything but the camera in the reverse?

And by moving the modelview matrix, does this actualy MOVE any part of the world?? Or does it simply move the camera??

If I dont draw or (translate or rotate) objects in the world, but move the camera, do those objects stay in possision releative to where they were last time??

LostInTheWoods
08-05-2002, 10:35 AM
COREDUMP....

That helps quite a bit. The only problem is what i am attempting to do with it. If I dont draw something because its out of view, I still have to move it via the Movement of the ENTIRE world, because the camera stays stationary. SO i need to move an object that isnt visable.
In order to move a visable object in the world i simply put my verts and normals calls after my WORLD rotation and translation. But a non visable object, i simply dont call those verts or normals. So is there a way to move those Verts and Normals with the WORLD, by using glTranslate, glRotate.??

nexusone
08-05-2002, 11:25 AM
I think you are understanding it..
The world coords do not change, only the location of the camara view. So you are correct to say that only the view has changed.

As per my last message, only other object in motion will need to be updated and that can be updaing there position without drawing them.


Originally posted by LostInTheWoods:
Ok. I understand if you move the player forward, then "only" the player moves. My Problem is this. When i update my 'camera'. I simply rotate, and translate the entire scene around, because there is no 'camera' in OpenGL. So when i Move my player around, like I would Move a camera. Does the worlds coords actualy change?? or does my view simply change??

Does this make sence??

//Step player forward..
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslate(0, 5, 0);

//Draw my world
DrawRoom();

//Draw my objects
for(int a=0; a<NumObjects; a++)
{
if(ObjectVisability == true)
{
DrawObject(a); //Select wich object to draw
}
}

..........
Now if i do this, and lets say 4 objects dont get drawn, and 1 does (because its in view). The other 4 objects dont get 'moved' along with the scene as it moves 'because the player is what seems to be moving, but the world is what is actualy moving?' or is this incorrect??
So if the 4 objects dont move with the scene, then i have to update them manualy correct??

LostInTheWoods
08-05-2002, 02:26 PM
Ok guys, one more question I SWEAR.
If I draw my scene without drawing certain objects for lets say 30 frames, the Player has now moved lets say 60 feet forward, so all the world has moved 60 feet backward. If i suddenly come accross an object that has yet to be drawn, it will not have been multiplied by the last 30 moves of the world. WIll it be in the correct place???

Like if i have a box 5 feet behind me to start. I am looking the other way, so its not drawn (by way of my culling function) thus only the parts of teh world that are visable are drawn ( and only they are multiplied by the modelview matrix each frame) so then after walking 60 feet forward, the modelview matrix has been multiplied to the 'viewable' objects 30 times, with a glLoadIdentity before each consecutive frame. but not the box behind me. Know I turn around, so the box is visable. WIll the box be 65 feet behind me, or just 5, because it was never multiplied by the modelview matrix??? Man i am SEROUSLY having a hard time with this. And im sorry its been such a long road. Thanks for ALL your help, even if you do disown me.


Edit:
Is the modelview matrix cumulative, meaning, does it simply add to its self each time, or does it reset so that the new location is the origin??
That would explain my problem with this so far, if the ModelView Matrix simply added to itsself each time, it wouldnt matter HOW many moves were made before an object was moved, because it would move that distance any ways?? Or am i wrong there too??

[This message has been edited by LostInTheWoods (edited 08-05-2002).]

[This message has been edited by LostInTheWoods (edited 08-05-2002).]

nexusone
08-05-2002, 07:14 PM
Think of your world of objects as being points on a map, and your finger is your view port.

Now your map has set points that do not change, that is not matter where your finger is point A on the map stays the same coordinates.

Let talk about your box, it has a set point on our map of 10,10,5(xyz).
We walk away from the box 35 units on the z-axis and turn around. The box will still be located at 10, 10, 5, but we will be looking at the box from 10,10, 40.
So even though we are moving the world around us, the points in the world stay the same.



Originally posted by LostInTheWoods:
Ok guys, one more question I SWEAR.
If I draw my scene without drawing certain objects for lets say 30 frames, the Player has now moved lets say 60 feet forward, so all the world has moved 60 feet backward. If i suddenly come accross an object that has yet to be drawn, it will not have been multiplied by the last 30 moves of the world. WIll it be in the correct place???

Like if i have a box 5 feet behind me to start. I am looking the other way, so its not drawn (by way of my culling function) thus only the parts of teh world that are visable are drawn ( and only they are multiplied by the modelview matrix each frame) so then after walking 60 feet forward, the modelview matrix has been multiplied to the 'viewable' objects 30 times, with a glLoadIdentity before each consecutive frame. but not the box behind me. Know I turn around, so the box is visable. WIll the box be 65 feet behind me, or just 5, because it was never multiplied by the modelview matrix??? Man i am SEROUSLY having a hard time with this. And im sorry its been such a long road. Thanks for ALL your help, even if you do disown me.


Edit:
Is the modelview matrix cumulative, meaning, does it simply add to its self each time, or does it reset so that the new location is the origin??
That would explain my problem with this so far, if the ModelView Matrix simply added to itsself each time, it wouldnt matter HOW many moves were made before an object was moved, because it would move that distance any ways?? Or am i wrong there too??

[This message has been edited by LostInTheWoods (edited 08-05-2002).]

[This message has been edited by LostInTheWoods (edited 08-05-2002).]

LostInTheWoods
08-06-2002, 04:58 AM
Thank you for that annalogy, that helps quite a bit.

So if i want to turn my camera, i would call glLoadidentity();
then rotate and translate;

Should i then call glLoadidentity again??

Because i only want to rotate the camera??

And what exactly does glTranslate, and glRotate due? Do they simply move the objects view? Or do they actualy move the object??

I wonder this because, say i want to MOVE a box from point 0,0,0 to point 0,10,0 in the ACTUAL world. Would glTranslate move the box? or simply the view of the box??

Edit:
And if it dosnt actualy move the box, then How would i move the box, by editing the xyz components of the actual model??

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

Deiussum
08-06-2002, 05:33 AM
I thought you were beginning to get it, but you are going back to thinking that the modelview matrix is actually changing the coordinates of your object.

I said this above, but I'll say it again. OpenGL has NO CONCEPT OF OBJECTS.

Example of how it works. You give OpenGL coordinates for Vertex V1, V2, and V3 for drawing a triangle. Now for each of those vertices it performs the following calculations.

newVx = MODELVIEW * Vx
newVx = PROJECTION * Vx

Now... it takes newV1, newV2, newV3, calculates if they are in the viewport, and then draws them, possibly doing depth testing. NOWHERE in there was V1, V2 and V3 changed. Also, NOWHERE in there was the MODELVIEW or PROJECTION matrices changed. The only things that will change the matrices are the functions glRotate, glTranslate, glScale, glFrustum, glOrtho, gluPerspective, gluOrtho2d, glLoadIdentity, glMultMatrix, glLoadMatrix, and gluLookAt.

Now.. an example of how you should be doing your rendering.





void Render()
{
glLoadIdentity();
gluLookAt(camera params);


for each object
{
if object is visible()
{
glPushMatrix();
glTranslate(object position);
glRotatef(object orientation);
object.Draw();
glPopMatrix();
}
}
}

void UpdateScene
{
for each object
{
// NOTE: You do NOT check if it's visible
object.UpdatePositionAndOrientation();
}
}

void OnCameraMove()
{
update camera params
}

void Idle()
{
UpdateScene();
glutPostRedisplay();
}



You see how that works? You are updating all the objects positions whether they are visible or not, and only drawing the ones that are visible. So it DOESN'T MATTER if an object hasn't been drawn for a frame because you STILL updating the position of the object yourself. OpenGL WILL NOT update the position of your objects for you.

nexusone
08-06-2002, 05:39 AM
Here come the part that really get's people is understanding how the matrix is effected.

Let look at it from the point of drawing a scene.

void display(void)
{

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

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.

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.

// What has happen is that we have drawn the box on the map as if it was laying flat and not been translated of rotated, but after we combine both matrix's. The box is still in the location we had drawn it, just now we have move it a long with the world to give us our current view point.

When creating a 3D world you should think of it like making a map, draw out the locations of all your objects on the map.
Each object will have a location relative to your world coordinate system.
Just remember we don't really care where our camara view is in regards to an objects location. We keep track of it as compared to is location on our map.



Originally posted by LostInTheWoods:
Thank you for that annalogy, that helps quite a bit.

So if i want to turn my camera, i would call glLoadidentity();
then rotate and translate;

Should i then call glLoadidentity again??

Because i only want to rotate the camera??

And what exactly does glTranslate, and glRotate due? Do they simply move the objects view? Or do they actualy move the object??

I wonder this because, say i want to MOVE a box from point 0,0,0 to point 0,10,0 in the ACTUAL world. Would glTranslate move the box? or simply the view of the box??

Deiussum
08-06-2002, 05:58 AM
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).]

LostInTheWoods
08-06-2002, 06:09 AM
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????

Deiussum
08-06-2002, 06:24 AM
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
}

LostInTheWoods
08-06-2002, 06:31 AM
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??

LostInTheWoods
08-06-2002, 06:45 AM
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.

Deiussum
08-06-2002, 06:47 AM
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.)

LostInTheWoods
08-06-2002, 07:12 AM
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.

nexusone
08-06-2002, 07:22 AM
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...
http://www.opengl.org/discussion_boards/ubb/smile.gif





#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) &amp;#0124; &amp;#0124; (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[iz*100+iy*10+ix].Int_point.xyz[0] = ix * 2 - 9;
My_Object[iz*100+iy*10+ix].Int_point.xyz[1] = iy * 2 - 9;
My_Object[iz*100+iy*10+ix].Int_point.xyz[2] = iz * 2 - 34;
My_Object[iz*100+iy*10+ix].Curent_point.xyz[0] = 0;
My_Object[iz*100+iy*10+ix].Curent_point.xyz[1] = 0;
My_Object[iz*100+iy*10+ix].Curent_point.xyz[2] = -24;
My_Object[iz*100+iy*10+ix].Rotation_x = 0;
My_Object[iz*100+iy*10+ix].Rotation_y = 0;
My_Object[iz*100+iy*10+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( &amp;pryamid[(int)i] );
glVertex3fv( &amp;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( &amp;pryamid[(int)i] );
glVertex3fv( &amp;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) &amp;&amp; (state == GLUT_DOWN)) Worldz++;

if ((button == GLUT_LEFT_BUTTON) &amp;&amp; (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) &amp;&amp; (Mouse_y < -1))
{
WrotateX++;
WrotateY--;
}

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

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

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


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

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

}

int main(int argc, char** argv)
{
glutInit(&amp;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;
};

nexusone
08-06-2002, 07:49 AM
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.

LostInTheWoods
08-06-2002, 09:15 AM
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.

killercow
08-06-2002, 09:30 AM
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?

Deiussum
08-06-2002, 10:08 AM
killercow, you've pretty much hit the solution on the head. http://www.opengl.org/discussion_boards/ubb/smile.gif

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);

nexusone
08-06-2002, 10:48 AM
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:
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.



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

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

Deiussum
08-06-2002, 11:31 AM
Sorry, I don't mean to correct you again, but I think for your example 2you mean this instead... http://www.opengl.org/discussion_boards/ubb/smile.gif

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();

nexusone
08-06-2002, 12:04 PM
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:
Sorry, I don't mean to correct you again, but I think for your example 2you mean this instead... http://www.opengl.org/discussion_boards/ubb/smile.gif

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();

LostInTheWoods
08-06-2002, 12:04 PM
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.

Turbo_Pascal
08-06-2002, 03:57 PM
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

nexusone
08-06-2002, 06:17 PM
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:
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.



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