first person XNA camera
I have been searching a free camera component.
I have found:
"Free Floating Camera Game Component with Mouse Control " here:
http://xbox360homebrew.com/content/XNATutorialMasterList.aspx
however, it is not available.
In the XNA insttaller, in the documentation, there is a first person camera,
but it does not use the mouse.
Can anybody help?
Doesn't really matter other than to get a feel for how experienced you are with 3D concepts.
More than likely you will have to write your own camera.
I assume your effect file takes View and Projection parameters (or ViewProjection).
The cameras job is to generate those Matrices. I use a camera with the following interface:
public interface ICamera : IComponent
{
Matrix View { get; set; }
Matrix Projection { get; set; }
// view properties (setting these invalidates the View matrix causing it to be recalculated next time it's retrieved)
Vector3 Position { get; set; }
Vector3 Target { get; set; }
Vector3 UpVector { get; set; }
// derived from Vector3.Normalize(Target-Position)
Vector3 Direction { get; set; }
// projection properties (setting these invalidates the Projection matrix causing it to be recalculated next time it's retrieved)
float AspectRatio { get; set; }
float FieldOfView { get; set; }
float ZFarPlane { get; set; }
float ZNearPlane { get; set; }
}
Then I make separate CameraController classes that "control" the "camera". One of these is the "FlyingCameraController". My flying controller listens for mouse input, and then modifies the cameras position and direction vectors. (I always keep the same UpVector). Since you want to fly around thru space and "roll" your spaceship, you will be changing the UpVector as well.
To look up:
Camera.Direction += Camera.UpVector * positiveFactor;
To look down:
Camera.Direction += Camera.UpVector * negativeFactor;
To look left or right
Camera.Direction += Vector3.Cross(Camera.UpVector, Camera.Direction) * someFactor
To roll left or right
Camera.UpVector += Vector3.Cross(Camera.UpVector, Camera.Direction) * someFactor
// all this is assuming that the Direction and UpVectors properties automatically normalize themselves in their setters.
hope this helps if you decide to write your own.
The best way I have found to implement a camera is using Quaternions. That way you don't really have to worry about up vectors and all that, and since we have to use shaders for everything now anyway, it is easier to just turn quaternions into matrices to pass to shaders. I currently have a simple camera game component and an input component that I use to send it movement implemented in my XNA Game Engine tutorials at
http://www.thehazymind.com. I actually just finished the Input component integration to it tonight as my 4th tutorial in my XNA series, so I would suggest taking a look there. Hope it helps