   Rotating a camera
  To build my camera I use a right vector, an up vector and a look at vector. By default here are their valuesright = D3DXVECTOR3(1.0f, 0.0f, 0.0f);up = D3DXVECTOR3(0.0f, 1.0f, 0.0f);lookAt = D3DXVECTOR3(0.0f, 0.0f, 1.0f);Building the view matrix will than cause the camera to be built with z out, y up. However, if I want to rotate the camera to say look down, how can I calculate this based up a measurement I give it (radians or degrees)? This is how I build my view matrixD3DXVec3Normalize(&lookAt, &lookAt);D3DXVec3Cross(&up, &lookAt, &right);D3DXVec3Normalize(&up, &up);D3DXVec3Cross(&right, &up, &lookAt);D3DXVec3Normalize(&right, &right);// Fill in the view matrix entries.float x = -D3DXVec3Dot(&m_vPosition, &right);float y = -D3DXVec3Dot(&m_vPosition, &up);float z = -D3DXVec3Dot(&m_vPosition, &lookAt);viewMatrix(0,0) = right.x; viewMatrix(1,0) = right.y; viewMatrix(2,0) = right.z; viewMatrix(3,0) = x;   viewMatrix(0,1) = up.x;viewMatrix(1,1) = up.y;viewMatrix(2,1) = up.z;viewMatrix(3,1) = y;  viewMatrix(0,2) = lookAt.x; viewMatrix(1,2) = lookAt.y; viewMatrix(2,2) = lookAt.z; viewMatrix(3,2) = z;   viewMatrix(0,3) = 0.0f;viewMatrix(1,3) = 0.0f;viewMatrix(2,3) = 0.0f;viewMatrix(3,3) = 1.0f;
  One of these might help:http://www.gamedev.net/community/forums/topic.asp?topic_id=535023http://www.gamedev.net/community/forums/topic.asp?topic_id=443548http://www.gamedev.net/community/forums/topic.asp?topic_id=550529That's just from a search. I've never used DirectX so I wouldn't know for sure.   ;Quote:Original post by HurpHowever, if I want to rotate the camera to say look down, how can I calculate this based up a measurement I give it (radians or degrees)?I'm not quite sure what you mean by this, but my advice would be to abandon the whole right/up/look thing and just work with matrices directly.IMX, when people are looking for first-person motion, they're usually either looking for FPS-style motion (yaw and pitch only) or 6DOF motion (free rotation where rotations always occur about the current local axes).Can you describe the type of motion you're looking for? Or perhaps name a game that exhibits this type of motion? That might make the question a little more clear.   ;Quote:Original post by jykQuote:Original post by HurpHowever, if I want to rotate the camera to say look down, how can I calculate this based up a measurement I give it (radians or degrees)?I'm not quite sure what you mean by this, but my advice would be to abandon the whole right/up/look thing and just work with matrices directly.IMX, when people are looking for first-person motion, they're usually either looking for FPS-style motion (yaw and pitch only) or 6DOF motion (free rotation where rotations always occur about the current local axes).Can you describe the type of motion you're looking for? Or perhaps name a game that exhibits this type of motion? That might make the question a little more clear.The type of viewI am looking for is basically just like looking from a top down perspective, such as an RTS style game. However, I am just unsure how to rotate a camera correctly when using a matrix built from right/up/look.I have tried to work with matrices directly and I am now working with right/up/look so I can experiment, learn more and see what I like better.   ;  There are several ways you could do it. You could make your camera an 'orbital' camera and use spherical angles (e.g. azimuth, elevation, and distance) and build the matrix from there, or you could use a standard 'look at' function (the DX math library includes these) and just make the camera 'look at' the desired target.If you go with the latter approach, the eye position will be the camera position, the target position will be the point you want to look at, and the 'up' vector will be the world up vector for your simulation. This will work unless you happen to be looking straight down or nearly straight down at the target; if you anticipate that happening, you may need to use a different method.I wouldn't recommend trying to rotate the side/up/look vectors manually though, as this will basically just be doing work manually that can be done more elegantly using matrices.   ;  Well that problem is that I do want to just look straight down, so I can't just use a "LookAt" function, such as the on D3DX provides, or one I write on my own.I suppose that if there is "no correct way" to have a camera look down when using a right/up/look vectors then I will once again go back to using just plain matricies.However, my reason to going from matricies to right/up/view was because I could never figure out how to do mouse look and how to apply a forward motion to the camera. Could you please explain how to do this or where I can learn how to do this?   ;Quote:Original post by HurpWell that problem is that I do want to just look straight down, so I can't just use a "LookAt" function, such as the on D3DX provides, or one I write on my own.I suppose that if there is "no correct way" to have a camera look down when using a right/up/look vectors then I will once again go back to using just plain matricies.However, my reason to going from matricies to right/up/view was because I could never figure out how to do mouse look and how to apply a forward motion to the camera. Could you please explain how to do this or where I can learn how to do this?Well, I'm not really sure what type of motion you're looking for, so I probably can't offer specific suggestions in that area. However, regarding the 'look at' problem, you can certainly use a 'look at' function even if the camera is pointing straight down; you just have to use an appropriate 'reference up' vector (one that won't cause the 'look at' function to fail).If you can explain in more detail what type of interface you want for the camera, I or someone else could probably make some suggestions.   ;  The camera I am creating I want to be used for two things, my game (first person) and my level editor. There is a few "must have things" that I need for the camera.1) Ability to apply forward motion (Can do with Right/Up/Look, not with matrices)2) Ability to do a mouse look (Can do with Right/Up/Look, not with matrices)3) Ability to "rotate" the camera, ie, look straight down, look straight at the left size (Can do with matrices, not with Right/Up/Look)The looking straight down would be the same for if it was maya or any other level editor, it would simply be looking down at all times while I can then move around the x/z and zoom the y.   ;Quote:Original post by Hurp1) Ability to apply forward motion (Can do with Right/Up/Look, not with matrices)2) Ability to do a mouse look (Can do with Right/Up/Look, not with matrices)3) Ability to "rotate" the camera, ie, look straight down, look straight at the left size (Can do with matrices, not with Right/Up/Look)You can do all three of those with either matrices or axis-vectors, though the one may be simpler than the other for a given operation.Keep in mind that you can *always* derive the right/up/left vectors from a given matrix. Just multiply the unit right/up/left vector by the matrix, and viola, you have the right/up/left vector represented by the matrix...   ;Quote:Original post by swiftcoderYou can do all three of those with either matrices or axis-vectors, though the one may be simpler than the other for a given operation.I knew that it was possible, what I wanted to say was that I do not understand how to do it.Quote:Original post by swiftcoderKeep in mind that you can *always* derive the right/up/left vectors from a given matrix. Just multiply the unit right/up/left vector by the matrix, and viola, you have the right/up/left vector represented by the matrix...I thought about something like this, here is what I was thinkingD3DXMatrixRotationYawPitchRoll(&mRotation, vRotation.y, vRotation.x, m_vRotation.z);D3DXVec3TransformCoord(&right, &right, &mRotation);D3DXVec3TransformCoord(&up, &up, &mRotation);D3DXVec3TransformCoord(&lookAt, &lookAt, &mRotation);Should I be rotating all of the vectors? I mean, I thought if it was a y up simulation then the up vector should always be (0, 1, 0)   