Original Post
I'm not sure if this is in the right forum or not, but it's the closest one I could find. I'm using MDX(yea, so sue me). I'm trying to make a Quaternion-based camera based off of this tutorial: http://www.gamedev.net/reference/programming/features/quatcam/ Anyways, I've got a good grasp on how Quaternions work but I still can't seem to get my Camera class to work properly. None of the rotations effect the camera AT ALL, it just keeps looking in the same direction. I don't think this is a programming issue, but more math related. Here's the Camera class:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace MDXTemplate
{
public class Camera
{
private Vector3 Position;
private Vector3 LookAt;
private Vector3 UpDir;
public Camera( )
{
Position = Vector3.Empty;
LookAt = Vector3.Empty;
UpDir = new Vector3( 0, 1, 0 );
}
public Camera( Vector3 position, Vector3 lookAt, Vector3 upDir )
{
Position = position;
LookAt = lookAt;
UpDir = upDir;
}
public void RotateCamera( float angle, Vector3 axis )
{
Quaternion rotation, lookAt, result;
rotation = new Quaternion( );
rotation.X = axis.X * (float) Math.Sin( angle / 2 );
rotation.Y = axis.Y * (float) Math.Sin( angle / 2 );
rotation.Z = axis.Z * (float) Math.Sin( angle / 2 );
rotation.W = (float) Math.Cos( angle / 2 );
lookAt = new Quaternion( LookAt.X, LookAt.Y, LookAt.Z, 0 );
result = ( rotation * lookAt ) * Quaternion.Conjugate( rotation );
LookAt = new Vector3( result.X, result.Y, result.Z );
}
// Aspect Ratio is Window width/height.
public void UpdateCamera( Device device, float aspectRatio )
{
device.Transform.Projection = Matrix.PerspectiveFovLH( (float) Math.PI / 4, aspectRatio, 100.0f, -10000.0f );
device.Transform.View = Matrix.LookAtLH( Position, LookAt, UpDir );
}
}
}
Any help would be greatly appreciated.