summaryrefslogtreecommitdiff
path: root/indra/llmath/v3color.h
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llmath/v3color.h')
-rw-r--r--indra/llmath/v3color.h125
1 files changed, 95 insertions, 30 deletions
diff --git a/indra/llmath/v3color.h b/indra/llmath/v3color.h
index 56820148d5..327e452bf7 100644
--- a/indra/llmath/v3color.h
+++ b/indra/llmath/v3color.h
@@ -2,30 +2,25 @@
* @file v3color.h
* @brief LLColor3 class header file.
*
- * $LicenseInfo:firstyear=2001&license=viewergpl$
- *
- * Copyright (c) 2001-2007, Linden Research, Inc.
- *
+ * $LicenseInfo:firstyear=2001&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.
*
- * 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 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.
*
- * 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.
+ * 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.
*
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
+ * 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$
*/
@@ -56,7 +51,7 @@ public:
LLColor3(); // Initializes LLColor3 to (0, 0, 0)
LLColor3(F32 r, F32 g, F32 b); // Initializes LLColor3 to (r, g, b)
LLColor3(const F32 *vec); // Initializes LLColor3 to (vec[0]. vec[1], vec[2])
- LLColor3(char *color_string); // html format color ie "#FFDDEE"
+ LLColor3(const char *color_string); // html format color ie "#FFDDEE"
explicit LLColor3(const LLColor4& color4); // "explicit" to avoid automatic conversion
explicit LLColor3(const LLVector4& vector4); // "explicit" to avoid automatic conversion
LLColor3(const LLSD& sd);
@@ -78,17 +73,28 @@ public:
mV[2] = (F32) sd[2].asReal();;
}
+ void setHSL(F32 hue, F32 saturation, F32 luminance);
void calcHSL(F32* hue, F32* saturation, F32* luminance) const;
const LLColor3& setToBlack(); // Clears LLColor3 to (0, 0, 0)
const LLColor3& setToWhite(); // Zero LLColor3 to (0, 0, 0)
- const LLColor3& setVec(F32 x, F32 y, F32 z); // Sets LLColor3 to (x, y, z)
- const LLColor3& setVec(const LLColor3 &vec); // Sets LLColor3 to vec
- const LLColor3& setVec(const F32 *vec); // Sets LLColor3 to vec
+
+ const LLColor3& setVec(F32 x, F32 y, F32 z); // deprecated
+ const LLColor3& setVec(const LLColor3 &vec); // deprecated
+ const LLColor3& setVec(const F32 *vec); // deprecated
+
+ const LLColor3& set(F32 x, F32 y, F32 z); // Sets LLColor3 to (x, y, z)
+ const LLColor3& set(const LLColor3 &vec); // Sets LLColor3 to vec
+ const LLColor3& set(const F32 *vec); // Sets LLColor3 to vec
+
+ F32 magVec() const; // deprecated
+ F32 magVecSquared() const; // deprecated
+ F32 normVec(); // deprecated
+
+ F32 length() const; // Returns magnitude of LLColor3
+ F32 lengthSquared() const; // Returns magnitude squared of LLColor3
+ F32 normalize(); // Normalizes and returns the magnitude of LLColor3
- F32 magVec() const; // Returns magnitude of LLColor3
- F32 magVecSquared() const; // Returns magnitude squared of LLColor3
- F32 normVec(); // Normalizes and returns the magnitude of LLColor3
F32 brightness() const; // Returns brightness of LLColor3
const LLColor3& operator=(const LLColor4 &a);
@@ -150,7 +156,7 @@ void LLColor3::clamp()
// Non-member functions
F32 distVec(const LLColor3 &a, const LLColor3 &b); // Returns distance between a and b
-F32 distVec_squared(const LLColor3 &a, const LLColor3 &b);// Returns distance sqaured between a and b
+F32 distVec_squared(const LLColor3 &a, const LLColor3 &b);// Returns distance squared between a and b
inline LLColor3::LLColor3(void)
{
@@ -174,7 +180,11 @@ inline LLColor3::LLColor3(const F32 *vec)
mV[VZ] = vec[VZ];
}
-inline LLColor3::LLColor3(char* color_string) // takes a string of format "RRGGBB" where RR is hex 00..FF
+#if LL_WINDOWS
+# pragma warning( disable : 4996 ) // strncpy teh sux0r
+#endif
+
+inline LLColor3::LLColor3(const char* color_string) // takes a string of format "RRGGBB" where RR is hex 00..FF
{
if (strlen(color_string) < 6) /* Flawfinder: ignore */
{
@@ -184,7 +194,7 @@ inline LLColor3::LLColor3(char* color_string) // takes a string of format "RRGGB
return;
}
- static char tempstr[7]; /* Flawfinder: ignore */
+ char tempstr[7];
strncpy(tempstr,color_string,6); /* Flawfinder: ignore */
tempstr[6] = '\0';
mV[VZ] = (F32)strtol(&tempstr[4],NULL,16)/255.f;
@@ -210,6 +220,31 @@ inline const LLColor3& LLColor3::setToWhite(void)
return (*this);
}
+inline const LLColor3& LLColor3::set(F32 r, F32 g, F32 b)
+{
+ mV[0] = r;
+ mV[1] = g;
+ mV[2] = b;
+ return (*this);
+}
+
+inline const LLColor3& LLColor3::set(const LLColor3 &vec)
+{
+ mV[0] = vec.mV[0];
+ mV[1] = vec.mV[1];
+ mV[2] = vec.mV[2];
+ return (*this);
+}
+
+inline const LLColor3& LLColor3::set(const F32 *vec)
+{
+ mV[0] = vec[0];
+ mV[1] = vec[1];
+ mV[2] = vec[2];
+ return (*this);
+}
+
+// deprecated
inline const LLColor3& LLColor3::setVec(F32 r, F32 g, F32 b)
{
mV[0] = r;
@@ -218,6 +253,7 @@ inline const LLColor3& LLColor3::setVec(F32 r, F32 g, F32 b)
return (*this);
}
+// deprecated
inline const LLColor3& LLColor3::setVec(const LLColor3 &vec)
{
mV[0] = vec.mV[0];
@@ -226,6 +262,7 @@ inline const LLColor3& LLColor3::setVec(const LLColor3 &vec)
return (*this);
}
+// deprecated
inline const LLColor3& LLColor3::setVec(const F32 *vec)
{
mV[0] = vec[0];
@@ -239,16 +276,44 @@ inline F32 LLColor3::brightness(void) const
return (mV[0] + mV[1] + mV[2]) / 3.0f;
}
+inline F32 LLColor3::length(void) const
+{
+ return fsqrtf(mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2]);
+}
+
+inline F32 LLColor3::lengthSquared(void) const
+{
+ return mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2];
+}
+
+inline F32 LLColor3::normalize(void)
+{
+ F32 mag = fsqrtf(mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2]);
+ F32 oomag;
+
+ if (mag)
+ {
+ oomag = 1.f/mag;
+ mV[0] *= oomag;
+ mV[1] *= oomag;
+ mV[2] *= oomag;
+ }
+ return (mag);
+}
+
+// deprecated
inline F32 LLColor3::magVec(void) const
{
return fsqrtf(mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2]);
}
+// deprecated
inline F32 LLColor3::magVecSquared(void) const
{
return mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2];
}
+// deprecated
inline F32 LLColor3::normVec(void)
{
F32 mag = fsqrtf(mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2]);