summaryrefslogtreecommitdiff
path: root/indra/llmath
diff options
context:
space:
mode:
authorDon Kjer <don@lindenlab.com>2007-09-28 23:32:53 +0000
committerDon Kjer <don@lindenlab.com>2007-09-28 23:32:53 +0000
commitb089fc559a5dc527ed5e0422e82abf3b1dd5f1b2 (patch)
treebaa68e98452406c03a3dbe21c99a901f769c8890 /indra/llmath
parentab8dd2b55008090a1f18fb107f897c736d98a760 (diff)
EFFECTIVE MERGE: svn merge -r 68999:69916 svn+ssh://svn.lindenlab.com/svn/linden/branches/maintenance into release
** This should be the last merge from branches/maintenance. All future merges will be from new maintenance-# branches off release ** ACTUAL MERGE: svn merge -r70609:70621 svn+ssh://svn/svn/linden/branches/maintenance-0-qa-r70556 RELATED MERGE: svn merge -r69921:70316 svn+ssh://svn/svn/linden/branches/maintenance-0-qa
Diffstat (limited to 'indra/llmath')
-rw-r--r--indra/llmath/llquantize.h25
-rw-r--r--indra/llmath/llquaternion.cpp20
2 files changed, 37 insertions, 8 deletions
diff --git a/indra/llmath/llquantize.h b/indra/llmath/llquantize.h
index 8aa03628f2..93cd16c13a 100644
--- a/indra/llmath/llquantize.h
+++ b/indra/llmath/llquantize.h
@@ -20,6 +20,18 @@ const U8 FIRSTVALIDCHAR = 54;
const U8 MAXSTRINGVAL = U8MAX - FIRSTVALIDCHAR; //we don't allow newline or null
+inline U16 F32_to_U16_ROUND(F32 val, F32 lower, F32 upper)
+{
+ val = llclamp(val, lower, upper);
+ // make sure that the value is positive and normalized to <0, 1>
+ val -= lower;
+ val /= (upper - lower);
+
+ // round the value. Sreturn the U16
+ return (U16)(llround(val*U16MAX));
+}
+
+
inline U16 F32_to_U16(F32 val, F32 lower, F32 upper)
{
val = llclamp(val, lower, upper);
@@ -47,6 +59,19 @@ inline F32 U16_to_F32(U16 ival, F32 lower, F32 upper)
return val;
}
+
+inline U8 F32_to_U8_ROUND(F32 val, F32 lower, F32 upper)
+{
+ val = llclamp(val, lower, upper);
+ // make sure that the value is positive and normalized to <0, 1>
+ val -= lower;
+ val /= (upper - lower);
+
+ // return the rounded U8
+ return (U8)(llround(val*U8MAX));
+}
+
+
inline U8 F32_to_U8(F32 val, F32 lower, F32 upper)
{
val = llclamp(val, lower, upper);
diff --git a/indra/llmath/llquaternion.cpp b/indra/llmath/llquaternion.cpp
index 8b2808164f..d5fe931187 100644
--- a/indra/llmath/llquaternion.cpp
+++ b/indra/llmath/llquaternion.cpp
@@ -87,23 +87,27 @@ void LLQuaternion::quantize16(F32 lower, F32 upper)
F32 z = mQ[VZ];
F32 s = mQ[VS];
- x = U16_to_F32(F32_to_U16(x, lower, upper), lower, upper);
- y = U16_to_F32(F32_to_U16(y, lower, upper), lower, upper);
- z = U16_to_F32(F32_to_U16(z, lower, upper), lower, upper);
- s = U16_to_F32(F32_to_U16(s, lower, upper), lower, upper);
+ x = U16_to_F32(F32_to_U16_ROUND(x, lower, upper), lower, upper);
+ y = U16_to_F32(F32_to_U16_ROUND(y, lower, upper), lower, upper);
+ z = U16_to_F32(F32_to_U16_ROUND(z, lower, upper), lower, upper);
+ s = U16_to_F32(F32_to_U16_ROUND(s, lower, upper), lower, upper);
mQ[VX] = x;
mQ[VY] = y;
mQ[VZ] = z;
mQ[VS] = s;
+
+ normQuat();
}
void LLQuaternion::quantize8(F32 lower, F32 upper)
{
- mQ[VX] = U8_to_F32(F32_to_U8(mQ[VX], lower, upper), lower, upper);
- mQ[VY] = U8_to_F32(F32_to_U8(mQ[VY], lower, upper), lower, upper);
- mQ[VZ] = U8_to_F32(F32_to_U8(mQ[VZ], lower, upper), lower, upper);
- mQ[VS] = U8_to_F32(F32_to_U8(mQ[VS], lower, upper), lower, upper);
+ mQ[VX] = U8_to_F32(F32_to_U8_ROUND(mQ[VX], lower, upper), lower, upper);
+ mQ[VY] = U8_to_F32(F32_to_U8_ROUND(mQ[VY], lower, upper), lower, upper);
+ mQ[VZ] = U8_to_F32(F32_to_U8_ROUND(mQ[VZ], lower, upper), lower, upper);
+ mQ[VS] = U8_to_F32(F32_to_U8_ROUND(mQ[VS], lower, upper), lower, upper);
+
+ normQuat();
}
// LLVector3 Magnitude and Normalization Functions