MAJOR issues, Please help me.

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).]

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).]

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???

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).]

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.

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??

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:
[b]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??[/b]

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??

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

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…

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

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

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??

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.??

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:
[b]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?? [/b]

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).]

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:
[b]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).][/b]

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).]

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.

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:
[b]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??[/b]