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

Camera rotation

Started by f001error Nov 10, 2006 at 9:17 AM 5 replies 1.8k views
Original Post
f001error
f001error
G'day, I'm trying to write a Camera class for my DX engine that i'm building to teach myself DX programming. I can get it to move along the 3 axis fine, but rotation has got me stumped. I'm using the D3DXMatrixLookAtLH function to create my view matrix and it needs two D3DXMatrix's, one for it's position (easy) and one for the location it's looking at (hard). If I want to create a flying FPS style camera, so when you move the mouse around it rotates the camera. I thought about working out how far the mouse moved and feeding that into D3DXMatrixRotationYawPitchRoll, but that seem's to be only for mesh's when your doing the world transform. So then I thought about trying to calculate where I would be looking at if I rotated along the X/Y axis by a certain amount and couldn't really work out how'd I'ld do such a thing. I've had a flick through the matrix math functions, and none of them seem promising, so I'm stuck :P So, any idea's tips greatly appricated
cNoob
cNoob
Check This Out! Its a very nice way of implementing a camera system using D3D. I havnt read over the tutorial yet but I did download the example project and it uses the mouse to look around. Good luck in implenting it!
f001error
f001error
It wouldn't compile for me straight off the bat, some of the Y variables in the for loop weren't declared properly. Fixed it, and its working now. Now to see how it works :D Thx 4 the link
cNoob
cNoob
Yeh I had the same problems too, but the code looks very interesting I will defiantly be looking at it in more detail later on tonight.
f001error
f001error
Hmm, well I've hacked it into my code, but having a werid problem with mouse rotation. Looking up and down works fine, but when I look left or right it spin's the entire world around a fixed point on the screen, rather than rotate the camera so a different perspective is seen. Screenies probably make more sense :P

Start view,
Free Image Hosting at allyoucanupload.com

Looking down a bit, works fine.
Free Image Hosting at allyoucanupload.com

Looking left, spins the world around an imaginary point on the screen
Free Image Hosting at allyoucanupload.com

Edit a zillion times, finally got images working. Clicky for bigger image
f001error
f001error
Okay...fixed it, but I really don't understand how i fixed it I just followed my gut making hacky changes, and yeah it works now. Changed:

void CCamera::Rotate(){D3DXVECTOR3 vDirection,vRotAxis;D3DXMATRIX matRotAxis,matRotZ;D3DXVec3Normalize(&vDirection,&(m_vLookAtPt - m_vEyePt));D3DXVec3Cross(&vRotAxis,&vDirection,&m_vUp);D3DXVec3Normalize(&vRotAxis,&vRotAxis);D3DXMatrixRotationAxis(&matRotAxis,&vRotAxis,g_pInput->GetRelativeY() / -360);D3DXMatrixRotationZ(&matRotZ,g_pInput->GetRelativeX() / -360);D3DXVec3TransformCoord(&vDirection,&vDirection,&(matRotAxis * matRotZ));D3DXVec3TransformCoord(&m_vUp,&m_vUp,&(matRotAxis * matRotZ));m_vLookAtPt = vDirection + m_vEyePt;}//Rotate


to D3DXMatrixRotationY(&matRotZ,g_pInput->GetRelativeX() / -360);


Can anyone explain what on earth I just did lol
Murdocr
Murdocr
Before, it was spinning on the z axis, which is why your world was rotated onto it's side. Now that you changed the z to a y, it rotates on th y axis.

Topic Locked

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

Sign in to reply to this topic.