Archived

This topic is now archived and is closed to further replies.

jjthebear

Camera Controls

Recommended Posts

jjthebear    122
Ok, I''m redoing my camera controls approach and I have a new idea. First of all, lets talk about my vectors: Vector position; // this is where the camera is Vector viewing; // this is what the camera is looking at Vector up; // this is the "up" vector My question is regarding the up vector. When I move the mouse, I want the viewing vector to change. However, that also means that the up vector must change as well (doesn''t it?). So for example, when the cameras viewing''s pitch goes down, the up vector must pan forward so to speak so that it is perpendicular to the line segment between the viewing vector and the position vector. How do I get the new up vector based off of just the viewing vector and the position vector. It has to be possible, but my friends say I must use a vector to the right of the position or some other shannagins. How does the cross product play into this? Thanks a lot

Share this post


Link to post
Share on other sites
I prefer using Quaternions for Camera controls to avoid Gimbal lock. But I''ve encounter this problem before using vector cameras. First off, I have a Position, a Look-At point and an Up vector. I use the those three variables to calculate a "Right" vector. To Calculate the right vector I simply take the cross of the Up vector and the vector that is form from the Position and the Look-At point. When calculating Yaw you rotate the LookAt vector(Normalize(Look-At point - Position)) and the Right vector around the Up vector. Then for pitch rotation the Up and the LookAt vector around the right. Roll would be the Up and Right around the LookAt vector


  
Vector Position;
Vector LookAt;
Vector UpDir;
Vector Right;
Vector LookAtDir;

Position = ...;
LookAt = ...;
UpDir = ...;

LookAtDir = LookAt - Position;
Normalize(LookAtDir);

Right = Cross(LookAtDir, UpDir);

// perform rotations here


Share this post


Link to post
Share on other sites
jjthebear    122
I''m a little confused. Why do you need to calculate yaw and why do you need to calculate the right vector if you already have your up, position, and viewing? Check out my approach for changing the viewing vector:

void CCamera::UpdateByMouse(int nChangeX, int nChangeY) {
CVector vecs;
CMatrixMath mats;
m_fYaw+= (float)nChangeX / m_fSensitivity;
// Create the x rotation matrix
float xRotMat[16];
memset(xRotMat, 0, sizeof(float)*16);
xRotMat[0] = 1;
xRotMat[5] = cos(m_fYaw);
xRotMat[6] = -1*sin(m_fYaw);
xRotMat[9] = sin(m_fYaw);
xRotMat[10] = cos(m_fYaw);
mats.MatrixByVector(xRotMat, &m_camViewing, &m_camViewing);
m_camUp = vecs.CrossProductVEC(m_camRightside, m_camViewing);
vecs.Normalize(&m_camUp);
return;
}

I tried this out, and it works except for two things.

1) The viewing keeps changing even when I''m not moving my mouse.
2) The my right vector (which is used to calculate the up vector) does not change, which I believe to be causing a problem with the viewing.

Share this post


Link to post
Share on other sites
jjthebear    122
My New Approach (MNA copyright 2003 :

My plan is to store three unit vectors. They start as being:

1, 0, 0 (x axis)
0, 1, 0 (y axis)
0, 0, 1 (z axis)

I am also going to store some points in 3d which are:

camera position
camera viewing

When the player moves the mouse left, the first thing that will happen is all 3 of my vectors on the x, y, and z axis''s get multiplied by the same matrix glRotatef uses however only after my yaw angle gets enlarged.

Now suppose the player moves forward, then the x vector gets added onto the camera position. Suppose the player moves up, the y value gets added onto the camera position. When strafing, the z axis. Isn''t that insane?

However I need to find the glRotatef() matrix. A teacher at my school told me that was what I needed but I can''t seem to find it. Any help would be appreciated. Thanks

Share this post


Link to post
Share on other sites