Skip to main content
GameDev.net gamedev.net
🔒 Locked

pan,zoom,rotation

Started by TeSsL Mar 19, 2009 at 4:05 AM 5 replies 3k views
Original Post
TeSsL
TeSsL
how am i suppose to do it? i tried using glulookat to change my camera position but after i rotate the lookat point, how am i suppose to do the math?
Lord_Evil
Lord_Evil
Does the camera stay at the same position and just follow the lookat point? Then gluLookAt should suffice. Otherwise you'd have to update the camera position first - based on the change of the lookat point, e.g. calculate cam.pos - lookat, apply the rotation to that vector and add the result to the new look at in order to update the position.

However, you should definitly have a look into vector and matrix math. There are plenty of tutorials on the net and a lot of good primers out there. Even if glTranslate et.al. make transformations quite easy you need a good understanding of matrix and vector math in order to understand how to use them properly (or skip them and use your own calculations).
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
BionicBytes
BionicBytes
Nothing in 3D graphics is easy or free. You will need to invest some time/effort into creating a camera class of sorts. I have different camera classes to allow for different things - eg. one for tracking a player - one for following a spline curve and a basic one for UI work etc... I would suggest defining a camera class interface and then have all camera class instances adhere to this interface. That way later on, regardless of the specific camera class used to interact with the world - you can always call on a standard virtual interface method.

TeSsL
TeSsL
okay i got the translation and rotation part. But how ahould i approach the zoom?
Lord_Evil
Lord_Evil
Generally zoom is achieved by changing the field of view, i.e. zoom in -> decrease FoV
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
Steadtler
Steadtler
And remember that a zoom is different than a dolly (moving the camera forward/backward).
TeSsL
TeSsL
ohh.. but i am trying to achieve my zoom by moving in/out cause am told that it is better to do it like that. thou not sure y.

// Get the resulting matrix from OpenGL it will have our
// direction vector in the 3rd row.
gl.glGetFloatv(GL.GL_MODELVIEW_MATRIX, Matrix, 0);

// Get the direction vector from the matrix. Element 10 must
// be inverted!
m_DirectionVector.x = Matrix[8];
m_DirectionVector.y = Matrix[9];
m_DirectionVector.z = -Matrix[10];

//limit zoom to the lower ground
float yPos;
if(-m_Position.y+m_Zoom>=-2.2)
yPos=-m_Position.y+m_Zoom;
else
yPos=-2.2f;
glu.gluLookAt(m_Position.x+m_Zoom,yPos,m_Position.y+m_Zoom,target.x,target.z,target.y-100,0,1,0);

where target is my mousePosition.

It is moving towards the mouseposition but in a straight manner. How should i form my direction vector? and how should i place it?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.