C# Class Reactor.RCameraComponent

A general purpose quaternion based camera component for XNA. This camera component provides the necessary bindings to the XNA framework to allow the camera to be manipulated by the keyboard, mouse, and game pad. This camera component is implemented in terms of the Camera class. As a result the camera component supports all of the features of the Camera class. The camera component maps input to a series of actions. These actions are defined by the Actions enumeration. Methods are provided to remap the camera components default bindings.
Inheritance: Microsoft.Xna.Framework.GameComponent
Datei anzeigen Open project: reisergames/reactor-v1

Public Methods

Method Description
Initialize ( ) : void

Initializes the CameraComponent class. This method repositions the mouse to the center of the game window.

LookAt ( R3DVECTOR target ) : void

Builds a look at style viewing matrix.

LookAt ( R3DVECTOR eye, R3DVECTOR target, R3DVECTOR up ) : void

Builds a look at style viewing matrix.

MapActionToKey ( Actions action, Keys key ) : void

Binds an action to a keyboard key.

Move ( R3DVECTOR direction, R3DVECTOR distance ) : void

Moves the camera the specified distance in the specified direction.

Move ( float dx, float dy, float dz ) : void

Moves the camera by dx world units to the left or right; dy world units upwards or downwards; and dz world units forwards or backwards.

Perspective ( float fovx, float aspect, float znear, float zfar ) : void

Builds a perspective projection matrix based on a horizontal field of view.

RCameraComponent ( Microsoft.Xna.Framework.Game game ) : System

Constructs a new instance of the CameraComponent class. The camera will have a spectator behavior, and will be initially positioned at the world origin looking down the world negative z axis. An initial perspective projection matrix is created as well as setting up initial key bindings to the actions.

Rotate ( float headingDegrees, float pitchDegrees, float rollDegrees ) : void

Rotates the camera. Positive angles specify counter clockwise rotations when looking down the axis of rotation towards the origin.

UndoRoll ( ) : void

Undo any camera rolling by leveling the camera. When the camera is orbiting this method will cause the camera to become level with the orbit target.

Update ( GameTime gameTime ) : void

Updates the state of the CameraComponent class.

Zoom ( float zoom, float minZoom, float maxZoom ) : void

Zooms the camera. This method functions differently depending on the camera's current behavior. When the camera is orbiting this method will move the camera closer to or further away from the orbit target. For the other camera behaviors this method will change the camera's horizontal field of view.

Private Methods

Method Description
GetMouseWheelDirection ( ) : float

Determines which way the mouse wheel has been rolled. The returned value is in the range [-1,1].

GetMovementDirection ( Vector3 &direction ) : void

Determines which way to move the camera based on player input. The returned values are in the range [-1,1].

HandleGameActivatedEvent ( object sender, EventArgs e ) : void

Event handler for when the game window acquires input focus.

HandleGameDeactivatedEvent ( object sender, EventArgs e ) : void

Event hander for when the game window loses input focus.

PerformMouseFiltering ( float x, float y ) : void

Filters the mouse movement based on a weighted sum of mouse movement from previous frames.

For further details see: Nettle, Paul "Smooth Mouse Filtering", flipCode's Ask Midnight column. http://www.flipcode.com/cgi-bin/fcarticles.cgi?show=64462

PerformMouseSmoothing ( float x, float y ) : void

Averages the mouse movement over a couple of frames to smooth out the mouse movement.

RotateSmoothly ( float headingDegrees, float pitchDegrees, float rollDegrees ) : void

Dampens the rotation by applying the rotation speed to it.

UpdateCamera ( GameTime gameTime ) : void

Updates the state of the camera based on player input.

UpdateInput ( ) : void

Gathers and updates input from all supported input devices for use by the CameraComponent class.

UpdatePosition ( Vector3 &direction, float elapsedTimeSec ) : void

Moves the camera based on player input.

UpdateVelocity ( Vector3 &direction, float elapsedTimeSec ) : void

Updates the camera's velocity based on the supplied movement direction and the elapsed time (since this method was last called). The movement direction is the in the range [-1,1].

Method Details

Initialize() public method

Initializes the CameraComponent class. This method repositions the mouse to the center of the game window.
public Initialize ( ) : void
return void

LookAt() public method

Builds a look at style viewing matrix.
public LookAt ( R3DVECTOR target ) : void
target R3DVECTOR The target position to look at.
return void

LookAt() public method

Builds a look at style viewing matrix.
public LookAt ( R3DVECTOR eye, R3DVECTOR target, R3DVECTOR up ) : void
eye R3DVECTOR The camera position.
target R3DVECTOR The target position to look at.
up R3DVECTOR The up direction.
return void

MapActionToKey() public method

Binds an action to a keyboard key.
public MapActionToKey ( Actions action, Keys key ) : void
action Actions The action to bind.
key Keys The key to map the action to.
return void

Move() public method

Moves the camera the specified distance in the specified direction.
public Move ( R3DVECTOR direction, R3DVECTOR distance ) : void
direction R3DVECTOR Direction to move.
distance R3DVECTOR How far to move.
return void

Move() public method

Moves the camera by dx world units to the left or right; dy world units upwards or downwards; and dz world units forwards or backwards.
public Move ( float dx, float dy, float dz ) : void
dx float Distance to move left or right.
dy float Distance to move up or down.
dz float Distance to move forwards or backwards.
return void

Perspective() public method

Builds a perspective projection matrix based on a horizontal field of view.
public Perspective ( float fovx, float aspect, float znear, float zfar ) : void
fovx float Horizontal field of view in degrees.
aspect float The viewport's aspect ratio.
znear float The distance to the near clip plane.
zfar float The distance to the far clip plane.
return void

RCameraComponent() public method

Constructs a new instance of the CameraComponent class. The camera will have a spectator behavior, and will be initially positioned at the world origin looking down the world negative z axis. An initial perspective projection matrix is created as well as setting up initial key bindings to the actions.
public RCameraComponent ( Microsoft.Xna.Framework.Game game ) : System
game Microsoft.Xna.Framework.Game
return System

Rotate() public method

Rotates the camera. Positive angles specify counter clockwise rotations when looking down the axis of rotation towards the origin.
public Rotate ( float headingDegrees, float pitchDegrees, float rollDegrees ) : void
headingDegrees float Y axis rotation in degrees.
pitchDegrees float X axis rotation in degrees.
rollDegrees float Z axis rotation in degrees.
return void

UndoRoll() public method

Undo any camera rolling by leveling the camera. When the camera is orbiting this method will cause the camera to become level with the orbit target.
public UndoRoll ( ) : void
return void

Update() public method

Updates the state of the CameraComponent class.
public Update ( GameTime gameTime ) : void
gameTime Microsoft.Xna.Framework.GameTime Time elapsed since the last call to Update.
return void

Zoom() public method

Zooms the camera. This method functions differently depending on the camera's current behavior. When the camera is orbiting this method will move the camera closer to or further away from the orbit target. For the other camera behaviors this method will change the camera's horizontal field of view.
public Zoom ( float zoom, float minZoom, float maxZoom ) : void
zoom float /// When orbiting this parameter is how far to move the camera. /// For the other behaviors this parameter is the new horizontal /// field of view. ///
minZoom float /// When orbiting this parameter is the min allowed zoom distance to /// the orbit target. For the other behaviors this parameter is the /// min allowed horizontal field of view. ///
maxZoom float /// When orbiting this parameter is the max allowed zoom distance to /// the orbit target. For the other behaviors this parameter is the max /// allowed horizontal field of view. ///
return void