Game Development Reference

In-Depth Information

is nearest to. We could just switch when the contact normal is exactly in the direction

of the Y axis, but if it were very close to being in that direction, we might end up with

numerical problems and an inaccurate result.

if (real_abs(x.x) > real_abs(x.y))

{

// We're nearer the X axis, so use the Y axis as before.

// ...

}

else

{

// We're nearer the Y axis, so use the X axis as a guess.

// ...

}

The Basis Matrix

Before we look at the complete code for calculating the basis, we need to review what

it needs to output. So far I've assumed we'll end up with three vectors that make up

an orthonormal basis.

It is often more convenient to work with a matrix rather than a set of three vectors.

Recall from section 9.4.2 that a matrix can be thought of as a transformation from one

set of axes to another.

At several points in this section we will need to convert between the contact axes

(called “contact coordinates” or “contact space”) and world space. To do this we need

a matrix that performs the conversion.

We saw in section 9.4.2 that a transform matrix from local space into world space

can be constructed by placing the three local-space axes as columns in the matrix. So,

if we have an orthonormal basis consisting of the three vectors

⎡

⎣

⎤

⎦

⎡

⎣

⎤

⎦

⎡

⎣

⎤

⎦

a

b

c

d

e

f

g

h

i

x
local
=

,

y
local
=

,

and

z
local
=

we can combine them into a transform matrix:

⎡

⎤

adg

beh

cf i

⎣

⎦

M
basis
=

If we have a set of coordinates expressed in local space, and we want the coordi-

nates of the same point in world space, we can simply multiply the transform matrix