dhpoware logo
home products source demos contact us
navbar navbar
box top left corner box top right corner
Direct3D Third Person Camera Demo - Part 2 (Springs).

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

In this demo we extend the third person camera model to include a spring system. The camera and the 3D model are attached to each other by a spring. As the user moves the 3D model around the scene the camera is dragged along with it. When the user stops moving the 3D model the camera slowly moves back to its resting position behind the 3D model.

The purpose of the spring system in the third person camera is to smooth out the camera movement. If you disable the camera spring system in the demo the camera will instantly snap to its new position in response to the user's input.

The behavior of the spring system is governed by the spring's stiffness. The less stiff the spring the more laggy the camera becomes. Increasing the spring's stiffness will make the camera less laggy. The correct spring stiffness will depend on your application. However very small stiffness values will cause the camera to lag too far behind the 3D model, and very large stiffness values will negate the spring damping effect on the camera.

A new third person camera implementation is used in this demo. This demo's ThirdPersonCamera class now incorporates the quaternion based orbit camera implementation introduced in the Direct3D Camera Demo - Part 3. The orbit camera implementation has been extended in this demo to a full third person style camera model.

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.

20 February 2008.
main.cpp: Changed field of view to 80 degrees. Renamed CAMERA_MAX_SPRING_STIFFNESS to CAMERA_MAX_SPRING_CONSTANT. Renamed CAMERA_MIN_SPRING_STIFFNESS to CAMERA_MIN_SPRING_CONSTANT. Updated references to Camera::getSpringStiffness() to Camera::getSpringConstant(). Updated RenderText() to display the camera damping constant.

third_person_camera.h: Added getDampingConstant() method. Renamed getSpringStiffness() to getSpringConstant(). Renamed setSpringStiffness() to setSpringConstant(). Renamed class constant DEFAULT_SPRING_STIFFNESS to DEFAULT_SPRING_CONSTANT. Added class constant DEFAULT_DAMPING_CONSTANT. Renamed member variable m_springStiffness to m_springConstant. Added member variables: m_dampingConstant and m_velocity.

third_person_camera.cpp: Updated setSpringConstant() to calculate m_dampingConstant from the springConstant. Changed the spring system calculations in the updateViewMatrix() method.

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