Game Development Reference
In-Depth Information
friend D3DXVECTOR3 operator * ( FLOAT,
CONST struct D3DXVECTOR3& );
BOOL operator == ( CONST D3DXVECTOR3& ) const;
BOOL operator != ( CONST D3DXVECTOR3& ) const;
} D3DXVECTOR3, *LPD3DXVECTOR3;
Note that D3DXVECTOR3 inherits its component data from
D3DVECTOR , which is defined as:
typedef struct _D3DVECTOR {
float x;
float y;
float z;
} D3DVECTOR;
Like scalar quantities, vectors have their own arithmetic, as you can
see from the mathematical operations that the D3DXVECTOR3 class
defines. Presently you are not expected to know what these methods
do. The following subsections introduce these vector operations as well
as some other D3DX vector utility functions and other important
details about vectors.
Note: Although we are primarily concerned with 3D vectors, we
sometimes work with 2D and 4D vectors in 3D graphics programming.
The D3DX library provides a D3DXVECTOR2 and D3DXVECTOR4 class for
representing 2D and 4D vectors, respectively. Vectors of different
dimensions have the same properties as 3D vectors, namely they
describe magnitudes and directions, only in different dimensions. In
addition, the mathematical operations of vectors can be generalized to
any dimensional vector with the exception of the vector cross product
(see the section titled “Cross Products”), which is only defined in
3 .
Thus, with the exception of the cross product, the operations we dis-
cuss for 3D vectors carry over to 2D, 4D, and even n -dimensional
vectors.
Vector Equality
Geometrically, two vectors are equal if they point in the same direction
and have the same length. Algebraically, we say they are equal if they
are of the same dimension and their corresponding components are
equal. For example, ( u x , u y , u z )=( v x , v y , v z )if u x = v x , u y = v y , and u z = v z .
In code we can test if two vectors are equal using the overloaded
equals operator:
D3DXVECTOR u(1.0f, 0.0f, 1.0f);
D3DXVECTOR v(0.0f, 1.0f, 0.0f);
if( u == v ) return true;
Search WWH ::




Custom Search