Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

Vector3.h

00001 /*************************************************************************** 00002 * This file is part of OpenCAL: Open Computer Animation Library * 00003 * I created OpenCAL as my master's thesis Computer Science (multimedia) * 00004 * at the tUL university in Diepenbeek, Belgium * 00005 * * 00006 * Copyright (C) 2003-2004 by Jeroen Dierckx * 00007 * jeroen.dierckx@student.luc.ac.be * 00008 * * 00009 ***************************************************************************/ 00010 00011 #ifndef OPENCAL_UTILS_VECTOR3_H 00012 #define OPENCAL_UTILS_VECTOR3_H 00013 00014 // Includes 00015 #include <OpenCAL/global.h> 00016 #include <OpenCAL/Matrix33.h> 00017 #include <OpenCAL/Blendable.h> 00018 00019 namespace OpenCAL 00020 { 00021 namespace Utils 00022 { 00023 // Forward declarations 00024 class Quaternion; 00025 00030 class OPENCAL_API Vector3/*: public Blendable<Vector3>*/ 00031 { 00032 protected: 00033 // Member variables 00034 float m_values[3]; 00035 00036 public: 00037 // Static member variables 00038 static Vector3 zero; 00039 00040 public: 00041 // Constructors and destructor 00042 Vector3(); 00043 Vector3(float x, float y, float z = 0.0f); 00044 Vector3(float *values); 00045 Vector3(const Vector3 &source); 00046 virtual ~Vector3(); 00047 00048 // Get functions 00049 const float *get() const { return m_values; } 00050 float getX() const { return m_values[0]; } 00051 float getY() const { return m_values[1]; } 00052 float getZ() const { return m_values[2]; } 00053 00054 // Set functions 00055 void set(float x, float y, float z = 0.0f); 00056 void set(float *values); 00057 void add(float x, float y, float z = 0.0f); 00058 void add(float *values); 00059 void setX(float x) { m_values[0] = x; } 00060 void setY(float y) { m_values[1] = y; } 00061 void setZ(float z) { m_values[2] = z; } 00062 00063 // Operator functions 00064 Vector3 operator+(const Vector3 &v) const; 00065 Vector3 operator-(const Vector3 &v) const; 00066 Vector3 operator-() const; 00067 Vector3 operator*(float factor) const; 00068 Vector3 operator/(float factor) const; 00069 00070 void operator+=(const Vector3 &v); 00071 void operator-=(const Vector3 &v); 00072 void operator*=(float factor); 00073 void operator/=(float factor); 00074 00075 bool operator==(const Vector3 &v); 00076 bool operator!=(const Vector3 &v); 00077 00078 // Cast operators 00079 operator const float *() const { return m_values; } 00080 00081 // Blend functions 00082 void blend(float u, const Vector3 &dest) { blend(u, *this, dest); } 00083 void blend(float u, const Vector3 &source, const Vector3 &dest); 00084 Vector3 blended(float u, const Vector3 &dest) const { return blended(u, *this, dest); } 00085 Vector3 blended(float u, const Vector3 &source, const Vector3 &dest) const; 00086 00087 // Other functions 00088 float dotProduct(const Vector3 &v) const; 00089 Vector3 crossProduct(const Vector3 &v) const; 00090 00091 float length() const; 00092 float squaredLength() const; 00093 float distance(const Vector3 &v) const; 00094 float squaredDistance(const Vector3 &v) const; 00095 00096 Vector3 normalized() const; 00097 void normalize(); 00098 00099 void rotate(const Quaternion &rot); 00100 Vector3 rotated(const Quaternion &rot) const; 00101 void rotated(const Quaternion &rot, Vector3 *result) const; 00102 00103 Matrix33 star() const; 00104 00105 void print() const; 00106 00107 // Friend functions 00108 friend Vector3 operator*(float factor, const Vector3 &v); 00109 friend Vector3 operator/(float factor, const Vector3 &v); 00110 friend std::ostream &operator<<(std::ostream &stream, const Vector3 &v); 00111 }; 00112 } 00113 } 00114 00115 #endif // OPENCAL_UTILS_VECTOR3_H

Generated on Sun Aug 15 19:19:23 2004 for OpenCAL: Open Computer Animation Library by doxygen 1.3.8