Jump to content
  • Advertisement
Sign in to follow this  
sunmozhou

About viewing and model transformation

This topic is 4840 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!