1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
#ifndef VECTOR_3F_H
#define VECTOR_3F_H
class Vector2f;
class Vector3f
{
public:
static const Vector3f ZERO;
static const Vector3f UP;
static const Vector3f RIGHT;
static const Vector3f FORWARD;
Vector3f( float f = 0.f );
Vector3f( float x, float y, float z );
Vector3f( const Vector2f& xy, float z );
Vector3f( float x, const Vector2f& yz );
// copy constructors
Vector3f( const Vector3f& rv );
// assignment operators
Vector3f& operator = ( const Vector3f& rv );
// no destructor necessary
// returns the ith element
const float& operator [] ( int i ) const;
float& operator [] ( int i );
float& x();
float& y();
float& z();
float x() const;
float y() const;
float z() const;
Vector2f xy() const;
Vector2f xz() const;
Vector2f yz() const;
Vector3f xyz() const;
Vector3f yzx() const;
Vector3f zxy() const;
float abs() const;
float absSquared() const;
void normalize();
Vector3f normalized() const;
Vector2f homogenized() const;
void negate();
// ---- Utility ----
operator const float* () const; // automatic type conversion for OpenGL
operator float* (); // automatic type conversion for OpenGL
void print() const;
Vector3f& operator += ( const Vector3f& v );
Vector3f& operator -= ( const Vector3f& v );
Vector3f& operator *= ( float f );
static float dot( const Vector3f& v0, const Vector3f& v1 );
static Vector3f cross( const Vector3f& v0, const Vector3f& v1 );
// computes the linear interpolation between v0 and v1 by alpha \in [0,1]
// returns v0 * ( 1 - alpha ) * v1 * alpha
static Vector3f lerp( const Vector3f& v0, const Vector3f& v1, float alpha );
// computes the cubic catmull-rom interpolation between p0, p1, p2, p3
// by t \in [0,1]. Guarantees that at t = 0, the result is p0 and
// at p1, the result is p2.
static Vector3f cubicInterpolate( const Vector3f& p0, const Vector3f& p1, const Vector3f& p2, const Vector3f& p3, float t );
private:
float m_elements[ 3 ];
};
// component-wise operators
Vector3f operator + ( const Vector3f& v0, const Vector3f& v1 );
Vector3f operator - ( const Vector3f& v0, const Vector3f& v1 );
Vector3f operator * ( const Vector3f& v0, const Vector3f& v1 );
Vector3f operator / ( const Vector3f& v0, const Vector3f& v1 );
// unary negation
Vector3f operator - ( const Vector3f& v );
// multiply and divide by scalar
Vector3f operator * ( float f, const Vector3f& v );
Vector3f operator * ( const Vector3f& v, float f );
Vector3f operator / ( const Vector3f& v, float f );
bool operator == ( const Vector3f& v0, const Vector3f& v1 );
bool operator != ( const Vector3f& v0, const Vector3f& v1 );
#endif // VECTOR_3F_H
|