dhpoware logo
home products source demos contact us
navbar navbar
box top left corner box top right corner
XNA 4.0 Camera Demo.

This Windows XNA application demonstrates how various camera behaviors can be implemented. The following camera behaviors are implemented by 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.

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 is an XNA game component. It's designed to be plugged straight into an existing XNA application and automatically provides the application with an interactive in-game camera. The CameraComponent class processes player input and manipulates the camera based on that input. 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.

This demo makes use of the shaders from the XNA 4.0 Parallax Normal Mapping Demo.

1. This demo requires shader model 2.0 or higher support.
2. This demo is provided in source form only. No pre built binaries are supplied.


zip file Download source, assets, and XNA Game Studio 4.0 solution files.

Change History:

31 March 2011.
Demo.cs: Mouse click-and-drag camera rotation is toggled by pressing the 'C' key. Replaced the existing DemoFont with a new Sprite Font Texture.

CameraComponent.cs: Renamed the file to CameraComponent.cs. Added a new property to the CameraComponent class called ClickAndDragMouseRotation. Added support to the CameraComponent class for mouse click-and-drag camera rotations. This is currently bound to the left mouse button. When this mode is enabled the camera will only rotate when the left mouse button is held down and the mouse dragged in the desired direction to rotate. Quickly pressing the left mouse button and then flicking the mouse in the desired direction to rotate will cause the camera to continuously rotate until the left mouse button is pressed again. This automatic rotation is most useful when combined with the orbit camera behavior.

15 January 2011.
Initial release of demo for XNA Game Studio 4.0. The previous XNA Game Studio 3.0 version of the demo is no longer supported and is now only available upon request.

16 November 2008.
Initial release of demo for XNA Game Studio 3.0. The previous XNA Game Studio 2.0 version of the demo is no longer supported and is now only available upon request.

24 August 2008.
Camera.cs: Updated the elapsed time calculation in the CameraComponent.UpdateCamera() method. The elapsed time in seconds is now calculated based on whether the Game is running with a fixed time step.

30 January 2008.
Initial release of demo for XNA Game Studio 2.0. The original XNA Game Studio Express 1.0 Refresh version of the demo is no longer supported and is now only available upon request.

4 January 2008.
Replaced floor_normal_map.dds with an improved normal map.

Demos.cs: Changed default window size to be a quarter of the desktop resolution. Consolidated the various lighting fields into a Light structure. This is the same Light structure as the one appearing in the parallax_normal_mapping.fx file. Consolidated the various material fields into a Material structure. This is this same Material structure as the one appearing in the effect file. Added ability to turn on/off the floor color map at runtime. Added a simple frame rate counter. Removed the light attenuation field. Replaced it with a light radius. Added specular highlights to the floor material. Renamed UpdateParallaxNormalMappingEffect() method to UpdateEffect(). Some method comments have been removed.

parallax_normal_mapping.fx: Added light attenuation comments. Changed vector outputs from the vertex shaders to float3. Fixed bug in vertex shaders where the worldInverseTransposeMatrix was not being cast to a float3x3. Updated the pixel shaders to use the float3 vector outputs from the vertex shaders.

11 November 2007.
Demo.cs: Enabled parallax normal mapping on the floor by default.

NormalMappingUtils.cs: Replaced the NormalMappedVertex.CalcTangentSpaceVectors() method with the NormalMappedVertex.CalcTangent() method. Removed the bitangent field from the NormalMappedVertex structure.

parallax_normal_mapping.fx: Fixed a bug in the vertex shaders where the tbnMatrix was being incorrectly calculated. The vertex shaders now calculate the bitangent vectors. The vertex shaders now use the handedness stored in the tangent vectors when calculating the bitangent vectors. Removed the no texturing techniques. Added techniques for parallax normal mapping and normal mapping.

14 July 2007.
The demo has been updated with all of the new features from the Direct3D Camera Demo - Part 3. There are too many changes to list here. Please consult the included Changes.txt file for a full list of changes. Some of the more important changes includes:

Replaced arrow.fbx with bigship1.fbx.

parallax_normal_mapping.fx: Added NormalMappingSpotLighting technique.

Demos.cs: Added help text to the DrawText() method. Added camera statistics text to the DrawText() method. Added ability to toggle between parallax and normal mapping for the floor.

Camera.cs: ICamera interface has been updated with the following new methods: Move() and Zoom(). The CameraComponent class now supports 2 different types of camera movement: fixed step, and time based. Fixed step movement is what the previous version of the CameraComponent class supported. This is still supported in this new version of the class through the Move() methods. Time based movement moves the camera based on user supplied velocity and acceleration vectors. Updated Camera.RotateOrbit() method with a new orbit rotation algorithm to improve support for target Y axis orbiting and free orbiting.

box bottom left corner content box box bottom right corner
logo logo