About viewing and model transformation

Started by
0 comments, last by blizzard999 18 years, 8 months ago
i have two problems: 1.if i want to change the default viewpoint position,then when i draw some objects,i also take some model transformations(translate,rotate and scale and so on)the code like this: glLoadIdentity(); gluLookAt(......); // position (x,y,z) glTranslated(...); glRotated(....); drawobject1(); ..... glLoadIdentity(); gluLookAt(......);// the same position glTranslated(...); glRotated(....); drawobject2(); Is this code right? 2.the model transformation and view transformation are equivalent,but i read a lot of codes using default viewpoint position.if i want change the viewpoint instead of changing the model,is the following code right? glLoadIdentity(); gluLookAt(......); // position (x1,y1,z1) drawobject1(); // draw object1 ..... glLoadIdentity(); gluLookAt(......); // position (x2,y2,z2) drawobject2(); // draw object2 thanks
Advertisement
1)It seems right; GL matrices are transposed respect standard math notation and the matrix multiplications are reversed accordingly (final result must be the same!)
The basic idea is to load the view matrix (camera, ortho, trackball,...) then apply the transformations as you have done.

2)The second question you posted can be used but it's more difficult!!! In practice you can use the matrix you want but the final result must be the same.
Yes, you can move your observer to 'simulate' an object position but this is not simple/usefull! It's more simple to say:

my observer is here -> LookAt
my object 1 is here -> translate1, rotate1
my object 2 is there -> translate2, rotate2

something like this

LookAt()for each object{  PushMatrix();  Translate(object.position);  Rotate(object.rotation);  PopMatrix();}


I suggest you also to implement your own matrix math : you can find a lot of tutorials (google for matrix faq). And you can 'look at' the glu code provided in the Mesa library if you are interested (so you can see how OpenGL project the points you pass)

This topic is closed to new replies.

Advertisement