pfVec3(3pf) OpenGL Performer 3.2.2 libpr C++ Reference Pages pfVec3(3pf)NAMEpfVec3 - Set and operate on 3-component vectors
FUNCTION SPECIFICATION
#include <Performer/pr/pfLinMath.h>
void* pfVec3::operator new(size_t);
void* pfVec3::operator new(size_t, void *arena);
pfVec3::pfVec3();
pfVec3::pfVec3(float x, float y, float z);
void pfVec3::addScaled(const pfVec3& v1, float s,
const pfVec3& v2);
void pfVec3::add(const pfVec3& v1, const pfVec3& v2);
int pfVec3::equal(const pfVec3& v2);
int pfVec3::almostEqual(const pfVec3& v2, float tol);
void pfVec3::combine(float s1, const pfVec3& v1, float s2,
const pfVec3& v2);
void pfVec3::copy(const pfVec3& v);
void pfVec3::cross(const pfVec3& v1, const pfVec3& v2);
float pfVec3::distance(const pfVec3& pt2);
float pfVec3::dot(const pfVec3& v2);
float pfVec3::length(void);
void pfVec3::negate(const pfVec3& v);
float pfVec3::normalize(void);
void pfVec3::scale(float s, const pfVec3& v);
void pfVec3::set(float x, float y, float z);
float pfVec3::sqrDistance(const pfVec3& pt2);
void pfVec3::sub(const pfVec3& v1, const pfVec3& v2);
void pfVec3::xformVec(const pfVec3& v, const pfMatrix& m);
Page 1
pfVec3(3pf) OpenGL Performer 3.2.2 libpr C++ Reference Pages pfVec3(3pf)
void pfVec3::xformPt(const pfVec3& v, const pfMatrix& m);
void pfVec3::fullXformPt(const pfVec3& v, const pfMatrix& m);
float& pfVec3::operator [](int i);
const float& pfVec3::operator [](int i);
int pfVec3::operator ==(const pfVec3& v);
pfVec3 pfVec3::operator -() const;
pfVec3 pfVec3::operator +(const pfVec3& v);
pfVec3 pfVec3::operator -(const pfVec3& v);
pfVec3& pfVec3::operator =(const pfVec3& v);
pfVec3& pfVec3::operator *=(float d);
pfVec3& pfVec3::operator /=(float d);
pfVec3& pfVec3::operator +=(const pfVec3& v);
pfVec3& pfVec3::operator -=(const pfVec3& v);
pfVec3 pfVec3::operator *(const pfVec3& v, float d);
pfVec3 pfVec3::operator *(float d, const pfVec3& v);
pfVec3 pfVec3::operator /(const pfVec3& v, float d);
pfVec3 pfVec3::operator *(const pfVec3& v, const pfMatrix& m);
struct pfVec3 {
float vec[3];
};
DESCRIPTION
Math functions for 3-component vectors. Most of these routines have
macro equivalents.
Most accesses to pfVec3 go through pfVec3::operator[], but pfVec3 is a
public struct whose data member vec is directly accessible, e.g. when
necessary for passing to a routine expecting a float* such as glColor3fv.
The default constructor pfVec3() is empty and does not initialize the
values in the vector. An initializing constructor pfVec3(float, float,
float) accepts the initial values for the vector. new(arena) allocates a
pfVec3 from the specified memory arena, or from the heap if arena is
Page 2
pfVec3(3pf) OpenGL Performer 3.2.2 libpr C++ Reference Pages pfVec3(3pf)
NULL. new allocates a pfVec3 from the default memory arena (-
pfGetSharedArena). pfVec3s can also be created automatically on the
stack or statically. pfVec3s allocated with new can should be deleted
with pfDelete, not delete.
The name vec has been used below to indicate the pfVec3 on which the
member function is being invoked.
pfVec3::set: vec[0] = x, vec[1] = y, vec[2] = z. Macro equivalent is
PFSET_VEC3.
pfVec3::copy: vec = v. Macro equivalent is PFCOPY_VEC3.
pfVec3::negate: vec = -v. Macro equivalent is PFNEGATE_VEC3.
pfVec3::add: vec = v1 + v2. Sets vec to the sum of vectors v1 and v2.
Macro equivalent is PFADD_VEC3.
pfVec3::sub: vec = v1 - v2. Sets vec to the difference of v1 and v2.
Macro equivalent is PFSUB_VEC3.
pfVec3::scale: vec = s * v1. Sets vec to the vector v scaled by s.
Macro equivalent is PFSCALE_VEC3.
pfVec3::addScaled: vec = v1 + s * v2. Sets vec to the vector v1 plus the
vector v2 scaled by s. Macro equivalent is PFADD_SCALED_VEC3.
pfVec3::combine: vec = s1 * v1 + s2 * v2. Sets vec to be the linear
combination of v1 and v2 with scales s1 and s2, respectively. Macro
equivalent: PFCOMBINE_VEC3.
pfVec3::normalize: vec = vec / length(vec). Normalizes the vector vec to
have unit length and returns the original length of the vector.
pfVec3::cross: vec = v1 X v2. Sets vec to the cross-product of two
vectors v1 and v2.
pfVec3::xformVec: vec = v * m (vec[i]=v[i] i=0, 1, 2; v[3] = 0).
Transforms v as a vector by the matrix m.
pfVec3::xformPt: vec = vec * m (vec[i]=vec[i] i=0, 1, 2; vec[3] = 1).
Transforms vec as a point by the matrix m using the 4X3 submatrix.
pfVec3::fullXformPt: vec = v * m (vec[i]=v[i] i=0, 1, 2; vec[3] = 1).
Transforms vec as a point by the matrix m using the full 4X4 matrix and
scaling dst by the resulting w coordinate.
pfVec3::dot = vec dot v2 = vec[0] * v2[0] + vec[1] * v2[1] + vec[2] *
v2[2]. Returns dot product of the vectors vec and v2. Macro equivalent
is PFDOT_VEC3.
pfVec3::length = |vec| = sqrt(vec dot vec). Returns length of the vector
Page 3
pfVec3(3pf) OpenGL Performer 3.2.2 libpr C++ Reference Pages pfVec3(3pf)
vec. Macro equivalent is PFLENGTH_VEC3.
pfVec3::sqrDistance = (vec - v2) dot (vec - v2). Returns square of
distance between two points vec and v2. Macro equivalent is
PFSQR_DISTANCE_PT3.
pfVec3::distance = sqrt((vec - v2) dot (vec - v2)). Returns distance
between two points vec and v2. Macro equivalent is PFDISTANCE_PT3.
pfVec3::equal = (vec == v2). Tests for strict component-wise equality of
two vectors vec and v2 and returns FALSE or TRUE. Macro equivalent is
PFEQUAL_VEC3.
pfVec3::almostEqual. Tests for approximate component-wise equality of
two vectors vec and v2. It returns FALSE or TRUE depending on whether
the absolute value of the difference between each pair of components is
less than the tolerance tol. Macro equivalent is PFALMOST_EQUAL_VEC3.
float& operator [](int) const float& operator [](int) Accesses indexed
component of vector.
int operator ==(const pfVec3&) Equality comparison operator.
pfVec3 operator -() const Nondestructive unary negation - returns a new
vector.
pfVec3 operator +(const pfVec3&) pfVec3 operator -(const pfVec3&)
Component-wise binary vector addition and subtraction operators.
pfVec3& operator =(const pfVec3&) Vector assignment operator.
pfVec3& operator *=(float) pfVec3& operator /=(float) Component-wise
scalar multiplication and division operators.
pfVec3& operator +=(const pfVec3&) pfVec3& operator -=(const pfVec3&)
Component-wise vector addition and subtraction operators.
pfVec3 operator *(const pfVec3&, float) pfVec3 operator *(float d, const
pfVec3&) pfVec3 operator /(const pfVec3&, float) pfVec3 operator *(const
pfVec3&, const pfMatrix&) Component-wise binary scalar multiplication and
division operators.
Routines can accept the same vector as source, destination, or as a
repeated operand.
NOTES
When using overloaded operators in C++, assignment operators, e.g. "+=",
are somewhat more efficient than the corresponding binary operators, e.g.
"+", because the latter construct a temporary intermediate object. Use
assignment operators or macros for binary operations where optimal speed
is important.
Page 4
pfVec3(3pf) OpenGL Performer 3.2.2 libpr C++ Reference Pages pfVec3(3pf)
C++ does not support array deletion (i.e. delete[]) for arrays of objects
allocated new operators that take additional arguments. Hence, the array
deletion operator delete[] should not be used on arrays of objects
created with new(arena) pfVec3[n].
SEE ALSO
pfMatrix, pfVec2, pfVec4
Page 5