184
Appendix A: Cosmo Basic Types
Vector Math
Vectors are used in a variety of ways in Cosmo 3D. Commonly, they are used to define
orientation, rotation, and transformations. Cosmo 3D provides the following
multi-dimensional vectors.
• csVec2f— represents a two-element floating point vector.
• csVec3f— represents a three-element floating point vector.
• csVec3s— represents a three-element short-integer vector.
• csVec4f— represents a four-element floating point vector, often used as a
homogenous space coordinate.
• csVec4ub— represents a four-element unsigned byte vector, most often used as a
color value. The elements range from 0 to 255, inclusive.
Vector Methods
The methods in the csVec2f, csVec3f, csVec3s, csVec4f, classes are similar; the differences
between them stem only from additional argument members that account for the
different dimensions of the classes. The following discussion describes the csVec4f class,
but can easily be extended to the other classes as well.
The classes use the following overridden get() and set() methods to return and define,
respectively, the vectors.
void set(float a, float b, float c, float d);
void get(float *a, float *b, float *c, float *d) const;
void set(int i, float f);
float get(int i) const;
void set(const csVec4f &v);
void get(csVec4f &v) const;
For the csVec2f and csVec3f classes, only two or three arguments, respectively, are
passed to the set and get methods.