XNA Creators Club Online
Page 1 of 1 (9 items)
Sort Posts: Previous Next

General purpose quaternion camera component released

Last post 10-05-2007 1:08 PM by Virag Stefan. 8 replies.
  • 05-31-2007 11:01 AM

    General purpose quaternion camera component released

    I've been using a camera game component for some time in my projects. This camera code started off as a bunch of loosely related utility functions that I needed at the time in my projects. More and more features were added over time and eventually the code got refactored into an XNA game component. I use this camera component all the time and I'm hoping the community will benefit from it as well.

    I've put together a small demo that shows off most of the camera component's features. The camera component is quaternion based and implements 4 different camera types - the camera component refers to these camera types as behaviors. These are: first person, spectator, flight, and orbit. First person is self explanatory. Spectator is similar to first person but the camera moves in the direction that it's pointing. Flight mimics a flight sim's controls. Finally orbit is a third person style camera mode that rotates around a target.

    All of the camera logic is contained in the camera.cs file. This file contains an interface (ICamera) and 2 implementations of this interface (Camera and CameraComponent).

    The Camera class contains the implementation of the ICamera interface and is designed to be directly manipulated by other classes in your application. The Camera class does not contain any kind of logic to process player input. You should look at the Camera class to understand the math behind the various camera behaviors.

    The CameraComponent class contains an instance of the Camera class. The CameraComponent interacts with the XNA framework and then processes player input by delegating all camera logic to the Camera class.

    For further details and download links please visit www.dhpoware.com.
  • 06-27-2007 9:15 PM In reply to

    Re: General purpose quaternion camera component released

    How do I use your Camera class in my 3D game? I wish to replace the floor in the demo program with a 3D model loaded from DirectX mesh file.
  • 06-28-2007 10:48 AM In reply to

    Re: General purpose quaternion camera component released

    Thanks for adding this to the community.  I'm going to give it a try. :)
    --
    Gamer Outfit - XNA News and Reviews
    Maker of Exisled - Helicopter 2d/3d Shooter available now!
  • 07-02-2007 1:04 AM In reply to

    Re: General purpose quaternion camera component released

    jeff1956:
    How do I use your Camera class in my 3D game? I wish to replace the floor in the demo program with a 3D model loaded from DirectX mesh file.


    I'm assuming you want to use the CameraComponent class.

    Here's the basic steps:

    1. Create an instance of the CameraComponent class and pass it your Game class.
    CameraComponent camera = new CameraComponent(this);

    2. Register the CameraComponent with the framework.
    this.Components.Add(camera);

    That's all there is to it. The framework will call the CameraComponent's Update() method once per frame to update the camera's state.

    The CameraComponent class' constructor sets up a bunch of default keyboard mappings. These can be changed using the MapActionToKey() method.

    There's a bunch of properties that you can call to retrieve important state information from the CameraComponent. The most important ones include: ProjectionMatrix, Position, ViewDirection, and ViewMatrix.

    HTH.
  • 07-02-2007 6:25 AM In reply to

    Re: General purpose quaternion camera component released

    I have two suggestions:

    Add keys for turning the camera to left or right. The "A" and "D" keys move the camera left or right without turning the camera.

    A camera mode for driving/racing games with the camera attached to a 3D model of a vehicle.

  • 07-14-2007 7:55 AM In reply to

    Re: General purpose quaternion camera component released

    I've released a new version of the XNA Camera demo. This new version contains many new features and bug fixes. For further details and download links visit www.dhpoware.com.
  • 10-02-2007 12:25 AM In reply to

    Re: General purpose quaternion camera component released

    I just want to give you my thanks for this component!!!  I know that conceptually an orbit camera is not terribly complex, yet there's been something not clicking about it for me. 

    Moving from conceptual descriptions and technical papers to an implementation that can orbit around an arbitrary point rather than just the origin has been a challenge for me thus far, and your demo demonstrates the behavior that I want PERFECTLY!

    Much thanks!

    [EDIT] After peeking around in the code some, I am motivated to come back here and give additional thanks for the several links I've found so far in the code's comments for "further reading".  I love it when people do that.
  • 10-04-2007 8:37 PM In reply to

    Re: General purpose quaternion camera component released

    Takuan Daikon:
    After peeking around in the code some, I am motivated to come back here and give additional thanks for the several links I've found so far in the code's comments for "further reading".  I love it when people do that.

    Thanks. Camera code can get very tricky. Those links helped me out when I was writing the camera component.
  • 10-05-2007 1:08 PM In reply to

    Re: General purpose quaternion camera component released

    Nice!
    I haven't had any camera isuess so far, but still the way you laid the demo scene, commented everything, really deservers more comments ;) .. And apart from this, all of your samples are great (c#-wise)..
    __________________________________________________________________
    Stefan Virag | XNA Framework Developer
Page 1 of 1 (9 items) Previous Next
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG