diff --git a/indra/llmath/v4math.cpp b/indra/llmath/v4math.cpp index 2782cf29661c6e00cd1920b164b3a3436bfaa534..0e697919ebccc6a2c6d251ef06b984a19ac4b621 100644 --- a/indra/llmath/v4math.cpp +++ b/indra/llmath/v4math.cpp @@ -35,6 +35,12 @@ // LLVector4 +// WARNING: Don't use these for global const definitions! +// For example: +// const LLQuaternion(0.5f * F_PI, LLVector3d::zero); +// at the top of a *.cpp file might not give you what you think. +const LLVector4 LLVector4::zero(0.f, 0.f, 0.f, 0.f); + // Axis-Angle rotations /* @@ -102,6 +108,24 @@ std::ostream& operator<<(std::ostream& s, const LLVector4 &a) } +BOOL LLVector4::parseVector4(const std::string& buf, LLVector4* value) +{ + if (buf.empty() || value == NULL) + { + return FALSE; + } + + LLVector4 v; + S32 count = sscanf(buf.c_str(), "%lf %lf %lf %lf", v.mV + 0, v.mV + 1, v.mV + 2, v.mV + 3); + if (4 == count) + { + value->setVec(v); + return TRUE; + } + + return FALSE; +} + // Non-member functions F32 angle_between( const LLVector4& a, const LLVector4& b ) diff --git a/indra/llmath/v4math.h b/indra/llmath/v4math.h index b8835ba2e40331b292a970a61d218bd3870a672d..1100f96b6e3da8dde11e673de7120260d151bd9b 100644 --- a/indra/llmath/v4math.h +++ b/indra/llmath/v4math.h @@ -44,6 +44,9 @@ class LLVector4 { public: F32 mV[LENGTHOFVECTOR4]; + + const static LLVector4 zero; + LLVector4(); // Initializes LLVector4 to (0, 0, 0, 1) explicit LLVector4(const F32 *vec); // Initializes LLVector4 to (vec[0]. vec[1], vec[2], vec[3]) explicit LLVector4(const F64 *vec); // Initialized LLVector4 to ((F32) vec[0], (F32) vec[1], (F32) vec[3], (F32) vec[4]); @@ -135,6 +138,8 @@ class LLVector4 friend const LLVector4& operator/=(LLVector4 &a, F32 k); // Return a divided by scaler k friend LLVector4 operator-(const LLVector4 &a); // Return vector -a + + static BOOL parseVector4(const std::string& buf, LLVector4* value); }; // Non-member functions