Advertisement

Positioning models

Started by May 27, 2002 11:07 AM
3 comments, last by llvllatrix 22 years, 9 months ago
Ive been working on a project and have come to the point where im ready to position my objects. I came up with a neat solution to sychronizing your camera and objects, that might benefit some of the newer programmers. Usually when you deal with objects you manipulate the modelview matrix using glTranslatef,glRotatef and so on. This is great if you want to position one or two objects but it becomes cumbersome with many. This is because you either have to undo the previous transformation or glLoadIdentity and start again. What i do is position my camera with my a negation of the camera''s positioning and then, instead of manipulating the modelview matrix, i manipulate the object itself. Basically, i changed rsn''s milkshape loader to first manipulate the points that are drawn by a "final displacement" matrix before they are drawn. Easy right ? I suck at explaining things, so if you have any questions or want to see the code just ask and ill post.
Hmm, sounds like more work than

glMatrixMode(GL_MODELVIEW);glRotatef(blah); // camera rotationglTranslatef(-eyeX,-eyeY,-eyeZ); // camera translationfor( all models ){  glPushMatrix();  glTranslatef(modelX,modelY,modelZ);  DrawMyModel( ... );   glPopMatrix(); } 


Unless I''ve missed something?
Advertisement
So you''re saying you move the model in the modeling program, so if you position it at 0,0,0 it will show up at 50,6,75 or something?
That''s not good, now you have to keep track of how ''off'' the model is. So if you want to check for collisions it has to be:
model.pos.x+50 instead of model.pos.x. Very annoying. Not to mention if you ever want the model to move , you''ll have to translate it anyways.
(apologies if this is not what you meant, sounded like it)

------------
http://aud.vze.com <-- Newbie alert, look at your own risk. Can induce severe laughing fits and other variations of hysterical outburst.
_______________________________________Pixelante Game Studios - Fowl Language
In my system matricies are used to do transformations (including rotation). I also use these to do roatation and so on.

It is my impression that when you manipulate the modelview matrix and then push that matrix when starting a new model, you have to redo the camera transformation and apply the newer transformation to get the desired effect. With my system you have to transform the modelview once for your camera. Once that is done all you do is supply your transformation matrix to each model, draw, and Bob''s your uncle.

I think its easier for those who are more familiar with 3d math and matricies than opengl. It also helps when you are trying to sync your model with a collision model (im refering to the coldet library).

I think it also saves on memory but i could be wrong.
See my code. Is this exactly what you mean you are doing? It''s all you need really.

You setup your modelview matrix once for the camera, then push it before applying the model''s transform and pop after drawing each model (which is a straight push of the models verts to the card).

I think you are saying you do all of your transforms in your code, rather than letting OpenGL do it yes? There isn''t a problem with this except on newer (T&L) cards you will get acceleration of the matrix routines if you use GL.

This topic is closed to new replies.

Advertisement