absolute coordinates(not glTranslatef!)

Started by
2 comments, last by Sven 23 years, 1 month ago
with glTranslatef()i can move the "center of drawing", it''s always relative to the last position of glTranslatef(). this is shit when i want to draw a few objects... is it possible to set the new center of drawing to absolute coordinate?
Advertisement
If I''m understnding you right, you can just use glLookAt(). You could also call glPush/PopMatrix() before and after evry item. A slowere yet easier version of this is to call glLoadIdentity() before every glTranslatef().



Open mouth, insert foot
call glLoadIdentity(); before translating each time should work

thuned

life is unfair, take advantage of it.
UNMB2 - if the link doesn''t work, try clicking it
life is unfair, take advantage of it.UNMB2 - if the link doesn't work, try clicking it :)
Well, there are several ways to solve this problem...
One use glLoadIdentity() before drawing each object. the problem with this is that it also resest the rotation.
the second is to push the matrix draw the object the pop the matrix. this works good if you don''t have nested objects as theres no garuentee of the stack depth.
the third method works the best for me and will work great for nested and hirarcial object drawing. use glTranslatef() to translate to the center of drawing before drawing the object then use the negitives of the value to glTranslate to the previous postition afterwords.
A good exapmle of how this can be handy is if you have an object that is made up of 2 or more other objects...

void DrawObjectA(){
glTranslate(CenterOfA_X,CenterOfA_Y,CenterOfA_Z);
< Draw Object A >
glTranslate(-CenterOfA_X,-CenterOfA_Y,-CenterOfA_Z);
}

void DrawObjectB(){
glTranslate(CenterOfB_X,CenterOfB_Y,CenterOfB_Z);
< Draw Object B >
glTranslate(-CenterOfB_X,-CenterOfB_Y,-CenterOfB_Z);
}

void DrawObjectC(){
glTranslate(CenterOfC_X,CenterOfC_Y,CenterOfC_Z);
DrawObjectA();
DrawObjectB();
glTranslate(-CenterOfC_X,-CenterOfC_Y,-CenterOfC_Z);
}

Hope this didn''t confuse you too much!
------------------------------Piggies, I need more piggies![pig][pig][pig][pig][pig][pig]------------------------------Do not invoke the wrath of the Irken elite. [flaming]

This topic is closed to new replies.

Advertisement