00001 #ifndef __VEC4__
00002 #define __VEC4__
00003
00004 #include "Vec3.h"
00005 #include <QString>
00006 #include <QDomElement>
00007 #include <QDomDocument>
00008
00009 namespace apig {
00010
00014 class Vec4 {
00015 public:
00016 Vec4(float x, float y, float z, float w = 1);
00017 Vec4();
00018 Vec4(float c);
00019 Vec4(Vec3 v, float w = 1);
00020 Vec4(const float *v);
00021
00022 Vec4(const QDomElement &element);
00023
00024
00025
00026
00027 inline float& operator[](int i) { return v[i]; }
00028 inline operator const float* () const { return v; }
00029
00030 Vec3 toVec3() const;
00031 QString toQString() const;
00032
00033 QDomElement domElement(const QString &name, QDomDocument &document) const;
00034 void initFromDOMElement(const QDomElement &element);
00035
00036
00037
00038 friend Vec4 dir(const Vec4 &a, const Vec4 &b);
00039 void homogenize();
00040
00041 float xn() const { return x / w; }
00042 float yn() const { return y / w; }
00043 float zn() const { return z / w; }
00044
00045
00046
00047
00048 friend Vec4 operator-(const Vec4 &a);
00049
00050
00051 friend Vec4 operator+(const Vec4 &a, const Vec4 &b);
00052 friend Vec4 operator-(const Vec4 &a, const Vec4 &b);
00053 friend Vec4 operator*(const Vec4 &a, const Vec4 &b);
00054 friend Vec4 operator/(const Vec4 &a, const Vec4 &b);
00055
00056
00057 friend Vec4 operator*(float s, const Vec4 &a);
00058 friend Vec4 operator*(const Vec4 &a, float s);
00059 friend Vec4 operator/(float s, const Vec4 &a);
00060 friend Vec4 operator/(const Vec4 &a, float s);
00061
00062
00063 Vec4& operator+=(const Vec4 &a);
00064 Vec4& operator-=(const Vec4 &a);
00065 Vec4& operator*=(const Vec4 &a);
00066 Vec4& operator/=(const Vec4 &a);
00067 Vec4& operator*=(float s);
00068 Vec4& operator/=(float s);
00069
00070
00071
00072 friend bool operator==(const Vec4 &a, const Vec4 &b);
00073 friend bool operator!=(const Vec4 &a, const Vec4 &b);
00074
00075 friend bool operator>=(const Vec4 &a, const Vec4 &b);
00076 friend bool operator<=(const Vec4 &a, const Vec4 &b);
00077 friend bool operator>(const Vec4 &a, const Vec4 &b);
00078 friend bool operator<(const Vec4 &a, const Vec4 &b);
00079 friend bool operator>=(const Vec4 &a, float b);
00080 friend bool operator<=(const Vec4 &a, float b);
00081 friend bool operator>(const Vec4 &a, float b);
00082 friend bool operator<(const Vec4 &a, float b);
00083
00084
00085
00086 friend Vec4 abs(const Vec4 &a);
00087 friend Vec4 sign(const Vec4 &a);
00088 friend Vec4 floor(const Vec4 &a);
00089 friend Vec4 ceil(const Vec4 &a);
00090 friend Vec4 fract(const Vec4 &a);
00091 friend Vec4 min(const Vec4 &a, const Vec4 &b);
00092 friend Vec4 min(const Vec4 &a, float b);
00093 friend Vec4 max(const Vec4 &a, const Vec4 &b);
00094 friend Vec4 max(const Vec4 &a, float b);
00095 friend Vec4 clamp(const Vec4 &a, const Vec4 &min, const Vec4 &max);
00096 friend Vec4 clamp(const Vec4 &a, float min, float max);
00097 friend Vec4 mix(const Vec4 &a, const Vec4 &b, const Vec4 &alpha);
00098 friend Vec4 mix(const Vec4 &a, const Vec4 &b, float alpha);
00099 friend Vec4 step(const Vec4 &e, const Vec4 &a);
00100 friend Vec4 step(float e, const Vec4 &a);
00101 friend float min(const Vec4 &a);
00102 friend float max(const Vec4 &a);
00103
00104
00105
00106 Vec3 xyz() const { return Vec3(x,y,z); }
00107
00108
00109
00110 static Vec4 random();
00111 static Vec4 random(float min, float max);
00112 static Vec4 random(Vec4 min, Vec4 max);
00113
00114
00115
00116 void glVertex() const;
00117
00118 private:
00119 union {
00120 struct { float x, y, z, w; };
00121 float v[4];
00122 };
00123 };
00124
00125 }
00126
00127 #endif
00128