diff options
Diffstat (limited to 'indra/llmath/v4coloru.h')
-rw-r--r-- | indra/llmath/v4coloru.h | 140 |
1 files changed, 93 insertions, 47 deletions
diff --git a/indra/llmath/v4coloru.h b/indra/llmath/v4coloru.h index fc7845ad15..7471aebe02 100644 --- a/indra/llmath/v4coloru.h +++ b/indra/llmath/v4coloru.h @@ -2,30 +2,25 @@ * @file v4coloru.h * @brief The LLColor4U class. * - * $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$ */ @@ -65,7 +60,7 @@ public: LLColor4U(U8 r, U8 g, U8 b); // Initializes LLColor4U to (r, g, b, 1) LLColor4U(U8 r, U8 g, U8 b, U8 a); // Initializes LLColor4U to (r. g, b, a) LLColor4U(const U8 *vec); // Initializes LLColor4U to (vec[0]. vec[1], vec[2], 1) - LLColor4U(const LLSD& sd) + explicit LLColor4U(const LLSD& sd) { setValue(sd); } @@ -78,12 +73,6 @@ public: mV[3] = sd[3].asInteger(); } - const LLColor4U& operator=(const LLSD& sd) - { - setValue(sd); - return *this; - } - LLSD getValue() const { LLSD ret; @@ -97,15 +86,23 @@ public: const LLColor4U& setToBlack(); // zero LLColor4U to (0, 0, 0, 1) const LLColor4U& setToWhite(); // zero LLColor4U to (0, 0, 0, 1) - const LLColor4U& setVec(U8 r, U8 g, U8 b, U8 a); // Sets LLColor4U to (r, g, b, a) - const LLColor4U& setVec(U8 r, U8 g, U8 b); // Sets LLColor4U to (r, g, b) (no change in a) - const LLColor4U& setVec(const LLColor4U &vec); // Sets LLColor4U to vec - const LLColor4U& setVec(const U8 *vec); // Sets LLColor4U to vec + const LLColor4U& set(U8 r, U8 g, U8 b, U8 a);// Sets LLColor4U to (r, g, b, a) + const LLColor4U& set(U8 r, U8 g, U8 b); // Sets LLColor4U to (r, g, b) (no change in a) + const LLColor4U& set(const LLColor4U &vec); // Sets LLColor4U to vec + const LLColor4U& set(const U8 *vec); // Sets LLColor4U to vec + + const LLColor4U& setVec(U8 r, U8 g, U8 b, U8 a); // deprecated -- use set() + const LLColor4U& setVec(U8 r, U8 g, U8 b); // deprecated -- use set() + const LLColor4U& setVec(const LLColor4U &vec); // deprecated -- use set() + const LLColor4U& setVec(const U8 *vec); // deprecated -- use set() const LLColor4U& setAlpha(U8 a); - F32 magVec() const; // Returns magnitude of LLColor4U - F32 magVecSquared() const; // Returns magnitude squared of LLColor4U + F32 magVec() const; // deprecated -- use length() + F32 magVecSquared() const; // deprecated -- use lengthSquared() + + F32 length() const; // Returns magnitude squared of LLColor4U + F32 lengthSquared() const; // Returns magnitude squared of LLColor4U friend std::ostream& operator<<(std::ostream& s, const LLColor4U &a); // Print a friend LLColor4U operator+(const LLColor4U &a, const LLColor4U &b); // Return vector a + b @@ -127,7 +124,13 @@ public: inline void setVecScaleClamp(const LLColor3 &color); inline void setVecScaleClamp(const LLColor4 &color); - static BOOL parseColor4U(const char* buf, LLColor4U* value); + static BOOL parseColor4U(const std::string& buf, LLColor4U* value); + + // conversion + operator const LLColor4() const + { + return LLColor4(*this); + } static LLColor4U white; static LLColor4U black; @@ -199,7 +202,7 @@ inline const LLColor4U& LLColor4U::setToWhite(void) return (*this); } -inline const LLColor4U& LLColor4U::setVec(const U8 x, const U8 y, const U8 z) +inline const LLColor4U& LLColor4U::set(const U8 x, const U8 y, const U8 z) { mV[VX] = x; mV[VY] = y; @@ -211,7 +214,7 @@ inline const LLColor4U& LLColor4U::setVec(const U8 x, const U8 y, const U8 z) return (*this); } -inline const LLColor4U& LLColor4U::setVec(const U8 r, const U8 g, const U8 b, U8 a) +inline const LLColor4U& LLColor4U::set(const U8 r, const U8 g, const U8 b, U8 a) { mV[0] = r; mV[1] = g; @@ -220,7 +223,7 @@ inline const LLColor4U& LLColor4U::setVec(const U8 r, const U8 g, const U8 b, U8 return (*this); } -inline const LLColor4U& LLColor4U::setVec(const LLColor4U &vec) +inline const LLColor4U& LLColor4U::set(const LLColor4U &vec) { mV[VX] = vec.mV[VX]; mV[VY] = vec.mV[VY]; @@ -229,17 +232,49 @@ inline const LLColor4U& LLColor4U::setVec(const LLColor4U &vec) return (*this); } -/* -inline const LLColor4U& LLColor4U::setVec(const LLColor4 &vec) +inline const LLColor4U& LLColor4U::set(const U8 *vec) { - mV[VX] = (U8) (llmin(1.f, vec.mV[VX]) * 255.f); - mV[VY] = (U8) (llmin(1.f, vec.mV[VY]) * 255.f); - mV[VZ] = (U8) (llmin(1.f, vec.mV[VZ]) * 255.f); - mV[VW] = (U8) (llmin(1.f, vec.mV[VW]) * 255.f); + mV[VX] = vec[VX]; + mV[VY] = vec[VY]; + mV[VZ] = vec[VZ]; + mV[VW] = vec[VW]; return (*this); } -*/ +// deprecated +inline const LLColor4U& LLColor4U::setVec(const U8 x, const U8 y, const U8 z) +{ + mV[VX] = x; + mV[VY] = y; + mV[VZ] = z; + +// no change to alpha! +// mV[VW] = 255; + + return (*this); +} + +// deprecated +inline const LLColor4U& LLColor4U::setVec(const U8 r, const U8 g, const U8 b, U8 a) +{ + mV[0] = r; + mV[1] = g; + mV[2] = b; + mV[3] = a; + return (*this); +} + +// deprecated +inline const LLColor4U& LLColor4U::setVec(const LLColor4U &vec) +{ + mV[VX] = vec.mV[VX]; + mV[VY] = vec.mV[VY]; + mV[VZ] = vec.mV[VZ]; + mV[VW] = vec.mV[VW]; + return (*this); +} + +// deprecated inline const LLColor4U& LLColor4U::setVec(const U8 *vec) { mV[VX] = vec[VX]; @@ -256,13 +291,24 @@ inline const LLColor4U& LLColor4U::setAlpha(U8 a) } // LLColor4U Magnitude and Normalization Functions -// bookmark +inline F32 LLColor4U::length(void) const +{ + return fsqrtf( ((F32)mV[VX]) * mV[VX] + ((F32)mV[VY]) * mV[VY] + ((F32)mV[VZ]) * mV[VZ] ); +} + +inline F32 LLColor4U::lengthSquared(void) const +{ + return ((F32)mV[VX]) * mV[VX] + ((F32)mV[VY]) * mV[VY] + ((F32)mV[VZ]) * mV[VZ]; +} + +// deprecated inline F32 LLColor4U::magVec(void) const { return fsqrtf( ((F32)mV[VX]) * mV[VX] + ((F32)mV[VY]) * mV[VY] + ((F32)mV[VZ]) * mV[VZ] ); } +// deprecated inline F32 LLColor4U::magVecSquared(void) const { return ((F32)mV[VX]) * mV[VX] + ((F32)mV[VY]) * mV[VY] + ((F32)mV[VZ]) * mV[VZ]; @@ -407,13 +453,13 @@ inline const LLColor4U& operator%=(LLColor4U &a, U8 k) inline F32 distVec(const LLColor4U &a, const LLColor4U &b) { LLColor4U vec = a - b; - return (vec.magVec()); + return (vec.length()); } inline F32 distVec_squared(const LLColor4U &a, const LLColor4U &b) { LLColor4U vec = a - b; - return (vec.magVecSquared()); + return (vec.lengthSquared()); } void LLColor4U::setVecScaleClamp(const LLColor4& color) |