C++ Man Page

C Man Page


C++ man page

pfVec3(3pf)

NAME

pfVec3 - 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);
     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

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
     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.

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


C man page

pfVec3(3pf)

NAME

pfAddScaledVec3, pfAddVec3, pfEqualVec3, pfAlmostEqualVec3, pfCombineVec3, pfCopyVec3, pfCrossVec3, pfDistancePt3, pfDotVec3, pfLengthVec3, pfNegateVec3, pfNormalizeVec3, pfScaleVec3, pfSetVec3, pfSqrDistancePt3, pfSubVec3, pfXformVec3, pfXformPt3, pfFullXformPt3 - Set and operate on 3-component vectors

FUNCTION SPECIFICATION

#include <Performer/pr.h>
#include <Performer/prmath.h>
void
pfAddScaledVec3(pfVec3 dst, const pfVec3 v1, float s, const pfVec3 v2);
     void    pfAddVec3(pfVec3 dst, const pfVec3 v1, const pfVec3 v2);
     int     pfEqualVec3(const pfVec3 v1, const pfVec3 v2);
     int     pfAlmostEqualVec3(const pfVec3 v1, const pfVec3 v2, float tol);
void
pfCombineVec3(pfVec3 dst, float s1, const pfVec3 v1, float s2, const pfVec3 v2);
     void    pfCopyVec3(pfVec3 dst, const pfVec3 v);
     void    pfCrossVec3(pfVec3 dst, const pfVec3 v1, const pfVec3 v2);
     float   pfDistancePt3(const pfVec3 pt1, const pfVec3 pt2);
     float   pfDotVec3(const pfVec3 v1, const pfVec3 v2);
     float   pfLengthVec3(const pfVec3 v);
     void    pfNegateVec3(pfVec3 dst, const pfVec3 v);
     float   pfNormalizeVec3(pfVec3 v);
     void    pfScaleVec3(pfVec3 dst, float s, const pfVec3 v);
     void    pfSetVec3(pfVec3 dst, float x, float y, float z);
     float   pfSqrDistancePt3(const pfVec3 pt1, const pfVec3 pt2);
     void    pfSubVec3(pfVec3 dst, const pfVec3 v1, const pfVec3 v2);
     void    pfXformVec3(pfVec3 dst, const pfVec3 v, const pfMatrix m);
     void    pfXformPt3(pfVec3 dst, const pfVec3 v, const pfMatrix m);
     void    pfFullXformPt3(pfVec3 dst, const pfVec3 v, const pfMatrix m);
typedef float pfVec3[3];

DESCRIPTION

Math functions for 3-component vectors. Most of these routines have macro equivalents.

     pfSetVec3(dst, x, y, z): dst[0] = x, dst[1] = y, dst[2] = z.  Macro
     equivalent is  PFSET_VEC3.
     pfCopyVec3(dst, v): dst = v.  Macro equivalent is  PFCOPY_VEC3.
     pfNegateVec3(dst, v): dst = -v.  Macro equivalent is  PFNEGATE_VEC3.

pfAddVec3(dst, v1, v2): dst = v1 + v2. Sets dst to the sum of vectors v1 and v2. Macro equivalent is PFADD_VEC3.

     pfSubVec3(dst, v1, v2): dst = v1 - v2.  Sets dst to the difference of v1
     and v2.  Macro equivalent is  PFSUB_VEC3.
     pfScaleVec3(dst, s, v): dst = s * v1.  Sets dst to the vector v scaled by
     s.  Macro equivalent is  PFSCALE_VEC3.

pfAddScaledVec3(dst, v1, s, v2): dst = v1 + s * v2. Sets dst to the vector v1 plus the vector v2 scaled by s. Macro equivalent is PFADD_SCALED_VEC3.

pfCombineVec3(dst, s1, v1, s2, v2): dst = s1 * v1 + s2 * v2. Sets dst to be the linear combination of v1 and v2 with scales s1 and s2, respectively. Macro equivalent: PFCOMBINE_VEC3.

pfNormalizeVec3(v): v = v / length(v). Normalizes the vector v to have unit length and returns the original length of the vector.

pfCrossVec3(dst, v1, v2): dst = v1 X v2. Sets dst to the cross-product of two vectors v1 and v2.

pfXformVec3(dst, v, m): dst = v4 * m (v4[i]=v[i] i=0, 1, 2; v4[3] = 0). Transforms v as a vector by the matrix m.

pfXformPt3(dst, v, m): dst = v4 * m (v4[i]=v[i] i=0, 1, 2; v4[3] = 1). Transforms v as a point by the matrix m using the 4X3 submatrix.

pfFullXformPt3(dst, v, m): dst = v4 * m (v4[i]=v[i] i=0, 1, 2; v4[3] = 1). Transforms v as a point by the matrix m using the full 4X4 matrix and scaling dst by the resulting w coordinate.

     pfDotVec3(v1, v2) = v1 dot v2 = v1[0] * v2[0] + v1[1] * v2[1] + v1[2] *
     v2[2].  Returns dot product of the vectors v1 and v2.  Macro equivalent
     is  PFDOT_VEC3.
     pfLengthVec3(v) = |v| = sqrt(v dot v).  Returns length of the vector v.
     Macro equivalent is  PFLENGTH_VEC3.

pfSqrDistancePt3(v1, v2) = (v1 - v2) dot (v1 - v2). Returns square of distance between two points v1 and v2. Macro equivalent is PFSQR_DISTANCE_PT3.

     pfDistancePt3(v1, v2) = sqrt((v1 - v2) dot (v1 - v2)).  Returns distance
     between two points v1 and v2.  Macro equivalent is  PFDISTANCE_PT3.
     pfEqualVec3(v1, v2) = (v1 == v2).  Tests for strict component-wise
     equality of two vectors v1 and v2 and returns FALSE or TRUE.  Macro
     equivalent is  PFEQUAL_VEC3.

pfAlmostEqualVec3(v1, v2, tol). Tests for approximate component-wise equality of two vectors v1 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.

Routines can accept the same vector as source, destination, or as a repeated operand.

SEE ALSO

pfMatrix, pfVec2, pfVec4