pfVec2(3pf) OpenGL Performer 3.2.2 libpr C++ Reference Pages pfVec2(3pf)NAMEpfVec2 - Set and operate on 2-component vectors
FUNCTION SPECIFICATION
#include <Performer/pr/pfLinMath.h>
void* pfVec2::operator new(size_t);
void* pfVec2::operator new(size_t, void *arena);
pfVec2::pfVec2();
pfVec2::pfVec2(float x, float y);
void pfVec2::addScaled(const pfVec2& v1, float s, const pfVec2& v2);
void pfVec2::add(const pfVec2& v1, const pfVec2& v2);
int pfVec2::almostEqual(const pfVec2& v2, float tol);
void pfVec2::combine(float s1, const pfVec2& v1, float s2,
const pfVec2& v2);
void pfVec2::copy(const pfVec2& v);
float pfVec2::distance(const pfVec2& pt2);
float pfVec2::dot(const pfVec2& v2);
int pfVec2::equal(const pfVec2& v2);
float pfVec2::length(void);
void pfVec2::negate(const pfVec2& v);
float pfVec2::normalize(void);
void pfVec2::scale(float s, const pfVec2& v);
void pfVec2::set(float x, float y);
float pfVec2::sqrDistance(const pfVec2& pt2);
void pfVec2::sub(const pfVec2& v1, const pfVec2& v2);
float& pfVec2::operator [](int i);
int pfVec2::operator ==(const pfVec2& v);
pfVec2 pfVec2::operator -() const;
Page 1
pfVec2(3pf) OpenGL Performer 3.2.2 libpr C++ Reference Pages pfVec2(3pf)pfVec2 pfVec2::operator +(const pfVec2& v);
pfVec2 pfVec2::operator -(const pfVec2& v);
pfVec2& pfVec2::operator =(const pfVec2& v);
pfVec2& pfVec2::operator *=(float d);
pfVec2& pfVec2::operator /=(float d);
pfVec2& pfVec2::operator +=(const pfVec2& v);
pfVec2& pfVec2::operator -=(const pfVec2& v);
pfVec2 pfVec2::operator *(const pfVec2& v, float d);
pfVec2 pfVec2::operator *(float d, const pfVec2& v);
pfVec2 pfVec2::operator /(const pfVec2& v, float d);
struct pfVec2 {
float vec[2];
};
DESCRIPTION
Math functions for 2-component vectors. Most of these routines have
macro equivalents.
Most accesses to pfVec2 go through pfVec2::operator[], but pfVec2 is a
public struct whose data member vec is directly accessible, e.g. for
passing to a routine expecting a float* such as glTexCoord2fv. The
default constructor pfVec2() is empty and does not initialize the values
in the vector. An initializing constructor pfVec2(float, float) accepts
the initial values for the vector. new(arena) allocates a pfVec2 from
the specified memory arena, or from the heap if arena is NULL. new
allocates a pfVec2 from the default memory arena (pfGetSharedArena).
pfVec2s can also be created automatically on the stack or statically.
pfVec2s allocated with new can be deleted with pfDelete, not delete.
The name vec has been used below to indicate the pfVec2 on which the
member function is being invoked.
pfVec2::set: vec[0] = x, vec[1] = y. Macro equivalent is PFSET_VEC2.
pfVec2::copy: vec = v. Macro equivalent is PFCOPY_VEC2.
pfVec2::negate: vec = -v. Macro equivalent is PFNEGATE_VEC2.
pfVec2::add: vec = v1 + v2. Sets vec to the sum of vectors v1 and v2.
Page 2
pfVec2(3pf) OpenGL Performer 3.2.2 libpr C++ Reference Pages pfVec2(3pf)
Macro equivalent is PFADD_VEC2.
pfVec2::sub: vec = v1 - v2. Sets vec to the difference of v1 and v2.
Macro equivalent is PFSUB_VEC2.
pfVec2::addScaled: vec = v1 + s * v2. Sets vec to the vector v1 plus the
vector v2 scaled by s. Macro equivalent is PFADD_SCALED_VEC2.
pfVec2::scale: vec = s * v1. Sets vec to the vector v scaled by s.
Macro equivalent is PFSCALE_VEC2.
pfVec2::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_VEC2.
pfVec2::normalize: vec = vec / length(vec). Normalizes the vector vec to
have unit length and returns the original length of the vector.
pfVec2::dot = vec dot v2 = vec[0] * v2[0] + vec[1] * v2[1] . Returns dot
product of the vectors vec and v2. Macro equivalent is PFDOT_VEC2.
pfVec2::length = |vec| = sqrt(vec dot vec). Returns length of the vector
vec. Macro equivalent is PFLENGTH_VEC2.
pfVec2::sqrDistance = (vec - v2) dot (vec - v2). Returns square of
distance between two points v1 and v2. Macro equivalent is
PFSQR_DISTANCE_PT2.
pfVec2::distance = sqrt((vec - v2) dot (vec - v2)). Returns distance
between two points vec and v2. Macro equivalent is PFDISTANCE_PT2.
pfVec2::equal = (vec == v2). Tests for strict component-wise equality of
two vectors vec and v2 and returns FALSE or TRUE. Macro equivalent is
PFEQUAL_VEC2.
pfVec2::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_VEC2.
float& operator [](int i) Accesses indexed component of the vector.
int operator ==(const pfVec2&) Equality comparison operator.
pfVec2 operator -() const Nondestructive unary negation - returns a new
vector.
pfVec2 operator +(const pfVec2&) pfVec2 operator -(const pfVec2&)
Component-wise binary vector addition and subtraction operators.
pfVec2& operator =(const pfVec2&) Vector assignment operator.
Page 3
pfVec2(3pf) OpenGL Performer 3.2.2 libpr C++ Reference Pages pfVec2(3pf)
pfVec2& operator *=(float) pfVec2& operator /=(float) Component-wise
scalar multiplication and division operators.
pfVec2& operator +=(const pfVec2&) pfVec2& operator -=(const pfVec2&)
Component-wise vector addition and subtraction operators.
pfVec2 operator *(const pfVec2&, float) pfVec2 operator *(float, const
pfVec2&) pfVec2 operator /(const pfVec2&, float) 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) pfVec2[n].
SEE ALSO
pfMatrix, pfVec3, pfVec4
Page 4