00001
00032 #include "linden_common.h"
00033
00034
00035
00036 #include "v3dmath.h"
00037
00038
00039 #include "v4math.h"
00040 #include "m4math.h"
00041 #include "m3math.h"
00042 #include "llquaternion.h"
00043 #include "llquantize.h"
00044
00045
00046
00047
00048
00049
00050 const LLVector3d LLVector3d::zero(0,0,0);
00051 const LLVector3d LLVector3d::x_axis(1, 0, 0);
00052 const LLVector3d LLVector3d::y_axis(0, 1, 0);
00053 const LLVector3d LLVector3d::z_axis(0, 0, 1);
00054 const LLVector3d LLVector3d::x_axis_neg(-1, 0, 0);
00055 const LLVector3d LLVector3d::y_axis_neg(0, -1, 0);
00056 const LLVector3d LLVector3d::z_axis_neg(0, 0, -1);
00057
00058
00059
00060
00061 BOOL LLVector3d::clamp(F64 min, F64 max)
00062 {
00063 BOOL ret = FALSE;
00064
00065 if (mdV[0] < min) { mdV[0] = min; ret = TRUE; }
00066 if (mdV[1] < min) { mdV[1] = min; ret = TRUE; }
00067 if (mdV[2] < min) { mdV[2] = min; ret = TRUE; }
00068
00069 if (mdV[0] > max) { mdV[0] = max; ret = TRUE; }
00070 if (mdV[1] > max) { mdV[1] = max; ret = TRUE; }
00071 if (mdV[2] > max) { mdV[2] = max; ret = TRUE; }
00072
00073 return ret;
00074 }
00075
00076
00077
00078 BOOL LLVector3d::abs()
00079 {
00080 BOOL ret = FALSE;
00081
00082 if (mdV[0] < 0.0) { mdV[0] = -mdV[0]; ret = TRUE; }
00083 if (mdV[1] < 0.0) { mdV[1] = -mdV[1]; ret = TRUE; }
00084 if (mdV[2] < 0.0) { mdV[2] = -mdV[2]; ret = TRUE; }
00085
00086 return ret;
00087 }
00088
00089 std::ostream& operator<<(std::ostream& s, const LLVector3d &a)
00090 {
00091 s << "{ " << a.mdV[VX] << ", " << a.mdV[VY] << ", " << a.mdV[VZ] << " }";
00092 return s;
00093 }
00094
00095 const LLVector3d& LLVector3d::operator=(const LLVector4 &a)
00096 {
00097 mdV[0] = a.mV[0];
00098 mdV[1] = a.mV[1];
00099 mdV[2] = a.mV[2];
00100 return *this;
00101 }
00102
00103 const LLVector3d& LLVector3d::rotVec(const LLMatrix3 &mat)
00104 {
00105 *this = *this * mat;
00106 return *this;
00107 }
00108
00109 const LLVector3d& LLVector3d::rotVec(const LLQuaternion &q)
00110 {
00111 *this = *this * q;
00112 return *this;
00113 }
00114
00115 const LLVector3d& LLVector3d::rotVec(F64 angle, const LLVector3d &vec)
00116 {
00117 if ( !vec.isExactlyZero() && angle )
00118 {
00119 *this = *this * LLMatrix3((F32)angle, vec);
00120 }
00121 return *this;
00122 }
00123
00124 const LLVector3d& LLVector3d::rotVec(F64 angle, F64 x, F64 y, F64 z)
00125 {
00126 LLVector3d vec(x, y, z);
00127 if ( !vec.isExactlyZero() && angle )
00128 {
00129 *this = *this * LLMatrix3((F32)angle, vec);
00130 }
00131 return *this;
00132 }
00133
00134
00135 BOOL LLVector3d::parseVector3d(const char* buf, LLVector3d* value)
00136 {
00137 if( buf == NULL || buf[0] == '\0' || value == NULL)
00138 {
00139 return FALSE;
00140 }
00141
00142 LLVector3d v;
00143 S32 count = sscanf( buf, "%lf %lf %lf", v.mdV + 0, v.mdV + 1, v.mdV + 2 );
00144 if( 3 == count )
00145 {
00146 value->setVec( v );
00147 return TRUE;
00148 }
00149
00150 return FALSE;
00151 }
00152