Game Development Reference
In-Depth Information
matrix. The class also has an operator * to multiply two quaternions, which performs
a similar mathematical operation as concatenating matrices. The modifiers let you
normalize a quaternion and perform a spherical linear interpolation on them. You
saw the interpolation in the previous pages when I showed you how to orient the
teapot in between two different rotations. Slerp() does the same thing.
The identity quaternion is also provided as a global static so you can get to it quickly,
especially for initializing a quaternion. This is something I like to do instead of forc-
ing a default initialization all the time. You can use it if you want and start with the
identity, or you can use one of the builder methods.
The Plane Class
The plane is an extremely useful mathematical device for 3D games. Here
'
s a simple
wrapper around the DirectX plane structure, D3DXPLANE:
class Plane : public D3DXPLANE
{
public:
inline void Normalize();
// normal faces away from you if you send in verts
// in counter clockwise order....
inline void Init(const Vec3 &p0, const Vec3 &p1, const Vec3 &p2);
bool Inside(const Vec3 &point, const float radius) const;
bool Inside(const Vec3 &point) const;
};
inline void Plane::Normalize()
{
float mag;
mag = sqrt(a *a+b*b+c*c);
a = a / mag;
b = b / mag;
c = c / mag;
d = d / mag;
}
inline void Plane::Init(const Vec3 &p0, const Vec3 &p1, const Vec3 &p2)
{
D3DXPlaneFromPoints(this, &p0, &p1, &p2);
Normalize();
}
bool Plane::Inside(const Vec3 &point) const
 
Search WWH ::




Custom Search