Blender V2.61 - r43446
|
00001 #include "MT_Optimize.h" 00002 00003 GEN_INLINE MT_Vector3& MT_Vector3::operator+=(const MT_Vector3& v) { 00004 m_co[0] += v[0]; m_co[1] += v[1]; m_co[2] += v[2]; 00005 return *this; 00006 } 00007 00008 GEN_INLINE MT_Vector3& MT_Vector3::operator-=(const MT_Vector3& v) { 00009 m_co[0] -= v[0]; m_co[1] -= v[1]; m_co[2] -= v[2]; 00010 return *this; 00011 } 00012 00013 GEN_INLINE MT_Vector3& MT_Vector3::operator*=(MT_Scalar s) { 00014 m_co[0] *= s; m_co[1] *= s; m_co[2] *= s; 00015 return *this; 00016 } 00017 00018 GEN_INLINE MT_Vector3& MT_Vector3::operator/=(MT_Scalar s) { 00019 MT_assert(!MT_fuzzyZero(s)); 00020 return *this *= MT_Scalar(1.0) / s; 00021 } 00022 00023 GEN_INLINE MT_Vector3 operator+(const MT_Vector3& v1, const MT_Vector3& v2) { 00024 return MT_Vector3(v1[0] + v2[0], v1[1] + v2[1], v1[2] + v2[2]); 00025 } 00026 00027 GEN_INLINE MT_Vector3 operator-(const MT_Vector3& v1, const MT_Vector3& v2) { 00028 return MT_Vector3(v1[0] - v2[0], v1[1] - v2[1], v1[2] - v2[2]); 00029 } 00030 00031 GEN_INLINE MT_Vector3 operator-(const MT_Vector3& v) { 00032 return MT_Vector3(-v[0], -v[1], -v[2]); 00033 } 00034 00035 GEN_INLINE MT_Vector3 operator*(const MT_Vector3& v, MT_Scalar s) { 00036 return MT_Vector3(v[0] * s, v[1] * s, v[2] * s); 00037 } 00038 00039 GEN_INLINE MT_Vector3 operator*(MT_Scalar s, const MT_Vector3& v) { return v * s; } 00040 00041 GEN_INLINE MT_Vector3 operator/(const MT_Vector3& v, MT_Scalar s) { 00042 MT_assert(!MT_fuzzyZero(s)); 00043 return v * (MT_Scalar(1.0) / s); 00044 } 00045 00046 GEN_INLINE MT_Vector3 operator*(const MT_Vector3& v1, const MT_Vector3& v2) { 00047 return MT_Vector3(v1[0] * v2[0], v1[1] * v2[1], v1[2] * v2[2]); 00048 } 00049 00050 GEN_INLINE MT_Scalar MT_Vector3::dot(const MT_Vector3& v) const { 00051 return m_co[0] * v[0] + m_co[1] * v[1] + m_co[2] * v[2]; 00052 } 00053 00054 GEN_INLINE MT_Scalar MT_Vector3::length2() const { return dot(*this); } 00055 GEN_INLINE MT_Scalar MT_Vector3::length() const { return sqrt(length2()); } 00056 00057 GEN_INLINE MT_Vector3 MT_Vector3::absolute() const { 00058 return MT_Vector3(MT_abs(m_co[0]), MT_abs(m_co[1]), MT_abs(m_co[2])); 00059 } 00060 00061 GEN_INLINE bool MT_Vector3::fuzzyZero() const { 00062 return MT_fuzzyZero(length2()); 00063 } 00064 00065 GEN_INLINE void MT_Vector3::noiseGate(MT_Scalar threshold) { 00066 if (length2() < threshold) { 00067 setValue(MT_Scalar(0.0), MT_Scalar(0.0), MT_Scalar(0.0)); 00068 } 00069 } 00070 00071 GEN_INLINE void MT_Vector3::normalize() { *this /= length(); } 00072 GEN_INLINE MT_Vector3 MT_Vector3::normalized() const { return *this / length(); } 00073 GEN_INLINE MT_Vector3 MT_Vector3::safe_normalized() const { 00074 MT_Scalar len = length(); 00075 return MT_fuzzyZero(len) ? 00076 MT_Vector3(MT_Scalar(1.0), MT_Scalar(0.0), MT_Scalar(0.0)) : 00077 *this / len; 00078 } 00079 00080 GEN_INLINE void MT_Vector3::scale(MT_Scalar xx, MT_Scalar yy, MT_Scalar zz) { 00081 m_co[0] *= xx; m_co[1] *= yy; m_co[2] *= zz; 00082 } 00083 00084 GEN_INLINE MT_Vector3 MT_Vector3::scaled(MT_Scalar xx, MT_Scalar yy, MT_Scalar zz) const { 00085 return MT_Vector3(m_co[0] * xx, m_co[1] * yy, m_co[2] * zz); 00086 } 00087 00088 GEN_INLINE MT_Scalar MT_Vector3::angle(const MT_Vector3& v) const { 00089 MT_Scalar s = sqrt(length2() * v.length2()); 00090 MT_assert(!MT_fuzzyZero(s)); 00091 return acos(dot(v) / s); 00092 } 00093 00094 GEN_INLINE MT_Vector3 MT_Vector3::cross(const MT_Vector3& v) const { 00095 return MT_Vector3(m_co[1] * v[2] - m_co[2] * v[1], 00096 m_co[2] * v[0] - m_co[0] * v[2], 00097 m_co[0] * v[1] - m_co[1] * v[0]); 00098 } 00099 00100 GEN_INLINE MT_Scalar MT_Vector3::triple(const MT_Vector3& v1, const MT_Vector3& v2) const { 00101 return m_co[0] * (v1[1] * v2[2] - v1[2] * v2[1]) + 00102 m_co[1] * (v1[2] * v2[0] - v1[0] * v2[2]) + 00103 m_co[2] * (v1[0] * v2[1] - v1[1] * v2[0]); 00104 } 00105 00106 GEN_INLINE int MT_Vector3::closestAxis() const { 00107 MT_Vector3 a = absolute(); 00108 return a[0] < a[1] ? (a[1] < a[2] ? 2 : 1) : (a[0] < a[2] ? 2 : 0); 00109 } 00110 00111 GEN_INLINE MT_Vector3 MT_Vector3::random() { 00112 MT_Scalar z = MT_Scalar(2.0) * MT_random() - MT_Scalar(1.0); 00113 MT_Scalar r = sqrt(MT_Scalar(1.0) - z * z); 00114 MT_Scalar t = MT_2_PI * MT_random(); 00115 return MT_Vector3(r * cos(t), r * sin(t), z); 00116 } 00117 00118 GEN_INLINE MT_Scalar MT_dot(const MT_Vector3& v1, const MT_Vector3& v2) { 00119 return v1.dot(v2); 00120 } 00121 00122 GEN_INLINE MT_Scalar MT_length2(const MT_Vector3& v) { return v.length2(); } 00123 GEN_INLINE MT_Scalar MT_length(const MT_Vector3& v) { return v.length(); } 00124 00125 GEN_INLINE bool MT_fuzzyZero(const MT_Vector3& v) { return v.fuzzyZero(); } 00126 GEN_INLINE bool MT_fuzzyEqual(const MT_Vector3& v1, const MT_Vector3& v2) { 00127 return MT_fuzzyZero(v1 - v2); 00128 } 00129 00130 GEN_INLINE MT_Scalar MT_angle(const MT_Vector3& v1, const MT_Vector3& v2) { return v1.angle(v2); } 00131 GEN_INLINE MT_Vector3 MT_cross(const MT_Vector3& v1, const MT_Vector3& v2) { return v1.cross(v2); } 00132 GEN_INLINE MT_Scalar MT_triple(const MT_Vector3& v1, const MT_Vector3& v2, const MT_Vector3& v3) { 00133 return v1.triple(v2, v3); 00134 }