summaryrefslogtreecommitdiff
path: root/indra/llmath/v3dmath.h
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llmath/v3dmath.h')
-rw-r--r--indra/llmath/v3dmath.h104
1 files changed, 69 insertions, 35 deletions
diff --git a/indra/llmath/v3dmath.h b/indra/llmath/v3dmath.h
index ac3f06c453..664c986ad0 100644
--- a/indra/llmath/v3dmath.h
+++ b/indra/llmath/v3dmath.h
@@ -2,30 +2,25 @@
* @file v3dmath.h
* @brief High precision 3 dimensional vector.
*
- * $LicenseInfo:firstyear=2000&license=viewergpl$
- *
- * Copyright (c) 2000-2007, Linden Research, Inc.
- *
+ * $LicenseInfo:firstyear=2000&license=viewerlgpl$
* Second Life Viewer Source Code
- * The source code in this file ("Source Code") is provided by Linden Lab
- * to you under the terms of the GNU General Public License, version 2.0
- * ("GPL"), unless you have obtained a separate licensing agreement
- * ("Other License"), formally executed by you and Linden Lab. Terms of
- * the GPL can be found in doc/GPL-license.txt in this distribution, or
- * online at http://secondlife.com/developers/opensource/gplv2
+ * 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.
*
- * There are special exceptions to the terms and conditions of the GPL as
- * it is applied to this Source Code. View the full text of the exception
- * in the file doc/FLOSS-exception.txt in this software distribution, or
- * online at http://secondlife.com/developers/opensource/flossexception
+ * 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.
*
- * By copying, modifying or distributing this software, you acknowledge
- * that you have read and understood your obligations described above,
- * and agree to abide by those obligations.
+ * 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
*
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
@@ -52,7 +47,7 @@ class LLVector3d
inline LLVector3d(const F64 x, const F64 y, const F64 z); // Initializes LLVector3d to (x. y, z)
inline explicit LLVector3d(const F64 *vec); // Initializes LLVector3d to (vec[0]. vec[1], vec[2])
inline explicit LLVector3d(const LLVector3 &vec);
- LLVector3d(const LLSD& sd)
+ explicit LLVector3d(const LLSD& sd)
{
setValue(sd);
}
@@ -64,12 +59,6 @@ class LLVector3d
mdV[2] = sd[2].asReal();
}
- const LLVector3d& operator=(const LLSD& sd)
- {
- setValue(sd);
- return *this;
- }
-
LLSD getValue() const
{
LLSD ret;
@@ -83,8 +72,9 @@ class LLVector3d
BOOL clamp(const F64 min, const F64 max); // Clamps all values to (min,max), returns TRUE if data changed
BOOL abs(); // sets all values to absolute value of original value (first octant), returns TRUE if changed
- inline const LLVector3d& clearVec(); // Clears LLVector3d to (0, 0, 0, 1)
- inline const LLVector3d& zeroVec(); // Zero LLVector3d to (0, 0, 0, 0)
+ inline const LLVector3d& clearVec(); // Clears LLVector3d to (0, 0, 0, 1)
+ inline const LLVector3d& setZero(); // Zero LLVector3d to (0, 0, 0, 0)
+ inline const LLVector3d& zeroVec(); // deprecated
inline const LLVector3d& setVec(const F64 x, const F64 y, const F64 z); // Sets LLVector3d to (x, y, z, 1)
inline const LLVector3d& setVec(const LLVector3d &vec); // Sets LLVector3d to vec
inline const LLVector3d& setVec(const F64 *vec); // Sets LLVector3d to vec
@@ -94,6 +84,10 @@ class LLVector3d
F64 magVecSquared() const; // Returns magnitude squared of LLVector3d
inline F64 normVec(); // Normalizes and returns the magnitude of LLVector3d
+ F64 length() const; // Returns magnitude of LLVector3d
+ F64 lengthSquared() const; // Returns magnitude squared of LLVector3d
+ inline F64 normalize(); // Normalizes and returns the magnitude of LLVector3d
+
const LLVector3d& rotVec(const F64 angle, const LLVector3d &vec); // Rotates about vec by angle radians
const LLVector3d& rotVec(const F64 angle, const F64 x, const F64 y, const F64 z); // Rotates about x,y,z by angle radians
const LLVector3d& rotVec(const LLMatrix3 &mat); // Rotates by LLMatrix4 mat
@@ -127,7 +121,7 @@ class LLVector3d
friend std::ostream& operator<<(std::ostream& s, const LLVector3d &a); // Stream a
- static BOOL parseVector3d(const char* buf, LLVector3d* value);
+ static BOOL parseVector3d(const std::string& buf, LLVector3d* value);
};
@@ -198,6 +192,14 @@ inline const LLVector3d& LLVector3d::clearVec(void)
return (*this);
}
+inline const LLVector3d& LLVector3d::setZero(void)
+{
+ mdV[0] = 0.f;
+ mdV[1] = 0.f;
+ mdV[2] = 0.f;
+ return (*this);
+}
+
inline const LLVector3d& LLVector3d::zeroVec(void)
{
mdV[0] = 0.f;
@@ -252,6 +254,28 @@ inline F64 LLVector3d::normVec(void)
return (mag);
}
+inline F64 LLVector3d::normalize(void)
+{
+ F64 mag = fsqrtf(mdV[0]*mdV[0] + mdV[1]*mdV[1] + mdV[2]*mdV[2]);
+ F64 oomag;
+
+ if (mag > FP_MAG_THRESHOLD)
+ {
+ oomag = 1.f/mag;
+ mdV[0] *= oomag;
+ mdV[1] *= oomag;
+ mdV[2] *= oomag;
+ }
+ else
+ {
+ mdV[0] = 0.f;
+ mdV[1] = 0.f;
+ mdV[2] = 0.f;
+ mag = 0;
+ }
+ return (mag);
+}
+
// LLVector3d Magnitude and Normalization Functions
inline F64 LLVector3d::magVec(void) const
@@ -264,6 +288,16 @@ inline F64 LLVector3d::magVecSquared(void) const
return mdV[0]*mdV[0] + mdV[1]*mdV[1] + mdV[2]*mdV[2];
}
+inline F64 LLVector3d::length(void) const
+{
+ return fsqrtf(mdV[0]*mdV[0] + mdV[1]*mdV[1] + mdV[2]*mdV[2]);
+}
+
+inline F64 LLVector3d::lengthSquared(void) const
+{
+ return mdV[0]*mdV[0] + mdV[1]*mdV[1] + mdV[2]*mdV[2];
+}
+
inline LLVector3d operator+(const LLVector3d &a, const LLVector3d &b)
{
LLVector3d c(a);
@@ -407,8 +441,8 @@ inline F64 angle_between(const LLVector3d& a, const LLVector3d& b)
{
LLVector3d an = a;
LLVector3d bn = b;
- an.normVec();
- bn.normVec();
+ an.normalize();
+ bn.normalize();
F64 cosine = an * bn;
F64 angle = (cosine >= 1.0f) ? 0.0f :
(cosine <= -1.0f) ? F_PI :
@@ -420,8 +454,8 @@ inline BOOL are_parallel(const LLVector3d &a, const LLVector3d &b, const F64 eps
{
LLVector3d an = a;
LLVector3d bn = b;
- an.normVec();
- bn.normVec();
+ an.normalize();
+ bn.normalize();
F64 dot = an * bn;
if ( (1.0f - fabs(dot)) < epsilon)
{
@@ -434,7 +468,7 @@ inline BOOL are_parallel(const LLVector3d &a, const LLVector3d &b, const F64 eps
inline LLVector3d projected_vec(const LLVector3d &a, const LLVector3d &b)
{
LLVector3d project_axis = b;
- project_axis.normVec();
+ project_axis.normalize();
return project_axis * (a * project_axis);
}