A question about 3D rotation( HELP! )

Started by
1 comment, last by KyosukeNo1 20 years, 6 months ago
I want to make a program that my camera will rotate around the center -- It means, whatever angle my model is in, I can rotate it by the current longitude and latitude, but NOT just rotate it simply like this way: glLoadIdentity(); glTranslatef( 0.0f, 0.0f, m_fDistance ); glRotatef( m_fLatitude, 1.0f, 0, 0 ); glRotatef( m_fLongitude, 0, 1.0f, 0 ); Now I have two ideas: 1. Use m_fDistance, m_fLatitude and m_fLongitude to be the camera position, and then cumulate the rotation angle. It means, translate the model back to origin and then rotate it in current angle: Initial£º glLoadIdentity(); glTranslatef( 0.0f, 0.0f, m_fDistance ); Change£º glTranslatef( 0.0f, 0.0f, m_fDistance ); glRotatef( m_fLatitude, 1.0f, 0, 0 ); glRotatef( m_fLongitude, 0, 1.0f, 0 ); glTranslatef( 0.0f, 0.0f, -m_fDistance ); With my matrix calculation in paper, it seems it can work. But when I practise it in program, it can''t... 2. Use 3 vectors "vPosition, vView, vUpDirection" to be the camera position( like D3D ). In this case, vView will always be the origin. The following is what I do: Latitude rotation: rotate around the vUpDirection. Longitude rotation: "vView - vPosition" to find the forward direction, and then cross product with vUpDirection to find out the right direction. Then rotate around the right direction. Is my second idea right? I haven''t practise it because I can''t find a function to "rotate a position around a vector".
Advertisement
http://www.gametutorials.com

Check out the camera tutorials in the OpenGL section.

Can we add this to the faq or something?

[edited by - Raloth on September 30, 2003 11:08:30 PM]
____________________________________________________________AAAAA: American Association Against Adobe AcrobatYou know you hate PDFs...
In fact, I had read most of the chapters in gametutorials and learnt a lot from it. *^_^*

But I can''t find the solution because that''s not the same case... in camera tutorials it just discuss the "free" move( their "UpDirection" will alway be the Y-axis) but now I want to move around the center and always change my up direction...

This topic is closed to new replies.

Advertisement