Game Development Reference
In-Depth Information
We use the following D3DX function to compute the dot product
between two vectors:
FLOAT D3DXVec3Dot( // Returns the result.
CONST D3DXVECTOR3* pV1, // Left sided operand.
CONST D3DXVECTOR3* pV2 // Right sided operand.
);
D3DXVECTOR3 u(1.0f, -1.0f, 0.0f);
D3DXVECTOR3 v(3.0f, 2.0f, 1.0f);
// 1.0*3.0 + -1.0*2.0 + 0.0*1.0
// = 3.0 + -2.0
float dot = D3DXVec3Dot( &u, &v ); // = 1.0
Cross Products
The second form of multiplication that vector math defines is the cross
product. Unlike the dot product, which evaluates to a scalar, the cross
product evaluates to another vector. Taking the cross product of two
vectors,
u
and
v
, yields another vector,
p
, that is mutually orthogonal to
u
and
v
. By that we mean
p
is orthogonal to
u
, and
p
is orthogonal to
v
.
The cross product is computed like so:
puv
[(
uv uv
),
(
uv uv
),
(
uv uv
)]
yz zy
zx xz
xy yx
In component form:
p
(
u
v
u
v
)
x
y
z
z
y
p
(
u
v
u
v
)
y
z
x
x
z
p
(
u
v
u
v
)
z
x
y
y
x
Figure 7: Cross product. The vector
u
v=p
is orthogonal
to both
u
and
v
.
Example
: Find
j
=
k
i
= (0, 0, 1)
(1, 0, 0) and verify that
j
is
orthogonal to both
k
and
i
.
Search WWH ::
Custom Search