Game Development Reference
In-Depth Information
C++ Math Classes
Before we get into the guts of a scene graph and how it works, we
ll need some sim-
ple math classes for handling 3D and 4D vectors, matrices, and quaternions. Most
programmers will create a math library with ultra-efficient implementations of these
and other useful tidbits. For this topic, I ' m using DirectX D3DX math functions and
structures as a base. Here are the reasons why I
'
'
m using this approach:
n The DirectX math functions are fairly well optimized for PC development and
are a fair place to start for console development.
n The new XNA math libraries, which many of the Direct3D 11 samples and
tutorials use, do not easily support encapsulation into classes meant to abstract
their lineage, and they cannot be used by DirectX 9, which is still supported by
the code in this topic. D3DX based structures can be used in Direct3D 9, 10,
and 11.
n By creating some platform-agnostic math classes for use in the scene graph code,
you can replace them with any C++ implementation you like. Personally, I think
the C++ versions are much easier to read, too. These classes are bare bones,
really not much more than the very basics.
The classes you will use throughout the 3D code in this topic include the following:
n Vec3 & Vec4 : Three- and four-dimensional vectors.
n Quaternion : A quaternion that describes orientation in 3D space.
n Mat4 x 4 : A matrix that holds both orientation and translation.
n Plane : A flat surface that stretches to infinity; it has an
inside
and an
outside.
n Frustum : A shape like a pyramid with the point clipped off, usually used to
describe the viewable area of a camera.
Vector Classes
You should already be very familiar with the vector structures used by DirectX
D3DXVECTOR3 and D3DXVECTOR4 . Here
'
s a very simple C++ wrapper for both of
those structures:
class Vec3 : public D3DXVECTOR3
{
public:
inline float Length()
 
 
 
Search WWH ::




Custom Search