Blender V2.61 - r43446

MT_Vector4.inl

Go to the documentation of this file.
00001 #include "MT_Optimize.h"
00002 
00003 GEN_INLINE MT_Vector4& MT_Vector4::operator+=(const MT_Vector4& v) {
00004     m_co[0] += v[0]; m_co[1] += v[1]; m_co[2] += v[2]; m_co[3] += v[3];
00005     return *this;
00006 }
00007 
00008 GEN_INLINE MT_Vector4& MT_Vector4::operator-=(const MT_Vector4& v) {
00009     m_co[0] -= v[0]; m_co[1] -= v[1]; m_co[2] -= v[2]; m_co[3] -= v[3];
00010     return *this;
00011 }
00012  
00013 GEN_INLINE MT_Vector4& MT_Vector4::operator*=(MT_Scalar s) {
00014     m_co[0] *= s; m_co[1] *= s; m_co[2] *= s; m_co[3] *= s;
00015     return *this;
00016 }
00017 
00018 GEN_INLINE MT_Vector4& MT_Vector4::operator/=(MT_Scalar s) {
00019     MT_assert(!MT_fuzzyZero(s));
00020     return *this *= MT_Scalar(1.0) / s;
00021 }
00022 
00023 GEN_INLINE MT_Vector4 operator+(const MT_Vector4& v1, const MT_Vector4& v2) {
00024     return MT_Vector4(v1[0] + v2[0], v1[1] + v2[1], v1[2] + v2[2], v1[3] + v2[3]);
00025 }
00026 
00027 GEN_INLINE MT_Vector4 operator-(const MT_Vector4& v1, const MT_Vector4& v2) {
00028     return MT_Vector4(v1[0] - v2[0], v1[1] - v2[1], v1[2] - v2[2], v1[3] - v2[3]);
00029 }
00030 
00031 GEN_INLINE MT_Vector4 operator-(const MT_Vector4& v) {
00032     return MT_Vector4(-v[0], -v[1], -v[2], -v[3]);
00033 }
00034 
00035 GEN_INLINE MT_Vector4 operator*(const MT_Vector4& v, MT_Scalar s) {
00036     return MT_Vector4(v[0] * s, v[1] * s, v[2] * s, v[3] * s);
00037 }
00038 
00039 GEN_INLINE MT_Vector4 operator*(MT_Scalar s, const MT_Vector4& v) { return v * s; }
00040 
00041 GEN_INLINE MT_Vector4 operator/(const MT_Vector4& v, MT_Scalar s) {
00042     MT_assert(!MT_fuzzyZero(s));
00043     return v * (MT_Scalar(1.0) / s);
00044 }
00045 
00046 GEN_INLINE MT_Scalar MT_Vector4::dot(const MT_Vector4& v) const {
00047     return m_co[0] * v[0] + m_co[1] * v[1] + m_co[2] * v[2] + m_co[3] * v[3];
00048 }
00049 
00050 GEN_INLINE MT_Scalar MT_Vector4::length2() const { return MT_dot(*this, *this); }
00051 GEN_INLINE MT_Scalar MT_Vector4::length() const { return sqrt(length2()); }
00052 
00053 GEN_INLINE MT_Vector4 MT_Vector4::absolute() const {
00054     return MT_Vector4(MT_abs(m_co[0]), MT_abs(m_co[1]), MT_abs(m_co[2]), MT_abs(m_co[3]));
00055 }
00056 
00057 GEN_INLINE void MT_Vector4::scale(MT_Scalar xx, MT_Scalar yy, MT_Scalar zz, MT_Scalar ww) {
00058     m_co[0] *= xx; m_co[1] *= yy; m_co[2] *= zz; m_co[3] *= ww;
00059 }
00060 
00061 GEN_INLINE MT_Vector4 MT_Vector4::scaled(MT_Scalar xx, MT_Scalar yy, MT_Scalar zz, MT_Scalar ww) const {
00062     return MT_Vector4(m_co[0] * xx, m_co[1] * yy, m_co[2] * zz, m_co[3] * ww);
00063 }
00064 
00065 GEN_INLINE bool MT_Vector4::fuzzyZero() const { return MT_fuzzyZero2(length2()); }
00066 
00067 GEN_INLINE void MT_Vector4::normalize() { *this /= length(); }
00068 GEN_INLINE MT_Vector4 MT_Vector4::normalized() const { return *this / length(); }
00069 
00070 GEN_INLINE MT_Scalar  MT_dot(const MT_Vector4& v1, const MT_Vector4& v2) { 
00071     return v1.dot(v2);
00072 }
00073 
00074 GEN_INLINE MT_Scalar  MT_length2(const MT_Vector4& v) { return v.length2(); }
00075 GEN_INLINE MT_Scalar  MT_length(const MT_Vector4& v) { return v.length(); }
00076 
00077 GEN_INLINE bool MT_fuzzyZero(const MT_Vector4& v) { return v.fuzzyZero(); }
00078 GEN_INLINE bool MT_fuzzyEqual(const MT_Vector4& v1, const MT_Vector4& v2) { 
00079     return MT_fuzzyZero(v1 - v2); 
00080 }