diff options
Diffstat (limited to 'indra/llmath')
| -rw-r--r-- | indra/llmath/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | indra/llmath/llquaternion.cpp | 24 | ||||
| -rw-r--r-- | indra/llmath/llquaternion.h | 28 | ||||
| -rw-r--r-- | indra/llmath/v2math.cpp | 2 | ||||
| -rw-r--r-- | indra/llmath/v2math.h | 7 | ||||
| -rw-r--r-- | indra/llmath/v3colorutil.h | 115 | ||||
| -rw-r--r-- | indra/llmath/v4color.h | 11 | ||||
| -rw-r--r-- | indra/llmath/v4math.h | 34 | 
8 files changed, 219 insertions, 3 deletions
| diff --git a/indra/llmath/CMakeLists.txt b/indra/llmath/CMakeLists.txt index 4c8bcdac91..61d13c0b1c 100644 --- a/indra/llmath/CMakeLists.txt +++ b/indra/llmath/CMakeLists.txt @@ -87,6 +87,7 @@ set(llmath_HEADER_FILES      raytrace.h      v2math.h      v3color.h +    v3colorutil.h      v3dmath.h      v3math.h      v4color.h diff --git a/indra/llmath/llquaternion.cpp b/indra/llmath/llquaternion.cpp index 47374c287f..a8d9eba2a0 100644 --- a/indra/llmath/llquaternion.cpp +++ b/indra/llmath/llquaternion.cpp @@ -103,6 +103,10 @@ LLQuaternion::LLQuaternion(const LLVector3 &x_axis,  	*this = mat.quaternion();  	normalize();  } +LLQuaternion::LLQuaternion(const LLSD &sd) +{ +    setValue(sd); +}  // Quatizations  void	LLQuaternion::quantize16(F32 lower, F32 upper) @@ -860,6 +864,26 @@ void LLQuaternion::getAngleAxis(F32* angle, LLVector3 &vec) const  	}  } +const LLQuaternion& LLQuaternion::setFromAzimuthAndAltitude(F32 azimuthRadians, F32 altitudeRadians) +{ +    // euler angle inputs are complements of azimuth/altitude which are measured from zenith +    F32 pitch = llclamp(F_PI_BY_TWO - altitudeRadians, 0.0f, F_PI_BY_TWO); +    F32 yaw   = llclamp(F_PI_BY_TWO - azimuthRadians,  0.0f, F_PI_BY_TWO); +    setEulerAngles(0.0f, pitch, yaw); +    return *this; +} + +void LLQuaternion::getAzimuthAndAltitude(F32 &azimuthRadians, F32 &altitudeRadians) +{ +    F32 rick_roll; +    F32 pitch; +    F32 yaw; +    getEulerAngles(&rick_roll, &pitch, &yaw); +    // make these measured from zenith +    altitudeRadians = llclamp(F_PI_BY_TWO - pitch, 0.0f, F_PI_BY_TWO); +    azimuthRadians  = llclamp(F_PI_BY_TWO - yaw,   0.0f, F_PI_BY_TWO); +} +  // quaternion does not need to be normalized  void LLQuaternion::getEulerAngles(F32 *roll, F32 *pitch, F32 *yaw) const  { diff --git a/indra/llmath/llquaternion.h b/indra/llmath/llquaternion.h index aa0b1752f4..e2cdad548b 100644 --- a/indra/llmath/llquaternion.h +++ b/indra/llmath/llquaternion.h @@ -28,6 +28,7 @@  #define LLQUATERNION_H  #include <iostream> +#include "llsd.h"  #ifndef LLMATH_H //enforce specific include order to avoid tangling inline dependencies  #error "Please include llmath.h first." @@ -63,6 +64,10 @@ public:  	LLQuaternion(const LLVector3 &x_axis,  				 const LLVector3 &y_axis,  				 const LLVector3 &z_axis);			// Initializes Quaternion from Matrix3 = [x_axis ; y_axis ; z_axis] +    explicit LLQuaternion(const LLSD &sd);          // Initializes Quaternion from LLSD array. + +    LLSD getValue() const; +    void setValue(const LLSD& sd);  	BOOL isIdentity() const;  	BOOL isNotIdentity() const; @@ -79,7 +84,8 @@ public:  	const LLQuaternion&	set(const F32 *q);						// Sets Quaternion to normalize(quat[VX], quat[VY], quat[VZ], quat[VW])  	const LLQuaternion&	set(const LLMatrix3 &mat);				// Sets Quaternion to mat2quat(mat)  	const LLQuaternion&	set(const LLMatrix4 &mat);				// Sets Quaternion to mat2quat(mat) - +    const LLQuaternion& setFromAzimuthAndAltitude(F32 azimuth, F32 altitude); +      	const LLQuaternion&	setAngleAxis(F32 angle, F32 x, F32 y, F32 z);	// Sets Quaternion to axis_angle2quat(angle, x, y, z)  	const LLQuaternion&	setAngleAxis(F32 angle, const LLVector3 &vec);	// Sets Quaternion to axis_angle2quat(angle, vec)  	const LLQuaternion&	setAngleAxis(F32 angle, const LLVector4 &vec);	// Sets Quaternion to axis_angle2quat(angle, vec) @@ -100,6 +106,7 @@ public:  	void		getAngleAxis(F32* angle, F32* x, F32* y, F32* z) const;	// returns rotation in radians about axis x,y,z  	void		getAngleAxis(F32* angle, LLVector3 &vec) const;  	void		getEulerAngles(F32 *roll, F32* pitch, F32 *yaw) const; +    void        getAzimuthAndAltitude(F32 &azimuth, F32 &altitude);  	F32	normalize();	// Normalizes Quaternion and returns magnitude  	F32	normQuat();		// deprecated @@ -166,6 +173,25 @@ public:  	//static U32 mMultCount;  }; +inline LLSD LLQuaternion::getValue() const +{ +    LLSD ret; +    ret[0] = mQ[0]; +    ret[1] = mQ[1]; +    ret[2] = mQ[2]; +    ret[3] = mQ[3]; +    return ret; +} + +inline void LLQuaternion::setValue(const LLSD& sd) +{ +    mQ[0] = sd[0].asReal(); +    mQ[1] = sd[1].asReal(); +    mQ[2] = sd[2].asReal(); +    mQ[3] = sd[3].asReal(); +} + +  // checker  inline BOOL	LLQuaternion::isFinite() const  { diff --git a/indra/llmath/v2math.cpp b/indra/llmath/v2math.cpp index a0cd642853..a24571f2c8 100644 --- a/indra/llmath/v2math.cpp +++ b/indra/llmath/v2math.cpp @@ -118,7 +118,7 @@ LLSD LLVector2::getValue() const  	return ret;  } -void LLVector2::setValue(LLSD& sd) +void LLVector2::setValue(const LLSD& sd)  {  	mV[0] = (F32) sd[0].asReal();  	mV[1] = (F32) sd[1].asReal(); diff --git a/indra/llmath/v2math.h b/indra/llmath/v2math.h index 8d5db96f5e..2335a2e327 100644 --- a/indra/llmath/v2math.h +++ b/indra/llmath/v2math.h @@ -49,6 +49,7 @@ class LLVector2  		LLVector2(F32 x, F32 y);			      // Initializes LLVector2 to (x. y)  		LLVector2(const F32 *vec);				  // Initializes LLVector2 to (vec[0]. vec[1])          explicit LLVector2(const LLVector3 &vec); // Initializes LLVector2 to (vec[0]. vec[1]) +        explicit LLVector2(const LLSD &sd);  		// Clears LLVector2 to (0, 0).  DEPRECATED - prefer zeroVec.  		void	clear(); @@ -61,7 +62,7 @@ class LLVector2  		void	set(const F32 *vec);			// Sets LLVector2 to vec  		LLSD	getValue() const; -		void	setValue(LLSD& sd); +		void	setValue(const LLSD& sd);  		void	setVec(F32 x, F32 y);	        // deprecated  		void	setVec(const LLVector2 &vec);	// deprecated @@ -145,6 +146,10 @@ inline LLVector2::LLVector2(const LLVector3 &vec)  	mV[VY] = vec.mV[VY];  } +inline LLVector2::LLVector2(const LLSD &sd) +{ +    setValue(sd); +}  // Clear and Assignment Functions diff --git a/indra/llmath/v3colorutil.h b/indra/llmath/v3colorutil.h new file mode 100644 index 0000000000..6d8cd9329b --- /dev/null +++ b/indra/llmath/v3colorutil.h @@ -0,0 +1,115 @@ +/**  + * @file v3color.h + * @brief LLColor3 class header file. + * + * $LicenseInfo:firstyear=2001&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + *  + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + *  + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU + * Lesser General Public License for more details. + *  + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA + *  + * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA + * $/LicenseInfo$ + */ + +#ifndef LL_V3COLORUTIL_H +#define LL_V3COLORUTIL_H + +#include "v3color.h" + +inline LLColor3 componentDiv(LLColor3 const &left, LLColor3 const & right) +{ +    return LLColor3(left.mV[0] / right.mV[0], +        left.mV[1] / right.mV[1], +        left.mV[2] / right.mV[2]); +} + + +inline LLColor3 componentMult(LLColor3 const &left, LLColor3 const & right) +{ +    return LLColor3(left.mV[0] * right.mV[0], +        left.mV[1] * right.mV[1], +        left.mV[2] * right.mV[2]); +} + + +inline LLColor3 componentExp(LLColor3 const &v) +{ +    return LLColor3(exp(v.mV[0]), +        exp(v.mV[1]), +        exp(v.mV[2])); +} + +inline LLColor3 componentPow(LLColor3 const &v, F32 exponent) +{ +    return LLColor3(pow(v.mV[0], exponent), +        pow(v.mV[1], exponent), +        pow(v.mV[2], exponent)); +} + +inline LLColor3 componentSaturate(LLColor3 const &v) +{ +    return LLColor3(std::max(std::min(v.mV[0], 1.f), 0.f), +        std::max(std::min(v.mV[1], 1.f), 0.f), +        std::max(std::min(v.mV[2], 1.f), 0.f)); +} + + +inline LLColor3 componentSqrt(LLColor3 const &v) +{ +    return LLColor3(sqrt(v.mV[0]), +        sqrt(v.mV[1]), +        sqrt(v.mV[2])); +} + +inline void componentMultBy(LLColor3 & left, LLColor3 const & right) +{ +    left.mV[0] *= right.mV[0]; +    left.mV[1] *= right.mV[1]; +    left.mV[2] *= right.mV[2]; +} + +inline LLColor3 colorMix(LLColor3 const & left, LLColor3 const & right, F32 amount) +{ +    return (left + ((right - left) * amount)); +} + +inline LLColor3 smear(F32 val) +{ +    return LLColor3(val, val, val); +} + +inline F32 color_intens(const LLColor3 &col) +{ +    return col.mV[0] + col.mV[1] + col.mV[2]; +} + +inline F32 color_max(const LLColor3 &col) +{ +    return llmax(col.mV[0], col.mV[1], col.mV[2]); +} + +inline F32 color_max(const LLColor4 &col) +{ +    return llmax(col.mV[0], col.mV[1], col.mV[2]); +} + + +inline F32 color_min(const LLColor3 &col) +{ +    return llmin(col.mV[0], col.mV[1], col.mV[2]); +} + +#endif diff --git a/indra/llmath/v4color.h b/indra/llmath/v4color.h index 8f353ead5a..614cdc9f3e 100644 --- a/indra/llmath/v4color.h +++ b/indra/llmath/v4color.h @@ -114,9 +114,11 @@ class LLColor4  		friend LLColor4 operator-(const LLColor4 &a, const LLColor4 &b);	// Return vector a minus b  		friend LLColor4 operator*(const LLColor4 &a, const LLColor4 &b);	// Return component wise a * b  		friend LLColor4 operator*(const LLColor4 &a, F32 k);				// Return rgb times scaler k (no alpha change) +        friend LLColor4 operator/(const LLColor4 &a, F32 k);                // Return rgb divided by scalar k (no alpha change)  		friend LLColor4 operator*(F32 k, const LLColor4 &a);				// Return rgb times scaler k (no alpha change)  		friend LLColor4 operator%(const LLColor4 &a, F32 k);				// Return alpha times scaler k (no rgb change)  		friend LLColor4 operator%(F32 k, const LLColor4 &a);				// Return alpha times scaler k (no rgb change) +  		friend bool operator==(const LLColor4 &a, const LLColor4 &b);		// Return a == b  		friend bool operator!=(const LLColor4 &a, const LLColor4 &b);		// Return a != b @@ -477,6 +479,15 @@ inline LLColor4 operator*(const LLColor4 &a, F32 k)  		a.mV[VW]);  } +inline LLColor4 operator/(const LLColor4 &a, F32 k) +{ +    return LLColor4( +        a.mV[VX] / k, +        a.mV[VY] / k, +        a.mV[VZ] / k, +        a.mV[VW]); +} +  inline LLColor4 operator*(F32 k, const LLColor4 &a)  {  	// only affects rgb (not a!) diff --git a/indra/llmath/v4math.h b/indra/llmath/v4math.h index 623c8b2003..3f6d480ed9 100644 --- a/indra/llmath/v4math.h +++ b/indra/llmath/v4math.h @@ -30,6 +30,7 @@  #include "llerror.h"  #include "llmath.h"  #include "v3math.h" +#include "v2math.h"  class LLMatrix3;  class LLMatrix4; @@ -46,8 +47,11 @@ class LLVector4  		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]); +        explicit LLVector4(const LLVector2 &vec); +        explicit LLVector4(const LLVector2 &vec, F32 z, F32 w);  		explicit LLVector4(const LLVector3 &vec);			// Initializes LLVector4 to (vec, 1)  		explicit LLVector4(const LLVector3 &vec, F32 w);	// Initializes LLVector4 to (vec, w) +        explicit LLVector4(const LLSD &sd);  		LLVector4(F32 x, F32 y, F32 z);		// Initializes LLVector4 to (x. y, z, 1)  		LLVector4(F32 x, F32 y, F32 z, F32 w); @@ -61,6 +65,15 @@ class LLVector4  			return ret;  		} +        void setValue(const LLSD& sd) +        { +            mV[0] = sd[0].asReal(); +            mV[1] = sd[1].asReal(); +            mV[2] = sd[2].asReal(); +            mV[3] = sd[3].asReal(); +        } + +  		inline BOOL isFinite() const;									// checks to see if all values of LLVector3 are finite  		inline void	clear();		// Clears LLVector4 to (0, 0, 0, 1) @@ -175,6 +188,22 @@ inline LLVector4::LLVector4(const F64 *vec)  	mV[VW] = (F32) vec[VW];  } +inline LLVector4::LLVector4(const LLVector2 &vec) +{ +    mV[VX] = vec[VX]; +    mV[VY] = vec[VY]; +    mV[VZ] = 0.f; +    mV[VW] = 0.f; +} + +inline LLVector4::LLVector4(const LLVector2 &vec, F32 z, F32 w) +{ +    mV[VX] = vec[VX]; +    mV[VY] = vec[VY]; +    mV[VZ] = z; +    mV[VW] = w; +} +  inline LLVector4::LLVector4(const LLVector3 &vec)  {  	mV[VX] = vec.mV[VX]; @@ -191,6 +220,11 @@ inline LLVector4::LLVector4(const LLVector3 &vec, F32 w)  	mV[VW] = w;  } +inline LLVector4::LLVector4(const LLSD &sd) +{ +    setValue(sd); +} +  inline BOOL LLVector4::isFinite() const  { | 
