mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-29 16:25:42 +00:00
Improved BitStream writeQuat/readQuat methods.
Replaces the writeQuat/readQuat implementations with one that utilizes smallest three compression.
This commit is contained in:
parent
54f1d8c18e
commit
e3793184b6
2 changed files with 44 additions and 17 deletions
|
|
@ -488,24 +488,51 @@ void BitStream::readAffineTransform(MatrixF* matrix)
|
||||||
|
|
||||||
void BitStream::writeQuat( const QuatF& quat, U32 bitCount )
|
void BitStream::writeQuat( const QuatF& quat, U32 bitCount )
|
||||||
{
|
{
|
||||||
writeSignedFloat( quat.x, bitCount );
|
F32 quatVals[4] = { quat.x, quat.y, quat.z, quat.w };
|
||||||
writeSignedFloat( quat.y, bitCount );
|
bool flipQuat = (quatVals[0] < 0);
|
||||||
writeSignedFloat( quat.z, bitCount );
|
F32 maxVal = mFabs(quatVals[0]);
|
||||||
writeFlag( quat.w < 0.0f );
|
S32 idxMax = 0;
|
||||||
|
|
||||||
|
for (S32 i = 1; i < 4; ++i)
|
||||||
|
{
|
||||||
|
if (mFabs(quatVals[i]) > maxVal)
|
||||||
|
{
|
||||||
|
idxMax = i;
|
||||||
|
maxVal = mFabs(quatVals[i]);
|
||||||
|
flipQuat = (quatVals[i] < 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writeInt(idxMax, 2);
|
||||||
|
|
||||||
|
for (S32 i = 0; i < 4; ++i)
|
||||||
|
{
|
||||||
|
if (i == idxMax)
|
||||||
|
continue;
|
||||||
|
F32 curValue = (flipQuat ? -quatVals[i] : quatVals[i]) * (F32) M_SQRT2;
|
||||||
|
writeSignedFloat( curValue, bitCount );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitStream::readQuat( QuatF *outQuat, U32 bitCount )
|
void BitStream::readQuat( QuatF *outQuat, U32 bitCount )
|
||||||
{
|
{
|
||||||
outQuat->x = readSignedFloat( bitCount );
|
F32 quatVals[4];
|
||||||
outQuat->y = readSignedFloat( bitCount );
|
F32 sum = 0.0f;
|
||||||
outQuat->z = readSignedFloat( bitCount );
|
|
||||||
|
|
||||||
outQuat->w = mSqrt( 1.0 - getMin( mSquared( outQuat->x ) +
|
S32 idxMax = readInt( 2 );
|
||||||
mSquared( outQuat->y ) +
|
for (S32 i = 0; i < 4; ++i)
|
||||||
mSquared( outQuat->z ),
|
{
|
||||||
1.0f ) );
|
if (i == idxMax)
|
||||||
if ( readFlag() )
|
continue;
|
||||||
outQuat->w = -outQuat->w;
|
quatVals[i] = readSignedFloat( bitCount ) * M_SQRTHALF_F;
|
||||||
|
sum += quatVals[i] * quatVals[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sum > 1.0f)
|
||||||
|
quatVals[idxMax] = 1.0f;
|
||||||
|
else
|
||||||
|
quatVals[idxMax] = mSqrt(1.0f - sum);
|
||||||
|
|
||||||
|
outQuat->set(quatVals[0], quatVals[1], quatVals[2], quatVals[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitStream::writeBits( const BitVector &bitvec )
|
void BitStream::writeBits( const BitVector &bitvec )
|
||||||
|
|
|
||||||
|
|
@ -207,18 +207,18 @@ public:
|
||||||
void readAffineTransform(MatrixF*);
|
void readAffineTransform(MatrixF*);
|
||||||
|
|
||||||
/// Writes a quaternion in a lossy compressed format that
|
/// Writes a quaternion in a lossy compressed format that
|
||||||
/// is ( bitCount * 3 ) + 1 bits in size.
|
/// is ( bitCount * 3 ) + 2 bits in size.
|
||||||
///
|
///
|
||||||
/// @param quat The normalized quaternion to write.
|
/// @param quat The normalized quaternion to write.
|
||||||
/// @param bitCount The the storage space for the xyz component of
|
/// @param bitCount The the storage space for the packed components of
|
||||||
/// the quaternion.
|
/// the quaternion.
|
||||||
///
|
///
|
||||||
void writeQuat( const QuatF& quat, U32 bitCount = 9 );
|
void writeQuat( const QuatF& quat, U32 bitCount = 9 );
|
||||||
|
|
||||||
/// Reads a quaternion written with writeQuat.
|
/// Reads a quaternion written with writeQuat.
|
||||||
///
|
///
|
||||||
/// @param quat The normalized quaternion to write.
|
/// @param quat The quaternion that was read.
|
||||||
/// @param bitCount The the storage space for the xyz component of
|
/// @param bitCount The the storage space for the packed components of
|
||||||
/// the quaternion. Must match the bitCount at write.
|
/// the quaternion. Must match the bitCount at write.
|
||||||
/// @see writeQuat
|
/// @see writeQuat
|
||||||
///
|
///
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue