dhpoware logo
home products source demos contact us
navbar navbar
box top left corner box top right corner
Direct3D Camera Demo - Part 3.

This is the fourth demo in the Direct3D camera demo series and it builds on the Direct3D Camera Demo - Part 2 and the Direct3D Third Person Camera Demo - Part 1.

This demo uses the shaders from the Direct3D 9 HLSL Pixel Lighting Demo and the Direct3D 9 Parallax Normal Mapping Demo.

This demo shows how various camera behaviors can be combined together. The following camera behaviors are implemented in 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.

The camera class that accompanies this demo uses quaternions throughout. Of particular note is the class' implementation of the orbit camera behavior. The orbit camera implementation differs considerably from the third person camera model used in the Direct3D Third Person Camera Demo - Part 1.

The Direct3D Third Person Camera Demo maintains an offset vector and uses quaternions to rotate this offset vector when the camera is being rotated. The new camera position is then used to build a look-at style view matrix.

This demo's orbit logic begins by setting the camera's orientation to that of the orbit target. Rotating the camera will affect this orientation. So far this is exactly how the other camera behaviors (first person, spectator, and flight) work. But once the orbit camera is rotated the camera's view matrix is updated to accommodate the new orientation. To implement a third person orbit style view of the target the camera's position is calculated to be a fixed distance from the target's position. Specifically this demo takes the orbit target's world position and translates this point by m_orbitOffsetDistance world units along the camera's local negative Z axis. This new camera position is then used to update the view matrix.

This demo was built using the June 2010 update of the Microsoft DirectX SDK. The required end-user runtimes can be downloaded here.

1. This demo requires shader model 2.0 or higher support.
2. This demo requires the Visual C++ 2010 Library Runtimes. Download instructions can be found here.

screen shot

zip file Download executable, source, and Visual C++ 2010 solution files.

Change History:

10 July 2010.
Added missing .vcxproj.filters file to the project.

13 June 2010.
Updated solution to Microsoft Visual Studio 2010.

10 April 2008.
blinn_phong.fx: Fixed a bug in the PS_PointLighting() and PS_SpotLighting() functions where the computed light attenuation was not being clamped.

25 March 2008.
Fixed memory leak in CreateNullTexture() function where 'pSurface' was not being released.

2 February 2008.
Updated solution to Microsoft Visual Studio 2008.

19 January 2008.
camera.cpp: Fixed bug in updatePosition() where the displacement was being accidentally clamped to zero when the camera was no longer moving in a particular direction. This resulted in the camera abruptly stopping when it was no longer moving rather than slowly decelerating back to a stationary position.

input.h: Added new methods to the Mouse class: isMouseSmoothing(), weightModifier(), setWeightModifier(), and smoothMouse().

input.cpp: Updated implementation of the Mouse class. Changed WEIGHT_MODIFIER to 0.2f. Modified the update() method to filter the mouse only if mouse smoothing is enabled. Added implementations of the setWeightModifier() and smoothMouse() methods.

main.cpp: Updated the help text in the RenderText() function. Added additional on screen text for the mouse settings. Changed font size to 8 points.

4 January 2008.
blinn_phong.fx: Changed vector outputs from the vertex shaders to float3 types. Moved some of the diffuse and specular color calculations to the vertex shaders. Updated the pixel shaders accordingly.

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.

2 January 2008.
Replaced per_pixel_blinn_phong.fx with blinn_phong.fx.

blinn_phong.fx: Updated with the latest version from the Direct3D 9 HLSL Pixel Lighting Demo.

parallax_normal_mapping.fx: Updated with the latest version from the Direct3D 9 Parallax Normal Mapping Demo.

main.cpp: Refactored lighting and material variables into a Light and Material structure. Renamed DrawFloor(), DrawFrame(), DrawMesh(), and DrawText() to RenderFloor(), RenderFrame(), RenderMesh(), and RenderText(). Replaced sprintf() style string output to using ostringstream.

17 December 2007.
Added new normal map for the floor.

parallax_normal_mapping.fx: Replaced with the version of the parallax_normal_mapping.fx file as found in the Direct3D Parallax Normal Mapping demo.

normal_mapping_utils.h: Replaced the CalcTangentSpaceVectors() function with the CalcTangentVector() function. The CalcTangentVector() function contains the fixed tangent calculation code from the Direct3D Parallax Normal Mapping demo. Changed the tangent member of the Vertex structure from a float[3] to a float[4] array. Removed the bitangent member. Removed setVertexTangentSpace() method. Updated setVertex() method to accept tangent and normal vectors.

normal_mapping_utils.cpp: Added implementation of the CalcTangentVector() function. Updated generate() method calls to CalcTangentSpaceVectors(). Updated the implementation of the setVertex() method.

camera.h: Added setCurrentVelocity() methods. Added overloaded setVelocity() method.

camera.cpp: Added implementations of the setCurrentVelocity() methods. Added implementation of the overloaded setVelocity() method.

main.cpp: Refactored functions so they appear in sorted order. Added function prototypes. Updated the InitFont() function to use ClearType font quality where available. Added GetMovementDirection() function. Updated UpdateCamera() function to call GetMovementDirection() function. The GetMovementDirection() function detects when a movement key is pressed and released and adjusts the camera's current velocity accordingly. When a movement key is first pressed the current velocity for movement in that direction is reset back to zero. This prevents the camera from slowly decelerating and then accelerating in the desired direction of movement. Added ability to disable the floor's color map texture. This is more of a debugging feature to ensure the tangents are correct.

14 July 2007.
input.cpp: Fixed a bug in the Mouse::performMouseSmoothing() method where the m_deltaMouseX and m_deltaMouseY values were being incorrectly calculated.

13 July 2007.
camera.cpp: Updated the updatePosition() method to clamp the displacement along each axis to zero if the camera hasn't moved along that axis. This will prevent floating point rounding errors from slowly accumulating and causing the camera to accidentally move along that axis.

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