Sign in to follow this  

D3D Quaternion Camera demo released.

Recommended Posts

Not sure whether this should belong here or in the DirectX forums. So please move if the DirectX forums is more appropriate. I've just released the next demo in my Direct3D camera demo series over on my website. This demo shows how various camera behaviors can be combined together. The following camera behaviors are implemented in this demo: first person, spectator, flight, and orbit. The first person camera behavior simulates the view from the perspective of the player. The spectator camera behavior simulates a floating camera that moves in the direction that the camera is looking. The flight camera behavior simulates the view from the cockpit of an airplane. Finally the orbit camera behavior simulates a third person view of the player and allows the camera to orbit the player. The camera class that accompanies this demo uses quaternions throughout. I could have used vectors and/or matrices instead, but I wanted to implement as much of the camera as I could using only quaternions. Of particular note is the camera class' implementation of the orbit camera behavior. Many quaternion-based third person orbit style cameras maintain an offset vector and uses quaternions to rotate this offset vector when the camera is being rotated. The new camera position is then used to rebuild a look-at style view matrix. This demo's orbit logic begins by setting the camera's orientation to that of the orbit target. Rotating the camera will affect this orientation. So far this is exactly how the other camera behaviors (first person, spectator, and flight) work. But once the orbit camera is rotated the camera's view matrix is updated to accommodate the new orientation. To implement a third person orbit style view of the target the camera's position is calculated to be a fixed distance from the target's position. Specifically this demo takes the orbit target's world position and translates this point by a fixed amount along the camera's local negative Z axis. This new camera position is then used to update the view matrix. Further details and download links can be found here.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this