From dcbb39d640d62661ab4787da2bfb863b890df577 Mon Sep 17 00:00:00 2001 From: smallmodel <15067410+smallmodel@users.noreply.github.com> Date: Mon, 6 Nov 2023 17:58:58 +0100 Subject: [PATCH] Formatted skeletor source files --- code/skeletor/SkelMat3.h | 194 +- code/skeletor/SkelMat4.h | 477 ++-- code/skeletor/SkelQuat.h | 337 ++- code/skeletor/SkelVec3.h | 221 +- code/skeletor/SkelVec4.h | 62 +- code/skeletor/bonetable.cpp | 518 ++--- code/skeletor/skeletor.cpp | 1939 ++++++++--------- code/skeletor/skeletor.h | 265 ++- .../skeletor/skeletor_animation_file_format.h | 118 +- code/skeletor/skeletor_imports.cpp | 32 +- code/skeletor/skeletor_internal.h | 248 ++- code/skeletor/skeletor_loadanimation.cpp | 848 ++++--- code/skeletor/skeletor_model_file_format.h | 126 +- code/skeletor/skeletor_model_files.cpp | 291 +-- code/skeletor/skeletor_name_lists.h | 45 +- code/skeletor/skeletor_utilities.cpp | 395 ++-- code/skeletor/skeletorbones.cpp | 1632 +++++++------- code/skeletor/tokenizer.cpp | 2 +- code/skeletor/tokenizer.h | 81 +- 19 files changed, 3789 insertions(+), 4042 deletions(-) diff --git a/code/skeletor/SkelMat3.h b/code/skeletor/SkelMat3.h index ad5f53b3..c8e85e66 100644 --- a/code/skeletor/SkelMat3.h +++ b/code/skeletor/SkelMat3.h @@ -1,6 +1,6 @@ /* =========================================================================== -Copyright (C) 2015 the OpenMoHAA team +Copyright (C) 2023 the OpenMoHAA team This file is part of OpenMoHAA source code. @@ -22,199 +22,175 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // SkelMat3.h : Skeletor -#ifndef __SKELMAT3_H__ -#define __SKELMAT3_H__ +#pragma once #ifdef __cplusplus -class SkelMat3 { +class SkelMat3 +{ public: - float val[ 3 ][ 3 ]; + float val[3][3]; protected: - void copy( const SkelMat3& m ); + void copy(const SkelMat3& m); public: - void MakeZero(); - void MakeIdentity(); + void MakeZero(); + void MakeIdentity(); - SkelMat3( const SkelVec3& x, const SkelVec3& y, const SkelVec3& z ); - SkelMat3( const float *mat[ 3 ] ); - SkelMat3(); + SkelMat3(const SkelVec3& x, const SkelVec3& y, const SkelVec3& z); + SkelMat3(const float *mat[3]); + SkelMat3(); - SkelVec3 *XAxis(); - SkelVec3 *YAxis(); - SkelVec3 *ZAxis(); + SkelVec3 *XAxis(); + SkelVec3 *YAxis(); + SkelVec3 *ZAxis(); - operator float *( ); - operator float *( ) const; + operator float *(); + operator float *() const; - float *operator[]( int index ); - float *operator[]( int index ) const; + float *operator[](int index); + float *operator[](int index) const; - void GetEulerAngles( float *vec ) const; - void GetScale( float *vec ) const; - bool IsOrthonormal() const; - bool IsValid() const; + void GetEulerAngles(float *vec) const; + void GetScale(float *vec) const; + bool IsOrthonormal() const; + bool IsValid() const; - void Multiply( const float mat1[ 3 ][ 3 ], const float mat2[ 3 ][ 3 ] ); - float det() const; - float trace() const; - SkelVec3 TransformVector( const SkelVec3 *skel ); - void Transpose(); + void Multiply(const float mat1[3][3], const float mat2[3][3]); + float det() const; + float trace() const; + SkelVec3 TransformVector(const SkelVec3 *skel); + void Transpose(); }; -inline -SkelMat3::SkelMat3( const SkelVec3& x, const SkelVec3& y, const SkelVec3& z ) +inline SkelMat3::SkelMat3(const SkelVec3& x, const SkelVec3& y, const SkelVec3& z) { - VectorCopy( x, val[ 0 ] ); - VectorCopy( y, val[ 1 ] ); - VectorCopy( z, val[ 2 ] ); + VectorCopy(x, val[0]); + VectorCopy(y, val[1]); + VectorCopy(z, val[2]); } -inline -SkelMat3::SkelMat3( const float *mat[ 3 ] ) +inline SkelMat3::SkelMat3(const float *mat[3]) { - memcpy( &val, mat, sizeof( val ) ); + memcpy(&val, mat, sizeof(val)); } -inline -SkelMat3::SkelMat3() +inline SkelMat3::SkelMat3() { - MakeIdentity(); + MakeIdentity(); } -inline -void SkelMat3::copy( const SkelMat3& m ) +inline void SkelMat3::copy(const SkelMat3& m) { - AxisCopy( m.val, val ); + AxisCopy(m.val, val); } -inline -void SkelMat3::MakeZero() +inline void SkelMat3::MakeZero() { - AxisClear( val ); + AxisClear(val); } -inline -void SkelMat3::MakeIdentity() +inline void SkelMat3::MakeIdentity() { - MakeZero(); - val[ 0 ][ 0 ] = 1.0f; - val[ 1 ][ 1 ] = 1.0f; - val[ 2 ][ 2 ] = 1.0f; + MakeZero(); + val[0][0] = 1.0f; + val[1][1] = 1.0f; + val[2][2] = 1.0f; } -inline -SkelVec3 *SkelMat3::XAxis() +inline SkelVec3 *SkelMat3::XAxis() { - return ( SkelVec3 * )&val[ 0 ]; + return (SkelVec3 *)&val[0]; } -inline -SkelVec3 *SkelMat3::YAxis() +inline SkelVec3 *SkelMat3::YAxis() { - return ( SkelVec3 * )&val[ 1 ]; + return (SkelVec3 *)&val[1]; } -inline -SkelVec3 *SkelMat3::ZAxis() +inline SkelVec3 *SkelMat3::ZAxis() { - return ( SkelVec3 * )&val[ 2 ]; + return (SkelVec3 *)&val[2]; } -inline -SkelMat3::operator float *( ) +inline SkelMat3::operator float *() { - return &val[ 0 ][ 0 ]; + return &val[0][0]; } -inline -SkelMat3::operator float *( ) const +inline SkelMat3::operator float *() const { - return ( float * )&val[ 0 ][ 0 ]; + return (float *)&val[0][0]; } -inline -float *SkelMat3::operator[]( int index ) +inline float *SkelMat3::operator[](int index) { - return val[ index ]; + return val[index]; } -inline -float *SkelMat3::operator[]( int index ) const +inline float *SkelMat3::operator[](int index) const { - return ( float * )val[ index ]; + return (float *)val[index]; } -inline -void SkelMat3::GetEulerAngles( float *vec ) const +inline void SkelMat3::GetEulerAngles(float *vec) const { - MatrixToEulerAngles( val, vec ); + MatrixToEulerAngles(val, vec); } -inline -void SkelMat3::GetScale( float *vec ) const +inline void SkelMat3::GetScale(float *vec) const { - // FIXME: stub + // FIXME: stub } -inline -bool SkelMat3::IsOrthonormal() const +inline bool SkelMat3::IsOrthonormal() const { - // FIXME: stub - return false; + // FIXME: stub + return false; } -inline -bool SkelMat3::IsValid() const +inline bool SkelMat3::IsValid() const { - // FIXME: stub - return false; + // FIXME: stub + return false; } -inline -void SkelMat3::Multiply( const float mat1[ 3 ][ 3 ], const float mat2[ 3 ][ 3 ] ) +inline void SkelMat3::Multiply(const float mat1[3][3], const float mat2[3][3]) { - MatrixMultiply( mat1, mat2, val ); + MatrixMultiply(mat1, mat2, val); } -inline -float SkelMat3::det() const +inline float SkelMat3::det() const { - return ( val[ 2 ][ 1 ] * val[ 1 ][ 0 ] - val[ 2 ][ 0 ] * val[ 1 ][ 1 ] ) * val[ 0 ][ 2 ] - + ( val[ 1 ][ 1 ] * val[ 2 ][ 2 ] - val[ 1 ][ 2 ] * val[ 2 ][ 1 ] ) * val[ 0 ][ 0 ] - - ( val[ 2 ][ 2 ] * val[ 1 ][ 0 ] - val[ 1 ][ 2 ] * val[ 2 ][ 0 ] ) * val[ 0 ][ 1 ]; + return (val[2][1] * val[1][0] - val[2][0] * val[1][1]) * val[0][2] + + (val[1][1] * val[2][2] - val[1][2] * val[2][1]) * val[0][0] + - (val[2][2] * val[1][0] - val[1][2] * val[2][0]) * val[0][1]; } -inline -float SkelMat3::trace() const +inline float SkelMat3::trace() const { - return val[ 0 ][ 0 ] + val[ 1 ][ 1 ] + val[ 2 ][ 2 ]; + return val[0][0] + val[1][1] + val[2][2]; } -inline -SkelVec3 SkelMat3::TransformVector( const SkelVec3 *skel ) +inline SkelVec3 SkelMat3::TransformVector(const SkelVec3 *skel) { - SkelVec3 out; - MatrixTransformVector( *skel, val, out ); - return out; + SkelVec3 out; + MatrixTransformVector(*skel, val, out); + return out; } -inline -void SkelMat3::Transpose() +inline void SkelMat3::Transpose() { - SkelMat3 out; - TransposeMatrix( val, out.val ); - memcpy( val, out, sizeof( SkelMat3 ) ); + SkelMat3 out; + TransposeMatrix(val, out.val); + memcpy(val, out, sizeof(SkelMat3)); } #else typedef struct { - float val[ 3 ][ 3 ]; + float val[3][3]; } SkelMat3; #endif - -#endif // __SKELMAT3_H__ diff --git a/code/skeletor/SkelMat4.h b/code/skeletor/SkelMat4.h index 16956c0d..e2c9fbba 100644 --- a/code/skeletor/SkelMat4.h +++ b/code/skeletor/SkelMat4.h @@ -1,6 +1,6 @@ /* =========================================================================== -Copyright (C) 2015 the OpenMoHAA team +Copyright (C) 2023 the OpenMoHAA team This file is part of OpenMoHAA source code. @@ -22,371 +22,338 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // SkelMat4.h : Skeletor -#ifndef __SKELMAT4_H__ -#define __SKELMAT4_H__ +#pragma once #ifdef __cplusplus class SkelQuat; -class SkelMat4 { +class SkelMat4 +{ public: - float val[ 4 ][ 3 ]; + float val[4][3]; protected: - void copy( const SkelMat4& ); + void copy(const SkelMat4&); public: - void MakeIdentity(); - void MakeTranslate( float, float, float ); - void MakeXRotation( float ); - void MakeYRotation( float ); - void MakeZRotation( float ); + void MakeIdentity(); + void MakeTranslate(float, float, float); + void MakeXRotation(float); + void MakeYRotation(float); + void MakeZRotation(float); - SkelMat4( const float mat[ 3 ][ 3 ] ); - SkelMat4(); + SkelMat4(const float mat[3][3]); + SkelMat4(); - SkelVec3 *XAxis(); - SkelVec3 *YAxis(); - SkelVec3 *ZAxis(); - SkelVec3 *XAxis() const; - SkelVec3 *YAxis() const; - SkelVec3 *ZAxis() const; + SkelVec3 *XAxis(); + SkelVec3 *YAxis(); + SkelVec3 *ZAxis(); + SkelVec3 *XAxis() const; + SkelVec3 *YAxis() const; + SkelVec3 *ZAxis() const; - operator float *( ); - operator float *( ) const; + operator float *(); + operator float *() const; - bool IsOrthonormal() const; - bool IsValid() const; + bool IsOrthonormal() const; + bool IsValid() const; - float *operator[]( int index ); - float *operator[]( int index ) const; + float *operator[](int index); + float *operator[](int index) const; - int CompareExact( const SkelMat4& skel ) const; + int CompareExact(const SkelMat4& skel) const; - void Sum( const SkelMat4& m1, const SkelMat4& m2 ); - void Difference( const SkelMat4& m1, const SkelMat4& m2 ); - void Multiply( const SkelMat4& m1, const SkelMat4& m2 ); - void InvertAxis( int ); - void RotateBy( const SkelMat3& m ); - void RotateByInverse( const SkelMat3& m ); - void RotateXAxis( float x ); - void RotateYAxis( float y ); - void RotateZAxis( float z ); - void RotateXAxis( float, float ); - void RotateYAxis( float, float ); - void RotateZAxis( float, float ); - void MoveOnXAxis( float x ); - void MoveOnYAxis( float y ); - void MoveOnZAxis( float z ); - void TransformVector( float * ) const; - void TransposeRot(); - void TransposeOf( const SkelMat4& m ); - void TransposeRotOf( const SkelMat4& m ); - void InverseRotOf( const SkelMat4& m ); - float Determinant( void ); - void Inverse( void ); - void GetRotationMatrix( float( *)[ 3 ] ) const; - void GetRotationMatrix( float( *)[ 4 ] ) const; - void ReplacePos( const float * ); - void ReplaceRot( const SkelMat3& m ); - void ReplaceRot( const SkelMat4& m ); - void GetPos( float *pos ) const; - void GetScale( float *scale ) const; - void DeltaPos( const SkelMat4& m, float *delta ) const; - void RotateYaw( float, float ); + void Sum(const SkelMat4 &m1, const SkelMat4 &m2); + void Difference(const SkelMat4 &m1, const SkelMat4 &m2); + void Multiply(const SkelMat4 &m1, const SkelMat4 &m2); + void InvertAxis(int); + void RotateBy(const SkelMat3 &m); + void RotateByInverse(const SkelMat3 &m); + void RotateXAxis(float x); + void RotateYAxis(float y); + void RotateZAxis(float z); + void RotateXAxis(float, float); + void RotateYAxis(float, float); + void RotateZAxis(float, float); + void MoveOnXAxis(float x); + void MoveOnYAxis(float y); + void MoveOnZAxis(float z); + void TransformVector(float *) const; + void TransposeRot(); + void TransposeOf(const SkelMat4 &m); + void TransposeRotOf(const SkelMat4 &m); + void InverseRotOf(const SkelMat4 &m); + float Determinant(void); + void Inverse(void); + void GetRotationMatrix(float (*)[3]) const; + void GetRotationMatrix(float (*)[4]) const; + void ReplacePos(const float *); + void ReplaceRot(const SkelMat3 &m); + void ReplaceRot(const SkelMat4 &m); + void GetPos(float *pos) const; + void GetScale(float *scale) const; + void DeltaPos(const SkelMat4 &m, float *delta) const; + void RotateYaw(float, float); - void GetQuat( SkelQuat& quat ); + void GetQuat(SkelQuat& quat); }; -inline -SkelMat4::SkelMat4( const float mat[ 3 ][ 3 ] ) +inline SkelMat4::SkelMat4(const float mat[3][3]) { - VectorCopy(mat[0], val[0]); - VectorCopy(mat[1], val[1]); - VectorCopy(mat[2], val[2]); - val[3][0] = 0.0f; - val[3][1] = 0.0f; - val[3][2] = 0.0f; + VectorCopy(mat[0], val[0]); + VectorCopy(mat[1], val[1]); + VectorCopy(mat[2], val[2]); + val[3][0] = 0.0f; + val[3][1] = 0.0f; + val[3][2] = 0.0f; } -inline -SkelMat4::SkelMat4() +inline SkelMat4::SkelMat4() { - MakeIdentity(); + MakeIdentity(); } -inline -void SkelMat4::copy( const SkelMat4& m ) +inline void SkelMat4::copy(const SkelMat4& m) { - MatrixCopy( *m.val, *val ); + MatrixCopy(*m.val, *val); } -inline -void SkelMat4::MakeIdentity() +inline void SkelMat4::MakeIdentity() { - memset( val, 0, sizeof( val ) ); - val[ 0 ][ 0 ] = 1.0f; - val[ 1 ][ 1 ] = 1.0f; - val[ 2 ][ 2 ] = 1.0f; + memset(val, 0, sizeof(val)); + val[0][0] = 1.0f; + val[1][1] = 1.0f; + val[2][2] = 1.0f; } -inline -SkelVec3 *SkelMat4::XAxis() +inline SkelVec3 *SkelMat4::XAxis() { - return ( SkelVec3 * )&val[ 0 ]; + return (SkelVec3 *)&val[0]; } -inline -SkelVec3 *SkelMat4::YAxis() +inline SkelVec3 *SkelMat4::YAxis() { - return ( SkelVec3 * )&val[ 1 ]; + return (SkelVec3 *)&val[1]; } -inline -SkelVec3 *SkelMat4::ZAxis() +inline SkelVec3 *SkelMat4::ZAxis() { - return ( SkelVec3 * )&val[ 2 ]; + return (SkelVec3 *)&val[2]; } -inline -SkelVec3 *SkelMat4::XAxis() const +inline SkelVec3 *SkelMat4::XAxis() const { - return ( SkelVec3 * )&val[ 0 ]; + return (SkelVec3 *)&val[0]; } -inline -SkelVec3 *SkelMat4::YAxis() const +inline SkelVec3 *SkelMat4::YAxis() const { - return ( SkelVec3 * )&val[ 1 ]; + return (SkelVec3 *)&val[1]; } -inline -SkelVec3 *SkelMat4::ZAxis() const +inline SkelVec3 *SkelMat4::ZAxis() const { - return ( SkelVec3 * )&val[ 2 ]; + return (SkelVec3 *)&val[2]; } -inline -SkelMat4::operator float *( ) +inline SkelMat4::operator float *() { - return &val[ 0 ][ 0 ]; + return &val[0][0]; } -inline -SkelMat4::operator float *( ) const +inline SkelMat4::operator float *() const { - return ( float * )&val[ 0 ][ 0 ]; + return (float *)&val[0][0]; } -inline -float *SkelMat4::operator[]( int index ) +inline float *SkelMat4::operator[](int index) { - return val[ index ]; + return val[index]; } -inline -float *SkelMat4::operator[]( int index ) const +inline float *SkelMat4::operator[](int index) const { - return ( float * )val[ index ]; + return (float *)val[index]; } -inline -bool SkelMat4::IsOrthonormal() const +inline bool SkelMat4::IsOrthonormal() const { - // FIXME: stub - return false; + // FIXME: stub + return false; } -inline -bool SkelMat4::IsValid() const +inline bool SkelMat4::IsValid() const { - // FIXME: stub - return false; + // FIXME: stub + return false; } -inline -void SkelMat4::Sum( const SkelMat4& m1, const SkelMat4& m2 ) +inline void SkelMat4::Sum(const SkelMat4& m1, const SkelMat4& m2) { - VectorAdd( m1.val[ 0 ], m2.val[ 0 ], val[ 0 ] ); - VectorAdd( m1.val[ 1 ], m2.val[ 1 ], val[ 1 ] ); - VectorAdd( m1.val[ 2 ], m2.val[ 2 ], val[ 2 ] ); + VectorAdd(m1.val[0], m2.val[0], val[0]); + VectorAdd(m1.val[1], m2.val[1], val[1]); + VectorAdd(m1.val[2], m2.val[2], val[2]); } -inline -void SkelMat4::Difference( const SkelMat4& m1, const SkelMat4& m2 ) +inline void SkelMat4::Difference(const SkelMat4& m1, const SkelMat4& m2) { - VectorSubtract( m1.val[ 0 ], m2.val[ 0 ], val[ 0 ] ); - VectorSubtract( m1.val[ 1 ], m2.val[ 1 ], val[ 1 ] ); - VectorSubtract( m1.val[ 2 ], m2.val[ 2 ], val[ 2 ] ); + VectorSubtract(m1.val[0], m2.val[0], val[0]); + VectorSubtract(m1.val[1], m2.val[1], val[1]); + VectorSubtract(m1.val[2], m2.val[2], val[2]); } -inline -void SkelMat4::Multiply( const SkelMat4& m1, const SkelMat4& m2 ) +inline void SkelMat4::Multiply(const SkelMat4& m1, const SkelMat4& m2) { - val[ 0 ][ 0 ] = m1[ 0 ][ 0 ] * m2[ 0 ][ 0 ] + m1[ 0 ][ 1 ] * m2[ 1 ][ 0 ] + m1[ 0 ][ 2 ] * m2[ 2 ][ 0 ]; - val[ 1 ][ 0 ] = m1[ 1 ][ 0 ] * m2[ 0 ][ 0 ] + m1[ 1 ][ 1 ] * m2[ 1 ][ 0 ] + m1[ 1 ][ 2 ] * m2[ 2 ][ 0 ]; - val[ 2 ][ 0 ] = m1[ 2 ][ 0 ] * m2[ 0 ][ 0 ] + m1[ 2 ][ 1 ] * m2[ 1 ][ 0 ] + m1[ 2 ][ 2 ] * m2[ 2 ][ 0 ]; - val[ 3 ][ 0 ] = m1[ 3 ][ 0 ] * m2[ 0 ][ 0 ] + m1[ 3 ][ 1 ] * m2[ 1 ][ 0 ] + m1[ 3 ][ 2 ] * m2[ 2 ][ 0 ] + m2[ 3 ][ 0 ]; + val[0][0] = m1[0][0] * m2[0][0] + m1[0][1] * m2[1][0] + m1[0][2] * m2[2][0]; + val[1][0] = m1[1][0] * m2[0][0] + m1[1][1] * m2[1][0] + m1[1][2] * m2[2][0]; + val[2][0] = m1[2][0] * m2[0][0] + m1[2][1] * m2[1][0] + m1[2][2] * m2[2][0]; + val[3][0] = m1[3][0] * m2[0][0] + m1[3][1] * m2[1][0] + m1[3][2] * m2[2][0] + m2[3][0]; - val[ 0 ][ 1 ] = m1[ 0 ][ 0 ] * m2[ 0 ][ 1 ] + m1[ 0 ][ 1 ] * m2[ 1 ][ 1 ] + m1[ 0 ][ 2 ] * m2[ 2 ][ 1 ]; - val[ 1 ][ 1 ] = m1[ 1 ][ 0 ] * m2[ 0 ][ 1 ] + m1[ 1 ][ 1 ] * m2[ 1 ][ 1 ] + m1[ 1 ][ 2 ] * m2[ 2 ][ 1 ]; - val[ 2 ][ 1 ] = m1[ 2 ][ 0 ] * m2[ 0 ][ 1 ] + m1[ 2 ][ 1 ] * m2[ 1 ][ 1 ] + m1[ 2 ][ 2 ] * m2[ 2 ][ 1 ]; - val[ 3 ][ 1 ] = m1[ 3 ][ 0 ] * m2[ 0 ][ 1 ] + m1[ 3 ][ 1 ] * m2[ 1 ][ 1 ] + m1[ 3 ][ 2 ] * m2[ 2 ][ 1 ] + m2[ 3 ][ 1 ]; + val[0][1] = m1[0][0] * m2[0][1] + m1[0][1] * m2[1][1] + m1[0][2] * m2[2][1]; + val[1][1] = m1[1][0] * m2[0][1] + m1[1][1] * m2[1][1] + m1[1][2] * m2[2][1]; + val[2][1] = m1[2][0] * m2[0][1] + m1[2][1] * m2[1][1] + m1[2][2] * m2[2][1]; + val[3][1] = m1[3][0] * m2[0][1] + m1[3][1] * m2[1][1] + m1[3][2] * m2[2][1] + m2[3][1]; - val[ 0 ][ 2 ] = m1[ 0 ][ 0 ] * m2[ 0 ][ 2 ] + m1[ 0 ][ 1 ] * m2[ 1 ][ 2 ] + m1[ 0 ][ 2 ] * m2[ 2 ][ 2 ]; - val[ 1 ][ 2 ] = m1[ 1 ][ 0 ] * m2[ 0 ][ 2 ] + m1[ 1 ][ 1 ] * m2[ 1 ][ 2 ] + m1[ 1 ][ 2 ] * m2[ 2 ][ 2 ]; - val[ 2 ][ 2 ] = m1[ 2 ][ 0 ] * m2[ 0 ][ 2 ] + m1[ 2 ][ 1 ] * m2[ 1 ][ 2 ] + m1[ 2 ][ 2 ] * m2[ 2 ][ 2 ]; - val[ 3 ][ 2 ] = m1[ 3 ][ 0 ] * m2[ 0 ][ 2 ] + m1[ 3 ][ 1 ] * m2[ 1 ][ 2 ] + m1[ 3 ][ 2 ] * m2[ 2 ][ 2 ] + m2[ 3 ][ 2 ]; + val[0][2] = m1[0][0] * m2[0][2] + m1[0][1] * m2[1][2] + m1[0][2] * m2[2][2]; + val[1][2] = m1[1][0] * m2[0][2] + m1[1][1] * m2[1][2] + m1[1][2] * m2[2][2]; + val[2][2] = m1[2][0] * m2[0][2] + m1[2][1] * m2[1][2] + m1[2][2] * m2[2][2]; + val[3][2] = m1[3][0] * m2[0][2] + m1[3][1] * m2[1][2] + m1[3][2] * m2[2][2] + m2[3][2]; } -inline -void SkelMat4::InvertAxis( int a ) +inline void SkelMat4::InvertAxis(int a) { - val[ a ][ 0 ] = -val[ a ][ 0 ]; val[ a ][ 1 ] = -val[ a ][ 1 ]; val[ a ][ 2 ] = -val[ a ][ 2 ]; + val[a][0] = -val[a][0]; + val[a][1] = -val[a][1]; + val[a][2] = -val[a][2]; } -inline -float SkelMat4::Determinant( void ) +inline float SkelMat4::Determinant(void) { - float mat4x4[ 4 ][ 4 ]; + float mat4x4[4][4]; - mat4x4[ 0 ][ 0 ] = val[ 0 ][ 0 ]; - mat4x4[ 0 ][ 1 ] = val[ 0 ][ 1 ]; - mat4x4[ 0 ][ 2 ] = val[ 0 ][ 2 ]; - mat4x4[ 0 ][ 3 ] = 0; - mat4x4[ 1 ][ 0 ] = val[ 1 ][ 0 ]; - mat4x4[ 1 ][ 1 ] = val[ 1 ][ 1 ]; - mat4x4[ 1 ][ 2 ] = val[ 1 ][ 2 ]; - mat4x4[ 1 ][ 3 ] = 0; - mat4x4[ 2 ][ 0 ] = val[ 2 ][ 0 ]; - mat4x4[ 2 ][ 1 ] = val[ 2 ][ 1 ]; - mat4x4[ 2 ][ 2 ] = val[ 2 ][ 2 ]; - mat4x4[ 2 ][ 3 ] = 0; - mat4x4[ 3 ][ 0 ] = val[ 3 ][ 0 ]; - mat4x4[ 3 ][ 1 ] = val[ 3 ][ 1 ]; - mat4x4[ 3 ][ 2 ] = val[ 3 ][ 2 ]; - mat4x4[ 3 ][ 3 ] = 1; + mat4x4[0][0] = val[0][0]; + mat4x4[0][1] = val[0][1]; + mat4x4[0][2] = val[0][2]; + mat4x4[0][3] = 0; + mat4x4[1][0] = val[1][0]; + mat4x4[1][1] = val[1][1]; + mat4x4[1][2] = val[1][2]; + mat4x4[1][3] = 0; + mat4x4[2][0] = val[2][0]; + mat4x4[2][1] = val[2][1]; + mat4x4[2][2] = val[2][2]; + mat4x4[2][3] = 0; + mat4x4[3][0] = val[3][0]; + mat4x4[3][1] = val[3][1]; + mat4x4[3][2] = val[3][2]; + mat4x4[3][3] = 1; - return mat4x4[ 0 ][ 0 ] * ( - mat4x4[ 1 ][ 1 ] * ( mat4x4[ 2 ][ 2 ] * mat4x4[ 3 ][ 3 ] - mat4x4[ 2 ][ 3 ] * mat4x4[ 3 ][ 2 ] ) - - mat4x4[ 2 ][ 1 ] * ( mat4x4[ 1 ][ 2 ] * mat4x4[ 3 ][ 3 ] - mat4x4[ 1 ][ 3 ] * mat4x4[ 3 ][ 2 ] ) + - mat4x4[ 3 ][ 1 ] * ( mat4x4[ 1 ][ 2 ] * mat4x4[ 2 ][ 3 ] - mat4x4[ 1 ][ 3 ] * mat4x4[ 2 ][ 2 ] ) - ) - - mat4x4[ 1 ][ 0 ] * ( - mat4x4[ 0 ][ 1 ] * ( mat4x4[ 2 ][ 2 ] * mat4x4[ 3 ][ 3 ] - mat4x4[ 2 ][ 3 ] * mat4x4[ 3 ][ 2 ] ) - - mat4x4[ 2 ][ 1 ] * ( mat4x4[ 0 ][ 2 ] * mat4x4[ 3 ][ 3 ] - mat4x4[ 0 ][ 3 ] * mat4x4[ 3 ][ 2 ] ) + - mat4x4[ 3 ][ 1 ] * ( mat4x4[ 0 ][ 2 ] * mat4x4[ 2 ][ 3 ] - mat4x4[ 0 ][ 3 ] * mat4x4[ 2 ][ 2 ] ) - ) + - mat4x4[ 2 ][ 0 ] * ( - mat4x4[ 0 ][ 1 ] * ( mat4x4[ 1 ][ 2 ] * mat4x4[ 3 ][ 3 ] - mat4x4[ 1 ][ 3 ] * mat4x4[ 3 ][ 2 ] ) - - mat4x4[ 1 ][ 1 ] * ( mat4x4[ 0 ][ 2 ] * mat4x4[ 3 ][ 3 ] - mat4x4[ 0 ][ 3 ] * mat4x4[ 3 ][ 2 ] ) + - mat4x4[ 3 ][ 1 ] * ( mat4x4[ 0 ][ 2 ] * mat4x4[ 1 ][ 3 ] - mat4x4[ 0 ][ 3 ] * mat4x4[ 1 ][ 2 ] ) - ) - - mat4x4[ 3 ][ 0 ] * ( - mat4x4[ 0 ][ 1 ] * ( mat4x4[ 1 ][ 2 ] * mat4x4[ 2 ][ 3 ] - mat4x4[ 1 ][ 3 ] * mat4x4[ 2 ][ 2 ] ) - - mat4x4[ 1 ][ 1 ] * ( mat4x4[ 0 ][ 2 ] * mat4x4[ 2 ][ 3 ] - mat4x4[ 0 ][ 3 ] * mat4x4[ 2 ][ 2 ] ) + - mat4x4[ 2 ][ 1 ] * ( mat4x4[ 0 ][ 2 ] * mat4x4[ 1 ][ 3 ] - mat4x4[ 0 ][ 3 ] * mat4x4[ 1 ][ 2 ] ) - ); + return mat4x4[0][0] + * (mat4x4[1][1] * (mat4x4[2][2] * mat4x4[3][3] - mat4x4[2][3] * mat4x4[3][2]) + - mat4x4[2][1] * (mat4x4[1][2] * mat4x4[3][3] - mat4x4[1][3] * mat4x4[3][2]) + + mat4x4[3][1] * (mat4x4[1][2] * mat4x4[2][3] - mat4x4[1][3] * mat4x4[2][2])) + - mat4x4[1][0] + * (mat4x4[0][1] * (mat4x4[2][2] * mat4x4[3][3] - mat4x4[2][3] * mat4x4[3][2]) + - mat4x4[2][1] * (mat4x4[0][2] * mat4x4[3][3] - mat4x4[0][3] * mat4x4[3][2]) + + mat4x4[3][1] * (mat4x4[0][2] * mat4x4[2][3] - mat4x4[0][3] * mat4x4[2][2])) + + mat4x4[2][0] + * (mat4x4[0][1] * (mat4x4[1][2] * mat4x4[3][3] - mat4x4[1][3] * mat4x4[3][2]) + - mat4x4[1][1] * (mat4x4[0][2] * mat4x4[3][3] - mat4x4[0][3] * mat4x4[3][2]) + + mat4x4[3][1] * (mat4x4[0][2] * mat4x4[1][3] - mat4x4[0][3] * mat4x4[1][2])) + - mat4x4[3][0] + * (mat4x4[0][1] * (mat4x4[1][2] * mat4x4[2][3] - mat4x4[1][3] * mat4x4[2][2]) + - mat4x4[1][1] * (mat4x4[0][2] * mat4x4[2][3] - mat4x4[0][3] * mat4x4[2][2]) + + mat4x4[2][1] * (mat4x4[0][2] * mat4x4[1][3] - mat4x4[0][3] * mat4x4[1][2])); } -inline -void SkelMat4::Inverse( void ) +inline void SkelMat4::Inverse(void) { - float mat4x4[ 4 ][ 4 ]; - float outmat4x4[ 4 ][ 4 ]; - const float Det = Determinant(); + float mat4x4[4][4]; + float outmat4x4[4][4]; + const float Det = Determinant(); - mat4x4[ 0 ][ 0 ] = val[ 0 ][ 0 ]; - mat4x4[ 0 ][ 1 ] = val[ 0 ][ 1 ]; - mat4x4[ 0 ][ 2 ] = val[ 0 ][ 2 ]; - mat4x4[ 0 ][ 3 ] = 0; - mat4x4[ 1 ][ 0 ] = val[ 1 ][ 0 ]; - mat4x4[ 1 ][ 1 ] = val[ 1 ][ 1 ]; - mat4x4[ 1 ][ 2 ] = val[ 1 ][ 2 ]; - mat4x4[ 1 ][ 3 ] = 0; - mat4x4[ 2 ][ 0 ] = val[ 2 ][ 0 ]; - mat4x4[ 2 ][ 1 ] = val[ 2 ][ 1 ]; - mat4x4[ 2 ][ 2 ] = val[ 2 ][ 2 ]; - mat4x4[ 2 ][ 3 ] = 0; - mat4x4[ 3 ][ 0 ] = val[ 3 ][ 0 ]; - mat4x4[ 3 ][ 1 ] = val[ 3 ][ 1 ]; - mat4x4[ 3 ][ 2 ] = val[ 3 ][ 2 ]; - mat4x4[ 3 ][ 3 ] = 1; + mat4x4[0][0] = val[0][0]; + mat4x4[0][1] = val[0][1]; + mat4x4[0][2] = val[0][2]; + mat4x4[0][3] = 0; + mat4x4[1][0] = val[1][0]; + mat4x4[1][1] = val[1][1]; + mat4x4[1][2] = val[1][2]; + mat4x4[1][3] = 0; + mat4x4[2][0] = val[2][0]; + mat4x4[2][1] = val[2][1]; + mat4x4[2][2] = val[2][2]; + mat4x4[2][3] = 0; + mat4x4[3][0] = val[3][0]; + mat4x4[3][1] = val[3][1]; + mat4x4[3][2] = val[3][2]; + mat4x4[3][3] = 1; - if( Det == 0.0f ) - { - MakeIdentity(); - } - else - { - VectorMatrixInverse( outmat4x4, mat4x4 ); + if (Det == 0.0f) { + MakeIdentity(); + } else { + VectorMatrixInverse(outmat4x4, mat4x4); - val[ 0 ][ 0 ] = outmat4x4[ 0 ][ 0 ]; - val[ 0 ][ 1 ] = outmat4x4[ 0 ][ 1 ]; - val[ 0 ][ 2 ] = outmat4x4[ 0 ][ 2 ]; - val[ 1 ][ 0 ] = outmat4x4[ 1 ][ 0 ]; - val[ 1 ][ 1 ] = outmat4x4[ 1 ][ 1 ]; - val[ 1 ][ 2 ] = outmat4x4[ 1 ][ 2 ]; - val[ 2 ][ 0 ] = outmat4x4[ 2 ][ 0 ]; - val[ 2 ][ 1 ] = outmat4x4[ 2 ][ 1 ]; - val[ 2 ][ 2 ] = outmat4x4[ 2 ][ 2 ]; - val[ 3 ][ 0 ] = outmat4x4[ 3 ][ 0 ]; - val[ 3 ][ 1 ] = outmat4x4[ 3 ][ 1 ]; - val[ 3 ][ 2 ] = outmat4x4[ 3 ][ 2 ]; - } + val[0][0] = outmat4x4[0][0]; + val[0][1] = outmat4x4[0][1]; + val[0][2] = outmat4x4[0][2]; + val[1][0] = outmat4x4[1][0]; + val[1][1] = outmat4x4[1][1]; + val[1][2] = outmat4x4[1][2]; + val[2][0] = outmat4x4[2][0]; + val[2][1] = outmat4x4[2][1]; + val[2][2] = outmat4x4[2][2]; + val[3][0] = outmat4x4[3][0]; + val[3][1] = outmat4x4[3][1]; + val[3][2] = outmat4x4[3][2]; + } } -inline -void SkelMat4::RotateBy( const SkelMat3& m ) +inline void SkelMat4::RotateBy(const SkelMat3& m) { - SkelMat4 temp = *this; + SkelMat4 temp = *this; - val[ 0 ][ 0 ] = temp[ 0 ][ 0 ] * m[ 0 ][ 0 ] + temp[ 0 ][ 1 ] * m[ 1 ][ 0 ] + temp[ 0 ][ 2 ] * m[ 2 ][ 0 ]; - val[ 0 ][ 1 ] = temp[ 0 ][ 0 ] * m[ 0 ][ 1 ] + temp[ 0 ][ 1 ] * m[ 1 ][ 1 ] + temp[ 0 ][ 2 ] * m[ 2 ][ 1 ]; - val[ 0 ][ 2 ] = temp[ 0 ][ 0 ] * m[ 0 ][ 2 ] + temp[ 0 ][ 1 ] * m[ 1 ][ 2 ] + temp[ 0 ][ 2 ] * m[ 2 ][ 2 ]; + val[0][0] = temp[0][0] * m[0][0] + temp[0][1] * m[1][0] + temp[0][2] * m[2][0]; + val[0][1] = temp[0][0] * m[0][1] + temp[0][1] * m[1][1] + temp[0][2] * m[2][1]; + val[0][2] = temp[0][0] * m[0][2] + temp[0][1] * m[1][2] + temp[0][2] * m[2][2]; - val[ 1 ][ 0 ] = temp[ 1 ][ 0 ] * m[ 0 ][ 0 ] + temp[ 1 ][ 1 ] * m[ 1 ][ 0 ] + temp[ 1 ][ 2 ] * m[ 2 ][ 0 ]; - val[ 1 ][ 1 ] = temp[ 1 ][ 0 ] * m[ 0 ][ 1 ] + temp[ 1 ][ 1 ] * m[ 1 ][ 1 ] + temp[ 1 ][ 2 ] * m[ 2 ][ 1 ]; - val[ 1 ][ 2 ] = temp[ 1 ][ 0 ] * m[ 0 ][ 2 ] + temp[ 1 ][ 1 ] * m[ 1 ][ 2 ] + temp[ 1 ][ 2 ] * m[ 2 ][ 2 ]; + val[1][0] = temp[1][0] * m[0][0] + temp[1][1] * m[1][0] + temp[1][2] * m[2][0]; + val[1][1] = temp[1][0] * m[0][1] + temp[1][1] * m[1][1] + temp[1][2] * m[2][1]; + val[1][2] = temp[1][0] * m[0][2] + temp[1][1] * m[1][2] + temp[1][2] * m[2][2]; - val[ 2 ][ 0 ] = temp[ 2 ][ 0 ] * m[ 0 ][ 0 ] + temp[ 2 ][ 1 ] * m[ 1 ][ 0 ] + temp[ 2 ][ 2 ] * m[ 2 ][ 0 ]; - val[ 2 ][ 1 ] = temp[ 2 ][ 0 ] * m[ 0 ][ 1 ] + temp[ 2 ][ 1 ] * m[ 1 ][ 1 ] + temp[ 2 ][ 2 ] * m[ 2 ][ 1 ]; - val[ 2 ][ 2 ] = temp[ 2 ][ 0 ] * m[ 0 ][ 2 ] + temp[ 2 ][ 1 ] * m[ 1 ][ 2 ] + temp[ 2 ][ 2 ] * m[ 2 ][ 2 ]; + val[2][0] = temp[2][0] * m[0][0] + temp[2][1] * m[1][0] + temp[2][2] * m[2][0]; + val[2][1] = temp[2][0] * m[0][1] + temp[2][1] * m[1][1] + temp[2][2] * m[2][1]; + val[2][2] = temp[2][0] * m[0][2] + temp[2][1] * m[1][2] + temp[2][2] * m[2][2]; } -inline -void SkelMat4::RotateByInverse( const SkelMat3& m ) +inline void SkelMat4::RotateByInverse(const SkelMat3& m) { - // FIXME: stub + // FIXME: stub } -inline -void SkelMat4::TransposeRotOf( const SkelMat4& m ) +inline void SkelMat4::TransposeRotOf(const SkelMat4& m) { - val[ 0 ][ 0 ] = m.val[ 0 ][ 0 ]; - val[ 0 ][ 1 ] = m.val[ 1 ][ 0 ]; - val[ 0 ][ 2 ] = m.val[ 2 ][ 0 ]; - val[ 1 ][ 0 ] = m.val[ 0 ][ 1 ]; - val[ 1 ][ 1 ] = m.val[ 1 ][ 1 ]; - val[ 1 ][ 2 ] = m.val[ 2 ][ 1 ]; - val[ 2 ][ 0 ] = m.val[ 0 ][ 2 ]; - val[ 2 ][ 1 ] = m.val[ 1 ][ 2 ]; - val[ 2 ][ 2 ] = m.val[ 2 ][ 2 ]; + val[0][0] = m.val[0][0]; + val[0][1] = m.val[1][0]; + val[0][2] = m.val[2][0]; + val[1][0] = m.val[0][1]; + val[1][1] = m.val[1][1]; + val[1][2] = m.val[2][1]; + val[2][0] = m.val[0][2]; + val[2][1] = m.val[1][2]; + val[2][2] = m.val[2][2]; } -inline -void SkelMat4::GetQuat( SkelQuat& quat ) +inline void SkelMat4::GetQuat(SkelQuat& quat) { - MatToQuat( val, ( float * )&quat ); + MatToQuat(val, (float *)&quat); } #else typedef struct { - float val[ 4 ][ 3 ]; + float val[4][3]; } SkelMat4; #endif - -#endif // __SKELMAT4_H__ diff --git a/code/skeletor/SkelQuat.h b/code/skeletor/SkelQuat.h index d4f718fb..1daa1ca9 100644 --- a/code/skeletor/SkelQuat.h +++ b/code/skeletor/SkelQuat.h @@ -1,6 +1,6 @@ /* =========================================================================== -Copyright (C) 2015 the OpenMoHAA team +Copyright (C) 2023 the OpenMoHAA team This file is part of OpenMoHAA source code. @@ -22,295 +22,266 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // SkelQuat.h : Skeletor Quat -#ifndef __SKELQUAT_H__ -#define __SKELQUAT_H__ +#pragma once #ifdef __cplusplus -#include "SkelVec3.h" -#include "SkelVec4.h" -#include "SkelMat3.h" -#include "SkelMat4.h" +# include "SkelVec3.h" +# include "SkelVec4.h" +# include "SkelMat3.h" +# include "SkelMat4.h" -class SkelQuat { +class SkelQuat +{ public: - union { - float val[ 4 ]; - struct { - float x; - float y; - float z; - float w; - }; - }; + union { + float val[4]; - SkelQuat(); - SkelQuat( SkelVec3 vec ); - SkelQuat( SkelMat3 mat3 ); - SkelQuat( SkelMat4 mat4 ); - SkelQuat( float x, float y, float z, float w ); - SkelQuat( float *quat ); - SkelQuat( const float *quat ); - SkelQuat( float w, const SkelVec3 *vec ); + struct { + float x; + float y; + float z; + float w; + }; + }; - float& operator[] ( int index ); - float operator[] ( int index ) const; + SkelQuat(); + SkelQuat(SkelVec3 vec); + SkelQuat(SkelMat3 mat3); + SkelQuat(SkelMat4 mat4); + SkelQuat(float x, float y, float z, float w); + SkelQuat(float *quat); + SkelQuat(const float *quat); + SkelQuat(float w, const SkelVec3 *vec); - operator float *( ); - operator float *( ) const; + float& operator[](int index); + float operator[](int index) const; - void Set( float x, float y, float z, float w ); - void Set( SkelVec4 vec4 ); - void Set( float *quat ); - void SetAngle( float a ); - void SetAxis( SkelVec3 vec ); + operator float *(); + operator float *() const; - void Invert(); - float Length() const; - float LengthSquared() const; - void Normalize(); + void Set(float x, float y, float z, float w); + void Set(SkelVec4 vec4); + void Set(float *quat); + void SetAngle(float a); + void SetAxis(SkelVec3 vec); - void GetMat3( SkelMat3& mat3 ) const; - void GetMat4( SkelMat4& mat4 ) const; - void GetEulerAngles( float *angles ) const; - bool IsUnit() const; - void MakeIdentity(); - bool IsIdentity(); - bool IsValid() const; + void Invert(); + float Length() const; + float LengthSquared() const; + void Normalize(); + + void GetMat3(SkelMat3& mat3) const; + void GetMat4(SkelMat4& mat4) const; + void GetEulerAngles(float *angles) const; + bool IsUnit() const; + void MakeIdentity(); + bool IsIdentity(); + bool IsValid() const; }; -inline -SkelQuat::SkelQuat() +inline SkelQuat::SkelQuat() { - QuatClear( val ); + QuatClear(val); } -inline -SkelQuat::SkelQuat( SkelVec3 vec ) +inline SkelQuat::SkelQuat(SkelVec3 vec) { - EulerToQuat( vec.val, val ); + EulerToQuat(vec.val, val); } -inline -SkelQuat::SkelQuat( SkelMat3 mat3 ) +inline SkelQuat::SkelQuat(SkelMat3 mat3) { - MatToQuat( mat3.val, val ); + MatToQuat(mat3.val, val); } -inline -SkelQuat::SkelQuat( SkelMat4 mat4 ) +inline SkelQuat::SkelQuat(SkelMat4 mat4) { - MatToQuat( mat4.val, val ); + MatToQuat(mat4.val, val); } -inline -SkelQuat::SkelQuat( float x, float y, float z, float w ) +inline SkelQuat::SkelQuat(float x, float y, float z, float w) { - Set( x, y, z, w ); + Set(x, y, z, w); } -inline -SkelQuat::SkelQuat( float *quat ) +inline SkelQuat::SkelQuat(float *quat) { - val[ 0 ] = quat[ 0 ]; - val[ 1 ] = quat[ 1 ]; - val[ 2 ] = quat[ 2 ]; - val[ 3 ] = quat[ 3 ]; + val[0] = quat[0]; + val[1] = quat[1]; + val[2] = quat[2]; + val[3] = quat[3]; } -inline -SkelQuat::SkelQuat( const float *quat ) +inline SkelQuat::SkelQuat(const float *quat) { - val[ 0 ] = quat[ 0 ]; - val[ 1 ] = quat[ 1 ]; - val[ 2 ] = quat[ 2 ]; - val[ 3 ] = quat[ 3 ]; + val[0] = quat[0]; + val[1] = quat[1]; + val[2] = quat[2]; + val[3] = quat[3]; } -inline -SkelQuat::SkelQuat( float w, const SkelVec3 *vec ) +inline SkelQuat::SkelQuat(float w, const SkelVec3 *vec) { - val[ 0 ] = vec->x; - val[ 1 ] = vec->y; - val[ 2 ] = vec->z; - val[ 3 ] = w; + val[0] = vec->x; + val[1] = vec->y; + val[2] = vec->z; + val[3] = w; } -inline -void SkelQuat::Set( float x, float y, float z, float w ) +inline void SkelQuat::Set(float x, float y, float z, float w) { - this->x = x; - this->y = y; - this->z = z; - this->w = w; + this->x = x; + this->y = y; + this->z = z; + this->w = w; } -inline -void SkelQuat::Set( SkelVec4 vec4 ) +inline void SkelQuat::Set(SkelVec4 vec4) { - val[ 0 ] = vec4.val[ 0 ]; - val[ 1 ] = vec4.val[ 1 ]; - val[ 2 ] = vec4.val[ 2 ]; - val[ 3 ] = vec4.val[ 3 ]; + val[0] = vec4.val[0]; + val[1] = vec4.val[1]; + val[2] = vec4.val[2]; + val[3] = vec4.val[3]; } -inline -void SkelQuat::Set( float *quat ) +inline void SkelQuat::Set(float *quat) { - val[ 0 ] = quat[ 0 ]; - val[ 1 ] = quat[ 1 ]; - val[ 2 ] = quat[ 2 ]; - val[ 3 ] = quat[ 3 ]; + val[0] = quat[0]; + val[1] = quat[1]; + val[2] = quat[2]; + val[3] = quat[3]; } -inline -void SkelQuat::SetAngle( float a ) +inline void SkelQuat::SetAngle(float a) { - SkelVec3 vec; - vec.y = a; - EulerToQuat( vec.val, val ); + SkelVec3 vec; + vec.y = a; + EulerToQuat(vec.val, val); } -inline -void SkelQuat::SetAxis( SkelVec3 vec ) +inline void SkelQuat::SetAxis(SkelVec3 vec) { - EulerToQuat( vec.val, val ); + EulerToQuat(vec.val, val); } -inline -void SkelQuat::Invert() +inline void SkelQuat::Invert() { - QuatInverse( val ); + QuatInverse(val); } -inline -float SkelQuat::Length() const +inline float SkelQuat::Length() const { - return ( float )sqrt( val[ 0 ] * val[ 0 ] + val[ 1 ] * val[ 1 ] + val[ 2 ] * val[ 2 ] + val[ 3 ] * val[ 3 ] ); + return (float)sqrt(val[0] * val[0] + val[1] * val[1] + val[2] * val[2] + val[3] * val[3]); } -inline -float SkelQuat::LengthSquared() const +inline float SkelQuat::LengthSquared() const { - return val[ 0 ] * val[ 0 ] + val[ 1 ] * val[ 1 ] + val[ 2 ] * val[ 2 ] + val[ 3 ] * val[ 3 ]; + return val[0] * val[0] + val[1] * val[1] + val[2] * val[2] + val[3] * val[3]; } -inline -void SkelQuat::Normalize() +inline void SkelQuat::Normalize() { - VectorNormalize( val ); + VectorNormalize(val); } -inline -void SkelQuat::GetMat3( SkelMat3& mat3 ) const +inline void SkelQuat::GetMat3(SkelMat3& mat3) const { - QuatToMat( val, mat3.val ); + QuatToMat(val, mat3.val); } -inline -void SkelQuat::GetMat4( SkelMat4& mat4 ) const +inline void SkelQuat::GetMat4(SkelMat4& mat4) const { - QuatToMat( val, mat4.val ); + QuatToMat(val, mat4.val); } -inline -void SkelQuat::GetEulerAngles( float *angles ) const +inline void SkelQuat::GetEulerAngles(float *angles) const { - QuatToAngles( val, angles ); + QuatToAngles(val, angles); } -inline -bool SkelQuat::IsUnit() const +inline bool SkelQuat::IsUnit() const { - // FIXME: stub - return false; + // FIXME: stub + return false; } -inline -void SkelQuat::MakeIdentity() +inline void SkelQuat::MakeIdentity() { - x = 0.0f; - y = 0.0f; - z = 0.0f; - w = 1.0f; + x = 0.0f; + y = 0.0f; + z = 0.0f; + w = 1.0f; } -inline -bool SkelQuat::IsIdentity() +inline bool SkelQuat::IsIdentity() { - return ( x == 0.0f ) && ( y == 0.0f ) && ( z == 0.0f ) && ( w == 1.0f ); + return (x == 0.0f) && (y == 0.0f) && (z == 0.0f) && (w == 1.0f); } -inline -bool SkelQuat::IsValid() const +inline bool SkelQuat::IsValid() const { - // FIXME: stub - return true; + // FIXME: stub + return true; } -inline -void Slerp( SkelQuat &from, SkelQuat &to, float t, SkelQuat *out ) +inline void Slerp(SkelQuat& from, SkelQuat& to, float t, SkelQuat *out) { - static_assert(sizeof(float) == sizeof(int), "Float must be the same size as Int"); - float f; - float f2; + static_assert(sizeof(float) == sizeof(int), "Float must be the same size as Int"); + float f; + float f2; - f = from.x * to.x + from.y * to.y + from.z * to.z + from.w * to.w; - f2 = 1.0 - t; + f = from.x * to.x + from.y * to.y + from.z * to.z + from.w * to.w; + f2 = 1.0 - t; - // little hack because I don't know how can this operation be converted to float... - *(int*)&f = (*(int*)&f & 0x80000000) ^ *(int*)&f2; + // little hack because I don't know how can this operation be converted to float... + *(int *)&f = (*(int *)&f & 0x80000000) ^ *(int *)&f2; - out->x = to.x * t + from.x * f; - out->y = to.y * t + from.y * f; - out->z = to.z * t + from.z * f; - out->w = to.w * t + from.w * f; + out->x = to.x * t + from.x * f; + out->y = to.y * t + from.y * f; + out->z = to.z * t + from.z * f; + out->w = to.w * t + from.w * f; - f = 1.0 / out->Length(); - out->x = out->x * f; - out->y = out->y * f; - out->z = out->z * f; - out->w = out->w * f; + f = 1.0 / out->Length(); + out->x = out->x * f; + out->y = out->y * f; + out->z = out->z * f; + out->w = out->w * f; } -inline -SkelQuat::operator float *( ) +inline SkelQuat::operator float *() { - return val; + return val; } -inline -SkelQuat::operator float *( ) const +inline SkelQuat::operator float *() const { - return ( float * )val; + return (float *)val; } -inline -float& SkelQuat::operator[]( int index ) +inline float& SkelQuat::operator[](int index) { - return val[ index ]; + return val[index]; } -inline -float SkelQuat::operator[]( int index ) const +inline float SkelQuat::operator[](int index) const { - return val[ index ]; + return val[index]; } #else typedef struct { - union { - float val[ 4 ]; - struct { - float x; - float y; - float z; - float w; - }; - }; + union { + float val[4]; + + struct { + float x; + float y; + float z; + float w; + }; + }; } SkelQuat; #endif - -#endif // __SKELQUAT_H__ diff --git a/code/skeletor/SkelVec3.h b/code/skeletor/SkelVec3.h index c19439a1..a678a90b 100644 --- a/code/skeletor/SkelVec3.h +++ b/code/skeletor/SkelVec3.h @@ -1,6 +1,6 @@ /* =========================================================================== -Copyright (C) 2015 the OpenMoHAA team +Copyright (C) 2023 the OpenMoHAA team This file is part of OpenMoHAA source code. @@ -22,198 +22,189 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // SkelVec3.h : Skeletor -#ifndef __SKELVEC3_H__ -#define __SKELVEC3_H__ +#pragma once -typedef enum { svX, svY, svZ, svW } SkelVec_Axis; -typedef enum { Vec3YAW, Vec3PITCH, Vec3ROLL } YPR_Axes; +typedef enum { + svX, + svY, + svZ, + svW +} SkelVec_Axis; + +typedef enum { + Vec3YAW, + Vec3PITCH, + Vec3ROLL +} YPR_Axes; #ifdef __cplusplus -class SkelVec3 { +class SkelVec3 +{ public: - union { - float val[ 3 ]; - struct { - float x; - float y; - float z; - }; - }; + union { + float val[3]; + + struct { + float x; + float y; + float z; + }; + }; + protected: - void copy( const SkelVec3& skel ); + void copy(const SkelVec3& skel); public: + SkelVec3(float x, float y, float z); + SkelVec3(vec3_t vec); + SkelVec3(); - SkelVec3( float x, float y, float z ); - SkelVec3( vec3_t vec ); - SkelVec3(); + operator float *(); + operator float *() const; - operator float *( ); - operator float *( ) const; + float& operator[](int index); + float operator[](int index) const; - float& operator[] ( int index ); - float operator[] ( int index ) const; + const SkelVec3& operator+=(const SkelVec3& a); + const SkelVec3& operator+=(vec3_t a); - const SkelVec3& operator+=( const SkelVec3 &a ); - const SkelVec3& operator+=( vec3_t a ); + bool IsZero() const; + bool IsUnit() const; + void set(float x, float y, float z); - bool IsZero() const; - bool IsUnit() const; - void set( float x, float y, float z ); + float Normalize(); + void NormalizeFast(); - float Normalize(); - void NormalizeFast(); - - void SetZero(); - void SetXAxis(); - void SetYAxis(); - void SetZAxis(); - void RotateYaw( float yaw, float deg ); + void SetZero(); + void SetXAxis(); + void SetYAxis(); + void SetZAxis(); + void RotateYaw(float yaw, float deg); }; -inline -SkelVec3::SkelVec3( float x, float y, float z ) +inline SkelVec3::SkelVec3(float x, float y, float z) { - set( x, y, z ); + set(x, y, z); } -inline -SkelVec3::SkelVec3( vec3_t vec ) +inline SkelVec3::SkelVec3(vec3_t vec) { - this->x = vec[ 0 ]; - this->y = vec[ 1 ]; - this->z = vec[ 2 ]; + this->x = vec[0]; + this->y = vec[1]; + this->z = vec[2]; } -inline -SkelVec3::SkelVec3() +inline SkelVec3::SkelVec3() { - SetZero(); + SetZero(); } -inline -SkelVec3::operator float *( ) +inline SkelVec3::operator float *() { - return val; + return val; } -inline -SkelVec3::operator float *( ) const +inline SkelVec3::operator float *() const { - return ( float * )val; + return (float *)val; } -inline -bool SkelVec3::IsZero() const +inline bool SkelVec3::IsZero() const { - return ( x == 0.0f ) && ( y == 0.0f ) && ( z == 0.0f ); + return (x == 0.0f) && (y == 0.0f) && (z == 0.0f); } -inline -bool SkelVec3::IsUnit() const +inline bool SkelVec3::IsUnit() const { - // FIXME: stub - return false; + // FIXME: stub + return false; } -inline -void SkelVec3::set( float x, float y, float z ) +inline void SkelVec3::set(float x, float y, float z) { - this->x = x; - this->y = y; - this->z = z; + this->x = x; + this->y = y; + this->z = z; } -inline -float SkelVec3::Normalize() +inline float SkelVec3::Normalize() { - return VectorNormalize( val ); + return VectorNormalize(val); } -inline -void SkelVec3::NormalizeFast() +inline void SkelVec3::NormalizeFast() { - VectorNormalizeFast( val ); + VectorNormalizeFast(val); } -inline -void SkelVec3::SetZero() +inline void SkelVec3::SetZero() { - this->x = 0.0f; - this->y = 0.0f; - this->z = 0.0f; + this->x = 0.0f; + this->y = 0.0f; + this->z = 0.0f; } -inline -void SkelVec3::SetXAxis() +inline void SkelVec3::SetXAxis() { - x = 0.0f; + x = 0.0f; } -inline -void SkelVec3::SetYAxis() +inline void SkelVec3::SetYAxis() { - y = 0.0f; + y = 0.0f; } -inline -void SkelVec3::SetZAxis() +inline void SkelVec3::SetZAxis() { - z = 0.0f; + z = 0.0f; } -inline -void SkelVec3::RotateYaw( float yaw, float deg ) +inline void SkelVec3::RotateYaw(float yaw, float deg) { - // FIXME: stub + // FIXME: stub } -inline -float& SkelVec3::operator[]( int index ) +inline float& SkelVec3::operator[](int index) { - return val[ index ]; + return val[index]; } -inline -float SkelVec3::operator[]( int index ) const +inline float SkelVec3::operator[](int index) const { - return val[ index ]; + return val[index]; } -inline -const SkelVec3& SkelVec3::operator+=( const SkelVec3 &a ) +inline const SkelVec3& SkelVec3::operator+=(const SkelVec3& a) { - x += a.x; - y += a.y; - z += a.z; + x += a.x; + y += a.y; + z += a.z; - return *this; + return *this; } -inline -const SkelVec3& SkelVec3::operator+=( vec3_t a ) +inline const SkelVec3& SkelVec3::operator+=(vec3_t a) { - x += a[ 0 ]; - y += a[ 1 ]; - z += a[ 2 ]; + x += a[0]; + y += a[1]; + z += a[2]; - return *this; + return *this; } #else typedef struct { - union { - float val[ 3 ]; - struct { - float x; - float y; - float z; - }; - }; + union { + float val[3]; + + struct { + float x; + float y; + float z; + }; + }; } SkelVec3; #endif - -#endif // __SKELVEC3_H__ diff --git a/code/skeletor/SkelVec4.h b/code/skeletor/SkelVec4.h index bdf41f3f..a4b7fcc5 100644 --- a/code/skeletor/SkelVec4.h +++ b/code/skeletor/SkelVec4.h @@ -1,6 +1,6 @@ /* =========================================================================== -Copyright (C) 2015 the OpenMoHAA team +Copyright (C) 2023 the OpenMoHAA team This file is part of OpenMoHAA source code. @@ -22,51 +22,51 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // SkelVec4.h : Skeletor Vec4 -#ifndef __SKELVEC4_H__ -#define __SKELVEC4_H__ +#pragma once #ifdef __cplusplus -class SkelVec4 { +class SkelVec4 +{ public: - union { - float val[ 4 ]; - struct { - float x; - float y; - float z; - float w; - } xyzw; - }; + union { + float val[4]; + + struct { + float x; + float y; + float z; + float w; + } xyzw; + }; protected: - void copy( class SkelVec4 const & ); + void copy(const SkelVec4&); public: - SkelVec4( float x, float y, float z, float w ); - SkelVec4( const SkelVec3& vec3, float w ); - SkelVec4( const float *vec4 ); + SkelVec4(float x, float y, float z, float w); + SkelVec4(const SkelVec3& vec3, float w); + SkelVec4(const float *vec4); - operator float *( ); - operator float *( ) const; + operator float *(); + operator float *() const; - void set( float x, float y, float z, float w ); + void set(float x, float y, float z, float w); }; #else typedef struct { - union { - float val[ 4 ]; - struct { - float x; - float y; - float z; - float w; - }; - }; + union { + float val[4]; + + struct { + float x; + float y; + float z; + float w; + }; + }; } SkelVec4; #endif - -#endif // __SKELVEC4_H__ diff --git a/code/skeletor/bonetable.cpp b/code/skeletor/bonetable.cpp index 942fc73d..02c8594a 100644 --- a/code/skeletor/bonetable.cpp +++ b/code/skeletor/bonetable.cpp @@ -1,6 +1,6 @@ /* =========================================================================== -Copyright (C) 2015 the OpenMoHAA team +Copyright (C) 2023 the OpenMoHAA team This file is part of OpenMoHAA source code. @@ -25,342 +25,300 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "q_shared.h" #include "tiki.h" -void ChannelNameTable::CopyChannel( ChannelName_t *dest, const ChannelName_t *source ) +void ChannelNameTable::CopyChannel(ChannelName_t *dest, const ChannelName_t *source) { - memcpy( dest, source, sizeof( ChannelName_t ) ); + memcpy(dest, source, sizeof(ChannelName_t)); } -void ChannelNameTable::SetChannelName( ChannelName_t *channel, const char *newName ) +void ChannelNameTable::SetChannelName(ChannelName_t *channel, const char *newName) { - strcpy( channel->name, newName ); + strcpy(channel->name, newName); } ChannelNameTable::ChannelNameTable() { - memset( this, 0, sizeof( ChannelNameTable ) ); - m_iNumChannels = 0; + memset(this, 0, sizeof(ChannelNameTable)); + m_iNumChannels = 0; } void ChannelNameTable::PrintContents() { - str channelList; - int i; + str channelList; + int i; - for( i = 0; i < m_iNumChannels; i++ ) - { - if( !m_Channels[ i ].name[ 0 ] ) - { - continue; - } + for (i = 0; i < m_iNumChannels; i++) { + if (!m_Channels[i].name[0]) { + continue; + } - channelList += str( "c" ) + m_Channels[ i ].channelNum + ":" + str( m_Channels[ i ].name ) + "\n"; - } + channelList += str("c") + m_Channels[i].channelNum + ":" + str(m_Channels[i].name) + "\n"; + } - SKEL_Message( "ChannelNameTable contents:\n%s", channelList.c_str() ); + SKEL_Message("ChannelNameTable contents:\n%s", channelList.c_str()); } -bool ChannelNameTable::FindIndexFromName( const char *name, int *indexPtr ) +bool ChannelNameTable::FindIndexFromName(const char *name, int *indexPtr) { - int sortValue; - int lowerBound; - int upperBound; - int index; + int sortValue; + int lowerBound; + int upperBound; + int index; - lowerBound = 0; - upperBound = m_iNumChannels - 1; - while( lowerBound <= upperBound ) - { - index = ( lowerBound + upperBound ) / 2; - sortValue = stricmp( name, m_Channels[ index ].name ); - if( !sortValue ) - { - if( indexPtr ) - *indexPtr = index; - return true; - } - if( sortValue <= 0 ) - { - upperBound = index - 1; - } - else - { - lowerBound = index + 1; - } - } + lowerBound = 0; + upperBound = m_iNumChannels - 1; + while (lowerBound <= upperBound) { + index = (lowerBound + upperBound) / 2; + sortValue = stricmp(name, m_Channels[index].name); + if (!sortValue) { + if (indexPtr) { + *indexPtr = index; + } + return true; + } + if (sortValue <= 0) { + upperBound = index - 1; + } else { + lowerBound = index + 1; + } + } - if( indexPtr ) - *indexPtr = lowerBound; - return false; + if (indexPtr) { + *indexPtr = lowerBound; + } + return false; } -int ChannelNameTable::FindNameLookup( const char *name ) +int ChannelNameTable::FindNameLookup(const char *name) { - int index; + int index; - if( FindIndexFromName( name, &index ) ) - { - return m_Channels[ index ].channelNum; - } - else - { - return -1; - } + if (FindIndexFromName(name, &index)) { + return m_Channels[index].channelNum; + } else { + return -1; + } } - -const char *ChannelNameTable::FindName( int index ) +const char *ChannelNameTable::FindName(int index) { - return FindNameFromLookup( m_lookup[ index ] ); + return FindNameFromLookup(m_lookup[index]); } - -void ChannelNameTable::SortIntoTable( int index ) +void ChannelNameTable::SortIntoTable(int index) { - int i; - ChannelName_t tempName; + int i; + ChannelName_t tempName; - CopyChannel( &tempName, &m_Channels[ m_iNumChannels ] ); + CopyChannel(&tempName, &m_Channels[m_iNumChannels]); - for( i = m_iNumChannels - 1; i >= index; i-- ) - { - m_lookup[ m_Channels[ i ].channelNum ] = i + 1; - CopyChannel( &m_Channels[ i + 1 ], &m_Channels[ i ] ); - } + for (i = m_iNumChannels - 1; i >= index; i--) { + m_lookup[m_Channels[i].channelNum] = i + 1; + CopyChannel(&m_Channels[i + 1], &m_Channels[i]); + } - m_lookup[ tempName.channelNum ] = index; - CopyChannel( &m_Channels[ index ], &tempName ); + m_lookup[tempName.channelNum] = index; + CopyChannel(&m_Channels[index], &tempName); } -static const char *bogusNameTable[] = +static const char *bogusNameTable[] = { + "Bip01 Spine pos", + "Bip01 Spine1 pos", + "Bip01 Spine2 pos", + "Bip01 Neck pos", + "Bip01 Head pos", + "helmet bone pos", + "helmet bone rot", + "Bip01 R Clavicle pos", + "Bip01 R UpperArm pos", + "Bip01 R Forearm pos", + "Bip01 R Hand pos", + "Bip01 R Finger0 pos", + "Bip01 R Finger01 pos", + "Bip01 R Finger02 pos", + "Bip01 R Finger1 pos", + "Bip01 R Finger11 pos", + "Bip01 R Finger12 pos", + "Bip01 R Finger2 pos", + "Bip01 R Finger21 pos", + "Bip01 R Finger22 pos", + "Bip01 R Finger3 pos", + "Bip01 R Finger31 pos", + "Bip01 R Finger32 pos", + "Bip01 R Finger4 pos", + "Bip01 R Finger41 pos", + "Bip01 R Finger42 pos", + "Bip01 L Clavicle pos", + "Bip01 L UpperArm pos", + "Bip01 L Forearm pos", + "Bip01 L Hand pos", + "Bip01 L Finger0 pos", + "Bip01 L Finger01 pos", + "Bip01 L Finger02 pos", + "Bip01 L Finger1 pos", + "Bip01 L Finger11 pos", + "Bip01 L Finger12 pos", + "Bip01 L Finger2 pos", + "Bip01 L Finger21 pos", + "Bip01 L Finger22 pos", + "Bip01 L Finger3 pos", + "Bip01 L Finger31 pos", + "Bip01 L Finger32 pos", + "Bip01 L Finger4 pos", + "Bip01 L Finger41 pos", + "Bip01 L Finger42 pos", + "Bip01 L Toe0 pos", + "Bip01 R Toe0 pos", + "buckle bone pos", + "buckle bone rot", + "belt attachments bone pos", + "belt attachments bone rot", + "backpack bone pos", + "backpack bone rot", + "helper Lelbow pos", + "helper Lelbow rot", + "helper Lshoulder pos", + "helper Lshoulder rot", + "helper Lshoulder01 pos", + "helper Lshoulder01 rot", + "helper Rshoulder pos", + "helper Rshoulder rot", + "helper Lshoulder02 pos", + "helper Lshoulder02 rot", + "helper Relbow pos", + "helper Relbow rot", + "helper Lankle pos", + "helper Lankle rot", + "helper Lknee pos", + "helper Lknee rot", + "helper Rankle pos", + "helper Rankle rot", + "helper Rknee pos", + "helper Rknee rot", + "helper Lhip pos", + "helper Lhip rot", + "helper Lhip01 pos", + "helper Lhip01 rot", + "helper Rhip pos", + "helper Rhip rot", + "helper Rhip01 pos", + "helper Rhip01 rot", + "target_left_hand pos", + "target_left_hand rot", + "target_right_hand pos", + "target_right_hand rot", + "JAW open-closed pos", + "JAW open-closed rot", + "BROW_worry$", + "EYES_down$", + "EYES_Excited_$", + "EYES_L_squint$", + "EYES_left$", + "EYES_right$", + "EYES_smile$", + "EYES_up_$", + "JAW_open-open$", + "MOUTH_L_smile_open$", + "VISEME_Eat$", + "right foot placeholder pos" + "right foot placeholder rot" + "left foot placeholder pos" + "left foot placeholder rot"}; + +bool IsBogusChannelName(const char *name) { - "Bip01 Spine pos", - "Bip01 Spine1 pos", - "Bip01 Spine2 pos", - "Bip01 Neck pos", - "Bip01 Head pos", - "helmet bone pos", - "helmet bone rot", - "Bip01 R Clavicle pos", - "Bip01 R UpperArm pos", - "Bip01 R Forearm pos", - "Bip01 R Hand pos", - "Bip01 R Finger0 pos", - "Bip01 R Finger01 pos", - "Bip01 R Finger02 pos", - "Bip01 R Finger1 pos", - "Bip01 R Finger11 pos", - "Bip01 R Finger12 pos", - "Bip01 R Finger2 pos", - "Bip01 R Finger21 pos", - "Bip01 R Finger22 pos", - "Bip01 R Finger3 pos", - "Bip01 R Finger31 pos", - "Bip01 R Finger32 pos", - "Bip01 R Finger4 pos", - "Bip01 R Finger41 pos", - "Bip01 R Finger42 pos", - "Bip01 L Clavicle pos", - "Bip01 L UpperArm pos", - "Bip01 L Forearm pos", - "Bip01 L Hand pos", - "Bip01 L Finger0 pos", - "Bip01 L Finger01 pos", - "Bip01 L Finger02 pos", - "Bip01 L Finger1 pos", - "Bip01 L Finger11 pos", - "Bip01 L Finger12 pos", - "Bip01 L Finger2 pos", - "Bip01 L Finger21 pos", - "Bip01 L Finger22 pos", - "Bip01 L Finger3 pos", - "Bip01 L Finger31 pos", - "Bip01 L Finger32 pos", - "Bip01 L Finger4 pos", - "Bip01 L Finger41 pos", - "Bip01 L Finger42 pos", - "Bip01 L Toe0 pos", - "Bip01 R Toe0 pos", - "buckle bone pos", - "buckle bone rot", - "belt attachments bone pos", - "belt attachments bone rot", - "backpack bone pos", - "backpack bone rot", - "helper Lelbow pos", - "helper Lelbow rot", - "helper Lshoulder pos", - "helper Lshoulder rot", - "helper Lshoulder01 pos", - "helper Lshoulder01 rot", - "helper Rshoulder pos", - "helper Rshoulder rot", - "helper Lshoulder02 pos", - "helper Lshoulder02 rot", - "helper Relbow pos", - "helper Relbow rot", - "helper Lankle pos", - "helper Lankle rot", - "helper Lknee pos", - "helper Lknee rot", - "helper Rankle pos", - "helper Rankle rot", - "helper Rknee pos", - "helper Rknee rot", - "helper Lhip pos", - "helper Lhip rot", - "helper Lhip01 pos", - "helper Lhip01 rot", - "helper Rhip pos", - "helper Rhip rot", - "helper Rhip01 pos", - "helper Rhip01 rot", - "target_left_hand pos", - "target_left_hand rot", - "target_right_hand pos", - "target_right_hand rot", - "JAW open-closed pos", - "JAW open-closed rot", - "BROW_worry$", - "EYES_down$", - "EYES_Excited_$", - "EYES_L_squint$", - "EYES_left$", - "EYES_right$", - "EYES_smile$", - "EYES_up_$", - "JAW_open-open$", - "MOUTH_L_smile_open$", - "VISEME_Eat$", - "right foot placeholder pos" - "right foot placeholder rot" - "left foot placeholder pos" - "left foot placeholder rot" -}; + int i; -bool IsBogusChannelName( const char *name ) -{ - int i; + for (i = 0; i < sizeof(bogusNameTable) / sizeof(bogusNameTable[0]); i++) { + if (!Q_stricmp(name, bogusNameTable[i])) { + return true; + } + } - for( i = 0; i < sizeof( bogusNameTable )/ sizeof( bogusNameTable[ 0 ] ); i++ ) - { - if( !Q_stricmp( name, bogusNameTable[ i ] ) ) - { - return true; - } - } + if (strstr(name, "Bip0") && !strstr(name, "Bip01") && !strstr(name, "Footsteps")) { + return true; + } - if( strstr( name, "Bip0" ) && !strstr( name, "Bip01" ) && !strstr( name, "Footsteps" ) ) - { - return true; - } - - return false; + return false; } -int GetChannelTypeFromName( const char *name ) +int GetChannelTypeFromName(const char *name) { - int i; - size_t len; + int i; + size_t len; - if( !name ) - { - return 2; - } + if (!name) { + return 2; + } - for( i = 0; i < sizeof( bogusNameTable ) / sizeof( bogusNameTable[ 0 ] ); i++ ) - { - if( !Q_stricmp( name, bogusNameTable[ i ] ) ) - { - return 2; - } - } + for (i = 0; i < sizeof(bogusNameTable) / sizeof(bogusNameTable[0]); i++) { + if (!Q_stricmp(name, bogusNameTable[i])) { + return 2; + } + } - if( strstr( name, "Bip0" ) && !strstr( name, "Bip01" ) && !strstr( name, "Footsteps" ) ) - { - return 2; - } + if (strstr(name, "Bip0") && !strstr(name, "Bip01") && !strstr(name, "Footsteps")) { + return 2; + } - len = strlen( name ); + len = strlen(name); - if( len >= 4 ) - { - if( !memcmp( name + len - 4, " rot", 5 ) ) - { - return 0; - } - else if( !memcmp( name + len - 4, " pos", 5 ) ) - { - return 1; - } - else if( len >= 6 ) - { - if( !memcmp( name + len - 4, " rotFK", 7 ) ) - { - return 2; - } - else - { - return 3; - } - } - else - { - return 3; - } - } - else - { - return 3; - } + if (len >= 4) { + if (!memcmp(name + len - 4, " rot", 5)) { + return 0; + } else if (!memcmp(name + len - 4, " pos", 5)) { + return 1; + } else if (len >= 6) { + if (!memcmp(name + len - 4, " rotFK", 7)) { + return 2; + } else { + return 3; + } + } else { + return 3; + } + } else { + return 3; + } - return false; + return false; } -int ChannelNameTable::RegisterChannel( const char *name ) +int ChannelNameTable::RegisterChannel(const char *name) { - int index; + int index; - if( IsBogusChannelName( name ) ) - { - return -1; - } + if (IsBogusChannelName(name)) { + return -1; + } - if( FindIndexFromName( name, &index ) ) - { - return m_Channels[ index ].channelNum; - } + if (FindIndexFromName(name, &index)) { + return m_Channels[index].channelNum; + } - if( m_iNumChannels >= MAX_SKELETOR_CHANNELS) - { - Com_Printf( "==========================================================================\n" ); - Com_Printf( "Skeletor channel name table, contents (in order of addition):\n" ); + if (m_iNumChannels >= MAX_SKELETOR_CHANNELS) { + Com_Printf("==========================================================================\n"); + Com_Printf("Skeletor channel name table, contents (in order of addition):\n"); - for( index = 0; index < MAX_SKELETOR_CHANNELS; index++ ) - { - Com_Printf( "%s\n", m_Channels[ m_lookup [ index ] ].name ); - } + for (index = 0; index < MAX_SKELETOR_CHANNELS; index++) { + Com_Printf("%s\n", m_Channels[m_lookup[index]].name); + } - Com_Printf( "==========================================================================\n" ); - SKEL_Error( "Channel name table already has %i channels, can't add any more.", MAX_SKELETOR_CHANNELS ); - return -1; - } - else - { - SetChannelName( &m_Channels[ m_iNumChannels ], name ); - m_Channels[ m_iNumChannels ].channelNum = m_iNumChannels; - SortIntoTable( index ); - return m_iNumChannels++; - } + Com_Printf("==========================================================================\n"); + SKEL_Error("Channel name table already has %i channels, can't add any more.", MAX_SKELETOR_CHANNELS); + return -1; + } else { + SetChannelName(&m_Channels[m_iNumChannels], name); + m_Channels[m_iNumChannels].channelNum = m_iNumChannels; + SortIntoTable(index); + return m_iNumChannels++; + } } -const char *ChannelNameTable::FindNameFromLookup( int index ) +const char *ChannelNameTable::FindNameFromLookup(int index) { - if( index < m_iNumChannels ) - { - return m_Channels[ index ].name; - } - else - { - return NULL; - } + if (index < m_iNumChannels) { + return m_Channels[index].name; + } else { + return NULL; + } } diff --git a/code/skeletor/skeletor.cpp b/code/skeletor/skeletor.cpp index 5fa4edda..59d9dbb0 100644 --- a/code/skeletor/skeletor.cpp +++ b/code/skeletor/skeletor.cpp @@ -1,6 +1,6 @@ /* =========================================================================== -Copyright (C) 2015 the OpenMoHAA team +Copyright (C) 2023 the OpenMoHAA team This file is part of OpenMoHAA source code. @@ -27,800 +27,762 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "skeletor.h" #include -#define EPSILON 0.000000000001f +#define EPSILON 0.000000000001f - -int skelAnimDataGameHeader_s::GetFrameNums( float timeSeconds, float timeTolerance, int *beforeFrame, int *afterFrame, float *beforeWeight, float *afterWeight ) +int skelAnimDataGameHeader_s::GetFrameNums( + float timeSeconds, float timeTolerance, int *beforeFrame, int *afterFrame, float *beforeWeight, float *afterWeight +) { - int frameNum1; - int frameNum2; + int frameNum1; + int frameNum2; - frameNum1 = ( int )( timeSeconds / frameTime ); - frameNum2 = frameNum1 + 1; + frameNum1 = (int)(timeSeconds / frameTime); + frameNum2 = frameNum1 + 1; - *afterWeight = ( timeSeconds / frameTime ) - ( float )frameNum1; + *afterWeight = (timeSeconds / frameTime) - (float)frameNum1; - if( ( 1.0 - *afterWeight ) * frameTime < timeTolerance || - *afterWeight * frameTime < timeTolerance ) - { - if( *afterWeight > 0.5 ) - frameNum1++; + if ((1.0 - *afterWeight) * frameTime < timeTolerance || *afterWeight * frameTime < timeTolerance) { + if (*afterWeight > 0.5) { + frameNum1++; + } - if( frameNum1 >= numFrames ) - { - if( ( flags & TAF_DELTADRIVEN ) ) { - frameNum1 %= numFrames; - } else { - frameNum1 = numFrames - 1; - } - } + if (frameNum1 >= numFrames) { + if ((flags & TAF_DELTADRIVEN)) { + frameNum1 %= numFrames; + } else { + frameNum1 = numFrames - 1; + } + } - *beforeFrame = frameNum1; - *beforeWeight = 1.0; - *afterFrame = 0; - *afterWeight = 0.0; + *beforeFrame = frameNum1; + *beforeWeight = 1.0; + *afterFrame = 0; + *afterWeight = 0.0; - return 1; - } - else if( frameNum2 >= numFrames ) - { - if( ( flags & TAF_DELTADRIVEN ) ) { - frameNum2 %= numFrames; - } else { - frameNum2 = numFrames - 1; - } + return 1; + } else if (frameNum2 >= numFrames) { + if ((flags & TAF_DELTADRIVEN)) { + frameNum2 %= numFrames; + } else { + frameNum2 = numFrames - 1; + } - if( frameNum1 >= numFrames ) - { - if( ( flags & TAF_DELTADRIVEN ) ) - { - frameNum1 %= numFrames; - } - else - { - *beforeFrame = numFrames - 1; - *beforeWeight = 1.0; - return 1; - } - } - } + if (frameNum1 >= numFrames) { + if ((flags & TAF_DELTADRIVEN)) { + frameNum1 %= numFrames; + } else { + *beforeFrame = numFrames - 1; + *beforeWeight = 1.0; + return 1; + } + } + } - *beforeFrame = frameNum1; - *afterFrame = frameNum2; - *beforeWeight = 1.0 - *afterWeight; + *beforeFrame = frameNum1; + *afterFrame = frameNum2; + *beforeWeight = 1.0 - *afterWeight; - return 2; + return 2; } -SkelVec3 skelAnimDataGameHeader_s::GetDeltaOverTime( float time1, float time2 ) +SkelVec3 skelAnimDataGameHeader_s::GetDeltaOverTime(float time1, float time2) { - float deltaWeight1; - int frameNum1; - float deltaWeight2; - int frameNum2; - SkelVec3 delta; - int currFrame; - float s, d; + float deltaWeight1; + int frameNum1; + float deltaWeight2; + int frameNum2; + SkelVec3 delta; + int currFrame; + float s, d; - deltaWeight1 = time1 / frameTime; - deltaWeight2 = time2 / frameTime; - frameNum1 = ( int )( deltaWeight1 + 1.0 ); - frameNum2 = ( int )( deltaWeight2 + 1.0 ); - - d = frameNum1 - deltaWeight1; - s = 1.0 - (frameNum2 - deltaWeight2); + deltaWeight1 = time1 / frameTime; + deltaWeight2 = time2 / frameTime; + frameNum1 = (int)(deltaWeight1 + 1.0); + frameNum2 = (int)(deltaWeight2 + 1.0); - if( frameNum1 < frameNum2 ) - { - delta = m_frame[ frameNum1 % numFrames ].delta; + d = frameNum1 - deltaWeight1; + s = 1.0 - (frameNum2 - deltaWeight2); - for( currFrame = frameNum1 + 1; currFrame < frameNum2; currFrame++ ) - { - delta += m_frame[ currFrame % numFrames ].delta; - } - } - else - { - s = s - ( 1.0 - d ); - } + if (frameNum1 < frameNum2) { + delta = m_frame[frameNum1 % numFrames].delta; - delta.x += m_frame[ frameNum2 % numFrames ].delta.x * s; - delta.y += m_frame[ frameNum2 % numFrames ].delta.y * s; - delta.z += m_frame[ frameNum2 % numFrames ].delta.z * s; + for (currFrame = frameNum1 + 1; currFrame < frameNum2; currFrame++) { + delta += m_frame[currFrame % numFrames].delta; + } + } else { + s = s - (1.0 - d); + } - if( delta.x > -0.001f && delta.x < 0.001f ) { - delta.x = 0; - } - if( delta.y > -0.001f && delta.y < 0.001f ) { - delta.y = 0; - } - if( delta.z > -0.001f && delta.z < 0.001f ) { - delta.z = 0; - } + delta.x += m_frame[frameNum2 % numFrames].delta.x * s; + delta.y += m_frame[frameNum2 % numFrames].delta.y * s; + delta.z += m_frame[frameNum2 % numFrames].delta.z * s; - return delta; + if (delta.x > -0.001f && delta.x < 0.001f) { + delta.x = 0; + } + if (delta.y > -0.001f && delta.y < 0.001f) { + delta.y = 0; + } + if (delta.z > -0.001f && delta.z < 0.001f) { + delta.z = 0; + } + + return delta; } float skelAnimDataGameHeader_s::GetAngularDeltaOverTime(float time1, float time2) { - float deltaWeight1; - int frameNum1; - float deltaWeight2; - int frameNum2; - float delta; - int currFrame; - float s, d; + float deltaWeight1; + int frameNum1; + float deltaWeight2; + int frameNum2; + float delta; + int currFrame; + float s, d; - deltaWeight1 = time1 / frameTime; - deltaWeight2 = time2 / frameTime; - frameNum1 = (int)(deltaWeight1 + 1.0); - frameNum2 = (int)(deltaWeight2 + 1.0); + deltaWeight1 = time1 / frameTime; + deltaWeight2 = time2 / frameTime; + frameNum1 = (int)(deltaWeight1 + 1.0); + frameNum2 = (int)(deltaWeight2 + 1.0); - d = frameNum1 - deltaWeight1; - s = 1.0 - (frameNum2 - deltaWeight2); - delta = 0; + d = frameNum1 - deltaWeight1; + s = 1.0 - (frameNum2 - deltaWeight2); + delta = 0; - if (frameNum2 > frameNum1) { - delta = m_frame[frameNum1 % numFrames].angleDelta; + if (frameNum2 > frameNum1) { + delta = m_frame[frameNum1 % numFrames].angleDelta; - for (currFrame = frameNum1 + 1; currFrame < frameNum2; currFrame++) - { - delta += m_frame[currFrame % numFrames].angleDelta; - } - } - else - { - s = s - (1.0 - d); - } + for (currFrame = frameNum1 + 1; currFrame < frameNum2; currFrame++) { + delta += m_frame[currFrame % numFrames].angleDelta; + } + } else { + s = s - (1.0 - d); + } - delta += m_frame[frameNum2 % numFrames].angleDelta * s; + delta += m_frame[frameNum2 % numFrames].angleDelta * s; - if (delta > -0.001f && delta < 0.001f) { - delta = 0; - } + if (delta > -0.001f && delta < 0.001f) { + delta = 0; + } - return delta; + return delta; } -skelAnimDataGameHeader_t *skelAnimDataGameHeader_s::AllocAnimData( size_t numFrames, size_t numChannels ) +skelAnimDataGameHeader_t *skelAnimDataGameHeader_s::AllocAnimData(size_t numFrames, size_t numChannels) { - skelAnimDataGameHeader_t *data; - - const size_t animSize = sizeof( skelAnimDataGameHeader_t ) + ( 16 * ( 3 * numFrames - 3 ) ) + 16 * numChannels * numFrames; + skelAnimDataGameHeader_t *data; - data = ( skelAnimDataGameHeader_t * )Skel_Alloc( animSize ); - data->flags = 0; - data->channelList.InitChannels(); - data->nBytesUsed = animSize; - data->numFrames = numFrames; - return data; + const size_t animSize = + sizeof(skelAnimDataGameHeader_t) + (16 * (3 * numFrames - 3)) + 16 * numChannels * numFrames; + + data = (skelAnimDataGameHeader_t *)Skel_Alloc(animSize); + data->flags = 0; + data->channelList.InitChannels(); + data->nBytesUsed = animSize; + data->numFrames = numFrames; + return data; } - skelAnimDataGameHeader_s *skelAnimDataGameHeader_s::AllocRLEChannelData(size_t numChannels) { - int animSize; - skelAnimDataGameHeader_t *data; + int animSize; + skelAnimDataGameHeader_t *data; - animSize = sizeof( skelAnimDataGameHeader_t ) + ( numChannels - 1 ) * sizeof( skanChannelHdr ); - data = ( skelAnimDataGameHeader_t * )Skel_Alloc( animSize ); - data->flags = 0; - data->nTotalChannels = numChannels; - data->channelList.InitChannels(); - data->nBytesUsed = animSize; - return data; + animSize = sizeof(skelAnimDataGameHeader_t) + (numChannels - 1) * sizeof(skanChannelHdr); + data = (skelAnimDataGameHeader_t *)Skel_Alloc(animSize); + data->flags = 0; + data->nTotalChannels = numChannels; + data->channelList.InitChannels(); + data->nBytesUsed = animSize; + return data; } -skeletor_c::skeletor_c( dtiki_t *tiki ) +skeletor_c::skeletor_c(dtiki_t *tiki) { - int numBones; - int mesh; - skelHeaderGame_t *skelmodel; + int numBones; + int mesh; + skelHeaderGame_t *skelmodel; - m_Tiki = tiki; + m_Tiki = tiki; - m_morphTargetList.InitChannels(); - m_morphTargetList.ZeroChannels(); + m_morphTargetList.InitChannels(); + m_morphTargetList.ZeroChannels(); - m_frameBounds[ 0 ].set( -32, -32, 0 ); - m_frameBounds[ 1 ].set( 32, 32, 28 ); - m_frameRadius = 64; - m_frameList.numActionFrames = 0; - m_frameList.numMovementFrames = 0; - m_targetLookLeft = 0; - m_targetLookRight = 0; - m_targetLookUp = 0; - m_targetLookDown = 0; - m_targetLookCrossed = 0; - m_targetBlink = 0; + m_frameBounds[0].set(-32, -32, 0); + m_frameBounds[1].set(32, 32, 28); + m_frameRadius = 64; + m_frameList.numActionFrames = 0; + m_frameList.numMovementFrames = 0; + m_targetLookLeft = 0; + m_targetLookRight = 0; + m_targetLookUp = 0; + m_targetLookDown = 0; + m_targetLookCrossed = 0; + m_targetBlink = 0; - VectorClear( m_eyeTargetPos ); - VectorClear( m_eyePrevTargetPos ); + VectorClear(m_eyeTargetPos); + VectorClear(m_eyePrevTargetPos); - m_timeNextBlink = Sys_Milliseconds(); - numBones = m_Tiki->m_boneList.NumChannels(); - m_bone = ( skelBone_Base ** )Skel_Alloc( numBones * sizeof( skelBone_Base * ) ); - memset( m_bone, 0, numBones * sizeof( skelBone_Base * ) ); + m_timeNextBlink = Sys_Milliseconds(); + numBones = m_Tiki->m_boneList.NumChannels(); + m_bone = (skelBone_Base **)Skel_Alloc(numBones * sizeof(skelBone_Base *)); + memset(m_bone, 0, numBones * sizeof(skelBone_Base *)); - for( mesh = 0; mesh < m_Tiki->numMeshes; mesh++ ) - { - skelmodel = TIKI_GetSkel( m_Tiki->mesh[ mesh ] ); - SkeletorLoadBonesFromBuffer( &m_Tiki->m_boneList, skelmodel, m_bone ); - LoadMorphTargetNames( skelmodel ); - } + for (mesh = 0; mesh < m_Tiki->numMeshes; mesh++) { + skelmodel = TIKI_GetSkel(m_Tiki->mesh[mesh]); + SkeletorLoadBonesFromBuffer(&m_Tiki->m_boneList, skelmodel, m_bone); + LoadMorphTargetNames(skelmodel); + } - m_morphTargetList.PackChannels(); - m_headBoneIndex = m_Tiki->GetBoneNumFromName( "Bip01 Head" ); + m_morphTargetList.PackChannels(); + m_headBoneIndex = m_Tiki->GetBoneNumFromName("Bip01 Head"); } skeletor_c::~skeletor_c() { - int i; + int i; - for( i = 0; i < m_Tiki->m_boneList.m_numChannels; i++ ) { - delete m_bone[ i ]; - } + for (i = 0; i < m_Tiki->m_boneList.m_numChannels; i++) { + delete m_bone[i]; + } - m_morphTargetList.CleanUpChannels(); - Skel_Free( m_bone ); - m_bone = NULL; + m_morphTargetList.CleanUpChannels(); + Skel_Free(m_bone); + m_bone = NULL; } -void skelAnimDataGameHeader_s::DeallocAnimData( skelAnimDataGameHeader_t *data ) +void skelAnimDataGameHeader_s::DeallocAnimData(skelAnimDataGameHeader_t *data) { - skanChannelHdr *pChannel; - int i; + skanChannelHdr *pChannel; + int i; - if( !data || data == ( skelAnimDataGameHeader_t * )-476 ) - { - return; - } + if (!data || data == (skelAnimDataGameHeader_t *)-476) { + return; + } - for( i = 0; i < data->nTotalChannels; i++ ) - { - pChannel = &data->ary_channels[ i ]; + for (i = 0; i < data->nTotalChannels; i++) { + pChannel = &data->ary_channels[i]; - if( pChannel->ary_frames ) - { - Skel_Free( pChannel->ary_frames ); - } - } + if (pChannel->ary_frames) { + Skel_Free(pChannel->ary_frames); + } + } - data->channelList.CleanUpChannels(); + data->channelList.CleanUpChannels(); - if( data->m_frame ) { - Skel_Free( data->m_frame ); - } + if (data->m_frame) { + Skel_Free(data->m_frame); + } - Skel_Free( data ); + Skel_Free(data); } -void ConvertToRotationName( const char *boneName, char *rotChannelName ) +void ConvertToRotationName(const char *boneName, char *rotChannelName) { - strcpy( rotChannelName, boneName ); - strcat( rotChannelName, " rot" ); + strcpy(rotChannelName, boneName); + strcat(rotChannelName, " rot"); } -void ConvertToPositionName( const char *boneName, char *posChannelName ) +void ConvertToPositionName(const char *boneName, char *posChannelName) { - strcpy( posChannelName, boneName ); - strcat( posChannelName, " rot" ); + strcpy(posChannelName, boneName); + strcat(posChannelName, " rot"); } -void ConvertToFKRotationName( const char *boneName, char *rotChannelName ) +void ConvertToFKRotationName(const char *boneName, char *rotChannelName) { - strcpy( rotChannelName, boneName ); - strcat( rotChannelName, " rot" ); - strcat( rotChannelName, "FK" ); + strcpy(rotChannelName, boneName); + strcat(rotChannelName, " rot"); + strcat(rotChannelName, "FK"); } -void ConvertToFKPositionName( const char *boneName, char *rotChannelName ) +void ConvertToFKPositionName(const char *boneName, char *rotChannelName) { - strcpy( rotChannelName, boneName ); - strcat( rotChannelName, " pos" ); - strcat( rotChannelName, "FK" ); + strcpy(rotChannelName, boneName); + strcat(rotChannelName, " pos"); + strcat(rotChannelName, "FK"); } -int GetHighestFloat( float *selection ) +int GetHighestFloat(float *selection) { - float currentHighest; - int currentHighestIndex; - int i; + float currentHighest; + int currentHighestIndex; + int i; - currentHighest = selection[ 0 ]; - currentHighestIndex = 0; + currentHighest = selection[0]; + currentHighestIndex = 0; - for( i = 0; i < 8; i++ ) - { - if( selection[ i ] > currentHighest ) - { - currentHighest = selection[ i ]; - currentHighestIndex = i; - } - } + for (i = 0; i < 8; i++) { + if (selection[i] > currentHighest) { + currentHighest = selection[i]; + currentHighestIndex = i; + } + } - return currentHighestIndex; -} -void AddToBounds( SkelVec3 *bounds, SkelVec3 *newBounds ) -{ - int i; - - for( i = 0; i < 3; i++ ) - { - if( bounds[ 0 ][ i ] > newBounds[ 0 ][ i ] ) - { - bounds[ 0 ][ i ] = newBounds[ 0 ][ i ]; - } - - if( bounds[ 1 ][ i ] > newBounds[ 1 ][ i ] ) - { - bounds[ 1 ][ i ] = newBounds[ 1 ][ i ]; - } - } + return currentHighestIndex; } -void skeletor_c::SetPose( const frameInfo_t *frameInfo, const int *contIndices, const vec4_t *contValues, float actionWeight ) +void AddToBounds(SkelVec3 *bounds, SkelVec3 *newBounds) { - skelAnimDataGameHeader_t *animData; - short int *aliases; - //int boneNum; - int blendNum; - int i; - int blendFrame; - int movementBlendFrame; - int actionBlendFrame; - //int realAnimIndex; - int beforeFrame; - int afterFrame; - float beforeWeight; - float afterWeight; - int numFramesAdded; - float cutoff_weight; - int contNum; - float animWeight; - skanBlendInfo *frame1, *frame2; + int i; - for( i = 0; i < m_Tiki->m_boneList.NumChannels(); i++ ) - { - m_bone[ i ]->m_controller = NULL; - m_bone[ i ]->m_isDirty = true; - } + for (i = 0; i < 3; i++) { + if (bounds[0][i] > newBounds[0][i]) { + bounds[0][i] = newBounds[0][i]; + } - if( contIndices && contValues ) - { - for( i = 0; i < 5; i++ ) - { - contNum = contIndices[ i ]; - if( contNum >= 0 && contNum < m_Tiki->m_boneList.NumChannels() ) - { - cutoff_weight = ( contValues[ i ][ 3 ] - 1.0 ) * ( contValues[ i ][ 3 ] - 1.0 ); - if( cutoff_weight >= EPSILON ) - { - m_bone[ contNum ]->m_controller = ( float * )contValues[ i ]; - } - } - } - } - - for( i = 0; i < 3; i++ ) - { - m_frameBounds[ 0 ][ i ] = -2.0f; - m_frameBounds[ 1 ][ i ] = 2.0f; - } - - m_frameRadius = 2.0f; - animWeight = 0.0f; - movementBlendFrame = 0; - actionBlendFrame = 32; - aliases = m_Tiki->a->m_aliases; - - for( i = 0; i < MAX_FRAMEINFOS; i++ ) - { - if( animWeight < frameInfo[ i ].weight ) { - animWeight = frameInfo[ i ].weight; - } - } - - cutoff_weight = animWeight * 0.01f; - - for( i = 0; i < MAX_FRAMEINFOS; i++ ) - { - if( frameInfo[ i ].weight > cutoff_weight ) - { - animData = SkeletorCacheGetData( aliases[ frameInfo[ i ].index ] ); - if( animData->bHasDelta ) { - blendFrame = movementBlendFrame; - } else { - blendFrame = actionBlendFrame; - } - - beforeWeight = 0.0; - afterWeight = 0.0; - beforeFrame = 0.0; - afterFrame = 0.0; - - numFramesAdded = animData->GetFrameNums( frameInfo[ i ].time, 0.01f, &beforeFrame, &afterFrame, &beforeWeight, &afterWeight ); - - frame1 = &m_frameList.m_blendInfo[ blendFrame ]; - frame1->frame = beforeFrame; - frame1->pAnimationData = animData; - frame1->weight = beforeWeight * frameInfo[ i ].weight; - - AddToBounds( m_frameBounds, animData->bounds ); - - if( frame1->pAnimationData->m_frame[ frame1->frame ].radius > m_frameRadius ) - m_frameRadius = frame1->pAnimationData->m_frame[ frame1->frame ].radius; - - if( numFramesAdded == 2 ) - { - frame2 = &m_frameList.m_blendInfo[ blendFrame + 1 ]; - frame2->frame = afterFrame; - frame2->pAnimationData = animData; - frame2->weight = afterWeight * frameInfo[ i ].weight; - AddToBounds( m_frameBounds, animData->bounds ); - - if( frame2->pAnimationData->m_frame[ frame2->frame ].radius > m_frameRadius ) - m_frameRadius = frame2->pAnimationData->m_frame[ frame2->frame ].radius; - - } - - blendNum = blendFrame + numFramesAdded; - - if( animData->bHasDelta ) { - movementBlendFrame = blendNum; - } else { - actionBlendFrame = blendNum; - } - } - } - - for( i = 0; i < 3; i++ ) - { - m_frameBounds[ 0 ][ i ] += -7.0f; - m_frameBounds[ 1 ][ i ] += 7.0f; - } - - m_frameList.numMovementFrames = movementBlendFrame; - m_frameList.numActionFrames = actionBlendFrame - 32; - m_frameList.actionWeight = actionWeight; + if (bounds[1][i] > newBounds[1][i]) { + bounds[1][i] = newBounds[1][i]; + } + } } -static SkelMat4 GetGlobalDefaultPosition( skelBone_Base *bone ) +void skeletor_c::SetPose( + const frameInfo_t *frameInfo, const int *contIndices, const vec4_t *contValues, float actionWeight +) { - SkelMat4 lLocalPosition; - SkelMat4 lGlobalPosition; - SkelMat4 lParentGlobalPosition; + skelAnimDataGameHeader_t *animData; + short int *aliases; + //int boneNum; + int blendNum; + int i; + int blendFrame; + int movementBlendFrame; + int actionBlendFrame; + //int realAnimIndex; + int beforeFrame; + int afterFrame; + float beforeWeight; + float afterWeight; + int numFramesAdded; + float cutoff_weight; + int contNum; + float animWeight; + skanBlendInfo *frame1, *frame2; - lLocalPosition = bone->GetTransform( NULL ); + for (i = 0; i < m_Tiki->m_boneList.NumChannels(); i++) { + m_bone[i]->m_controller = NULL; + m_bone[i]->m_isDirty = true; + } - if( bone->Parent() ) - { - //lParentGlobalPosition = GetGlobalDefaultPosition( bone->Parent() ); - //lGlobalPosition.Multiply( lParentGlobalPosition, lLocalPosition ); - lGlobalPosition = lLocalPosition; - } - else - { - lGlobalPosition = lLocalPosition; - } + if (contIndices && contValues) { + for (i = 0; i < 5; i++) { + contNum = contIndices[i]; + if (contNum >= 0 && contNum < m_Tiki->m_boneList.NumChannels()) { + cutoff_weight = (contValues[i][3] - 1.0) * (contValues[i][3] - 1.0); + if (cutoff_weight >= EPSILON) { + m_bone[contNum]->m_controller = (float *)contValues[i]; + } + } + } + } - return lGlobalPosition; + for (i = 0; i < 3; i++) { + m_frameBounds[0][i] = -2.0f; + m_frameBounds[1][i] = 2.0f; + } + + m_frameRadius = 2.0f; + animWeight = 0.0f; + movementBlendFrame = 0; + actionBlendFrame = 32; + aliases = m_Tiki->a->m_aliases; + + for (i = 0; i < MAX_FRAMEINFOS; i++) { + if (animWeight < frameInfo[i].weight) { + animWeight = frameInfo[i].weight; + } + } + + cutoff_weight = animWeight * 0.01f; + + for (i = 0; i < MAX_FRAMEINFOS; i++) { + if (frameInfo[i].weight > cutoff_weight) { + animData = SkeletorCacheGetData(aliases[frameInfo[i].index]); + if (animData->bHasDelta) { + blendFrame = movementBlendFrame; + } else { + blendFrame = actionBlendFrame; + } + + beforeWeight = 0.0; + afterWeight = 0.0; + beforeFrame = 0.0; + afterFrame = 0.0; + + numFramesAdded = animData->GetFrameNums( + frameInfo[i].time, 0.01f, &beforeFrame, &afterFrame, &beforeWeight, &afterWeight + ); + + frame1 = &m_frameList.m_blendInfo[blendFrame]; + frame1->frame = beforeFrame; + frame1->pAnimationData = animData; + frame1->weight = beforeWeight * frameInfo[i].weight; + + AddToBounds(m_frameBounds, animData->bounds); + + if (frame1->pAnimationData->m_frame[frame1->frame].radius > m_frameRadius) { + m_frameRadius = frame1->pAnimationData->m_frame[frame1->frame].radius; + } + + if (numFramesAdded == 2) { + frame2 = &m_frameList.m_blendInfo[blendFrame + 1]; + frame2->frame = afterFrame; + frame2->pAnimationData = animData; + frame2->weight = afterWeight * frameInfo[i].weight; + AddToBounds(m_frameBounds, animData->bounds); + + if (frame2->pAnimationData->m_frame[frame2->frame].radius > m_frameRadius) { + m_frameRadius = frame2->pAnimationData->m_frame[frame2->frame].radius; + } + } + + blendNum = blendFrame + numFramesAdded; + + if (animData->bHasDelta) { + movementBlendFrame = blendNum; + } else { + actionBlendFrame = blendNum; + } + } + } + + for (i = 0; i < 3; i++) { + m_frameBounds[0][i] += -7.0f; + m_frameBounds[1][i] += 7.0f; + } + + m_frameList.numMovementFrames = movementBlendFrame; + m_frameList.numActionFrames = actionBlendFrame - 32; + m_frameList.actionWeight = actionWeight; } -SkelMat4 GlobalToLocal( skelBone_Base *bone, SkelMat4 pGlobalPosition ) +static SkelMat4 GetGlobalDefaultPosition(skelBone_Base *bone) { - SkelMat4 lLocalPosition; - SkelMat4 lParentGlobalPosition; + SkelMat4 lLocalPosition; + SkelMat4 lGlobalPosition; + SkelMat4 lParentGlobalPosition; - if( bone->Parent() ) - { - lParentGlobalPosition = GetGlobalDefaultPosition( bone->Parent() ); - lParentGlobalPosition.Inverse(); - lLocalPosition.Multiply( lParentGlobalPosition, pGlobalPosition ); - } - else - { - lLocalPosition = pGlobalPosition; - } + lLocalPosition = bone->GetTransform(NULL); - return lLocalPosition; + if (bone->Parent()) { + //lParentGlobalPosition = GetGlobalDefaultPosition( bone->Parent() ); + //lGlobalPosition.Multiply( lParentGlobalPosition, lLocalPosition ); + lGlobalPosition = lLocalPosition; + } else { + lGlobalPosition = lLocalPosition; + } + + return lGlobalPosition; } -void BoneGetFrames( skelHeaderGame_t *skelmodel, skelAnimDataGameHeader_t *animData, skelChannelList_c *boneList, int boneNum, Container< skanAnimFrame >& outFrames ) +SkelMat4 GlobalToLocal(skelBone_Base *bone, SkelMat4 pGlobalPosition) { - int numBones; - skelBone_Base **bone; - int i; - skanAnimFrame frame; - int localChannelNum; + SkelMat4 lLocalPosition; + SkelMat4 lParentGlobalPosition; - outFrames.FreeObjectList(); + if (bone->Parent()) { + lParentGlobalPosition = GetGlobalDefaultPosition(bone->Parent()); + lParentGlobalPosition.Inverse(); + lLocalPosition.Multiply(lParentGlobalPosition, pGlobalPosition); + } else { + lLocalPosition = pGlobalPosition; + } - numBones = boneList->NumChannels(); - - bone = ( skelBone_Base ** )Skel_Alloc( sizeof( skelBone_Base * ) * numBones ); - memset( bone, 0, sizeof( skelBone_Base * ) * numBones ); - - SkeletorLoadBonesFromBuffer( boneList, skelmodel, bone ); - - for( i = 0; i < numBones; i++ ) - { - bone[ i ]->m_controller = NULL; - bone[ i ]->m_isDirty = true; - } - - // process the rot channel - localChannelNum = animData->channelList.GetLocalFromGlobal( bone[ boneNum ]->GetChannelIndex( 1 ) ); - if( localChannelNum >= 0 ) - { - skanChannelHdr *channel = &animData->ary_channels[ localChannelNum ]; - - for( i = 0; i < channel->nFramesInChannel; i++ ) - { - skanGameFrame *pFrame = &channel->ary_frames[ i ]; - - frame.nFrameNum = pFrame->nFrameNum; - VectorClear( frame.pos ); - QuatToAngles( pFrame->pChannelData, frame.rot ); - - outFrames.AddObject( frame ); - } - } - - if( bone[ i ]->GetChannelIndex( 0 ) != bone[ i ]->GetChannelIndex( 1 ) ) - { - // process the pos channel - localChannelNum = animData->channelList.GetLocalFromGlobal( bone[ boneNum ]->GetChannelIndex( 0 ) ); - if( localChannelNum >= 0 ) - { - skanChannelHdr *channel = &animData->ary_channels[ localChannelNum ]; - - for( i = 0; i < channel->nFramesInChannel; i++ ) - { - skanGameFrame *pFrame = &channel->ary_frames[ i ]; - skanAnimFrame *pOutFrame = &outFrames[ i ]; - - VectorCopy( pFrame->pChannelData, pOutFrame->pos ); - } - } - } + return lLocalPosition; } -void SkeletorGetAnimFrame2(skelHeaderGame_t *skelmodel, skelChannelList_c *boneList, skelBoneCache_t *bones, skelAnimStoreFrameList_c *frameList, float *radius, vec3_t *mins, vec3_t *maxes) +void BoneGetFrames( + skelHeaderGame_t *skelmodel, + skelAnimDataGameHeader_t *animData, + skelChannelList_c *boneList, + int boneNum, + Container& outFrames +) { - int numBones; - skelBone_Base **bone; - int i; - skelAnimFrame_t *newFrame; + int numBones; + skelBone_Base **bone; + int i; + skanAnimFrame frame; + int localChannelNum; - numBones = skelmodel->numBones; + outFrames.FreeObjectList(); - bone = (skelBone_Base **)Skel_Alloc(sizeof(skelBone_Base *) * numBones); - memset(bone, 0, sizeof(skelBone_Base *) * numBones); + numBones = boneList->NumChannels(); - SkeletorLoadBonesFromBuffer(boneList, skelmodel, bone); + bone = (skelBone_Base **)Skel_Alloc(sizeof(skelBone_Base *) * numBones); + memset(bone, 0, sizeof(skelBone_Base *) * numBones); - for (i = 0; i < numBones; i++) - { - bone[i]->m_controller = NULL; - bone[i]->m_isDirty = true; - } + SkeletorLoadBonesFromBuffer(boneList, skelmodel, bone); - newFrame = (skelAnimFrame_t *)Skel_Alloc(sizeof(skelAnimFrame_t) + sizeof(SkelMat4) * numBones); - newFrame->radius = 0; - newFrame->bounds[0] = SkelVec3(); - newFrame->bounds[1] = SkelVec3(); + for (i = 0; i < numBones; i++) { + bone[i]->m_controller = NULL; + bone[i]->m_isDirty = true; + } - for (i = 0; i < numBones; i++) - { - //skelBone_Base *Parent = bone[ i ]->Parent(); - //bone[ i ]->SetParent( &skeletor_c::m_worldBone ); - newFrame->bones[i] = bone[i]->GetTransform(frameList); - //bone[ i ]->SetParent( Parent ); - } + // process the rot channel + localChannelNum = animData->channelList.GetLocalFromGlobal(bone[boneNum]->GetChannelIndex(1)); + if (localChannelNum >= 0) { + skanChannelHdr *channel = &animData->ary_channels[localChannelNum]; - for (i = 0; i < numBones; i++) - { - VectorCopy(newFrame->bones[i][3], bones[i].offset); - bones[i].matrix[0][0] = newFrame->bones[i][0][0]; - bones[i].matrix[0][1] = newFrame->bones[i][0][1]; - bones[i].matrix[0][2] = newFrame->bones[i][0][2]; - bones[i].matrix[0][3] = 0; - bones[i].matrix[1][0] = newFrame->bones[i][1][0]; - bones[i].matrix[1][1] = newFrame->bones[i][1][1]; - bones[i].matrix[1][2] = newFrame->bones[i][1][2]; - bones[i].matrix[1][3] = 0; - bones[i].matrix[2][0] = newFrame->bones[i][2][0]; - bones[i].matrix[2][1] = newFrame->bones[i][2][1]; - bones[i].matrix[2][2] = newFrame->bones[i][2][2]; - bones[i].matrix[2][3] = 0; - } + for (i = 0; i < channel->nFramesInChannel; i++) { + skanGameFrame *pFrame = &channel->ary_frames[i]; - for (i = 0; i < numBones; i++) - { - delete bone[i]; - } + frame.nFrameNum = pFrame->nFrameNum; + VectorClear(frame.pos); + QuatToAngles(pFrame->pChannelData, frame.rot); - Skel_Free(bone); + outFrames.AddObject(frame); + } + } - if (radius) { - *radius = newFrame->radius; - } + if (bone[i]->GetChannelIndex(0) != bone[i]->GetChannelIndex(1)) { + // process the pos channel + localChannelNum = animData->channelList.GetLocalFromGlobal(bone[boneNum]->GetChannelIndex(0)); + if (localChannelNum >= 0) { + skanChannelHdr *channel = &animData->ary_channels[localChannelNum]; - if (mins || maxes) - { - for (i = 0; i < 3; i++) - { - if (mins) { - (*mins)[i] = newFrame->bounds[0][i]; - } - if (maxes) { - (*maxes)[i] = newFrame->bounds[1][i]; - } - } - } + for (i = 0; i < channel->nFramesInChannel; i++) { + skanGameFrame *pFrame = &channel->ary_frames[i]; + skanAnimFrame *pOutFrame = &outFrames[i]; - Skel_Free(newFrame); + VectorCopy(pFrame->pChannelData, pOutFrame->pos); + } + } + } } -void SkeletorGetAnimFrame( skelHeaderGame_t *skelmodel, skelAnimDataGameHeader_t *animData, skelChannelList_c *boneList, skelBoneCache_t *bones, int frame, float *radius, vec3_t *mins, vec3_t *maxes ) +void SkeletorGetAnimFrame2( + skelHeaderGame_t *skelmodel, + skelChannelList_c *boneList, + skelBoneCache_t *bones, + skelAnimStoreFrameList_c *frameList, + float *radius, + vec3_t *mins, + vec3_t *maxes +) { - int numBones; - skelBone_Base **bone; - int i; - skelAnimStoreFrameList_c frameList; - skelAnimFrame_t *newFrame; + int numBones; + skelBone_Base **bone; + int i; + skelAnimFrame_t *newFrame; - frameList.actionWeight = animData ? 1.0 : 0; + numBones = skelmodel->numBones; - if (animData) - { - if (!animData->bHasDelta) - { - frameList.numMovementFrames = 0; - frameList.numActionFrames = 1; - frameList.m_blendInfo[32].weight = 1.0; - frameList.m_blendInfo[32].pAnimationData = animData; - frameList.m_blendInfo[32].frame = frame; - } - else - { - frameList.numMovementFrames = 1; - frameList.numActionFrames = 0; - frameList.m_blendInfo[0].weight = 1.0; - frameList.m_blendInfo[0].pAnimationData = animData; - frameList.m_blendInfo[0].frame = frame; - } - } - numBones = skelmodel->numBones; + bone = (skelBone_Base **)Skel_Alloc(sizeof(skelBone_Base *) * numBones); + memset(bone, 0, sizeof(skelBone_Base *) * numBones); - bone = ( skelBone_Base ** )Skel_Alloc( sizeof( skelBone_Base * ) * numBones ); - memset( bone, 0, sizeof( skelBone_Base * ) * numBones ); + SkeletorLoadBonesFromBuffer(boneList, skelmodel, bone); - SkeletorLoadBonesFromBuffer( boneList, skelmodel, bone ); + for (i = 0; i < numBones; i++) { + bone[i]->m_controller = NULL; + bone[i]->m_isDirty = true; + } - for( i = 0; i < numBones; i++ ) - { - bone[ i ]->m_controller = NULL; - bone[ i ]->m_isDirty = true; - } + newFrame = (skelAnimFrame_t *)Skel_Alloc(sizeof(skelAnimFrame_t) + sizeof(SkelMat4) * numBones); + newFrame->radius = 0; + newFrame->bounds[0] = SkelVec3(); + newFrame->bounds[1] = SkelVec3(); - newFrame = ( skelAnimFrame_t * )Skel_Alloc( sizeof( skelAnimFrame_t ) + sizeof( SkelMat4 ) * numBones ); + for (i = 0; i < numBones; i++) { + //skelBone_Base *Parent = bone[ i ]->Parent(); + //bone[ i ]->SetParent( &skeletor_c::m_worldBone ); + newFrame->bones[i] = bone[i]->GetTransform(frameList); + //bone[ i ]->SetParent( Parent ); + } - if( animData ) - { - if( animData->m_frame ) - { - newFrame->radius = animData->m_frame->radius; - } - else - { - newFrame->radius = 0; - } + for (i = 0; i < numBones; i++) { + VectorCopy(newFrame->bones[i][3], bones[i].offset); + bones[i].matrix[0][0] = newFrame->bones[i][0][0]; + bones[i].matrix[0][1] = newFrame->bones[i][0][1]; + bones[i].matrix[0][2] = newFrame->bones[i][0][2]; + bones[i].matrix[0][3] = 0; + bones[i].matrix[1][0] = newFrame->bones[i][1][0]; + bones[i].matrix[1][1] = newFrame->bones[i][1][1]; + bones[i].matrix[1][2] = newFrame->bones[i][1][2]; + bones[i].matrix[1][3] = 0; + bones[i].matrix[2][0] = newFrame->bones[i][2][0]; + bones[i].matrix[2][1] = newFrame->bones[i][2][1]; + bones[i].matrix[2][2] = newFrame->bones[i][2][2]; + bones[i].matrix[2][3] = 0; + } - newFrame->bounds[ 0 ] = animData->bounds[ 0 ]; - newFrame->bounds[ 1 ] = animData->bounds[ 1 ]; - } - else - { - newFrame->radius = 0; - newFrame->bounds[ 0 ] = SkelVec3(); - newFrame->bounds[ 1 ] = SkelVec3(); - } + for (i = 0; i < numBones; i++) { + delete bone[i]; + } - if (animData) - { - for (i = 0; i < numBones; i++) - { - //skelBone_Base *Parent = bone[ i ]->Parent(); - //bone[ i ]->SetParent( &skeletor_c::m_worldBone ); - newFrame->bones[i] = bone[i]->GetTransform(&frameList); - //bone[ i ]->SetParent( Parent ); - } - } - else - { - for (i = 0; i < numBones; i++) - { - newFrame->bones[i] = SkelMat4(); - } - } + Skel_Free(bone); - for( i = 0; i < numBones; i++ ) - { - VectorCopy( newFrame->bones[ i ][ 3 ], bones[ i ].offset ); - bones[ i ].matrix[ 0 ][ 0 ] = newFrame->bones[ i ][ 0 ][ 0 ]; - bones[ i ].matrix[ 0 ][ 1 ] = newFrame->bones[ i ][ 0 ][ 1 ]; - bones[ i ].matrix[ 0 ][ 2 ] = newFrame->bones[ i ][ 0 ][ 2 ]; - bones[ i ].matrix[ 0 ][ 3 ] = 0; - bones[ i ].matrix[ 1 ][ 0 ] = newFrame->bones[ i ][ 1 ][ 0 ]; - bones[ i ].matrix[ 1 ][ 1 ] = newFrame->bones[ i ][ 1 ][ 1 ]; - bones[ i ].matrix[ 1 ][ 2 ] = newFrame->bones[ i ][ 1 ][ 2 ]; - bones[ i ].matrix[ 1 ][ 3 ] = 0; - bones[ i ].matrix[ 2 ][ 0 ] = newFrame->bones[ i ][ 2 ][ 0 ]; - bones[ i ].matrix[ 2 ][ 1 ] = newFrame->bones[ i ][ 2 ][ 1 ]; - bones[ i ].matrix[ 2 ][ 2 ] = newFrame->bones[ i ][ 2 ][ 2 ]; - bones[ i ].matrix[ 2 ][ 3 ] = 0; - } + if (radius) { + *radius = newFrame->radius; + } - for( i = 0; i < numBones; i++ ) - { - delete bone[ i ]; - } + if (mins || maxes) { + for (i = 0; i < 3; i++) { + if (mins) { + (*mins)[i] = newFrame->bounds[0][i]; + } + if (maxes) { + (*maxes)[i] = newFrame->bounds[1][i]; + } + } + } - Skel_Free( bone ); - - if( radius ) { - *radius = newFrame->radius; - } - - if( mins || maxes ) - { - for( i = 0; i < 3; i++ ) - { - if( mins ) { - ( *mins )[ i ] = newFrame->bounds[ 0 ][ i ]; - } - if( maxes ) { - ( *maxes )[ i ] = newFrame->bounds[ 1 ][ i ]; - } - } - } - - Skel_Free( newFrame ); + Skel_Free(newFrame); } -void TIKI_GetSkelAnimFrameInternal2(dtiki_t *tiki, skelBoneCache_t *bones, skelAnimStoreFrameList_c* frameList, float *radius, vec3_t *mins, vec3_t *maxes) +void SkeletorGetAnimFrame( + skelHeaderGame_t *skelmodel, + skelAnimDataGameHeader_t *animData, + skelChannelList_c *boneList, + skelBoneCache_t *bones, + int frame, + float *radius, + vec3_t *mins, + vec3_t *maxes +) { - //int boneNum; - int numBones; - skelBone_Base **bone; - int i; - skelAnimFrame_t *newFrame; - //int realAnimIndex; - //skanBlendInfo *frame; - skelHeaderGame_t *skelmodel; + int numBones; + skelBone_Base **bone; + int i; + skelAnimStoreFrameList_c frameList; + skelAnimFrame_t *newFrame; - numBones = tiki->m_boneList.NumChannels(); + frameList.actionWeight = animData ? 1.0 : 0; - bone = (skelBone_Base **)Skel_Alloc(sizeof(skelBone_Base *) * numBones); - memset(bone, 0, sizeof(skelBone_Base *) * numBones); + if (animData) { + if (!animData->bHasDelta) { + frameList.numMovementFrames = 0; + frameList.numActionFrames = 1; + frameList.m_blendInfo[32].weight = 1.0; + frameList.m_blendInfo[32].pAnimationData = animData; + frameList.m_blendInfo[32].frame = frame; + } else { + frameList.numMovementFrames = 1; + frameList.numActionFrames = 0; + frameList.m_blendInfo[0].weight = 1.0; + frameList.m_blendInfo[0].pAnimationData = animData; + frameList.m_blendInfo[0].frame = frame; + } + } + numBones = skelmodel->numBones; - for (i = 0; i < tiki->numMeshes; i++) - { - skelmodel = TIKI_GetSkel(tiki->mesh[i]); - SkeletorLoadBonesFromBuffer(&tiki->m_boneList, skelmodel, bone); - } + bone = (skelBone_Base **)Skel_Alloc(sizeof(skelBone_Base *) * numBones); + memset(bone, 0, sizeof(skelBone_Base *) * numBones); - for (i = 0; i < numBones; i++) - { - bone[i]->m_controller = NULL; - bone[i]->m_isDirty = true; - } + SkeletorLoadBonesFromBuffer(boneList, skelmodel, bone); - newFrame = (skelAnimFrame_t *)Skel_Alloc(sizeof(skelAnimFrame_t) + sizeof(SkelMat4) * numBones); + for (i = 0; i < numBones; i++) { + bone[i]->m_controller = NULL; + bone[i]->m_isDirty = true; + } - /* + newFrame = (skelAnimFrame_t *)Skel_Alloc(sizeof(skelAnimFrame_t) + sizeof(SkelMat4) * numBones); + + if (animData) { + if (animData->m_frame) { + newFrame->radius = animData->m_frame->radius; + } else { + newFrame->radius = 0; + } + + newFrame->bounds[0] = animData->bounds[0]; + newFrame->bounds[1] = animData->bounds[1]; + } else { + newFrame->radius = 0; + newFrame->bounds[0] = SkelVec3(); + newFrame->bounds[1] = SkelVec3(); + } + + if (animData) { + for (i = 0; i < numBones; i++) { + //skelBone_Base *Parent = bone[ i ]->Parent(); + //bone[ i ]->SetParent( &skeletor_c::m_worldBone ); + newFrame->bones[i] = bone[i]->GetTransform(&frameList); + //bone[ i ]->SetParent( Parent ); + } + } else { + for (i = 0; i < numBones; i++) { + newFrame->bones[i] = SkelMat4(); + } + } + + for (i = 0; i < numBones; i++) { + VectorCopy(newFrame->bones[i][3], bones[i].offset); + bones[i].matrix[0][0] = newFrame->bones[i][0][0]; + bones[i].matrix[0][1] = newFrame->bones[i][0][1]; + bones[i].matrix[0][2] = newFrame->bones[i][0][2]; + bones[i].matrix[0][3] = 0; + bones[i].matrix[1][0] = newFrame->bones[i][1][0]; + bones[i].matrix[1][1] = newFrame->bones[i][1][1]; + bones[i].matrix[1][2] = newFrame->bones[i][1][2]; + bones[i].matrix[1][3] = 0; + bones[i].matrix[2][0] = newFrame->bones[i][2][0]; + bones[i].matrix[2][1] = newFrame->bones[i][2][1]; + bones[i].matrix[2][2] = newFrame->bones[i][2][2]; + bones[i].matrix[2][3] = 0; + } + + for (i = 0; i < numBones; i++) { + delete bone[i]; + } + + Skel_Free(bone); + + if (radius) { + *radius = newFrame->radius; + } + + if (mins || maxes) { + for (i = 0; i < 3; i++) { + if (mins) { + (*mins)[i] = newFrame->bounds[0][i]; + } + if (maxes) { + (*maxes)[i] = newFrame->bounds[1][i]; + } + } + } + + Skel_Free(newFrame); +} + +void TIKI_GetSkelAnimFrameInternal2( + dtiki_t *tiki, + skelBoneCache_t *bones, + skelAnimStoreFrameList_c *frameList, + float *radius, + vec3_t *mins, + vec3_t *maxes +) +{ + //int boneNum; + int numBones; + skelBone_Base **bone; + int i; + skelAnimFrame_t *newFrame; + //int realAnimIndex; + //skanBlendInfo *frame; + skelHeaderGame_t *skelmodel; + + numBones = tiki->m_boneList.NumChannels(); + + bone = (skelBone_Base **)Skel_Alloc(sizeof(skelBone_Base *) * numBones); + memset(bone, 0, sizeof(skelBone_Base *) * numBones); + + for (i = 0; i < tiki->numMeshes; i++) { + skelmodel = TIKI_GetSkel(tiki->mesh[i]); + SkeletorLoadBonesFromBuffer(&tiki->m_boneList, skelmodel, bone); + } + + for (i = 0; i < numBones; i++) { + bone[i]->m_controller = NULL; + bone[i]->m_isDirty = true; + } + + newFrame = (skelAnimFrame_t *)Skel_Alloc(sizeof(skelAnimFrame_t) + sizeof(SkelMat4) * numBones); + + /* if (animData) { if (animData->m_frame) @@ -837,459 +799,422 @@ void TIKI_GetSkelAnimFrameInternal2(dtiki_t *tiki, skelBoneCache_t *bones, skelA } else */ - { - newFrame->radius = 0; - newFrame->bounds[0] = SkelVec3(); - newFrame->bounds[1] = SkelVec3(); - } + { + newFrame->radius = 0; + newFrame->bounds[0] = SkelVec3(); + newFrame->bounds[1] = SkelVec3(); + } - for (i = 0; i < numBones; i++) - { - newFrame->bones[i] = bone[i]->GetTransform(frameList); - } + for (i = 0; i < numBones; i++) { + newFrame->bones[i] = bone[i]->GetTransform(frameList); + } - for (i = 0; i < numBones; i++) - { - delete bone[i]; - } + for (i = 0; i < numBones; i++) { + delete bone[i]; + } - Skel_Free(bone); + Skel_Free(bone); - for (i = 0; i < numBones; i++) - { - VectorCopy(newFrame->bones[i][3], bones[i].offset); - bones[i].matrix[0][0] = newFrame->bones[i][0][0]; - bones[i].matrix[0][1] = newFrame->bones[i][0][1]; - bones[i].matrix[0][2] = newFrame->bones[i][0][2]; - bones[i].matrix[0][3] = 0; - bones[i].matrix[1][0] = newFrame->bones[i][1][0]; - bones[i].matrix[1][1] = newFrame->bones[i][1][1]; - bones[i].matrix[1][2] = newFrame->bones[i][1][2]; - bones[i].matrix[1][3] = 0; - bones[i].matrix[2][0] = newFrame->bones[i][2][0]; - bones[i].matrix[2][1] = newFrame->bones[i][2][1]; - bones[i].matrix[2][2] = newFrame->bones[i][2][2]; - bones[i].matrix[2][3] = 0; - } + for (i = 0; i < numBones; i++) { + VectorCopy(newFrame->bones[i][3], bones[i].offset); + bones[i].matrix[0][0] = newFrame->bones[i][0][0]; + bones[i].matrix[0][1] = newFrame->bones[i][0][1]; + bones[i].matrix[0][2] = newFrame->bones[i][0][2]; + bones[i].matrix[0][3] = 0; + bones[i].matrix[1][0] = newFrame->bones[i][1][0]; + bones[i].matrix[1][1] = newFrame->bones[i][1][1]; + bones[i].matrix[1][2] = newFrame->bones[i][1][2]; + bones[i].matrix[1][3] = 0; + bones[i].matrix[2][0] = newFrame->bones[i][2][0]; + bones[i].matrix[2][1] = newFrame->bones[i][2][1]; + bones[i].matrix[2][2] = newFrame->bones[i][2][2]; + bones[i].matrix[2][3] = 0; + } - if (radius) { - *radius = newFrame->radius; - } + if (radius) { + *radius = newFrame->radius; + } - if (mins && maxes) - { - for (i = 0; i < 3; i++) - { - (*mins)[i] = newFrame->bounds[0][i]; - (*maxes)[i] = newFrame->bounds[1][i]; - } - } + if (mins && maxes) { + for (i = 0; i < 3; i++) { + (*mins)[i] = newFrame->bounds[0][i]; + (*maxes)[i] = newFrame->bounds[1][i]; + } + } - Skel_Free(newFrame); + Skel_Free(newFrame); } -void TIKI_GetSkelAnimFrameInternal( dtiki_t *tiki, skelBoneCache_t *bones, skelAnimDataGameHeader_t *animData, int frame, float *radius, vec3_t *mins, vec3_t *maxes ) +void TIKI_GetSkelAnimFrameInternal( + dtiki_t *tiki, + skelBoneCache_t *bones, + skelAnimDataGameHeader_t *animData, + int frame, + float *radius, + vec3_t *mins, + vec3_t *maxes +) { - //int boneNum; - int numBones; - skelBone_Base **bone; - int i; - skelAnimStoreFrameList_c frameList; - skelAnimFrame_t *newFrame; - //int realAnimIndex; - //skanBlendInfo *frame; - skelHeaderGame_t *skelmodel; + //int boneNum; + int numBones; + skelBone_Base **bone; + int i; + skelAnimStoreFrameList_c frameList; + skelAnimFrame_t *newFrame; + //int realAnimIndex; + //skanBlendInfo *frame; + skelHeaderGame_t *skelmodel; - frameList.actionWeight = animData ? 1.0 : 0; - if (!animData || !animData->bHasDelta) - { - frameList.numMovementFrames = 0; - frameList.numActionFrames = 1; - frameList.m_blendInfo[32].weight = 1.0; - frameList.m_blendInfo[32].pAnimationData = animData; - frameList.m_blendInfo[32].frame = frame; - } - else - { - frameList.numMovementFrames = 1; - frameList.numActionFrames = 0; - frameList.m_blendInfo[0].weight = 1.0; - frameList.m_blendInfo[0].pAnimationData = animData; - frameList.m_blendInfo[0].frame = frame; - } - numBones = tiki->m_boneList.NumChannels(); + frameList.actionWeight = animData ? 1.0 : 0; + if (!animData || !animData->bHasDelta) { + frameList.numMovementFrames = 0; + frameList.numActionFrames = 1; + frameList.m_blendInfo[32].weight = 1.0; + frameList.m_blendInfo[32].pAnimationData = animData; + frameList.m_blendInfo[32].frame = frame; + } else { + frameList.numMovementFrames = 1; + frameList.numActionFrames = 0; + frameList.m_blendInfo[0].weight = 1.0; + frameList.m_blendInfo[0].pAnimationData = animData; + frameList.m_blendInfo[0].frame = frame; + } + numBones = tiki->m_boneList.NumChannels(); - bone = ( skelBone_Base ** )Skel_Alloc( sizeof( skelBone_Base * ) * numBones ); - memset( bone, 0, sizeof( skelBone_Base * ) * numBones ); + bone = (skelBone_Base **)Skel_Alloc(sizeof(skelBone_Base *) * numBones); + memset(bone, 0, sizeof(skelBone_Base *) * numBones); - for( i = 0; i < tiki->numMeshes; i++ ) - { - skelmodel = TIKI_GetSkel( tiki->mesh[ i ] ); - SkeletorLoadBonesFromBuffer( &tiki->m_boneList, skelmodel, bone ); - } + for (i = 0; i < tiki->numMeshes; i++) { + skelmodel = TIKI_GetSkel(tiki->mesh[i]); + SkeletorLoadBonesFromBuffer(&tiki->m_boneList, skelmodel, bone); + } - for( i = 0; i < numBones; i++ ) - { - bone[ i ]->m_controller = NULL; - bone[ i ]->m_isDirty = true; - } + for (i = 0; i < numBones; i++) { + bone[i]->m_controller = NULL; + bone[i]->m_isDirty = true; + } - newFrame = ( skelAnimFrame_t * )Skel_Alloc( sizeof( skelAnimFrame_t ) + sizeof( SkelMat4 ) * numBones ); + newFrame = (skelAnimFrame_t *)Skel_Alloc(sizeof(skelAnimFrame_t) + sizeof(SkelMat4) * numBones); - if( animData ) - { - if( animData->m_frame ) - { - newFrame->radius = animData->m_frame->radius; - } - else - { - newFrame->radius = 0; - } + if (animData) { + if (animData->m_frame) { + newFrame->radius = animData->m_frame->radius; + } else { + newFrame->radius = 0; + } - newFrame->bounds[ 0 ] = animData->bounds[ 0 ]; - newFrame->bounds[ 1 ] = animData->bounds[ 1 ]; - } - else - { - newFrame->radius = 0; - newFrame->bounds[ 0 ] = SkelVec3(); - newFrame->bounds[ 1 ] = SkelVec3(); - } + newFrame->bounds[0] = animData->bounds[0]; + newFrame->bounds[1] = animData->bounds[1]; + } else { + newFrame->radius = 0; + newFrame->bounds[0] = SkelVec3(); + newFrame->bounds[1] = SkelVec3(); + } - for( i = 0; i < numBones; i++ ) - { - newFrame->bones[ i ] = bone[ i ]->GetTransform( &frameList ); - } + for (i = 0; i < numBones; i++) { + newFrame->bones[i] = bone[i]->GetTransform(&frameList); + } - for( i = 0; i < numBones; i++ ) - { - delete bone[ i ]; - } + for (i = 0; i < numBones; i++) { + delete bone[i]; + } - Skel_Free( bone ); + Skel_Free(bone); - for( i = 0; i < numBones; i++ ) - { - VectorCopy( newFrame->bones[ i ][ 3 ], bones[ i ].offset ); - bones[ i ].matrix[ 0 ][ 0 ] = newFrame->bones[ i ][ 0 ][ 0 ]; - bones[ i ].matrix[ 0 ][ 1 ] = newFrame->bones[ i ][ 0 ][ 1 ]; - bones[ i ].matrix[ 0 ][ 2 ] = newFrame->bones[ i ][ 0 ][ 2 ]; - bones[ i ].matrix[ 0 ][ 3 ] = 0; - bones[ i ].matrix[ 1 ][ 0 ] = newFrame->bones[ i ][ 1 ][ 0 ]; - bones[ i ].matrix[ 1 ][ 1 ] = newFrame->bones[ i ][ 1 ][ 1 ]; - bones[ i ].matrix[ 1 ][ 2 ] = newFrame->bones[ i ][ 1 ][ 2 ]; - bones[ i ].matrix[ 1 ][ 3 ] = 0; - bones[ i ].matrix[ 2 ][ 0 ] = newFrame->bones[ i ][ 2 ][ 0 ]; - bones[ i ].matrix[ 2 ][ 1 ] = newFrame->bones[ i ][ 2 ][ 1 ]; - bones[ i ].matrix[ 2 ][ 2 ] = newFrame->bones[ i ][ 2 ][ 2 ]; - bones[ i ].matrix[ 2 ][ 3 ] = 0; - } + for (i = 0; i < numBones; i++) { + VectorCopy(newFrame->bones[i][3], bones[i].offset); + bones[i].matrix[0][0] = newFrame->bones[i][0][0]; + bones[i].matrix[0][1] = newFrame->bones[i][0][1]; + bones[i].matrix[0][2] = newFrame->bones[i][0][2]; + bones[i].matrix[0][3] = 0; + bones[i].matrix[1][0] = newFrame->bones[i][1][0]; + bones[i].matrix[1][1] = newFrame->bones[i][1][1]; + bones[i].matrix[1][2] = newFrame->bones[i][1][2]; + bones[i].matrix[1][3] = 0; + bones[i].matrix[2][0] = newFrame->bones[i][2][0]; + bones[i].matrix[2][1] = newFrame->bones[i][2][1]; + bones[i].matrix[2][2] = newFrame->bones[i][2][2]; + bones[i].matrix[2][3] = 0; + } - if( radius ) { - *radius = newFrame->radius; - } + if (radius) { + *radius = newFrame->radius; + } - if( mins && maxes ) - { - for( i = 0; i < 3; i++ ) - { - ( *mins )[ i ] = newFrame->bounds[ 0 ][ i ]; - ( *maxes )[ i ] = newFrame->bounds[ 1 ][ i ]; - } - } + if (mins && maxes) { + for (i = 0; i < 3; i++) { + (*mins)[i] = newFrame->bounds[0][i]; + (*maxes)[i] = newFrame->bounds[1][i]; + } + } - Skel_Free( newFrame ); + Skel_Free(newFrame); } -void TIKI_GetSkelAnimFrame2( dtiki_t *tiki, skelBoneCache_t *bones, int anim, int frame, float *radius, vec3_t *mins, vec3_t *maxes ) +void TIKI_GetSkelAnimFrame2( + dtiki_t *tiki, skelBoneCache_t *bones, int anim, int frame, float *radius, vec3_t *mins, vec3_t *maxes +) { - short *aliases; - skelAnimDataGameHeader_t *animData; + short *aliases; + skelAnimDataGameHeader_t *animData; - aliases = tiki->a->m_aliases; - if( *aliases == -1 ) - { - SKEL_Warning( "TIKI_GetSkelAnimFrame: Bad anim in static model %s, couldn't generate pose properly.\n", tiki->name ); - return; - } + aliases = tiki->a->m_aliases; + if (*aliases == -1) { + SKEL_Warning( + "TIKI_GetSkelAnimFrame: Bad anim in static model %s, couldn't generate pose properly.\n", tiki->name + ); + return; + } - animData = SkeletorCacheGetData( aliases[ anim ] ); + animData = SkeletorCacheGetData(aliases[anim]); - TIKI_GetSkelAnimFrameInternal( tiki, bones, animData, frame, radius, mins, maxes); + TIKI_GetSkelAnimFrameInternal(tiki, bones, animData, frame, radius, mins, maxes); } -void TIKI_GetSkelAnimFrame( dtiki_t *tiki, skelBoneCache_t *bones, float *radius, vec3_t *mins, vec3_t *maxes ) +void TIKI_GetSkelAnimFrame(dtiki_t *tiki, skelBoneCache_t *bones, float *radius, vec3_t *mins, vec3_t *maxes) { - TIKI_GetSkelAnimFrame2( tiki, bones, 0, 0, radius, mins, maxes ); + TIKI_GetSkelAnimFrame2(tiki, bones, 0, 0, radius, mins, maxes); } -void skeletor_c::GetFrame( skelAnimFrame_t *newFrame ) +void skeletor_c::GetFrame(skelAnimFrame_t *newFrame) { - int boneNum; - int numBones; + int boneNum; + int numBones; - numBones = m_Tiki->m_boneList.NumChannels(); + numBones = m_Tiki->m_boneList.NumChannels(); - for( boneNum = 0; boneNum < numBones; boneNum++ ) - { - newFrame->bones[ boneNum ] = GetBoneFrame( boneNum ); - } + for (boneNum = 0; boneNum < numBones; boneNum++) { + newFrame->bones[boneNum] = GetBoneFrame(boneNum); + } - newFrame->bounds[ 0 ] = m_frameBounds[ 0 ]; - newFrame->bounds[ 1 ] = m_frameBounds[ 1 ]; - newFrame->radius = m_frameRadius; + newFrame->bounds[0] = m_frameBounds[0]; + newFrame->bounds[1] = m_frameBounds[1]; + newFrame->radius = m_frameRadius; } - -SkelMat4 &skeletor_c::GetBoneFrame( int boneIndex ) const +SkelMat4& skeletor_c::GetBoneFrame(int boneIndex) const { - return m_bone[ boneIndex ]->GetTransform( &m_frameList ); + return m_bone[boneIndex]->GetTransform(&m_frameList); } -bool skeletor_c::IsBoneOnGround( int boneIndex, float threshold ) +bool skeletor_c::IsBoneOnGround(int boneIndex, float threshold) { - return GetBoneFrame( boneIndex ).val[ 3 ][ 2 ] < threshold; + return GetBoneFrame(boneIndex).val[3][2] < threshold; } float skeletor_c::GetRadius() { - return m_frameRadius; + return m_frameRadius; } - -float skeletor_c::GetCentroidRadius( float *centroid ) +float skeletor_c::GetCentroidRadius(float *centroid) { - centroid[ 0 ] = ( m_frameBounds[ 0 ][ 0 ] + m_frameBounds[ 1 ][ 0 ] ) * 0.5f; - centroid[ 1 ] = ( m_frameBounds[ 0 ][ 1 ] + m_frameBounds[ 1 ][ 1 ] ) * 0.5f; - centroid[ 2 ] = ( m_frameBounds[ 0 ][ 2 ] + m_frameBounds[ 1 ][ 2 ] ) * 0.5f; - return m_frameRadius; + centroid[0] = (m_frameBounds[0][0] + m_frameBounds[1][0]) * 0.5f; + centroid[1] = (m_frameBounds[0][1] + m_frameBounds[1][1]) * 0.5f; + centroid[2] = (m_frameBounds[0][2] + m_frameBounds[1][2]) * 0.5f; + return m_frameRadius; } - -int skeletor_c::GetMorphWeightFrame( int index, float time, int *data ) +int skeletor_c::GetMorphWeightFrame(int index, float time, int *data) { - return GetMorphWeightFrame( data ); + return GetMorphWeightFrame(data); } -vec4_t *DecodeFrameValue( skanChannelHdr *channelFrames, int desiredFrameNum ) +vec4_t *DecodeFrameValue(skanChannelHdr *channelFrames, int desiredFrameNum) { - skanGameFrame *foundFrame; - int i; + skanGameFrame *foundFrame; + int i; - foundFrame = channelFrames->ary_frames; + foundFrame = channelFrames->ary_frames; - for( i = 0; i < channelFrames->nFramesInChannel; i++ ) - { - if( channelFrames->ary_frames[ i ].nFrameNum >= desiredFrameNum ) - { - foundFrame = &channelFrames->ary_frames[ i ]; - break; - } - } + for (i = 0; i < channelFrames->nFramesInChannel; i++) { + if (channelFrames->ary_frames[i].nFrameNum >= desiredFrameNum) { + foundFrame = &channelFrames->ary_frames[i]; + break; + } + } - return &foundFrame->pChannelData; + return &foundFrame->pChannelData; } - -int skeletor_c::GetMorphWeightFrame( int *data ) +int skeletor_c::GetMorphWeightFrame(int *data) { - int numTargets; - int animChannelNum; - int blendNum; - float weight; - int modelChannelNum; - vec4_t *channelData; + int numTargets; + int animChannelNum; + int blendNum; + float weight; + int modelChannelNum; + vec4_t *channelData; - numTargets = m_morphTargetList.NumChannels(); + numTargets = m_morphTargetList.NumChannels(); - if( !numTargets ) { - return 0; - } + if (!numTargets) { + return 0; + } - memset( data, 0, sizeof( *data ) * numTargets ); + memset(data, 0, sizeof(*data) * numTargets); - for( blendNum = 0; blendNum < m_frameList.numMovementFrames; blendNum++ ) - { - weight = m_frameList.m_blendInfo[ blendNum ].weight; + for (blendNum = 0; blendNum < m_frameList.numMovementFrames; blendNum++) { + weight = m_frameList.m_blendInfo[blendNum].weight; - if( weight > 0.001 ) - { - for( modelChannelNum = 0; modelChannelNum < m_morphTargetList.NumChannels(); modelChannelNum++ ) - { - animChannelNum = m_morphTargetList.m_chanGlobalFromLocal[ modelChannelNum ]; - animChannelNum = m_morphTargetList.GetLocalFromGlobal( animChannelNum ); + if (weight > 0.001) { + for (modelChannelNum = 0; modelChannelNum < m_morphTargetList.NumChannels(); modelChannelNum++) { + animChannelNum = m_morphTargetList.m_chanGlobalFromLocal[modelChannelNum]; + animChannelNum = m_morphTargetList.GetLocalFromGlobal(animChannelNum); - if( animChannelNum >= 0 ) - { - channelData = DecodeFrameValue( &m_frameList.m_blendInfo[ blendNum ].pAnimationData->ary_channels[ animChannelNum ], m_frameList.m_blendInfo[ blendNum ].frame ); - data[ modelChannelNum ] += ( int )( ( *channelData )[ 0 ] * weight ); - } - } - } - } + if (animChannelNum >= 0) { + channelData = DecodeFrameValue( + &m_frameList.m_blendInfo[blendNum].pAnimationData->ary_channels[animChannelNum], + m_frameList.m_blendInfo[blendNum].frame + ); + data[modelChannelNum] += (int)((*channelData)[0] * weight); + } + } + } + } - for( blendNum = 32; blendNum < m_frameList.numActionFrames + 32; blendNum++ ) - { - weight = m_frameList.m_blendInfo[ blendNum ].weight; + for (blendNum = 32; blendNum < m_frameList.numActionFrames + 32; blendNum++) { + weight = m_frameList.m_blendInfo[blendNum].weight; - if( weight > 0.001 ) - { - for( modelChannelNum = 0; modelChannelNum < m_morphTargetList.NumChannels(); modelChannelNum++ ) - { - animChannelNum = m_morphTargetList.m_chanGlobalFromLocal[ modelChannelNum ]; - animChannelNum = m_morphTargetList.GetLocalFromGlobal( animChannelNum ); + if (weight > 0.001) { + for (modelChannelNum = 0; modelChannelNum < m_morphTargetList.NumChannels(); modelChannelNum++) { + animChannelNum = m_morphTargetList.m_chanGlobalFromLocal[modelChannelNum]; + animChannelNum = m_morphTargetList.GetLocalFromGlobal(animChannelNum); - if( animChannelNum >= 0 ) - { - channelData = DecodeFrameValue( &m_frameList.m_blendInfo[ blendNum ].pAnimationData->ary_channels[ animChannelNum ], m_frameList.m_blendInfo[ blendNum ].frame ); - data[ modelChannelNum ] += ( int )( ( *channelData )[ 0 ] * weight ); - } - } - } - } + if (animChannelNum >= 0) { + channelData = DecodeFrameValue( + &m_frameList.m_blendInfo[blendNum].pAnimationData->ary_channels[animChannelNum], + m_frameList.m_blendInfo[blendNum].frame + ); + data[modelChannelNum] += (int)((*channelData)[0] * weight); + } + } + } + } - if( m_headBoneIndex >= 0 && !VectorCompareEpsilon( m_eyeTargetPos, vec3_origin, EPSILON ) ) - { - SkelVec3 lookPos = m_eyeTargetPos; - const SkelMat4& headOrient = GetBoneFrame(m_headBoneIndex); - SkelMat4 invHeadOrient; - invHeadOrient.TransposeRotOf( headOrient ); + if (m_headBoneIndex >= 0 && !VectorCompareEpsilon(m_eyeTargetPos, vec3_origin, EPSILON)) { + SkelVec3 lookPos = m_eyeTargetPos; + const SkelMat4& headOrient = GetBoneFrame(m_headBoneIndex); + SkelMat4 invHeadOrient; + invHeadOrient.TransposeRotOf(headOrient); - SkelVec3 temp = lookPos; - lookPos[ 0 ] = temp[ 0 ] * invHeadOrient[ 0 ][ 0 ] * temp[ 1 ] * invHeadOrient[ 1 ][ 0 ] + temp[ 2 ] * invHeadOrient[ 2 ][ 0 ]; - lookPos[ 1 ] = temp[ 0 ] * invHeadOrient[ 0 ][ 1 ] * temp[ 1 ] * invHeadOrient[ 1 ][ 1 ] + temp[ 2 ] * invHeadOrient[ 2 ][ 1 ]; - lookPos[ 2 ] = temp[ 0 ] * invHeadOrient[ 0 ][ 2 ] * temp[ 1 ] * invHeadOrient[ 1 ][ 2 ] + temp[ 2 ] * invHeadOrient[ 2 ][ 2 ]; + SkelVec3 temp = lookPos; + lookPos[0] = temp[0] * invHeadOrient[0][0] * temp[1] * invHeadOrient[1][0] + temp[2] * invHeadOrient[2][0]; + lookPos[1] = temp[0] * invHeadOrient[0][1] * temp[1] * invHeadOrient[1][1] + temp[2] * invHeadOrient[2][1]; + lookPos[2] = temp[0] * invHeadOrient[0][2] * temp[1] * invHeadOrient[1][2] + temp[2] * invHeadOrient[2][2]; - float lookLeftAmount = lookPos[2] * 100 + data[m_targetLookLeft] - data[m_targetLookRight]; - float lookUpAmount = lookPos[0] * 100 + data[m_targetLookUp] - data[m_targetLookDown]; + float lookLeftAmount = lookPos[2] * 100 + data[m_targetLookLeft] - data[m_targetLookRight]; + float lookUpAmount = lookPos[0] * 100 + data[m_targetLookUp] - data[m_targetLookDown]; - const float s = VectorLengthSquared( lookPos ); + const float s = VectorLengthSquared(lookPos); - if( s == 0.0 ) { - lookPos[0] = 1.0; - } else if( s != 1.0 ) { - float l = 1.0 / sqrt( s ); - VectorScale( lookPos, l, lookPos ); - } + if (s == 0.0) { + lookPos[0] = 1.0; + } else if (s != 1.0) { + float l = 1.0 / sqrt(s); + VectorScale(lookPos, l, lookPos); + } - if( m_targetLookLeft >= 0 && m_targetLookRight >= 0 - && m_targetLookUp >= 0 && m_targetLookDown >= 0 ) - { - if( lookLeftAmount > 0.0 ) - { - if( lookLeftAmount > 100.0 ) { - lookLeftAmount = 100.0; - } + if (m_targetLookLeft >= 0 && m_targetLookRight >= 0 && m_targetLookUp >= 0 && m_targetLookDown >= 0) { + if (lookLeftAmount > 0.0) { + if (lookLeftAmount > 100.0) { + lookLeftAmount = 100.0; + } - data[ m_targetLookLeft ] = lookLeftAmount; - data[ m_targetLookRight ] = 0; - } - else - { - if( lookLeftAmount < -100.0 ) { - lookLeftAmount = -100.0; - } + data[m_targetLookLeft] = lookLeftAmount; + data[m_targetLookRight] = 0; + } else { + if (lookLeftAmount < -100.0) { + lookLeftAmount = -100.0; + } - data[ m_targetLookLeft ] = 0; - data[ m_targetLookRight ] = -lookLeftAmount; - } + data[m_targetLookLeft] = 0; + data[m_targetLookRight] = -lookLeftAmount; + } - if( m_targetLookUp > 0.0 ) - { - if( lookUpAmount > 100.0 ) { - lookUpAmount = 100.0; - } + if (m_targetLookUp > 0.0) { + if (lookUpAmount > 100.0) { + lookUpAmount = 100.0; + } - data[ m_targetLookUp ] = lookUpAmount; - data[ m_targetLookDown ] = 0; - } - else - { - if( lookUpAmount < -133.0 ) { - lookUpAmount = -133.0; - } + data[m_targetLookUp] = lookUpAmount; + data[m_targetLookDown] = 0; + } else { + if (lookUpAmount < -133.0) { + lookUpAmount = -133.0; + } - data[ m_targetLookUp ] = 0.0; - data[ m_targetLookDown ] = ( -lookUpAmount * 0.75 ); - } - } - } + data[m_targetLookUp] = 0.0; + data[m_targetLookDown] = (-lookUpAmount * 0.75); + } + } + } - // check for blink - if( m_targetBlink >= 0 ) - { - int sysMilliseconds; - int blinkAmount; + // check for blink + if (m_targetBlink >= 0) { + int sysMilliseconds; + int blinkAmount; - sysMilliseconds = Sys_Milliseconds(); + sysMilliseconds = Sys_Milliseconds(); - if( sysMilliseconds > m_timeNextBlink ) - { - if( sysMilliseconds <= m_timeNextBlink + 250 ) - { - blinkAmount = sysMilliseconds - m_timeNextBlink; + if (sysMilliseconds > m_timeNextBlink) { + if (sysMilliseconds <= m_timeNextBlink + 250) { + blinkAmount = sysMilliseconds - m_timeNextBlink; - if( blinkAmount > 100 ) - { - blinkAmount = 250 - blinkAmount; + if (blinkAmount > 100) { + blinkAmount = 250 - blinkAmount; - if( blinkAmount > 100 ) { - blinkAmount = 100; - } - } + if (blinkAmount > 100) { + blinkAmount = 100; + } + } - if( data[ m_targetBlink ] < blinkAmount ) { - data[ m_targetBlink ] = blinkAmount; - } - } - else - { - m_timeNextBlink = rand() / 5 + sysMilliseconds - 1000; - } - } - } + if (data[m_targetBlink] < blinkAmount) { + data[m_targetBlink] = blinkAmount; + } + } else { + m_timeNextBlink = rand() / 5 + sysMilliseconds - 1000; + } + } + } - return numTargets; + return numTargets; } -void skeletor_c::SetEyeTargetPos( const float *pEyeTargetPos ) +void skeletor_c::SetEyeTargetPos(const float *pEyeTargetPos) { - VectorCopy( pEyeTargetPos, m_eyeTargetPos ); + VectorCopy(pEyeTargetPos, m_eyeTargetPos); } - -int skeletor_c::GetBoneParent( int boneIndex ) { - int iBoneNum; - skelBone_Base *pBoneParent = m_bone[ boneIndex ]->Parent(); - - for( iBoneNum = 0; iBoneNum < m_Tiki->m_boneList.NumChannels(); iBoneNum++ ) - { - if( m_bone[ iBoneNum ] == pBoneParent ) { - return iBoneNum; - } - } - - return -1; - //return m_bone[ boneIndex ] - m_bone[ boneIndex ]->Parent(); -} - -const char *dtiki_s::GetBoneNameFromNum( int num ) const +int skeletor_c::GetBoneParent(int boneIndex) { - return m_boneList.ChannelName( &skeletor_c::m_boneNames, num ); + int iBoneNum; + skelBone_Base *pBoneParent = m_bone[boneIndex]->Parent(); + + for (iBoneNum = 0; iBoneNum < m_Tiki->m_boneList.NumChannels(); iBoneNum++) { + if (m_bone[iBoneNum] == pBoneParent) { + return iBoneNum; + } + } + + return -1; + //return m_bone[ boneIndex ] - m_bone[ boneIndex ]->Parent(); } - -int dtiki_s::GetBoneNumFromName( const char *name ) +const char *dtiki_s::GetBoneNameFromNum(int num) const { - int iGlobalChannel; - - iGlobalChannel = skeletor_c::m_boneNames.FindNameLookup( name ); - - if( iGlobalChannel < 0 ) - { - return -1; - } - - return m_boneList.GetLocalFromGlobal( iGlobalChannel ); + return m_boneList.ChannelName(&skeletor_c::m_boneNames, num); +} + +int dtiki_s::GetBoneNumFromName(const char *name) +{ + int iGlobalChannel; + + iGlobalChannel = skeletor_c::m_boneNames.FindNameLookup(name); + + if (iGlobalChannel < 0) { + return -1; + } + + return m_boneList.GetLocalFromGlobal(iGlobalChannel); } diff --git a/code/skeletor/skeletor.h b/code/skeletor/skeletor.h index 8805ce38..a6cf90e8 100644 --- a/code/skeletor/skeletor.h +++ b/code/skeletor/skeletor.h @@ -1,6 +1,6 @@ /* =========================================================================== -Copyright (C) 2015 the OpenMoHAA team +Copyright (C) 2023 the OpenMoHAA team This file is part of OpenMoHAA source code. @@ -22,8 +22,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // skeletor.h : General skeletor structures -#ifndef __SKELETOR__ -#define __SKELETOR__ +#pragma once #include "../tiki/tiki_shared.h" #include "SkelVec3.h" @@ -37,25 +36,25 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "skeletor_internal.h" typedef struct skelAnimFrame_s { - float radius; - SkelVec3 bounds[ 2 ]; - SkelMat4 bones[ 1 ]; + float radius; + SkelVec3 bounds[2]; + SkelMat4 bones[1]; } skelAnimFrame_t; typedef struct { - float seconds; + float seconds; } skelAnimTime_t; typedef struct { - float weight; - skelAnimDataGameHeader_t *pAnimationData; - skelAnimGameFrame_t *frame; + float weight; + skelAnimDataGameHeader_t *pAnimationData; + skelAnimGameFrame_t *frame; } skelAnimBlendFrame_t; typedef struct { - float weight; - skelAnimDataGameHeader_t *pAnimationData; - int frame; + float weight; + skelAnimDataGameHeader_t *pAnimationData; + int frame; } skanBlendInfo; #ifdef __cplusplus @@ -63,75 +62,79 @@ typedef struct { template class Container; -#include "container.h" +# include "container.h" -class skelAnimStoreFrameList_c { +class skelAnimStoreFrameList_c +{ public: - short int numMovementFrames; - short int numActionFrames; - float actionWeight; - skanBlendInfo m_blendInfo[ 64 ]; + short int numMovementFrames; + short int numActionFrames; + float actionWeight; + skanBlendInfo m_blendInfo[64]; public: - SkelQuat GetSlerpValue( int globalChannelNum ) const; - void GetLerpValue3( int globalChannelNum, SkelVec3 *outVec ) const; + SkelQuat GetSlerpValue(int globalChannelNum) const; + void GetLerpValue3(int globalChannelNum, SkelVec3 *outVec) const; }; -class skeletor_c { +class skeletor_c +{ public: - dtiki_t *m_Tiki; - static ChannelNameTable m_boneNames; - static ChannelNameTable m_channelNames; - static skelBone_World m_worldBone; + dtiki_t *m_Tiki; + static ChannelNameTable m_boneNames; + static ChannelNameTable m_channelNames; + static skelBone_World m_worldBone; private: - SkelVec3 m_frameBounds[ 2 ]; - float m_frameRadius; - skelAnimStoreFrameList_c m_frameList; - short int m_targetLookLeft; - short int m_targetLookRight; - short int m_targetLookUp; - short int m_targetLookDown; - short int m_targetLookCrossed; - short int m_targetBlink; - short int m_timeNextBlink; - short int m_headBoneIndex; - vec3_t m_eyeTargetPos; - vec3_t m_eyePrevTargetPos; - class skelBone_Base *m_leftFoot; - class skelBone_Base *m_rightFoot; - skelChannelList_c m_morphTargetList; - class skelBone_Base **m_bone; + SkelVec3 m_frameBounds[2]; + float m_frameRadius; + skelAnimStoreFrameList_c m_frameList; + short int m_targetLookLeft; + short int m_targetLookRight; + short int m_targetLookUp; + short int m_targetLookDown; + short int m_targetLookCrossed; + short int m_targetBlink; + short int m_timeNextBlink; + short int m_headBoneIndex; + vec3_t m_eyeTargetPos; + vec3_t m_eyePrevTargetPos; + class skelBone_Base *m_leftFoot; + class skelBone_Base *m_rightFoot; + skelChannelList_c m_morphTargetList; + class skelBone_Base **m_bone; public: - skeletor_c( dtiki_t *tiki ); - ~skeletor_c(); + skeletor_c(dtiki_t *tiki); + ~skeletor_c(); - static skelAnimDataGameHeader_t *ConvertSkelFileToGame( skelAnimDataFileHeader_t *pHeader, int iBuffLength, const char *path ); - static void SaveProcessedAnim( skelAnimDataGameHeader_t *enAnim, const char *path, skelAnimDataFileHeader_t *pHeader ); - static skelAnimDataGameHeader_t *LoadProcessedAnim( const char *path, void *buffer, int len, const char *name ); - static skelAnimDataGameHeader_t *LoadProcessedAnimEx( const char *path, void *buffer, int len, const char *name ); - void PrintBoneCacheList(); - void PrintBoneList(); - void LoadMorphTargetNames( skelHeaderGame_t *modelHeader ); - void GetFrame( skelAnimFrame_t *newFrame ); - int GetMorphWeightFrame( int *data ); - SkelMat4 &GetBoneFrame( int boneIndex ) const; - void GetFrameBounds( SkelVec3 *, SkelVec3 * ); - float GetModelLODRadius(); - bool IsBoneOnGround( int boneIndex, float threshold ); - int GetMorphWeightFrame( int index, float time, int *data ); - qboolean LoadSKB( const char * ); - float GetRadius(); - float GetCentroidRadius( float *centroid ); - void SetPose( const frameInfo_t *frameInfo, const int *contIndices, const vec4_t *contValues, float actionWeight ); - void SetEyeTargetPos( const float *pEyeTargetPos ); - int GetBoneParent( int boneIndex ); + static skelAnimDataGameHeader_t * + ConvertSkelFileToGame(skelAnimDataFileHeader_t *pHeader, int iBuffLength, const char *path); + static void + SaveProcessedAnim(skelAnimDataGameHeader_t *enAnim, const char *path, skelAnimDataFileHeader_t *pHeader); + static skelAnimDataGameHeader_t *LoadProcessedAnim(const char *path, void *buffer, int len, const char *name); + static skelAnimDataGameHeader_t *LoadProcessedAnimEx(const char *path, void *buffer, int len, const char *name); + void PrintBoneCacheList(); + void PrintBoneList(); + void LoadMorphTargetNames(skelHeaderGame_t *modelHeader); + void GetFrame(skelAnimFrame_t *newFrame); + int GetMorphWeightFrame(int *data); + SkelMat4 & GetBoneFrame(int boneIndex) const; + void GetFrameBounds(SkelVec3 *, SkelVec3 *); + float GetModelLODRadius(); + bool IsBoneOnGround(int boneIndex, float threshold); + int GetMorphWeightFrame(int index, float time, int *data); + qboolean LoadSKB(const char *); + float GetRadius(); + float GetCentroidRadius(float *centroid); + void SetPose(const frameInfo_t *frameInfo, const int *contIndices, const vec4_t *contValues, float actionWeight); + void SetEyeTargetPos(const float *pEyeTargetPos); + int GetBoneParent(int boneIndex); private: - void Init(); - static class ChannelNameTable *ChannelNames(); - SkelMat4 *BoneTransformation( int, int *, float( *)[ 4 ] ); + void Init(); + static class ChannelNameTable *ChannelNames(); + SkelMat4 *BoneTransformation(int, int *, float (*)[4]); }; #endif @@ -140,65 +143,103 @@ private: extern "C" { #endif -// -// skeletor.cpp -// + // + // skeletor.cpp + // -void ConvertToRotationName( const char *boneName, char *rotChannelName ); -void ConvertToPositionName( const char *boneName, char *posChannelName ); -void ConvertToFKRotationName( const char *boneName, char *rotChannelName ); -void ConvertToFKPositionName( const char *boneName, char *rotChannelName ); -void AddToBounds( SkelVec3 *bounds, SkelVec3 *newBounds ); + void ConvertToRotationName(const char *boneName, char *rotChannelName); + void ConvertToPositionName(const char *boneName, char *posChannelName); + void ConvertToFKRotationName(const char *boneName, char *rotChannelName); + void ConvertToFKPositionName(const char *boneName, char *rotChannelName); + void AddToBounds(SkelVec3 *bounds, SkelVec3 *newBounds); #ifdef __cplusplus -void BoneGetFrames( skelHeaderGame_t *skelmodel, skelAnimDataGameHeader_t *animData, skelChannelList_c *boneList, int boneNum, Container< skanAnimFrame >& outFrames ); -void TIKI_GetSkelAnimFrameInternal2(dtiki_t *tiki, skelBoneCache_t *bones, skelAnimStoreFrameList_c *frameList, float *radius, vec3_t *mins, vec3_t *maxes); -void SkeletorGetAnimFrame2(skelHeaderGame_t *skelmodel, skelChannelList_c *boneList, skelBoneCache_t *bones, skelAnimStoreFrameList_c *frameList, float *radius, vec3_t *mins, vec3_t *maxes); + void BoneGetFrames( + skelHeaderGame_t *skelmodel, + skelAnimDataGameHeader_t *animData, + skelChannelList_c *boneList, + int boneNum, + Container& outFrames + ); + void TIKI_GetSkelAnimFrameInternal2( + dtiki_t *tiki, + skelBoneCache_t *bones, + skelAnimStoreFrameList_c *frameList, + float *radius, + vec3_t *mins, + vec3_t *maxes + ); + void SkeletorGetAnimFrame2( + skelHeaderGame_t *skelmodel, + skelChannelList_c *boneList, + skelBoneCache_t *bones, + skelAnimStoreFrameList_c *frameList, + float *radius, + vec3_t *mins, + vec3_t *maxes + ); #endif -void SkeletorGetAnimFrame( skelHeaderGame_t *skelmodel, skelAnimDataGameHeader_t *animData, skelChannelList_c *boneList, skelBoneCache_t *bones, int frame, float *radius, vec3_t *mins, vec3_t *maxes ); -void TIKI_GetSkelAnimFrame( dtiki_t *tiki, skelBoneCache_t *bones, float *radius, vec3_t *mins, vec3_t *maxes ); -void TIKI_GetSkelAnimFrame2( dtiki_t *tiki, skelBoneCache_t *bones, int anim, int frame, float *radius, vec3_t *mins, vec3_t *maxes ); -void TIKI_GetSkelAnimFrameInternal( dtiki_t *tiki, skelBoneCache_t *bones, skelAnimDataGameHeader_t *animData, int frame, float *radius, vec3_t *mins, vec3_t *maxes ); + void SkeletorGetAnimFrame( + skelHeaderGame_t *skelmodel, + skelAnimDataGameHeader_t *animData, + skelChannelList_c *boneList, + skelBoneCache_t *bones, + int frame, + float *radius, + vec3_t *mins, + vec3_t *maxes + ); + void TIKI_GetSkelAnimFrame(dtiki_t *tiki, skelBoneCache_t *bones, float *radius, vec3_t *mins, vec3_t *maxes); + void TIKI_GetSkelAnimFrame2( + dtiki_t *tiki, skelBoneCache_t *bones, int anim, int frame, float *radius, vec3_t *mins, vec3_t *maxes + ); + void TIKI_GetSkelAnimFrameInternal( + dtiki_t *tiki, + skelBoneCache_t *bones, + skelAnimDataGameHeader_t *animData, + int frame, + float *radius, + vec3_t *mins, + vec3_t *maxes + ); -// -// skeletor_imports.cpp -// + // + // skeletor_imports.cpp + // -void Skel_DPrintf( const char *fmt, ... ); + void Skel_DPrintf(const char *fmt, ...); #ifndef _DEBUG_MEM - void Skel_Free( void *ptr ); - void *Skel_Alloc( size_t size ); + void Skel_Free(void *ptr); + void *Skel_Alloc(size_t size); #else -# define Skel_Free(ptr) free(ptr) -# define Skel_Alloc(size) malloc(size) +# define Skel_Free(ptr) free(ptr) +# define Skel_Alloc(size) malloc(size) #endif -void Skel_FreeFile( void *buffer ); -int Skel_ReadFileEx( const char *qpath, void **buffer, qboolean quiet ); + void Skel_FreeFile(void *buffer); + int Skel_ReadFileEx(const char *qpath, void **buffer, qboolean quiet); -// -// skeletor_utilities.cpp -// + // + // skeletor_utilities.cpp + // -void SKEL_Message( const char *fmt, ... ); -void SKEL_Warning( const char *fmt, ... ); -void SKEL_Error( const char *fmt, ... ); -void Skel_ExtractFilePath( const char *path, char *dest ); -void Skel_ExtractFileBase( const char *path, char *dest ); -void Skel_ExtractFileExtension( const char *path, char *dest ); -//const char *Skel_ExtractFileExtension( const char *in ); -void Skel_ExtractFileName( const char *path, char *dest ); -int FileLength( FILE *pFile ); + void SKEL_Message(const char *fmt, ...); + void SKEL_Warning(const char *fmt, ...); + void SKEL_Error(const char *fmt, ...); + void Skel_ExtractFilePath(const char *path, char *dest); + void Skel_ExtractFileBase(const char *path, char *dest); + void Skel_ExtractFileExtension(const char *path, char *dest); + //const char *Skel_ExtractFileExtension( const char *in ); + void Skel_ExtractFileName(const char *path, char *dest); + int FileLength(FILE *pFile); -// -// skeletorbones.cpp -// + // + // skeletorbones.cpp + // -void SkeletorLoadBoneFromBuffer( skelChannelList_c *boneList, boneData_t *boneData, skelBone_Base **bone ); -void SkeletorLoadBonesFromBuffer( skelChannelList_c *boneList, skelHeaderGame_t *buffer, skelBone_Base **bone ); + void SkeletorLoadBoneFromBuffer(skelChannelList_c *boneList, boneData_t *boneData, skelBone_Base **bone); + void SkeletorLoadBonesFromBuffer(skelChannelList_c *boneList, skelHeaderGame_t *buffer, skelBone_Base **bone); #ifdef __cplusplus } #endif - -#endif // __SKELETOR__ diff --git a/code/skeletor/skeletor_animation_file_format.h b/code/skeletor/skeletor_animation_file_format.h index ce2a04cb..8ba818f1 100644 --- a/code/skeletor/skeletor_animation_file_format.h +++ b/code/skeletor/skeletor_animation_file_format.h @@ -1,6 +1,6 @@ /* =========================================================================== -Copyright (C) 2015 the OpenMoHAA team +Copyright (C) 2023 the OpenMoHAA team This file is part of OpenMoHAA source code. @@ -22,56 +22,55 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // skeletor_animation_file_format.h : Skeletor animation file format -#ifndef __SKELETOR_ANIMATION_FILE_FORMAT_H__ -#define __SKELETOR_ANIMATION_FILE_FORMAT_H__ +#pragma once -typedef float skelAnimChannel_t[ 4 ]; +typedef float skelAnimChannel_t[4]; typedef struct { - SkelVec3 bounds[ 2 ]; - float radius; - SkelVec3 delta; - float angleDelta; - int iOfsChannels; + SkelVec3 bounds[2]; + float radius; + SkelVec3 delta; + float angleDelta; + int iOfsChannels; } skelAnimFileFrame_t; typedef struct { - int ident; - int version; - int flags; - int nBytesUsed; - float frameTime; - SkelVec3 totalDelta; - float totalAngleDelta; - int numChannels; - int ofsChannelNames; - int numFrames; - skelAnimFileFrame_t frame[ 1 ]; + int ident; + int version; + int flags; + int nBytesUsed; + float frameTime; + SkelVec3 totalDelta; + float totalAngleDelta; + int numChannels; + int ofsChannelNames; + int numFrames; + skelAnimFileFrame_t frame[1]; } skelAnimDataFileHeader_t; typedef struct { - SkelVec3 bounds[ 2 ]; - float radius; - SkelVec3 delta; - float angleDelta; - vec4_t *pChannels; + SkelVec3 bounds[2]; + float radius; + SkelVec3 delta; + float angleDelta; + vec4_t *pChannels; } skelAnimGameFrame_t; typedef struct { - short int nFrameNum; - short int nPrevFrameIndex; - vec4_t pChannelData; + short int nFrameNum; + short int nPrevFrameIndex; + vec4_t pChannelData; } skanGameFrame; typedef struct { - short int nFramesInChannel; - skanGameFrame *ary_frames; + short int nFramesInChannel; + skanGameFrame *ary_frames; } skanChannelHdr; typedef struct { - short nFrameNum; - vec3_t pos; - vec3_t rot; + short nFrameNum; + vec3_t pos; + vec3_t rot; } skanAnimFrame; typedef struct skelAnimDataGameHeader_s skelAnimDataGameHeader_t; @@ -79,32 +78,37 @@ typedef struct skelAnimDataGameHeader_s skelAnimDataGameHeader_t; #ifdef __cplusplus typedef struct skelAnimDataGameHeader_s { - int flags; - int nBytesUsed; - bool bHasDelta; - bool bHasMorph; - bool bHasUpper; - int numFrames; - SkelVec3 totalDelta; - float totalAngleDelta; - float frameTime; - skelChannelList_c channelList; - SkelVec3 bounds[ 2 ]; - skelAnimGameFrame_t *m_frame; - short int nTotalChannels; - skanChannelHdr ary_channels[ 1 ]; + int flags; + int nBytesUsed; + bool bHasDelta; + bool bHasMorph; + bool bHasUpper; + int numFrames; + SkelVec3 totalDelta; + float totalAngleDelta; + float frameTime; + skelChannelList_c channelList; + SkelVec3 bounds[2]; + skelAnimGameFrame_t *m_frame; + short int nTotalChannels; + skanChannelHdr ary_channels[1]; - skelAnimDataGameHeader_s( const skelAnimDataGameHeader_t& ); - skelAnimDataGameHeader_s(); + skelAnimDataGameHeader_s(const skelAnimDataGameHeader_t&); + skelAnimDataGameHeader_s(); - static skelAnimDataGameHeader_t *AllocRLEChannelData(size_t numChannels); - int GetFrameNums( float timeSeconds, float timeTolerance, int *beforeFrame, int *afterFrame, float *beforeWeight, float *afterWeight ); - SkelVec3 GetDeltaOverTime( float time1, float time2 ); - float GetAngularDeltaOverTime( float time1, float time2 ); - static skelAnimDataGameHeader_t *AllocAnimData(size_t numFrames, size_t numChannels ); - static void DeallocAnimData( skelAnimDataGameHeader_t *data ); + static skelAnimDataGameHeader_t *AllocRLEChannelData(size_t numChannels); + int GetFrameNums( + float timeSeconds, + float timeTolerance, + int *beforeFrame, + int *afterFrame, + float *beforeWeight, + float *afterWeight + ); + SkelVec3 GetDeltaOverTime(float time1, float time2); + float GetAngularDeltaOverTime(float time1, float time2); + static skelAnimDataGameHeader_t *AllocAnimData(size_t numFrames, size_t numChannels); + static void DeallocAnimData(skelAnimDataGameHeader_t *data); } skelAnimDataGameHeader_t; #endif - -#endif // __SKELETOR_ANIMATION_FILE_FORMAT_H__ diff --git a/code/skeletor/skeletor_imports.cpp b/code/skeletor/skeletor_imports.cpp index 5f6ddeb0..e79d9742 100644 --- a/code/skeletor/skeletor_imports.cpp +++ b/code/skeletor/skeletor_imports.cpp @@ -1,6 +1,6 @@ /* =========================================================================== -Copyright (C) 2015 the OpenMoHAA team +Copyright (C) 2023 the OpenMoHAA team This file is part of OpenMoHAA source code. @@ -26,38 +26,38 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "qcommon.h" #include "skeletor.h" -void Skel_DPrintf( const char *fmt, ... ) +void Skel_DPrintf(const char *fmt, ...) { - char msg[ 4096 ]; - va_list va; + char msg[4096]; + va_list va; - va_start( va, fmt ); - vsprintf( msg, fmt, va ); - va_end( va ); + va_start(va, fmt); + vsprintf(msg, fmt, va); + va_end(va); - Com_DPrintf( "%s", msg ); + Com_DPrintf("%s", msg); } #ifndef _DEBUG_MEM -void Skel_Free( void *ptr ) +void Skel_Free(void *ptr) { - Z_Free( ptr ); + Z_Free(ptr); } -void *Skel_Alloc( size_t size ) +void *Skel_Alloc(size_t size) { - return Z_TagMalloc( size, TAG_SKEL ); + return Z_TagMalloc(size, TAG_SKEL); } #endif -void Skel_FreeFile( void *buffer ) +void Skel_FreeFile(void *buffer) { - FS_FreeFile( buffer ); + FS_FreeFile(buffer); } -int Skel_ReadFileEx( const char *qpath, void **buffer, qboolean quiet ) +int Skel_ReadFileEx(const char *qpath, void **buffer, qboolean quiet) { - return FS_ReadFileEx( qpath, buffer, quiet ); + return FS_ReadFileEx(qpath, buffer, quiet); } diff --git a/code/skeletor/skeletor_internal.h b/code/skeletor/skeletor_internal.h index 0ccad12f..efc7eec6 100644 --- a/code/skeletor/skeletor_internal.h +++ b/code/skeletor/skeletor_internal.h @@ -1,6 +1,6 @@ /* =========================================================================== -Copyright (C) 2015 the OpenMoHAA team +Copyright (C) 2023 the OpenMoHAA team This file is part of OpenMoHAA source code. @@ -22,190 +22,204 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // skeletor_internal.h : General skeletor internal structures -#ifndef __SKELETOR_INTERNAL__ -#define __SKELETOR_INTERNAL__ +#pragma once #ifdef __cplusplus class skelAnimStoreFrameList_c; -class skelBone_Base { +class skelBone_Base +{ public: - qboolean m_isDirty; + qboolean m_isDirty; protected: - skelBone_Base *m_parent; - SkelMat4 m_cachedValue; + skelBone_Base *m_parent; + SkelMat4 m_cachedValue; public: - float *m_controller; + float *m_controller; public: - skelBone_Base(); - virtual ~skelBone_Base(); + skelBone_Base(); + virtual ~skelBone_Base(); - SkelMat4 &GetTransform( const skelAnimStoreFrameList_c *frames ); - virtual SkelMat4 &GetDirtyTransform( const skelAnimStoreFrameList_c *frames ) = 0; - void SetParent( skelBone_Base *parent ); - virtual void SetBaseValue( boneData_t *boneData ); - virtual int GetChannelIndex( int num ); - virtual skelBone_Base *GetBoneRef( int num ); - static int GetNumChannels( boneType_t boneType ); - static int GetNumBoneRefs( boneType_t boneType ); - skelBone_Base *Parent() const; - bool OnGround( const skelAnimStoreFrameList_c *frames, float threshold ); + SkelMat4 & GetTransform(const skelAnimStoreFrameList_c *frames); + virtual SkelMat4 & GetDirtyTransform(const skelAnimStoreFrameList_c *frames) = 0; + void SetParent(skelBone_Base *parent); + virtual void SetBaseValue(boneData_t *boneData); + virtual int GetChannelIndex(int num); + virtual skelBone_Base *GetBoneRef(int num); + static int GetNumChannels(boneType_t boneType); + static int GetNumBoneRefs(boneType_t boneType); + skelBone_Base *Parent() const; + bool OnGround(const skelAnimStoreFrameList_c *frames, float threshold); }; -class skelBone_World : public skelBone_Base { +class skelBone_World : public skelBone_Base +{ public: - skelBone_World(); + skelBone_World(); private: - SkelMat4 &GetDirtyTransform( const skelAnimStoreFrameList_c *frames ) override; - void SetBaseValue( boneData_t *boneData ) override; - int GetChannelIndex( int num ) override; - skelBone_Base *GetBoneRef( int num ) override; + SkelMat4 & GetDirtyTransform(const skelAnimStoreFrameList_c *frames) override; + void SetBaseValue(boneData_t *boneData) override; + int GetChannelIndex(int num) override; + skelBone_Base *GetBoneRef(int num) override; }; -class skelBone_Zero : public skelBone_Base { +class skelBone_Zero : public skelBone_Base +{ private: - SkelMat4 &GetDirtyTransform( const skelAnimStoreFrameList_c *frames ) override; - void SetBaseValue( boneData_t *boneData ) override; - int GetChannelIndex( int num ) override; - skelBone_Base *GetBoneRef( int num ) override; + SkelMat4 & GetDirtyTransform(const skelAnimStoreFrameList_c *frames) override; + void SetBaseValue(boneData_t *boneData) override; + int GetChannelIndex(int num) override; + skelBone_Base *GetBoneRef(int num) override; }; -class skelBone_Rotation : public skelBone_Base { +class skelBone_Rotation : public skelBone_Base +{ protected: - SkelVec3 m_baseValue; - int m_quatChannel; + SkelVec3 m_baseValue; + int m_quatChannel; protected: - SkelMat4 &GetDirtyTransform( const skelAnimStoreFrameList_c *frames ) override; + SkelMat4& GetDirtyTransform(const skelAnimStoreFrameList_c *frames) override; public: - void SetChannels( int num ); - void SetBaseValue( boneData_t *data ) override; - int GetChannelIndex( int num ) override; - skelBone_Base *GetBoneRef( int num ) override; + void SetChannels(int num); + void SetBaseValue(boneData_t *data) override; + int GetChannelIndex(int num) override; + skelBone_Base *GetBoneRef(int num) override; }; -class skelBone_PosRot : public skelBone_Base { +class skelBone_PosRot : public skelBone_Base +{ protected: - int m_quatChannel; - int m_offsetChannel; + int m_quatChannel; + int m_offsetChannel; public: + protected: - SkelMat4 &GetDirtyTransform( const skelAnimStoreFrameList_c *frames ) override; + SkelMat4& GetDirtyTransform(const skelAnimStoreFrameList_c *frames) override; + public: - void SetChannels( int quatChannel, int offsetChannel ); - void SetBaseValue( boneData_t *boneData ) override; - int GetChannelIndex( int num ) override; - skelBone_Base *GetBoneRef( int num ) override; + void SetChannels(int quatChannel, int offsetChannel); + void SetBaseValue(boneData_t *boneData) override; + int GetChannelIndex(int num) override; + skelBone_Base *GetBoneRef(int num) override; }; -class skelBone_Root : public skelBone_PosRot { +class skelBone_Root : public skelBone_PosRot +{ public: - SkelMat4 &GetDirtyTransform( const skelAnimStoreFrameList_c *frames ) override; + SkelMat4& GetDirtyTransform(const skelAnimStoreFrameList_c *frames) override; }; -class skelBone_IKshoulder : public skelBone_Base { +class skelBone_IKshoulder : public skelBone_Base +{ public: - class skelBone_IKwrist *m_wrist; - float m_upperLength; - float m_lowerLength; - SkelVec3 m_baseValue; - float m_cosElbowAngle; - SkelVec3 m_wristPos; - SkelQuat m_wristAngle; + class skelBone_IKwrist *m_wrist; + float m_upperLength; + float m_lowerLength; + SkelVec3 m_baseValue; + float m_cosElbowAngle; + SkelVec3 m_wristPos; + SkelQuat m_wristAngle; - skelBone_IKshoulder(); + skelBone_IKshoulder(); - SkelMat4 &GetDirtyTransform( const skelAnimStoreFrameList_c *frames ) override; - void SetBaseValue( boneData_t *boneData ) override; - int GetChannelIndex( int num ) override; - skelBone_Base *GetBoneRef( int num ) override; - void SetElbowValue( float elbowOffset ); - void SetWristValue( float wristOffset ); - void SetWristBone( skelBone_IKwrist *wrist ); - float GetUpperLength(); - float GetLowerLength(); + SkelMat4 & GetDirtyTransform(const skelAnimStoreFrameList_c *frames) override; + void SetBaseValue(boneData_t *boneData) override; + int GetChannelIndex(int num) override; + skelBone_Base *GetBoneRef(int num) override; + void SetElbowValue(float elbowOffset); + void SetWristValue(float wristOffset); + void SetWristBone(skelBone_IKwrist *wrist); + float GetUpperLength(); + float GetLowerLength(); }; -class skelBone_IKelbow : public skelBone_Base { +class skelBone_IKelbow : public skelBone_Base +{ public: - skelBone_IKshoulder *m_shoulder; + skelBone_IKshoulder *m_shoulder; public: - SkelMat4 &GetDirtyTransform( const skelAnimStoreFrameList_c *frames ) override; - void SetBoneRefs( skelBone_IKshoulder *shoulder ); - void SetBaseValue( boneData_t *boneData ) override; - int GetChannelIndex( int num ) override; - skelBone_Base *GetBoneRef( int num ) override; + SkelMat4 & GetDirtyTransform(const skelAnimStoreFrameList_c *frames) override; + void SetBoneRefs(skelBone_IKshoulder *shoulder); + void SetBaseValue(boneData_t *boneData) override; + int GetChannelIndex(int num) override; + skelBone_Base *GetBoneRef(int num) override; }; -class skelBone_IKwrist : public skelBone_Base { +class skelBone_IKwrist : public skelBone_Base +{ public: - skelBone_IKshoulder *m_shoulder; - int m_quatChannel; - int m_offsetChannel; + skelBone_IKshoulder *m_shoulder; + int m_quatChannel; + int m_offsetChannel; public: - SkelMat4 &GetDirtyTransform( const skelAnimStoreFrameList_c *frame ) override; - void SetChannels( int quatChannel, int offsetChannel ); - void SetBoneRefs( skelBone_IKshoulder *shoulder ); - void SetBaseValue( boneData_t *boneData ) override; - int GetChannelIndex( int num ) override; - skelBone_Base *GetBoneRef( int num ) override; + SkelMat4 & GetDirtyTransform(const skelAnimStoreFrameList_c *frame) override; + void SetChannels(int quatChannel, int offsetChannel); + void SetBoneRefs(skelBone_IKshoulder *shoulder); + void SetBaseValue(boneData_t *boneData) override; + int GetChannelIndex(int num) override; + skelBone_Base *GetBoneRef(int num) override; }; -class skelBone_AvRot : public skelBone_Base { +class skelBone_AvRot : public skelBone_Base +{ public: - SkelVec3 m_basePos; - SkelQuat m_cachedQuat; - skelBone_Base *m_reference1; - skelBone_Base *m_reference2; - float m_bone2weight; + SkelVec3 m_basePos; + SkelQuat m_cachedQuat; + skelBone_Base *m_reference1; + skelBone_Base *m_reference2; + float m_bone2weight; public: - skelBone_AvRot(); + skelBone_AvRot(); - SkelMat4 &GetDirtyTransform( const skelAnimStoreFrameList_c *frames ) override; - void SetBoneRefs( skelBone_Base *ref1, skelBone_Base *ref2 ); - void SetBaseValue( boneData_t *boneData ) override; - int GetChannelIndex( int num ) override; - skelBone_Base *GetBoneRef( int num ) override; + SkelMat4 & GetDirtyTransform(const skelAnimStoreFrameList_c *frames) override; + void SetBoneRefs(skelBone_Base *ref1, skelBone_Base *ref2); + void SetBaseValue(boneData_t *boneData) override; + int GetChannelIndex(int num) override; + skelBone_Base *GetBoneRef(int num) override; }; -class skelBone_HoseRot : public skelBone_Base { +class skelBone_HoseRot : public skelBone_Base +{ public: - SkelVec3 m_basePos; - SkelQuat m_cachedQuat; - skelBone_Base *m_target; - float m_bendRatio; - float m_bendMax; - float m_spinRatio; + SkelVec3 m_basePos; + SkelQuat m_cachedQuat; + skelBone_Base *m_target; + float m_bendRatio; + float m_bendMax; + float m_spinRatio; public: - SkelMat4 &GetDirtyTransform( const skelAnimStoreFrameList_c *frames ) override; - SkelMat4 &GetDirtyTransform( SkelMat4& myParentTM, SkelMat4& targetTM ); - void SetBoneRefs( skelBone_Base *ref ); - void SetBaseValue( boneData_t *boneData ) override; - int GetChannelIndex( int num ) override; - skelBone_Base *GetBoneRef( int num ) override; + SkelMat4 & GetDirtyTransform(const skelAnimStoreFrameList_c *frames) override; + SkelMat4 & GetDirtyTransform(SkelMat4 &myParentTM, SkelMat4 &targetTM); + void SetBoneRefs(skelBone_Base *ref); + void SetBaseValue(boneData_t *boneData) override; + int GetChannelIndex(int num) override; + skelBone_Base *GetBoneRef(int num) override; }; -class skelBone_HoseRotBoth : public skelBone_HoseRot { +class skelBone_HoseRotBoth : public skelBone_HoseRot +{ public: - SkelMat4 &GetDirtyTransform( const skelAnimStoreFrameList_c *frames ) override; - void SetBaseValue( boneData_t *boneData ) override; + SkelMat4& GetDirtyTransform(const skelAnimStoreFrameList_c *frames) override; + void SetBaseValue(boneData_t *boneData) override; }; -class skelBone_HoseRotParent : public skelBone_HoseRot { +class skelBone_HoseRotParent : public skelBone_HoseRot +{ public: - SkelMat4 &GetDirtyTransform( const skelAnimStoreFrameList_c *frames ) override; - void SetBaseValue( boneData_t *boneData ) override; + SkelMat4& GetDirtyTransform(const skelAnimStoreFrameList_c *frames) override; + void SetBaseValue(boneData_t *boneData) override; }; #else @@ -214,6 +228,4 @@ typedef void *skelBone_Base; #endif -typedef char skelChannelName_t[ 32 ]; - -#endif // __SKELETOR_INTERNAL__ +typedef char skelChannelName_t[32]; diff --git a/code/skeletor/skeletor_loadanimation.cpp b/code/skeletor/skeletor_loadanimation.cpp index 1fd780b5..612bb083 100644 --- a/code/skeletor/skeletor_loadanimation.cpp +++ b/code/skeletor/skeletor_loadanimation.cpp @@ -1,6 +1,6 @@ /* =========================================================================== -Copyright (C) 2015 the OpenMoHAA team +Copyright (C) 2023 the OpenMoHAA team This file is part of OpenMoHAA source code. @@ -26,307 +26,299 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "qcommon.h" #include "skeletor.h" -qboolean Compress( skelAnimGameFrame_t *current, skelAnimGameFrame_t *last, int channelIndex, skelChannelList_c *channelList, ChannelNameTable *channelNames ) +qboolean Compress( + skelAnimGameFrame_t *current, + skelAnimGameFrame_t *last, + int channelIndex, + skelChannelList_c *channelList, + ChannelNameTable *channelNames +) { - float tolerance; - float difference; + float tolerance; + float difference; - // high-end PC don't need to compress... - return false; + // high-end PC don't need to compress... + return false; - tolerance = current->pChannels[ channelIndex ][ 0 ]; - if( tolerance > -0.000001 && tolerance < 0.000001 ) - { - current->pChannels[ channelIndex ][ 0 ] = 0.0f; - } + tolerance = current->pChannels[channelIndex][0]; + if (tolerance > -0.000001 && tolerance < 0.000001) { + current->pChannels[channelIndex][0] = 0.0f; + } - tolerance = current->pChannels[ channelIndex ][ 1 ]; - if( tolerance > -0.000001 && tolerance < 0.000001 ) - { - current->pChannels[ channelIndex ][ 1 ] = 0.0f; - } + tolerance = current->pChannels[channelIndex][1]; + if (tolerance > -0.000001 && tolerance < 0.000001) { + current->pChannels[channelIndex][1] = 0.0f; + } - tolerance = current->pChannels[ channelIndex ][ 2 ]; - if( tolerance > -0.000001 && tolerance < 0.000001 ) - { - current->pChannels[ channelIndex ][ 2 ] = 0.0f; - } + tolerance = current->pChannels[channelIndex][2]; + if (tolerance > -0.000001 && tolerance < 0.000001) { + current->pChannels[channelIndex][2] = 0.0f; + } - if( !last ) - { - return false; - } + if (!last) { + return false; + } - difference = last->pChannels[ channelIndex ][ 0 ] - current->pChannels[ channelIndex ][ 0 ]; - if( difference < -0.001f || difference >= 0.001f ) - { - return false; - } + difference = last->pChannels[channelIndex][0] - current->pChannels[channelIndex][0]; + if (difference < -0.001f || difference >= 0.001f) { + return false; + } - difference = last->pChannels[ channelIndex ][ 1 ] - current->pChannels[ channelIndex ][ 1 ]; - if( difference < -0.001f || difference >= 0.001f ) - { - return false; - } + difference = last->pChannels[channelIndex][1] - current->pChannels[channelIndex][1]; + if (difference < -0.001f || difference >= 0.001f) { + return false; + } - difference = last->pChannels[ channelIndex ][ 2 ] - current->pChannels[ channelIndex ][ 2 ]; - if( difference < -0.001f || difference >= 0.001f ) - { - return false; - } + difference = last->pChannels[channelIndex][2] - current->pChannels[channelIndex][2]; + if (difference < -0.001f || difference >= 0.001f) { + return false; + } - return true; + return true; } -skelAnimDataGameHeader_t *EncodeFrames( skelAnimDataGameHeader_t *enAnim, skelAnimGameFrame_t *m_frame, qboolean bLog, skelChannelList_c *channelList, ChannelNameTable *channelNames ) +skelAnimDataGameHeader_t *EncodeFrames( + skelAnimDataGameHeader_t *enAnim, + skelAnimGameFrame_t *m_frame, + qboolean bLog, + skelChannelList_c *channelList, + ChannelNameTable *channelNames +) { - int endFrameCap; - skanChannelHdr *pChannel; - int i, j; - int frameCnt; - skelAnimGameFrame_t *pCurrFrame; - skelAnimGameFrame_t *pLastFrame; - skanGameFrame *pFrame; - int indexLastFrameAdded; + int endFrameCap; + skanChannelHdr *pChannel; + int i, j; + int frameCnt; + skelAnimGameFrame_t *pCurrFrame; + skelAnimGameFrame_t *pLastFrame; + skanGameFrame *pFrame; + int indexLastFrameAdded; - pChannel = enAnim->ary_channels; - endFrameCap = enAnim->numFrames - 2; + pChannel = enAnim->ary_channels; + endFrameCap = enAnim->numFrames - 2; - for( i = 0; i < enAnim->nTotalChannels; i++, pChannel++ ) - { - pLastFrame = NULL; - pCurrFrame = m_frame; + for (i = 0; i < enAnim->nTotalChannels; i++, pChannel++) { + pLastFrame = NULL; + pCurrFrame = m_frame; - frameCnt = 0; - for( j = 0; j < enAnim->numFrames; j++ ) - { - if( !Compress( pCurrFrame, pLastFrame, i, channelList, channelNames ) || j >= endFrameCap ) - { - frameCnt++; - pLastFrame = pCurrFrame; - } + frameCnt = 0; + for (j = 0; j < enAnim->numFrames; j++) { + if (!Compress(pCurrFrame, pLastFrame, i, channelList, channelNames) || j >= endFrameCap) { + frameCnt++; + pLastFrame = pCurrFrame; + } - pCurrFrame++; - } + pCurrFrame++; + } - pChannel->ary_frames = ( skanGameFrame * )Skel_Alloc( frameCnt * sizeof( skanGameFrame ) ); - pChannel->nFramesInChannel = frameCnt; - enAnim->nBytesUsed += frameCnt * sizeof( skanGameFrame ); + pChannel->ary_frames = (skanGameFrame *)Skel_Alloc(frameCnt * sizeof(skanGameFrame)); + pChannel->nFramesInChannel = frameCnt; + enAnim->nBytesUsed += frameCnt * sizeof(skanGameFrame); - pLastFrame = NULL; - indexLastFrameAdded = 0; + pLastFrame = NULL; + indexLastFrameAdded = 0; - pCurrFrame = m_frame; - pFrame = pChannel->ary_frames; + pCurrFrame = m_frame; + pFrame = pChannel->ary_frames; - for( j = 0; j < enAnim->numFrames; j++ ) - { - if( !Compress( pCurrFrame, pLastFrame, i, channelList, channelNames ) || j >= endFrameCap ) - { - pFrame->nFrameNum = j; - pFrame->nPrevFrameIndex = indexLastFrameAdded; + for (j = 0; j < enAnim->numFrames; j++) { + if (!Compress(pCurrFrame, pLastFrame, i, channelList, channelNames) || j >= endFrameCap) { + pFrame->nFrameNum = j; + pFrame->nPrevFrameIndex = indexLastFrameAdded; - if( j > 0 ) - indexLastFrameAdded++; + if (j > 0) { + indexLastFrameAdded++; + } - pFrame->pChannelData[ 0 ] = pCurrFrame->pChannels[ i ][ 0 ]; - pFrame->pChannelData[ 1 ] = pCurrFrame->pChannels[ i ][ 1 ]; - pFrame->pChannelData[ 2 ] = pCurrFrame->pChannels[ i ][ 2 ]; - pFrame->pChannelData[ 3 ] = pCurrFrame->pChannels[ i ][ 3 ]; - pFrame++; + pFrame->pChannelData[0] = pCurrFrame->pChannels[i][0]; + pFrame->pChannelData[1] = pCurrFrame->pChannels[i][1]; + pFrame->pChannelData[2] = pCurrFrame->pChannels[i][2]; + pFrame->pChannelData[3] = pCurrFrame->pChannels[i][3]; + pFrame++; - pLastFrame = pCurrFrame; - } + pLastFrame = pCurrFrame; + } - pCurrFrame++; - } - } + pCurrFrame++; + } + } - return enAnim; + return enAnim; } -skelAnimDataGameHeader_t *skeletor_c::ConvertSkelFileToGame( skelAnimDataFileHeader_t *pHeader, int iBuffLength, const char *path ) +skelAnimDataGameHeader_t * +skeletor_c::ConvertSkelFileToGame(skelAnimDataFileHeader_t *pHeader, int iBuffLength, const char *path) { - int i; - skelAnimFileFrame_t *pFileFrame; - skelAnimGameFrame_t *pGameFrame; - skelChannelName_t *pChannelNames; - skelAnimDataGameHeader_t *enAnim; - skelAnimGameFrame_t *oldFrame; - skelAnimGameFrame_t *newFrame; - int channelIndex; + int i; + skelAnimFileFrame_t *pFileFrame; + skelAnimGameFrame_t *pGameFrame; + skelChannelName_t *pChannelNames; + skelAnimDataGameHeader_t *enAnim; + skelAnimGameFrame_t *oldFrame; + skelAnimGameFrame_t *newFrame; + int channelIndex; - if( pHeader->numFrames <= 0 ) - { - return NULL; - } + if (pHeader->numFrames <= 0) { + return NULL; + } - pGameFrame = new skelAnimGameFrame_t[ pHeader->numFrames ]; - pFileFrame = pHeader->frame; - newFrame = pGameFrame; + pGameFrame = new skelAnimGameFrame_t[pHeader->numFrames]; + pFileFrame = pHeader->frame; + newFrame = pGameFrame; - for( i = 0; i < pHeader->numFrames; i++ ) - { - newFrame->bounds[ 0 ] = pFileFrame->bounds[ 0 ]; - newFrame->bounds[ 1 ] = pFileFrame->bounds[ 1 ]; - newFrame->delta = pFileFrame->delta; - newFrame->angleDelta = pFileFrame->angleDelta; - newFrame->pChannels = new vec4_t[ pHeader->numChannels ]; - memcpy( newFrame->pChannels, - ( char * )pHeader + ( sizeof( vec4_t ) * ( 3 * pHeader->numFrames - 3 ) + sizeof( vec4_t ) * pHeader->numChannels * i + 96 ), - pHeader->numChannels * sizeof( vec4_t ) ); - AddToBounds( newFrame->bounds, pFileFrame->bounds ); + for (i = 0; i < pHeader->numFrames; i++) { + newFrame->bounds[0] = pFileFrame->bounds[0]; + newFrame->bounds[1] = pFileFrame->bounds[1]; + newFrame->delta = pFileFrame->delta; + newFrame->angleDelta = pFileFrame->angleDelta; + newFrame->pChannels = new vec4_t[pHeader->numChannels]; + memcpy( + newFrame->pChannels, + (char *)pHeader + + (sizeof(vec4_t) * (3 * pHeader->numFrames - 3) + sizeof(vec4_t) * pHeader->numChannels * i + 96), + pHeader->numChannels * sizeof(vec4_t) + ); + AddToBounds(newFrame->bounds, pFileFrame->bounds); - pFileFrame++; - newFrame++; - } + pFileFrame++; + newFrame++; + } - enAnim = skelAnimDataGameHeader_t::AllocRLEChannelData( pHeader->numChannels ); - enAnim->flags = pHeader->flags; - enAnim->frameTime = pHeader->frameTime; - enAnim->totalDelta = pHeader->totalDelta; - enAnim->totalAngleDelta = pHeader->totalAngleDelta; - enAnim->numFrames = pHeader->numFrames; - enAnim->nTotalChannels = pHeader->numChannels; - ClearBounds( enAnim->bounds[ 0 ], enAnim->bounds[ 1 ] ); - enAnim->m_frame = ( skelAnimGameFrame_t * )Skel_Alloc( pHeader->numFrames * sizeof( skelAnimGameFrame_t ) ); + enAnim = skelAnimDataGameHeader_t::AllocRLEChannelData(pHeader->numChannels); + enAnim->flags = pHeader->flags; + enAnim->frameTime = pHeader->frameTime; + enAnim->totalDelta = pHeader->totalDelta; + enAnim->totalAngleDelta = pHeader->totalAngleDelta; + enAnim->numFrames = pHeader->numFrames; + enAnim->nTotalChannels = pHeader->numChannels; + ClearBounds(enAnim->bounds[0], enAnim->bounds[1]); + enAnim->m_frame = (skelAnimGameFrame_t *)Skel_Alloc(pHeader->numFrames * sizeof(skelAnimGameFrame_t)); - oldFrame = pGameFrame; - newFrame = enAnim->m_frame; + oldFrame = pGameFrame; + newFrame = enAnim->m_frame; - for( i = 0; i < pHeader->numFrames; i++ ) - { - newFrame->bounds[ 0 ] = oldFrame->bounds[ 0 ]; - newFrame->bounds[ 1 ] = oldFrame->bounds[ 1 ]; - newFrame->radius = oldFrame->radius; - newFrame->delta = oldFrame->delta; - newFrame->angleDelta = oldFrame->angleDelta; - newFrame->pChannels = NULL; - AddToBounds( enAnim->bounds, oldFrame->bounds ); + for (i = 0; i < pHeader->numFrames; i++) { + newFrame->bounds[0] = oldFrame->bounds[0]; + newFrame->bounds[1] = oldFrame->bounds[1]; + newFrame->radius = oldFrame->radius; + newFrame->delta = oldFrame->delta; + newFrame->angleDelta = oldFrame->angleDelta; + newFrame->pChannels = NULL; + AddToBounds(enAnim->bounds, oldFrame->bounds); - oldFrame++; - newFrame++; - } + oldFrame++; + newFrame++; + } - enAnim->channelList.ZeroChannels(); + enAnim->channelList.ZeroChannels(); - pChannelNames = ( skelChannelName_t * )( ( char * )pHeader + pHeader->ofsChannelNames ); + pChannelNames = (skelChannelName_t *)((char *)pHeader + pHeader->ofsChannelNames); - for( i = 0; i < pHeader->numChannels; i++ ) - { - channelIndex = m_channelNames.RegisterChannel( *pChannelNames ); - enAnim->channelList.AddChannel( channelIndex ); - pChannelNames++; - } + for (i = 0; i < pHeader->numChannels; i++) { + channelIndex = m_channelNames.RegisterChannel(*pChannelNames); + enAnim->channelList.AddChannel(channelIndex); + pChannelNames++; + } - enAnim->channelList.PackChannels(); - EncodeFrames( enAnim, pGameFrame, qfalse, &enAnim->channelList, &m_channelNames ); + enAnim->channelList.PackChannels(); + EncodeFrames(enAnim, pGameFrame, qfalse, &enAnim->channelList, &m_channelNames); - if( enAnim->channelList.HasChannel( &m_channelNames, "Bip01 pos" ) && - enAnim->channelList.HasChannel( &m_channelNames, "Bip01 R Foot pos" ) && - enAnim->channelList.HasChannel( &m_channelNames, "Bip01 L Foot pos" ) ) - { - enAnim->bHasDelta = true; - } - else - { - enAnim->bHasDelta = false; - } + if (enAnim->channelList.HasChannel(&m_channelNames, "Bip01 pos") + && enAnim->channelList.HasChannel(&m_channelNames, "Bip01 R Foot pos") + && enAnim->channelList.HasChannel(&m_channelNames, "Bip01 L Foot pos")) { + enAnim->bHasDelta = true; + } else { + enAnim->bHasDelta = false; + } - if( enAnim->channelList.HasChannel( &m_channelNames, "Bip01 Spine rot" ) && - enAnim->channelList.HasChannel( &m_channelNames, "Bip01 Spine1 rot" ) ) - { - enAnim->bHasUpper = true; - } - else - { - enAnim->bHasUpper = false; - } + if (enAnim->channelList.HasChannel(&m_channelNames, "Bip01 Spine rot") + && enAnim->channelList.HasChannel(&m_channelNames, "Bip01 Spine1 rot")) { + enAnim->bHasUpper = true; + } else { + enAnim->bHasUpper = false; + } - if( enAnim->channelList.HasChannel( &m_channelNames, "VISEME_Bump" ) - || enAnim->channelList.HasChannel( &m_channelNames, "VISME_Cage_" ) - || enAnim->channelList.HasChannel( &m_channelNames, "VISME_Earth" ) - || enAnim->channelList.HasChannel( &m_channelNames, "VISME_Fave" ) - || enAnim->channelList.HasChannel( &m_channelNames, "VISME_If" ) - || enAnim->channelList.HasChannel( &m_channelNames, "VISME_New" ) - || enAnim->channelList.HasChannel( &m_channelNames, "VISME_Ox" ) - || enAnim->channelList.HasChannel( &m_channelNames, "VISME_Roar" ) - || enAnim->channelList.HasChannel( &m_channelNames, "VISME_Size" ) - || enAnim->channelList.HasChannel( &m_channelNames, "VISME_Though" ) - || enAnim->channelList.HasChannel( &m_channelNames, "VISME_Told" ) - || enAnim->channelList.HasChannel( &m_channelNames, "VISME_Wet" ) - || enAnim->channelList.HasChannel( &m_channelNames, "BROW_frown" ) - || enAnim->channelList.HasChannel( &m_channelNames, "BROW_R_lift" ) - || enAnim->channelList.HasChannel( &m_channelNames, "BROW_lift" ) - || enAnim->channelList.HasChannel( &m_channelNames, "BROW_worry" ) - || enAnim->channelList.HasChannel( &m_channelNames, "EYE_blink" ) - || enAnim->channelList.HasChannel( &m_channelNames, "EYES_Excited__" ) - || enAnim->channelList.HasChannel( &m_channelNames, "EYES_L_squint" ) - || enAnim->channelList.HasChannel( &m_channelNames, "EYES_narrow__" ) - || enAnim->channelList.HasChannel( &m_channelNames, "EYES_down" ) - || enAnim->channelList.HasChannel( &m_channelNames, "EYES_left" ) - || enAnim->channelList.HasChannel( &m_channelNames, "EYES_right" ) - || enAnim->channelList.HasChannel( &m_channelNames, "EYES_smile" ) - || enAnim->channelList.HasChannel( &m_channelNames, "EYES_up__" ) - || enAnim->channelList.HasChannel( &m_channelNames, "JAW_open-closed" ) - || enAnim->channelList.HasChannel( &m_channelNames, "JAW_open-open" ) - || enAnim->channelList.HasChannel( &m_channelNames, "LIPS_compressed" ) - || enAnim->channelList.HasChannel( &m_channelNames, "MOUTH_L_smile_closed" ) - || enAnim->channelList.HasChannel( &m_channelNames, "MOUTH_L_smile_open" ) - || enAnim->channelList.HasChannel( &m_channelNames, "MOUTH_L_snarl_closed_" ) - || enAnim->channelList.HasChannel( &m_channelNames, "MOUTH_L_snarl_open" ) - || enAnim->channelList.HasChannel( &m_channelNames, "MOUTH_grimace" ) - || enAnim->channelList.HasChannel( &m_channelNames, "MOUTH_smile_closed" ) - || enAnim->channelList.HasChannel( &m_channelNames, "MOUTH_smile_open" ) - || enAnim->channelList.HasChannel( &m_channelNames, "MOUTH_Snarl_closed" ) - || enAnim->channelList.HasChannel( &m_channelNames, "MOUTH_Snarl_open" ) ) - { - enAnim->bHasMorph = true; - } - else - { - enAnim->bHasMorph = false; - } + if (enAnim->channelList.HasChannel(&m_channelNames, "VISEME_Bump") + || enAnim->channelList.HasChannel(&m_channelNames, "VISME_Cage_") + || enAnim->channelList.HasChannel(&m_channelNames, "VISME_Earth") + || enAnim->channelList.HasChannel(&m_channelNames, "VISME_Fave") + || enAnim->channelList.HasChannel(&m_channelNames, "VISME_If") + || enAnim->channelList.HasChannel(&m_channelNames, "VISME_New") + || enAnim->channelList.HasChannel(&m_channelNames, "VISME_Ox") + || enAnim->channelList.HasChannel(&m_channelNames, "VISME_Roar") + || enAnim->channelList.HasChannel(&m_channelNames, "VISME_Size") + || enAnim->channelList.HasChannel(&m_channelNames, "VISME_Though") + || enAnim->channelList.HasChannel(&m_channelNames, "VISME_Told") + || enAnim->channelList.HasChannel(&m_channelNames, "VISME_Wet") + || enAnim->channelList.HasChannel(&m_channelNames, "BROW_frown") + || enAnim->channelList.HasChannel(&m_channelNames, "BROW_R_lift") + || enAnim->channelList.HasChannel(&m_channelNames, "BROW_lift") + || enAnim->channelList.HasChannel(&m_channelNames, "BROW_worry") + || enAnim->channelList.HasChannel(&m_channelNames, "EYE_blink") + || enAnim->channelList.HasChannel(&m_channelNames, "EYES_Excited__") + || enAnim->channelList.HasChannel(&m_channelNames, "EYES_L_squint") + || enAnim->channelList.HasChannel(&m_channelNames, "EYES_narrow__") + || enAnim->channelList.HasChannel(&m_channelNames, "EYES_down") + || enAnim->channelList.HasChannel(&m_channelNames, "EYES_left") + || enAnim->channelList.HasChannel(&m_channelNames, "EYES_right") + || enAnim->channelList.HasChannel(&m_channelNames, "EYES_smile") + || enAnim->channelList.HasChannel(&m_channelNames, "EYES_up__") + || enAnim->channelList.HasChannel(&m_channelNames, "JAW_open-closed") + || enAnim->channelList.HasChannel(&m_channelNames, "JAW_open-open") + || enAnim->channelList.HasChannel(&m_channelNames, "LIPS_compressed") + || enAnim->channelList.HasChannel(&m_channelNames, "MOUTH_L_smile_closed") + || enAnim->channelList.HasChannel(&m_channelNames, "MOUTH_L_smile_open") + || enAnim->channelList.HasChannel(&m_channelNames, "MOUTH_L_snarl_closed_") + || enAnim->channelList.HasChannel(&m_channelNames, "MOUTH_L_snarl_open") + || enAnim->channelList.HasChannel(&m_channelNames, "MOUTH_grimace") + || enAnim->channelList.HasChannel(&m_channelNames, "MOUTH_smile_closed") + || enAnim->channelList.HasChannel(&m_channelNames, "MOUTH_smile_open") + || enAnim->channelList.HasChannel(&m_channelNames, "MOUTH_Snarl_closed") + || enAnim->channelList.HasChannel(&m_channelNames, "MOUTH_Snarl_open")) { + enAnim->bHasMorph = true; + } else { + enAnim->bHasMorph = false; + } - for( i = 0; i < pHeader->numFrames; i++ ) - { - if( pGameFrame[ i ].pChannels ) - delete[] pGameFrame[ i ].pChannels; - } + for (i = 0; i < pHeader->numFrames; i++) { + if (pGameFrame[i].pChannels) { + delete[] pGameFrame[i].pChannels; + } + } - delete[] pGameFrame; - return enAnim; + delete[] pGameFrame; + return enAnim; } -void WriteEncodedFrames( msg_t *msg, skelAnimDataGameHeader_t *enAnim ) +void WriteEncodedFrames(msg_t *msg, skelAnimDataGameHeader_t *enAnim) { - skanChannelHdr *pChannel; - skanGameFrame *pFrame; - int i, j; + skanChannelHdr *pChannel; + skanGameFrame *pFrame; + int i, j; - MSG_WriteLong( msg, enAnim->numFrames ); - MSG_WriteShort( msg, enAnim->nTotalChannels ); + MSG_WriteLong(msg, enAnim->numFrames); + MSG_WriteShort(msg, enAnim->nTotalChannels); - for( i = 0; i < enAnim->nTotalChannels; i++ ) - { - pChannel = &enAnim->ary_channels[ i ]; - MSG_WriteShort( msg, pChannel->nFramesInChannel ); + for (i = 0; i < enAnim->nTotalChannels; i++) { + pChannel = &enAnim->ary_channels[i]; + MSG_WriteShort(msg, pChannel->nFramesInChannel); - for( j = 0; j < pChannel->nFramesInChannel; j++ ) - { - pFrame = &pChannel->ary_frames[ i ]; - MSG_WriteShort( msg, pFrame->nFrameNum ); - MSG_WriteShort( msg, pFrame->nPrevFrameIndex ); - MSG_WriteData( msg, pFrame->pChannelData, sizeof( vec4_t ) ); - } - } + for (j = 0; j < pChannel->nFramesInChannel; j++) { + pFrame = &pChannel->ary_frames[i]; + MSG_WriteShort(msg, pFrame->nFrameNum); + MSG_WriteShort(msg, pFrame->nPrevFrameIndex); + MSG_WriteData(msg, pFrame->pChannelData, sizeof(vec4_t)); + } + } - MSG_WriteLong( msg, enAnim->nBytesUsed ); + MSG_WriteLong(msg, enAnim->nBytesUsed); } -void skeletor_c::SaveProcessedAnim( skelAnimDataGameHeader_t *enAnim, const char *path, skelAnimDataFileHeader_t *pHeader ) +void skeletor_c::SaveProcessedAnim( + skelAnimDataGameHeader_t *enAnim, const char *path, skelAnimDataFileHeader_t *pHeader +) { -/* + /* int i; skelChannelName_t *pChannelNames; msg_t msg; @@ -339,228 +331,212 @@ void skeletor_c::SaveProcessedAnim( skelAnimDataGameHeader_t *enAnim, const char */ } -void ReadEncodedFrames( msg_t *msg, skelAnimDataGameHeader_t *enAnim ) +void ReadEncodedFrames(msg_t *msg, skelAnimDataGameHeader_t *enAnim) { - skanChannelHdr *pChannel; - skanGameFrame *pFrame; - int frameCnt; - int i, j; + skanChannelHdr *pChannel; + skanGameFrame *pFrame; + int frameCnt; + int i, j; - enAnim->numFrames = MSG_ReadLong( msg ); - enAnim->nTotalChannels = MSG_ReadShort( msg ); + enAnim->numFrames = MSG_ReadLong(msg); + enAnim->nTotalChannels = MSG_ReadShort(msg); - for( i = 0; i < enAnim->nTotalChannels; i++ ) - { - pChannel = &enAnim->ary_channels[ i ]; - frameCnt = MSG_ReadShort( msg ); + for (i = 0; i < enAnim->nTotalChannels; i++) { + pChannel = &enAnim->ary_channels[i]; + frameCnt = MSG_ReadShort(msg); - pFrame = ( skanGameFrame * )Skel_Alloc( frameCnt * sizeof( skanGameFrame ) ); - pChannel->ary_frames = pFrame; - pChannel->nFramesInChannel = frameCnt; + pFrame = (skanGameFrame *)Skel_Alloc(frameCnt * sizeof(skanGameFrame)); + pChannel->ary_frames = pFrame; + pChannel->nFramesInChannel = frameCnt; - for( j = 0; j < pChannel->nFramesInChannel; j++ ) - { - pFrame = &pChannel->ary_frames[ j ]; - pFrame->nFrameNum = MSG_ReadShort( msg ); - pFrame->nPrevFrameIndex = MSG_ReadShort( msg ); - MSG_ReadData( msg, pFrame->pChannelData, sizeof( vec4_t ) ); - } - } + for (j = 0; j < pChannel->nFramesInChannel; j++) { + pFrame = &pChannel->ary_frames[j]; + pFrame->nFrameNum = MSG_ReadShort(msg); + pFrame->nPrevFrameIndex = MSG_ReadShort(msg); + MSG_ReadData(msg, pFrame->pChannelData, sizeof(vec4_t)); + } + } - enAnim->nBytesUsed = MSG_ReadLong( msg ); + enAnim->nBytesUsed = MSG_ReadLong(msg); } -void ReadEncodedFramesEx( msg_t *msg, skelAnimDataGameHeader_t *enAnim ) +void ReadEncodedFramesEx(msg_t *msg, skelAnimDataGameHeader_t *enAnim) { - skanChannelHdr *pChannel; - skanGameFrame *pFrame; - int frameCnt; - int i, j; - const char *name; - int type; + skanChannelHdr *pChannel; + skanGameFrame *pFrame; + int frameCnt; + int i, j; + const char *name; + int type; - for( i = 0; i < enAnim->nTotalChannels; i++ ) - { - pChannel = &enAnim->ary_channels[ i ]; + for (i = 0; i < enAnim->nTotalChannels; i++) { + pChannel = &enAnim->ary_channels[i]; - name = enAnim->channelList.ChannelName( &skeletor_c::m_channelNames, i ); - type = GetChannelTypeFromName( name ); - frameCnt = MSG_ReadShort( msg ); + name = enAnim->channelList.ChannelName(&skeletor_c::m_channelNames, i); + type = GetChannelTypeFromName(name); + frameCnt = MSG_ReadShort(msg); - pFrame = ( skanGameFrame * )Skel_Alloc( frameCnt * sizeof( skanGameFrame ) ); - pChannel->ary_frames = pFrame; - pChannel->nFramesInChannel = frameCnt; + pFrame = (skanGameFrame *)Skel_Alloc(frameCnt * sizeof(skanGameFrame)); + pChannel->ary_frames = pFrame; + pChannel->nFramesInChannel = frameCnt; - if( type ) - { - if( type == 1 ) - { - for( j = 0; j < pChannel->nFramesInChannel; j++ ) - { - pFrame = &pChannel->ary_frames[ j ]; - pFrame->nFrameNum = MSG_ReadShort( msg ); - pFrame->nPrevFrameIndex = MSG_ReadShort( msg ); - pFrame->pChannelData[ 0 ] = MSG_ReadFloat( msg ); - pFrame->pChannelData[ 1 ] = MSG_ReadFloat( msg ); - pFrame->pChannelData[ 2 ] = MSG_ReadFloat( msg ); - pFrame->pChannelData[ 3 ] = 0; - } - } - else if( type == 3 ) - { - for( j = 0; j < pChannel->nFramesInChannel; j++ ) - { - pFrame = &pChannel->ary_frames[ j ]; - pFrame->nFrameNum = MSG_ReadShort( msg ); - pFrame->nPrevFrameIndex = MSG_ReadShort( msg ); - pFrame->pChannelData[ 0 ] = MSG_ReadFloat( msg ); - pFrame->pChannelData[ 1 ] = 0; - pFrame->pChannelData[ 2 ] = 0; - pFrame->pChannelData[ 3 ] = 0; - } - } - } - else - { - for( j = 0; j < pChannel->nFramesInChannel; j++ ) - { - pFrame = &pChannel->ary_frames[ j ]; - pFrame->nFrameNum = MSG_ReadShort( msg ); - pFrame->nPrevFrameIndex = MSG_ReadShort( msg ); - pFrame->pChannelData[ 0 ] = MSG_ReadFloat( msg ); - pFrame->pChannelData[ 1 ] = MSG_ReadFloat( msg ); - pFrame->pChannelData[ 2 ] = MSG_ReadFloat( msg ); - pFrame->pChannelData[ 3 ] = MSG_ReadFloat( msg ); - } - } - } + if (type) { + if (type == 1) { + for (j = 0; j < pChannel->nFramesInChannel; j++) { + pFrame = &pChannel->ary_frames[j]; + pFrame->nFrameNum = MSG_ReadShort(msg); + pFrame->nPrevFrameIndex = MSG_ReadShort(msg); + pFrame->pChannelData[0] = MSG_ReadFloat(msg); + pFrame->pChannelData[1] = MSG_ReadFloat(msg); + pFrame->pChannelData[2] = MSG_ReadFloat(msg); + pFrame->pChannelData[3] = 0; + } + } else if (type == 3) { + for (j = 0; j < pChannel->nFramesInChannel; j++) { + pFrame = &pChannel->ary_frames[j]; + pFrame->nFrameNum = MSG_ReadShort(msg); + pFrame->nPrevFrameIndex = MSG_ReadShort(msg); + pFrame->pChannelData[0] = MSG_ReadFloat(msg); + pFrame->pChannelData[1] = 0; + pFrame->pChannelData[2] = 0; + pFrame->pChannelData[3] = 0; + } + } + } else { + for (j = 0; j < pChannel->nFramesInChannel; j++) { + pFrame = &pChannel->ary_frames[j]; + pFrame->nFrameNum = MSG_ReadShort(msg); + pFrame->nPrevFrameIndex = MSG_ReadShort(msg); + pFrame->pChannelData[0] = MSG_ReadFloat(msg); + pFrame->pChannelData[1] = MSG_ReadFloat(msg); + pFrame->pChannelData[2] = MSG_ReadFloat(msg); + pFrame->pChannelData[3] = MSG_ReadFloat(msg); + } + } + } } -skelAnimDataGameHeader_t *skeletor_c::LoadProcessedAnim( const char *path, void *buffer, int len, const char *name ) +skelAnimDataGameHeader_t *skeletor_c::LoadProcessedAnim(const char *path, void *buffer, int len, const char *name) { - skelAnimDataGameHeader_t *enAnim; - int i; - msg_t msg; - int numChannels; - skelAnimGameFrame_t *newFrame; + skelAnimDataGameHeader_t *enAnim; + int i; + msg_t msg; + int numChannels; + skelAnimGameFrame_t *newFrame; - MSG_Init( &msg, ( byte * )buffer, len ); - msg.cursize = len; - MSG_BeginReading( &msg ); + MSG_Init(&msg, (byte *)buffer, len); + msg.cursize = len; + MSG_BeginReading(&msg); - numChannels = MSG_ReadLong( &msg ); - enAnim = skelAnimDataGameHeader_t::AllocRLEChannelData( numChannels ); - enAnim->flags = MSG_ReadLong( &msg ); - enAnim->frameTime = MSG_ReadFloat( &msg ); - enAnim->totalDelta[ 0 ] = MSG_ReadFloat( &msg ); - enAnim->totalDelta[ 1 ] = MSG_ReadFloat( &msg ); - enAnim->totalDelta[ 2 ] = MSG_ReadFloat( &msg ); - enAnim->totalAngleDelta = MSG_ReadFloat( &msg ); - enAnim->numFrames = MSG_ReadLong( &msg ); - enAnim->nTotalChannels = MSG_ReadShort( &msg ); - enAnim->bHasDelta = MSG_ReadByte( &msg ) != 0; - enAnim->bHasUpper = MSG_ReadByte( &msg ) != 0; - enAnim->bHasMorph = MSG_ReadByte( &msg ) != 0; + numChannels = MSG_ReadLong(&msg); + enAnim = skelAnimDataGameHeader_t::AllocRLEChannelData(numChannels); + enAnim->flags = MSG_ReadLong(&msg); + enAnim->frameTime = MSG_ReadFloat(&msg); + enAnim->totalDelta[0] = MSG_ReadFloat(&msg); + enAnim->totalDelta[1] = MSG_ReadFloat(&msg); + enAnim->totalDelta[2] = MSG_ReadFloat(&msg); + enAnim->totalAngleDelta = MSG_ReadFloat(&msg); + enAnim->numFrames = MSG_ReadLong(&msg); + enAnim->nTotalChannels = MSG_ReadShort(&msg); + enAnim->bHasDelta = MSG_ReadByte(&msg) != 0; + enAnim->bHasUpper = MSG_ReadByte(&msg) != 0; + enAnim->bHasMorph = MSG_ReadByte(&msg) != 0; - newFrame = ( skelAnimGameFrame_t * )Skel_Alloc( enAnim->numFrames * sizeof( skelAnimGameFrame_t ) ); - enAnim->m_frame = newFrame; + newFrame = (skelAnimGameFrame_t *)Skel_Alloc(enAnim->numFrames * sizeof(skelAnimGameFrame_t)); + enAnim->m_frame = newFrame; - for( i = 0; i < enAnim->numFrames; i++ ) - { - newFrame->bounds[ 0 ][ 0 ] = MSG_ReadFloat( &msg ); - newFrame->bounds[ 0 ][ 1 ] = MSG_ReadFloat( &msg ); - newFrame->bounds[ 0 ][ 2 ] = MSG_ReadFloat( &msg ); - newFrame->bounds[ 1 ][ 0 ] = MSG_ReadFloat( &msg ); - newFrame->bounds[ 1 ][ 1 ] = MSG_ReadFloat( &msg ); - newFrame->bounds[ 1 ][ 2 ] = MSG_ReadFloat( &msg ); - newFrame->radius = MSG_ReadFloat( &msg ); - newFrame->delta[ 0 ] = MSG_ReadFloat( &msg ); - newFrame->delta[ 1 ] = MSG_ReadFloat( &msg ); - newFrame->delta[ 2 ] = MSG_ReadFloat( &msg ); - newFrame->angleDelta = MSG_ReadFloat( &msg ); - newFrame->pChannels = NULL; - newFrame++; - } + for (i = 0; i < enAnim->numFrames; i++) { + newFrame->bounds[0][0] = MSG_ReadFloat(&msg); + newFrame->bounds[0][1] = MSG_ReadFloat(&msg); + newFrame->bounds[0][2] = MSG_ReadFloat(&msg); + newFrame->bounds[1][0] = MSG_ReadFloat(&msg); + newFrame->bounds[1][1] = MSG_ReadFloat(&msg); + newFrame->bounds[1][2] = MSG_ReadFloat(&msg); + newFrame->radius = MSG_ReadFloat(&msg); + newFrame->delta[0] = MSG_ReadFloat(&msg); + newFrame->delta[1] = MSG_ReadFloat(&msg); + newFrame->delta[2] = MSG_ReadFloat(&msg); + newFrame->angleDelta = MSG_ReadFloat(&msg); + newFrame->pChannels = NULL; + newFrame++; + } - enAnim->bounds[ 0 ][ 0 ] = MSG_ReadFloat( &msg ); - enAnim->bounds[ 0 ][ 1 ] = MSG_ReadFloat( &msg ); - enAnim->bounds[ 0 ][ 2 ] = MSG_ReadFloat( &msg ); - enAnim->bounds[ 1 ][ 0 ] = MSG_ReadFloat( &msg ); - enAnim->bounds[ 1 ][ 1 ] = MSG_ReadFloat( &msg ); - enAnim->bounds[ 1 ][ 2 ] = MSG_ReadFloat( &msg ); - ReadEncodedFrames( &msg, enAnim ); - numChannels = MSG_ReadLong( &msg ); - enAnim->channelList.ZeroChannels(); + enAnim->bounds[0][0] = MSG_ReadFloat(&msg); + enAnim->bounds[0][1] = MSG_ReadFloat(&msg); + enAnim->bounds[0][2] = MSG_ReadFloat(&msg); + enAnim->bounds[1][0] = MSG_ReadFloat(&msg); + enAnim->bounds[1][1] = MSG_ReadFloat(&msg); + enAnim->bounds[1][2] = MSG_ReadFloat(&msg); + ReadEncodedFrames(&msg, enAnim); + numChannels = MSG_ReadLong(&msg); + enAnim->channelList.ZeroChannels(); - for( i = 0; i < numChannels; i++ ) - { - enAnim->channelList.AddChannel( m_channelNames.RegisterChannel( MSG_ReadString( &msg ) ) ); - } + for (i = 0; i < numChannels; i++) { + enAnim->channelList.AddChannel(m_channelNames.RegisterChannel(MSG_ReadString(&msg))); + } - enAnim->channelList.PackChannels(); - return enAnim; + enAnim->channelList.PackChannels(); + return enAnim; } -skelAnimDataGameHeader_t *skeletor_c::LoadProcessedAnimEx( const char *path, void *buffer, int len, const char *name ) +skelAnimDataGameHeader_t *skeletor_c::LoadProcessedAnimEx(const char *path, void *buffer, int len, const char *name) { - skelAnimDataGameHeader_t *enAnim; - int i; - msg_t msg; - int numChannels; - skelAnimGameFrame_t *newFrame; + skelAnimDataGameHeader_t *enAnim; + int i; + msg_t msg; + int numChannels; + skelAnimGameFrame_t *newFrame; - MSG_Init( &msg, ( byte * )buffer, len ); - msg.cursize = len; - MSG_BeginReading( &msg ); + MSG_Init(&msg, (byte *)buffer, len); + msg.cursize = len; + MSG_BeginReading(&msg); - numChannels = MSG_ReadShort( &msg ); - enAnim = skelAnimDataGameHeader_t::AllocRLEChannelData( numChannels ); - enAnim->channelList.ZeroChannels(); - enAnim->flags = MSG_ReadLong( &msg ); - enAnim->frameTime = MSG_ReadFloat( &msg ); - enAnim->totalDelta[ 0 ] = MSG_ReadFloat( &msg ); - enAnim->totalDelta[ 1 ] = MSG_ReadFloat( &msg ); - enAnim->totalDelta[ 2 ] = MSG_ReadFloat( &msg ); - enAnim->totalAngleDelta = MSG_ReadFloat( &msg ); - enAnim->numFrames = MSG_ReadLong( &msg ); - enAnim->bHasDelta = MSG_ReadByte( &msg ) != 0; - enAnim->bHasUpper = MSG_ReadByte( &msg ) != 0; - enAnim->bHasMorph = MSG_ReadByte( &msg ) != 0; + numChannels = MSG_ReadShort(&msg); + enAnim = skelAnimDataGameHeader_t::AllocRLEChannelData(numChannels); + enAnim->channelList.ZeroChannels(); + enAnim->flags = MSG_ReadLong(&msg); + enAnim->frameTime = MSG_ReadFloat(&msg); + enAnim->totalDelta[0] = MSG_ReadFloat(&msg); + enAnim->totalDelta[1] = MSG_ReadFloat(&msg); + enAnim->totalDelta[2] = MSG_ReadFloat(&msg); + enAnim->totalAngleDelta = MSG_ReadFloat(&msg); + enAnim->numFrames = MSG_ReadLong(&msg); + enAnim->bHasDelta = MSG_ReadByte(&msg) != 0; + enAnim->bHasUpper = MSG_ReadByte(&msg) != 0; + enAnim->bHasMorph = MSG_ReadByte(&msg) != 0; - for( i = 0; i < enAnim->nTotalChannels; i++ ) - { - enAnim->channelList.AddChannel( m_channelNames.RegisterChannel( MSG_ReadString( &msg ) ) ); - } + for (i = 0; i < enAnim->nTotalChannels; i++) { + enAnim->channelList.AddChannel(m_channelNames.RegisterChannel(MSG_ReadString(&msg))); + } - enAnim->channelList.PackChannels(); + enAnim->channelList.PackChannels(); - newFrame = ( skelAnimGameFrame_t * )Skel_Alloc( enAnim->numFrames * sizeof( skelAnimGameFrame_t ) ); - enAnim->m_frame = newFrame; + newFrame = (skelAnimGameFrame_t *)Skel_Alloc(enAnim->numFrames * sizeof(skelAnimGameFrame_t)); + enAnim->m_frame = newFrame; - for( i = 0; i < enAnim->numFrames; i++ ) - { - newFrame->bounds[ 0 ][ 0 ] = MSG_ReadFloat( &msg ); - newFrame->bounds[ 0 ][ 1 ] = MSG_ReadFloat( &msg ); - newFrame->bounds[ 0 ][ 2 ] = MSG_ReadFloat( &msg ); - newFrame->bounds[ 1 ][ 0 ] = MSG_ReadFloat( &msg ); - newFrame->bounds[ 1 ][ 1 ] = MSG_ReadFloat( &msg ); - newFrame->bounds[ 1 ][ 2 ] = MSG_ReadFloat( &msg ); - newFrame->radius = MSG_ReadFloat( &msg ); - newFrame->delta[ 0 ] = MSG_ReadFloat( &msg ); - newFrame->delta[ 1 ] = MSG_ReadFloat( &msg ); - newFrame->delta[ 2 ] = MSG_ReadFloat( &msg ); - newFrame->angleDelta = MSG_ReadFloat( &msg ); - newFrame->pChannels = NULL; - newFrame++; - } + for (i = 0; i < enAnim->numFrames; i++) { + newFrame->bounds[0][0] = MSG_ReadFloat(&msg); + newFrame->bounds[0][1] = MSG_ReadFloat(&msg); + newFrame->bounds[0][2] = MSG_ReadFloat(&msg); + newFrame->bounds[1][0] = MSG_ReadFloat(&msg); + newFrame->bounds[1][1] = MSG_ReadFloat(&msg); + newFrame->bounds[1][2] = MSG_ReadFloat(&msg); + newFrame->radius = MSG_ReadFloat(&msg); + newFrame->delta[0] = MSG_ReadFloat(&msg); + newFrame->delta[1] = MSG_ReadFloat(&msg); + newFrame->delta[2] = MSG_ReadFloat(&msg); + newFrame->angleDelta = MSG_ReadFloat(&msg); + newFrame->pChannels = NULL; + newFrame++; + } - enAnim->bounds[ 0 ][ 0 ] = MSG_ReadFloat( &msg ); - enAnim->bounds[ 0 ][ 1 ] = MSG_ReadFloat( &msg ); - enAnim->bounds[ 0 ][ 2 ] = MSG_ReadFloat( &msg ); - enAnim->bounds[ 1 ][ 0 ] = MSG_ReadFloat( &msg ); - enAnim->bounds[ 1 ][ 1 ] = MSG_ReadFloat( &msg ); - enAnim->bounds[ 1 ][ 2 ] = MSG_ReadFloat( &msg ); - ReadEncodedFramesEx( &msg, enAnim ); + enAnim->bounds[0][0] = MSG_ReadFloat(&msg); + enAnim->bounds[0][1] = MSG_ReadFloat(&msg); + enAnim->bounds[0][2] = MSG_ReadFloat(&msg); + enAnim->bounds[1][0] = MSG_ReadFloat(&msg); + enAnim->bounds[1][1] = MSG_ReadFloat(&msg); + enAnim->bounds[1][2] = MSG_ReadFloat(&msg); + ReadEncodedFramesEx(&msg, enAnim); - return enAnim; + return enAnim; } diff --git a/code/skeletor/skeletor_model_file_format.h b/code/skeletor/skeletor_model_file_format.h index 0babad7b..b2bf54ed 100644 --- a/code/skeletor/skeletor_model_file_format.h +++ b/code/skeletor/skeletor_model_file_format.h @@ -1,6 +1,6 @@ /* =========================================================================== -Copyright (C) 2015 the OpenMoHAA team +Copyright (C) 2023 the OpenMoHAA team This file is part of OpenMoHAA source code. @@ -27,72 +27,100 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA static const char *SKEL_BONENAME_WORLD = "worldbone"; typedef enum boneType_e { - SKELBONE_ROTATION, - SKELBONE_POSROT, - SKELBONE_IKSHOULDER, - SKELBONE_IKELBOW, - SKELBONE_IKWRIST, - SKELBONE_HOSEROT, - SKELBONE_AVROT, - SKELBONE_ZERO, - SKELBONE_NUMBONETYPES, - SKELBONE_WORLD, - SKELBONE_HOSEROTBOTH, - SKELBONE_HOSEROTPARENT + SKELBONE_ROTATION, + SKELBONE_POSROT, + SKELBONE_IKSHOULDER, + SKELBONE_IKELBOW, + SKELBONE_IKWRIST, + SKELBONE_HOSEROT, + SKELBONE_AVROT, + SKELBONE_ZERO, + SKELBONE_NUMBONETYPES, + SKELBONE_WORLD, + SKELBONE_HOSEROTBOTH, + SKELBONE_HOSEROTPARENT } boneType_t; typedef enum { - HRTYPE_PLAIN, - HRTYPE_ROTATEPARENT180Y, - HRTYPE_ROTATEBOTH180Y + HRTYPE_PLAIN, + HRTYPE_ROTATEPARENT180Y, + HRTYPE_ROTATEBOTH180Y } hoseRotType_t; typedef struct boneFileData_s { - char name[ 32 ]; - char parent[ 32 ]; - boneType_t boneType; - int ofsBaseData; - int ofsChannelNames; - int ofsBoneNames; - int ofsEnd; + char name[32]; + char parent[32]; + boneType_t boneType; + int ofsBaseData; + int ofsChannelNames; + int ofsBoneNames; + int ofsEnd; } boneFileData_t; typedef struct skelHitBox_s { - int boneIndex; + int boneIndex; } skelHitBox_t; typedef struct { - int ident; - int version; - char name[ 64 ]; - int numSurfaces; - int numBones; - int ofsBones; - int ofsSurfaces; - int ofsEnd; - int lodIndex[ 10 ]; - int numBoxes; - int ofsBoxes; - int numMorphTargets; - int ofsMorphTargets; + int ident; + int version; + char name[64]; + int numSurfaces; + int numBones; + int ofsBones; + int ofsSurfaces; + int ofsEnd; + int lodIndex[10]; + int numBoxes; + int ofsBoxes; + int numMorphTargets; + int ofsMorphTargets; } skelBaseHeader_t; #if __cplusplus -#include "SkelVec3.h" -#include "SkelQuat.h" +# include "SkelVec3.h" +# include "SkelQuat.h" struct boneData_s; -int CreateRotationBoneFileData( const char *newBoneName, const char *newBoneParentName, SkelVec3 basePos, boneFileData_t *fileData ); -int CreatePosRotBoneFileData( char *newBoneName, char *newBoneParentName, boneFileData_t *fileData ); -void CreatePosRotBoneData( const char *newBoneName, const char *newBoneParentName, boneData_s *boneData ); -int CreateIKShoulderBoneFileData( const char *newBoneName, const char *newBoneParentName, SkelQuat baseOrient, SkelVec3 basePos, boneData_s *boneData ); -int CreateIKElbowBoneFileData( const char *newBoneName, const char *newBoneParentName, SkelVec3 basePos, boneData_s *boneData ); -int CreateIKWristBoneFileData( const char *newBoneName, const char *newBoneParentName, const char *shoulderBoneName, SkelVec3 basePos, boneFileData_t *fileData ); -int CreateHoseRotBoneFileData( char *newBoneName, char *newBoneParentName, char *targetBoneName, float bendRatio, float bendMax, float spinRatio, - hoseRotType_t hoseRotType, SkelVec3 basePos, boneFileData_t *fileData ); -int CreateAvRotBoneFileData( char *newBoneName, char *newBoneParentName, char *baseBoneName, char *targetBoneName, float rotRatio, - SkelVec3 basePos, boneFileData_t *fileData ); +int CreateRotationBoneFileData( + const char *newBoneName, const char *newBoneParentName, SkelVec3 basePos, boneFileData_t *fileData +); +int CreatePosRotBoneFileData(char *newBoneName, char *newBoneParentName, boneFileData_t *fileData); +void CreatePosRotBoneData(const char *newBoneName, const char *newBoneParentName, boneData_s *boneData); +int CreateIKShoulderBoneFileData( + const char *newBoneName, const char *newBoneParentName, SkelQuat baseOrient, SkelVec3 basePos, boneData_s *boneData + ); +int CreateIKElbowBoneFileData( + const char *newBoneName, const char *newBoneParentName, SkelVec3 basePos, boneData_s *boneData +); +int CreateIKWristBoneFileData( + const char *newBoneName, + const char *newBoneParentName, + const char *shoulderBoneName, + SkelVec3 basePos, + boneFileData_t *fileData +); +int CreateHoseRotBoneFileData( + char *newBoneName, + char *newBoneParentName, + char *targetBoneName, + float bendRatio, + float bendMax, + float spinRatio, + hoseRotType_t hoseRotType, + SkelVec3 basePos, + boneFileData_t *fileData +); +int CreateAvRotBoneFileData( + char *newBoneName, + char *newBoneParentName, + char *baseBoneName, + char *targetBoneName, + float rotRatio, + SkelVec3 basePos, + boneFileData_t *fileData +); #endif diff --git a/code/skeletor/skeletor_model_files.cpp b/code/skeletor/skeletor_model_files.cpp index e3659664..a7b6d543 100644 --- a/code/skeletor/skeletor_model_files.cpp +++ b/code/skeletor/skeletor_model_files.cpp @@ -1,6 +1,6 @@ /* =========================================================================== -Copyright (C) 2015 the OpenMoHAA team +Copyright (C) 2023 the OpenMoHAA team This file is part of OpenMoHAA source code. @@ -26,184 +26,197 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "qcommon.h" #include "skeletor.h" -int CreateRotationBoneFileData( const char *newBoneName, const char *newBoneParentName, SkelVec3 basePos, boneFileData_t *fileData ) +int CreateRotationBoneFileData( + const char *newBoneName, const char *newBoneParentName, SkelVec3 basePos, boneFileData_t *fileData +) { - char *saveChannelName; - char *rotChannelName; - boneData_t *boneData; + char *saveChannelName; + char *rotChannelName; + boneData_t *boneData; - strncpy( fileData->name, newBoneName, sizeof( fileData->name ) ); - strncpy( fileData->parent, newBoneParentName, sizeof( fileData->parent ) ); - fileData->boneType = SKELBONE_ROTATION; - fileData->ofsBaseData = sizeof( boneFileData_t ); - boneData = ( boneData_t * )( ( char * )fileData + fileData->ofsBaseData ); - boneData->offset[ 0 ] = basePos[ 0 ]; - boneData->offset[ 1 ] = basePos[ 1 ]; - boneData->offset[ 2 ] = basePos[ 2 ]; - boneData->length = 1.0f; - boneData->weight = 1.0f; - boneData->bendRatio = 1.0f; - fileData->ofsChannelNames = fileData->ofsBaseData + 24; - saveChannelName = ( char * )( ( char * )fileData + fileData->ofsChannelNames ); + strncpy(fileData->name, newBoneName, sizeof(fileData->name)); + strncpy(fileData->parent, newBoneParentName, sizeof(fileData->parent)); + fileData->boneType = SKELBONE_ROTATION; + fileData->ofsBaseData = sizeof(boneFileData_t); + boneData = (boneData_t *)((char *)fileData + fileData->ofsBaseData); + boneData->offset[0] = basePos[0]; + boneData->offset[1] = basePos[1]; + boneData->offset[2] = basePos[2]; + boneData->length = 1.0f; + boneData->weight = 1.0f; + boneData->bendRatio = 1.0f; + fileData->ofsChannelNames = fileData->ofsBaseData + 24; + saveChannelName = (char *)((char *)fileData + fileData->ofsChannelNames); - rotChannelName = ( char * )Skel_Alloc( strlen( newBoneName ) + 5 ); - ConvertToRotationName( newBoneName, rotChannelName ); - strcpy( saveChannelName, rotChannelName ); - fileData->ofsBoneNames = fileData->ofsChannelNames + ( int )strlen( rotChannelName ) + 1; - fileData->ofsEnd = fileData->ofsBoneNames; - return fileData->ofsEnd; + rotChannelName = (char *)Skel_Alloc(strlen(newBoneName) + 5); + ConvertToRotationName(newBoneName, rotChannelName); + strcpy(saveChannelName, rotChannelName); + fileData->ofsBoneNames = fileData->ofsChannelNames + (int)strlen(rotChannelName) + 1; + fileData->ofsEnd = fileData->ofsBoneNames; + return fileData->ofsEnd; } -int CreatePosRotBoneFileData( char *newBoneName, char *newBoneParentName, boneFileData_t *fileData ) +int CreatePosRotBoneFileData(char *newBoneName, char *newBoneParentName, boneFileData_t *fileData) { - int channelNamesLength; - char *saveChannelName; - char *rotChannelName; - char *posChannelName; - boneData_t *boneData; + int channelNamesLength; + char *saveChannelName; + char *rotChannelName; + char *posChannelName; + boneData_t *boneData; - strncpy( fileData->name, newBoneName, sizeof( fileData->name ) ); - strncpy( fileData->parent, newBoneParentName, sizeof( fileData->parent ) ); - fileData->boneType = SKELBONE_POSROT; - fileData->ofsBaseData = sizeof( boneFileData_t ); - boneData = ( boneData_t * )( ( char * )fileData + fileData->ofsBaseData ); - boneData->offset[ 0 ] = 1.0f; - boneData->offset[ 1 ] = 1.0f; - boneData->offset[ 2 ] = 1.0f; - fileData->ofsChannelNames = fileData->ofsBaseData + 12; - saveChannelName = ( char * )( ( char * )fileData + fileData->ofsChannelNames ); + strncpy(fileData->name, newBoneName, sizeof(fileData->name)); + strncpy(fileData->parent, newBoneParentName, sizeof(fileData->parent)); + fileData->boneType = SKELBONE_POSROT; + fileData->ofsBaseData = sizeof(boneFileData_t); + boneData = (boneData_t *)((char *)fileData + fileData->ofsBaseData); + boneData->offset[0] = 1.0f; + boneData->offset[1] = 1.0f; + boneData->offset[2] = 1.0f; + fileData->ofsChannelNames = fileData->ofsBaseData + 12; + saveChannelName = (char *)((char *)fileData + fileData->ofsChannelNames); - rotChannelName = ( char * )Skel_Alloc( strlen( newBoneName ) + 5 ); - ConvertToRotationName( newBoneName, rotChannelName ); - strcpy( saveChannelName, rotChannelName ); - Skel_Free( rotChannelName ); + rotChannelName = (char *)Skel_Alloc(strlen(newBoneName) + 5); + ConvertToRotationName(newBoneName, rotChannelName); + strcpy(saveChannelName, rotChannelName); + Skel_Free(rotChannelName); - channelNamesLength = ( int )strlen( saveChannelName ); - saveChannelName = ( char * )( ( char * )fileData + fileData->ofsChannelNames + channelNamesLength ); - posChannelName = ( char * )Skel_Alloc( strlen( newBoneName ) + 5 ); - ConvertToPositionName( newBoneName, posChannelName ); - strcpy( saveChannelName, posChannelName ); - Skel_Free( posChannelName ); + channelNamesLength = (int)strlen(saveChannelName); + saveChannelName = (char *)((char *)fileData + fileData->ofsChannelNames + channelNamesLength); + posChannelName = (char *)Skel_Alloc(strlen(newBoneName) + 5); + ConvertToPositionName(newBoneName, posChannelName); + strcpy(saveChannelName, posChannelName); + Skel_Free(posChannelName); - channelNamesLength += ( int )strlen( saveChannelName ); + channelNamesLength += (int)strlen(saveChannelName); - fileData->ofsBoneNames = fileData->ofsChannelNames + channelNamesLength + 2; - fileData->ofsEnd = fileData->ofsBoneNames; - return fileData->ofsEnd; + fileData->ofsBoneNames = fileData->ofsChannelNames + channelNamesLength + 2; + fileData->ofsEnd = fileData->ofsBoneNames; + return fileData->ofsEnd; } -void CreatePosRotBoneData( const char *newBoneName, const char *newBoneParentName, boneData_t *boneData ) +void CreatePosRotBoneData(const char *newBoneName, const char *newBoneParentName, boneData_t *boneData) { - char *rotChannelName; - char *posChannelName; + char *rotChannelName; + char *posChannelName; - boneData->channel = skeletor_c::m_boneNames.RegisterChannel( newBoneName ); + boneData->channel = skeletor_c::m_boneNames.RegisterChannel(newBoneName); - if( !strcmp( newBoneParentName, "worldbone" ) ) - { - boneData->parent = -1; - } - else - { - boneData->parent = skeletor_c::m_boneNames.RegisterChannel( newBoneParentName ); - assert( boneData->parent >= 0 ); - } + if (!strcmp(newBoneParentName, "worldbone")) { + boneData->parent = -1; + } else { + boneData->parent = skeletor_c::m_boneNames.RegisterChannel(newBoneParentName); + assert(boneData->parent >= 0); + } - boneData->boneType = SKELBONE_POSROT; + boneData->boneType = SKELBONE_POSROT; - rotChannelName = ( char * )Skel_Alloc( strlen( newBoneName ) + 5 ); - ConvertToRotationName( newBoneName, rotChannelName ); - boneData->channelIndex[ 0 ] = skeletor_c::m_channelNames.RegisterChannel( rotChannelName ); - if( boneData->channelIndex[ 0 ] < 0 ) - { - SKEL_Warning( "Channel named %s not added. (Bone will not work without it)\n", rotChannelName ); - boneData->boneType = SKELBONE_ZERO; - } - Skel_Free( rotChannelName ); + rotChannelName = (char *)Skel_Alloc(strlen(newBoneName) + 5); + ConvertToRotationName(newBoneName, rotChannelName); + boneData->channelIndex[0] = skeletor_c::m_channelNames.RegisterChannel(rotChannelName); + if (boneData->channelIndex[0] < 0) { + SKEL_Warning("Channel named %s not added. (Bone will not work without it)\n", rotChannelName); + boneData->boneType = SKELBONE_ZERO; + } + Skel_Free(rotChannelName); - posChannelName = ( char * )Skel_Alloc( strlen( newBoneName ) + 5 ); - ConvertToPositionName( newBoneName, posChannelName ); - boneData->channelIndex[ 1 ] = skeletor_c::m_channelNames.RegisterChannel( posChannelName ); - if( boneData->channelIndex[ 1 ] < 0 ) - { - SKEL_Warning( "Channel named %s not added. (Bone will not work without it)\n", posChannelName ); - boneData->boneType = SKELBONE_ZERO; - } - Skel_Free( posChannelName ); + posChannelName = (char *)Skel_Alloc(strlen(newBoneName) + 5); + ConvertToPositionName(newBoneName, posChannelName); + boneData->channelIndex[1] = skeletor_c::m_channelNames.RegisterChannel(posChannelName); + if (boneData->channelIndex[1] < 0) { + SKEL_Warning("Channel named %s not added. (Bone will not work without it)\n", posChannelName); + boneData->boneType = SKELBONE_ZERO; + } + Skel_Free(posChannelName); - boneData->numChannels = 2; - boneData->numRefs = 0; + boneData->numChannels = 2; + boneData->numRefs = 0; } -int CreateIKShoulderBoneFileData( const char *newBoneName, const char *newBoneParentName, SkelQuat baseOrient, SkelVec3 basePos, boneData_t *boneData ) +int CreateIKShoulderBoneFileData( + const char *newBoneName, const char *newBoneParentName, SkelQuat baseOrient, SkelVec3 basePos, boneData_t *boneData +) { - // FIXME: stub - return 0; + // FIXME: stub + return 0; } -int CreateIKElbowBoneFileData( const char *newBoneName, const char *newBoneParentName, SkelVec3 basePos, boneData_t *boneData ) +int CreateIKElbowBoneFileData( + const char *newBoneName, const char *newBoneParentName, SkelVec3 basePos, boneData_t *boneData +) { - // FIXME: stub - return 0; + // FIXME: stub + return 0; } -int CreateIKWristBoneFileData( const char *newBoneName, const char *newBoneParentName, const char *shoulderBoneName, SkelVec3 basePos, boneFileData_t *fileData ) +int CreateIKWristBoneFileData( + const char *newBoneName, + const char *newBoneParentName, + const char *shoulderBoneName, + SkelVec3 basePos, + boneFileData_t *fileData +) { - // FIXME: stub - return 0; + // FIXME: stub + return 0; } -int CreateHoseRotBoneFileData( char *newBoneName, char *newBoneParentName, char *targetBoneName, float bendRatio, float bendMax, float spinRatio, - hoseRotType_t hoseRotType, SkelVec3 basePos, boneFileData_t *fileData ) +int CreateHoseRotBoneFileData( + char *newBoneName, + char *newBoneParentName, + char *targetBoneName, + float bendRatio, + float bendMax, + float spinRatio, + hoseRotType_t hoseRotType, + SkelVec3 basePos, + boneFileData_t *fileData +) { - // FIXME: stub - return 0; + // FIXME: stub + return 0; } -int CreateAvRotBoneFileData( char *newBoneName, char *newBoneParentName, char *baseBoneName, char *targetBoneName, float rotRatio, - SkelVec3 basePos, boneFileData_t *fileData ) +int CreateAvRotBoneFileData( + char *newBoneName, + char *newBoneParentName, + char *baseBoneName, + char *targetBoneName, + float rotRatio, + SkelVec3 basePos, + boneFileData_t *fileData +) { - // FIXME: stub - return 0; + // FIXME: stub + return 0; } -void skeletor_c::LoadMorphTargetNames( skelHeaderGame_t *modelHeader ) +void skeletor_c::LoadMorphTargetNames(skelHeaderGame_t *modelHeader) { - int numTargets; - char *newTargetName; - int i; - int newChannel; - int morphTargetIndex; + int numTargets; + char *newTargetName; + int i; + int newChannel; + int morphTargetIndex; - numTargets = modelHeader->numMorphTargets; - newTargetName = modelHeader->pMorphTargets; + numTargets = modelHeader->numMorphTargets; + newTargetName = modelHeader->pMorphTargets; - for( i = 0; i < numTargets; i++ ) - { - newChannel = m_channelNames.RegisterChannel( newTargetName ); - morphTargetIndex = m_morphTargetList.AddChannel( newChannel ); + for (i = 0; i < numTargets; i++) { + newChannel = m_channelNames.RegisterChannel(newTargetName); + morphTargetIndex = m_morphTargetList.AddChannel(newChannel); - if( !strncmp( newTargetName, "EYES_left", 9 ) ) - { - m_targetLookLeft = morphTargetIndex; - } - else if( !strncmp( newTargetName, "EYES_right", 10 ) ) - { - m_targetLookRight = morphTargetIndex; - } - else if( !strncmp( newTargetName, "EYES_up",70 ) ) - { - m_targetLookUp = morphTargetIndex; - } - else if( !strncmp( newTargetName, "EYES_down", 9 ) ) - { - m_targetLookDown = morphTargetIndex; - } - else if( !strncmp( newTargetName, "EYES_blink", 9 ) ) - { - m_targetBlink = morphTargetIndex; - } + if (!strncmp(newTargetName, "EYES_left", 9)) { + m_targetLookLeft = morphTargetIndex; + } else if (!strncmp(newTargetName, "EYES_right", 10)) { + m_targetLookRight = morphTargetIndex; + } else if (!strncmp(newTargetName, "EYES_up", 70)) { + m_targetLookUp = morphTargetIndex; + } else if (!strncmp(newTargetName, "EYES_down", 9)) { + m_targetLookDown = morphTargetIndex; + } else if (!strncmp(newTargetName, "EYES_blink", 9)) { + m_targetBlink = morphTargetIndex; + } - newTargetName += strlen( newTargetName + 1 ); - } + newTargetName += strlen(newTargetName + 1); + } } diff --git a/code/skeletor/skeletor_name_lists.h b/code/skeletor/skeletor_name_lists.h index c19b3577..c26f1ccd 100644 --- a/code/skeletor/skeletor_name_lists.h +++ b/code/skeletor/skeletor_name_lists.h @@ -1,6 +1,6 @@ /* =========================================================================== -Copyright (C) 2015 the OpenMoHAA team +Copyright (C) 2023 the OpenMoHAA team This file is part of OpenMoHAA source code. @@ -28,42 +28,43 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #define MAX_CHANNEL_NAME 32 typedef struct ChannelName_s { - char name[ MAX_CHANNEL_NAME ]; - short channelNum; + char name[MAX_CHANNEL_NAME]; + short channelNum; } ChannelName_t; #ifdef __cplusplus -class ChannelNameTable { - short int m_iNumChannels; - ChannelName_t m_Channels[MAX_SKELETOR_CHANNELS]; - short int m_lookup[MAX_SKELETOR_CHANNELS]; +class ChannelNameTable +{ + short int m_iNumChannels; + ChannelName_t m_Channels[MAX_SKELETOR_CHANNELS]; + short int m_lookup[MAX_SKELETOR_CHANNELS]; public: - ChannelNameTable(); + ChannelNameTable(); - int RegisterChannel( const char *name ); - int FindNameLookup( const char *name ); - void PrintContents(); - const char *FindName( int index ); - int NumChannels() const; + int RegisterChannel(const char *name); + int FindNameLookup(const char *name); + void PrintContents(); + const char *FindName(int index); + int NumChannels() const; private: - const char *FindNameFromLookup( int index ); - bool FindIndexFromName( const char *name, int *indexPtr ); - void SortIntoTable( int index ); - void CopyChannel( ChannelName_t *dest, const ChannelName_t *source ); - void SetChannelName( ChannelName_t *channel, const char *newName ); + const char *FindNameFromLookup(int index); + bool FindIndexFromName(const char *name, int *indexPtr); + void SortIntoTable(int index); + void CopyChannel(ChannelName_t *dest, const ChannelName_t *source); + void SetChannelName(ChannelName_t *channel, const char *newName); }; -int GetChannelTypeFromName( const char *name ); +int GetChannelTypeFromName(const char *name); #else typedef struct { - short int m_iNumChannels; - ChannelName_t m_Channels[MAX_SKELETOR_CHANNELS]; - short int m_lookup[MAX_SKELETOR_CHANNELS]; + short int m_iNumChannels; + ChannelName_t m_Channels[MAX_SKELETOR_CHANNELS]; + short int m_lookup[MAX_SKELETOR_CHANNELS]; } ChannelNameTable; #endif diff --git a/code/skeletor/skeletor_utilities.cpp b/code/skeletor/skeletor_utilities.cpp index 7a8876ad..8dc6f80b 100644 --- a/code/skeletor/skeletor_utilities.cpp +++ b/code/skeletor/skeletor_utilities.cpp @@ -1,6 +1,6 @@ /* =========================================================================== -Copyright (C) 2015 the OpenMoHAA team +Copyright (C) 2023 the OpenMoHAA team This file is part of OpenMoHAA source code. @@ -25,313 +25,276 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "q_shared.h" #include "skeletor.h" -void SKEL_Message( const char *fmt, ... ) +void SKEL_Message(const char *fmt, ...) { - static char msg[ 32000 ]; - va_list va; + static char msg[32000]; + va_list va; - va_start( va, fmt ); - vsprintf( msg, fmt, va ); - va_end( va ); - Skel_DPrintf( msg ); + va_start(va, fmt); + vsprintf(msg, fmt, va); + va_end(va); + Skel_DPrintf(msg); } -void SKEL_Warning( const char *fmt, ... ) +void SKEL_Warning(const char *fmt, ...) { - char msg[ 1024 ]; - va_list va; + char msg[1024]; + va_list va; - va_start( va, fmt ); - vsprintf( msg, fmt, va ); - va_end( va ); - Skel_DPrintf( msg ); + va_start(va, fmt); + vsprintf(msg, fmt, va); + va_end(va); + Skel_DPrintf(msg); } -void SKEL_Error( const char *fmt, ... ) +void SKEL_Error(const char *fmt, ...) { - char msg[ 1024 ]; - va_list va; + char msg[1024]; + va_list va; - va_start( va, fmt ); - vsprintf( msg, fmt, va ); - va_end( va ); - Skel_DPrintf( msg ); + va_start(va, fmt); + vsprintf(msg, fmt, va); + va_end(va); + Skel_DPrintf(msg); } -int FileLength( FILE *pFile ) +int FileLength(FILE *pFile) { - int iPos; - int iEnd; + int iPos; + int iEnd; - iPos = ftell( pFile ); - fseek( pFile, 0, SEEK_END ); - iEnd = ftell( pFile ); - fseek( pFile, iPos, SEEK_SET ); + iPos = ftell(pFile); + fseek(pFile, 0, SEEK_END); + iEnd = ftell(pFile); + fseek(pFile, iPos, SEEK_SET); - return iEnd; + return iEnd; } -int skelChannelList_s::GetLocalFromGlobal( int globalChannel ) const +int skelChannelList_s::GetLocalFromGlobal(int globalChannel) const { - if( m_chanLocalFromGlobal && globalChannel < m_numLocalFromGlobal ) - { - return m_chanLocalFromGlobal[ globalChannel ]; - } - else - { - return -1; - } + if (m_chanLocalFromGlobal && globalChannel < m_numLocalFromGlobal) { + return m_chanLocalFromGlobal[globalChannel]; + } else { + return -1; + } } -int skelChannelList_s::NumChannels( void ) const +int skelChannelList_s::NumChannels(void) const { - return m_numChannels; + return m_numChannels; } void skelChannelList_s::ZeroChannels() { - int i; + int i; - m_numChannels = 0; - m_chanLocalFromGlobal = ( short * )Skel_Alloc( MAX_SKELETOR_CHANNELS * sizeof( short ) ); - m_numLocalFromGlobal = MAX_SKELETOR_CHANNELS; + m_numChannels = 0; + m_chanLocalFromGlobal = (short *)Skel_Alloc(MAX_SKELETOR_CHANNELS * sizeof(short)); + m_numLocalFromGlobal = MAX_SKELETOR_CHANNELS; - for( i = 0; i < MAX_SKELETOR_CHANNELS; i++ ) - { - m_chanLocalFromGlobal[ i ] = -1; - } + for (i = 0; i < MAX_SKELETOR_CHANNELS; i++) { + m_chanLocalFromGlobal[i] = -1; + } } void skelChannelList_s::PackChannels() { - m_numLocalFromGlobal = MAX_SKELETOR_CHANNELS - 1; + m_numLocalFromGlobal = MAX_SKELETOR_CHANNELS - 1; - if( m_chanLocalFromGlobal[ m_numLocalFromGlobal ] == -1 ) - { - do - { - m_numLocalFromGlobal--; - } while( m_chanLocalFromGlobal[ m_numLocalFromGlobal ] == -1 && m_numLocalFromGlobal >= 0 ); - } + if (m_chanLocalFromGlobal[m_numLocalFromGlobal] == -1) { + do { + m_numLocalFromGlobal--; + } while (m_chanLocalFromGlobal[m_numLocalFromGlobal] == -1 && m_numLocalFromGlobal >= 0); + } - if( m_numLocalFromGlobal < MAX_SKELETOR_CHANNELS ) - { - m_numLocalFromGlobal++; - } + if (m_numLocalFromGlobal < MAX_SKELETOR_CHANNELS) { + m_numLocalFromGlobal++; + } - if( m_numLocalFromGlobal <= 0 ) - { - Skel_Free( m_chanLocalFromGlobal ); - m_chanLocalFromGlobal = NULL; - m_numLocalFromGlobal = -1; - } - else - { - short *old_array = m_chanLocalFromGlobal; - m_chanLocalFromGlobal = ( short * )Skel_Alloc( m_numLocalFromGlobal * sizeof( m_chanLocalFromGlobal[ 0 ] ) ); - memcpy( m_chanLocalFromGlobal, old_array, m_numLocalFromGlobal * sizeof( m_chanLocalFromGlobal[ 0 ] ) ); - Skel_Free( old_array ); - } + if (m_numLocalFromGlobal <= 0) { + Skel_Free(m_chanLocalFromGlobal); + m_chanLocalFromGlobal = NULL; + m_numLocalFromGlobal = -1; + } else { + short *old_array = m_chanLocalFromGlobal; + m_chanLocalFromGlobal = (short *)Skel_Alloc(m_numLocalFromGlobal * sizeof(m_chanLocalFromGlobal[0])); + memcpy(m_chanLocalFromGlobal, old_array, m_numLocalFromGlobal * sizeof(m_chanLocalFromGlobal[0])); + Skel_Free(old_array); + } } void skelChannelList_s::CleanUpChannels() { - if( m_chanLocalFromGlobal ) - { - Skel_Free( m_chanLocalFromGlobal ); - m_chanLocalFromGlobal = NULL; - } + if (m_chanLocalFromGlobal) { + Skel_Free(m_chanLocalFromGlobal); + m_chanLocalFromGlobal = NULL; + } - m_numLocalFromGlobal = 0; + m_numLocalFromGlobal = 0; } void skelChannelList_s::InitChannels() { - m_chanLocalFromGlobal = NULL; - m_numLocalFromGlobal = 0; + m_chanLocalFromGlobal = NULL; + m_numLocalFromGlobal = 0; } -int skelChannelList_s::AddChannel( int newGlobalChannelNum ) +int skelChannelList_s::AddChannel(int newGlobalChannelNum) { - short int iLocalChannel; + short int iLocalChannel; - if( newGlobalChannelNum == -1 ) - { - // Fixed in 2.0 - // Set the global from local to -1 - m_chanGlobalFromLocal[m_numChannels] = -1; - return m_numChannels++; - } + if (newGlobalChannelNum == -1) { + // Fixed in 2.0 + // Set the global from local to -1 + m_chanGlobalFromLocal[m_numChannels] = -1; + return m_numChannels++; + } - iLocalChannel = GetLocalFromGlobal( newGlobalChannelNum ); + iLocalChannel = GetLocalFromGlobal(newGlobalChannelNum); - if( iLocalChannel < 0 ) - { - iLocalChannel = m_numChannels++; - m_chanGlobalFromLocal[ iLocalChannel ] = newGlobalChannelNum; - m_chanLocalFromGlobal[ newGlobalChannelNum ] = iLocalChannel; - } + if (iLocalChannel < 0) { + iLocalChannel = m_numChannels++; + m_chanGlobalFromLocal[iLocalChannel] = newGlobalChannelNum; + m_chanLocalFromGlobal[newGlobalChannelNum] = iLocalChannel; + } - return iLocalChannel; + return iLocalChannel; } -qboolean skelChannelList_s::HasChannel( ChannelNameTable *nameTable, const char *channelName ) const +qboolean skelChannelList_s::HasChannel(ChannelNameTable *nameTable, const char *channelName) const { - short int iGlobalChannel = nameTable->FindNameLookup( channelName ); + short int iGlobalChannel = nameTable->FindNameLookup(channelName); - if( iGlobalChannel >= 0 ) - { - if( m_chanLocalFromGlobal && iGlobalChannel < m_numLocalFromGlobal ) - return ( unsigned int )~m_chanLocalFromGlobal[ iGlobalChannel ] >> 31; - else - return qtrue; - } - else - { - return qfalse; - } + if (iGlobalChannel >= 0) { + if (m_chanLocalFromGlobal && iGlobalChannel < m_numLocalFromGlobal) { + return (unsigned int)~m_chanLocalFromGlobal[iGlobalChannel] >> 31; + } else { + return qtrue; + } + } else { + return qfalse; + } } - -const char *skelChannelList_s::ChannelName( ChannelNameTable *nameTable, int localChannelNum ) const +const char *skelChannelList_s::ChannelName(ChannelNameTable *nameTable, int localChannelNum) const { - if( localChannelNum >= 0 && localChannelNum < m_numChannels ) - { - return nameTable->FindName( m_chanGlobalFromLocal[ localChannelNum ] ); - } - else - { - return NULL; - } + if (localChannelNum >= 0 && localChannelNum < m_numChannels) { + return nameTable->FindName(m_chanGlobalFromLocal[localChannelNum]); + } else { + return NULL; + } } -void Skel_ExtractFilePath( const char *path, char *dest ) +void Skel_ExtractFilePath(const char *path, char *dest) { - const char *src = path + strlen( path ); + const char *src = path + strlen(path); - while( src != path ) - { - if( *( src - 1 ) == '\\' ) - { - break; - } + while (src != path) { + if (*(src - 1) == '\\') { + break; + } - if( *( src - 1 ) == '/' ) - { - break; - } + if (*(src - 1) == '/') { + break; + } - src--; - } + src--; + } - memcpy( dest, src, src - path ); - dest[ src - path ] = 0; + memcpy(dest, src, src - path); + dest[src - path] = 0; } -void Skel_ExtractFileBase( const char *path, char *dest ) +void Skel_ExtractFileBase(const char *path, char *dest) { - const char *src = path + strlen( path ); - const char *dot = src; + const char *src = path + strlen(path); + const char *dot = src; - while( src != path ) - { - if( *( src - 1 ) == '\\' ) - { - break; - } + while (src != path) { + if (*(src - 1) == '\\') { + break; + } - if( *( src - 1 ) == '/' ) - { - break; - } + if (*(src - 1) == '/') { + break; + } - src--; - } + src--; + } - while( dot != src ) - { - if( *( dot - 1 ) != '.' ) - { - break; - } + while (dot != src) { + if (*(dot - 1) != '.') { + break; + } - dot--; - } + dot--; + } - if( dot == src ) - { - *dest = 0; - return; - } + if (dot == src) { + *dest = 0; + return; + } - memcpy( dest, src, dot - src ); - dest[ dot - src ] = 0; + memcpy(dest, src, dot - src); + dest[dot - src] = 0; } -void Skel_ExtractFileExtension( const char *path, char *dest ) +void Skel_ExtractFileExtension(const char *path, char *dest) { - const char *src = path + strlen( path ); + const char *src = path + strlen(path); - while( src != path ) - { - if( *( src - 1 ) == '.' ) - { - break; - } + while (src != path) { + if (*(src - 1) == '.') { + break; + } - src--; - } + src--; + } - if( src == path ) - { - *dest = 0; - return; - } + if (src == path) { + *dest = 0; + return; + } - strcpy( dest, src ); + strcpy(dest, src); } -const char *Skel_ExtractFileExtension( const char *in ) +const char *Skel_ExtractFileExtension(const char *in) { - static char exten[ 8 ]; - int i; + static char exten[8]; + int i; - for( i = 0; in[ i ] != 0; i++ ) - { - if( in[ i ] == '.' ) - { - i++; - break; - } - } + for (i = 0; in[i] != 0; i++) { + if (in[i] == '.') { + i++; + break; + } + } - if( !in[ i ] ) - { - return ""; - } + if (!in[i]) { + return ""; + } - strncpy( exten, &in[ i ], sizeof( exten ) ); - return exten; + strncpy(exten, &in[i], sizeof(exten)); + return exten; } -void Skel_ExtractFileName( const char *path, char *dest ) +void Skel_ExtractFileName(const char *path, char *dest) { - const char *src = path + strlen( path ); + const char *src = path + strlen(path); - while( src != path ) - { - if( *( src - 1 ) == '\\' ) - { - break; - } + while (src != path) { + if (*(src - 1) == '\\') { + break; + } - if( *( src - 1 ) == '/' ) - { - break; - } + if (*(src - 1) == '/') { + break; + } - src--; - } + src--; + } - strcpy( dest, src ); + strcpy(dest, src); } diff --git a/code/skeletor/skeletorbones.cpp b/code/skeletor/skeletorbones.cpp index 8c2e17e9..4f454d3a 100644 --- a/code/skeletor/skeletorbones.cpp +++ b/code/skeletor/skeletorbones.cpp @@ -1,6 +1,6 @@ /* =========================================================================== -Copyright (C) 2015 the OpenMoHAA team +Copyright (C) 2023 the OpenMoHAA team This file is part of OpenMoHAA source code. @@ -26,1185 +26,1107 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "qcommon.h" #include "skeletor.h" -char *skelBone_Names[ 8 ]; +char *skelBone_Names[8]; ChannelNameTable skeletor_c::m_channelNames; ChannelNameTable skeletor_c::m_boneNames; -skelBone_World skeletor_c::m_worldBone; +skelBone_World skeletor_c::m_worldBone; skelBone_World::skelBone_World() { - m_isDirty = false; + m_isDirty = false; } -void SkeletorLoadBoneFromBuffer( skelChannelList_c *boneList, boneData_t *boneData, skelBone_Base **bone ) +void SkeletorLoadBoneFromBuffer(skelChannelList_c *boneList, boneData_t *boneData, skelBone_Base **bone) { - int newBoneIndex; - const char *boneName; - int newBoneParent; - skelBone_Base *parentBone; + int newBoneIndex; + const char *boneName; + int newBoneParent; + skelBone_Base *parentBone; - newBoneIndex = boneList->GetLocalFromGlobal( boneData->channel ); + newBoneIndex = boneList->GetLocalFromGlobal(boneData->channel); - if( !bone[ newBoneIndex ] ) - { - boneName = skeletor_c::m_boneNames.FindName( boneData->channel ); + if (!bone[newBoneIndex]) { + boneName = skeletor_c::m_boneNames.FindName(boneData->channel); - if( boneData->parent < 0 ) - { - newBoneParent = -1; - } - else - { - newBoneParent = boneList->GetLocalFromGlobal( boneData->parent ); - } + if (boneData->parent < 0) { + newBoneParent = -1; + } else { + newBoneParent = boneList->GetLocalFromGlobal(boneData->parent); + } - switch( boneData->boneType ) - { - case SKELBONE_ZERO: - { - skelBone_Zero *newBone = new skelBone_Zero; - bone[ newBoneIndex ] = newBone; - break; - } - case SKELBONE_ROTATION: - { - skelBone_Rotation *newBone = new skelBone_Rotation; - bone[ newBoneIndex ] = newBone; - newBone->SetChannels( boneData->channelIndex[ 0 ] ); - break; - } - case SKELBONE_POSROT: - { - skelBone_PosRot *newBone; + switch (boneData->boneType) { + case SKELBONE_ZERO: + { + skelBone_Zero *newBone = new skelBone_Zero; + bone[newBoneIndex] = newBone; + break; + } + case SKELBONE_ROTATION: + { + skelBone_Rotation *newBone = new skelBone_Rotation; + bone[newBoneIndex] = newBone; + newBone->SetChannels(boneData->channelIndex[0]); + break; + } + case SKELBONE_POSROT: + { + skelBone_PosRot *newBone; - if( !strncmp( boneName, "Bip01", 5 ) ) - { - newBone = new skelBone_Root; - bone[ newBoneIndex ] = newBone; - } - else - { - newBone = new skelBone_PosRot; - bone[ newBoneIndex ] = newBone; - } + if (!strncmp(boneName, "Bip01", 5)) { + newBone = new skelBone_Root; + bone[newBoneIndex] = newBone; + } else { + newBone = new skelBone_PosRot; + bone[newBoneIndex] = newBone; + } - newBone->SetChannels( boneData->channelIndex[ 0 ], boneData->channelIndex[ 1 ] ); - break; - } - case SKELBONE_IKSHOULDER: - { - skelBone_IKshoulder *newBone = new skelBone_IKshoulder; - bone[ newBoneIndex ] = newBone; - break; - } - case SKELBONE_IKELBOW: - { - skelBone_IKelbow *newBone = new skelBone_IKelbow; - bone[ newBoneIndex ] = newBone; - newBone->SetBoneRefs( ( skelBone_IKshoulder * )bone[ boneList->GetLocalFromGlobal( boneData->refIndex[ 0 ] ) ] ); - break; - } - case SKELBONE_IKWRIST: - { - skelBone_IKwrist *newBone = new skelBone_IKwrist; - skelBone_IKshoulder *shoulder; - bone[ newBoneIndex ] = newBone; - shoulder = ( skelBone_IKshoulder * )bone[ boneList->GetLocalFromGlobal( boneData->refIndex[ 0 ] ) ]; - newBone->SetChannels( boneData->channelIndex[ 0 ], boneData->channelIndex[ 1 ] ); - newBone->SetBoneRefs( shoulder ); - shoulder->SetWristBone( newBone ); - break; - } - case SKELBONE_AVROT: - { - skelBone_AvRot *newBone = new skelBone_AvRot; - skelBone_AvRot *ref1, *ref2; - bone[ newBoneIndex ] = newBone; - ref1 = ( skelBone_AvRot * )bone[ boneList->GetLocalFromGlobal( boneData->refIndex[ 0 ] ) ]; - ref2 = ( skelBone_AvRot * )bone[ boneList->GetLocalFromGlobal( boneData->refIndex[ 1 ] ) ]; - newBone->SetBoneRefs( ref1, ref2 ); - break; - } - case SKELBONE_HOSEROT: - { - skelBone_HoseRot *newBone = new skelBone_HoseRot; - bone[ newBoneIndex ] = newBone; - newBone->SetBoneRefs( bone[ boneList->GetLocalFromGlobal( boneData->refIndex[ 0 ] ) ] ); - break; - } - case SKELBONE_HOSEROTBOTH: - { - skelBone_HoseRotBoth *newBone = new skelBone_HoseRotBoth; - bone[ newBoneIndex ] = newBone; - newBone->SetBoneRefs( bone[ boneList->GetLocalFromGlobal( boneData->refIndex[ 0 ] ) ] ); - break; - } - case SKELBONE_HOSEROTPARENT: - { - skelBone_HoseRotParent *newBone = new skelBone_HoseRotParent; - bone[ newBoneIndex ] = newBone; - newBone->SetBoneRefs( bone[ boneList->GetLocalFromGlobal( boneData->refIndex[ 0 ] ) ] ); - break; - } - default: - break; - } + newBone->SetChannels(boneData->channelIndex[0], boneData->channelIndex[1]); + break; + } + case SKELBONE_IKSHOULDER: + { + skelBone_IKshoulder *newBone = new skelBone_IKshoulder; + bone[newBoneIndex] = newBone; + break; + } + case SKELBONE_IKELBOW: + { + skelBone_IKelbow *newBone = new skelBone_IKelbow; + bone[newBoneIndex] = newBone; + newBone->SetBoneRefs((skelBone_IKshoulder *)bone[boneList->GetLocalFromGlobal(boneData->refIndex[0])]); + break; + } + case SKELBONE_IKWRIST: + { + skelBone_IKwrist *newBone = new skelBone_IKwrist; + skelBone_IKshoulder *shoulder; + bone[newBoneIndex] = newBone; + shoulder = (skelBone_IKshoulder *)bone[boneList->GetLocalFromGlobal(boneData->refIndex[0])]; + newBone->SetChannels(boneData->channelIndex[0], boneData->channelIndex[1]); + newBone->SetBoneRefs(shoulder); + shoulder->SetWristBone(newBone); + break; + } + case SKELBONE_AVROT: + { + skelBone_AvRot *newBone = new skelBone_AvRot; + skelBone_AvRot *ref1, *ref2; + bone[newBoneIndex] = newBone; + ref1 = (skelBone_AvRot *)bone[boneList->GetLocalFromGlobal(boneData->refIndex[0])]; + ref2 = (skelBone_AvRot *)bone[boneList->GetLocalFromGlobal(boneData->refIndex[1])]; + newBone->SetBoneRefs(ref1, ref2); + break; + } + case SKELBONE_HOSEROT: + { + skelBone_HoseRot *newBone = new skelBone_HoseRot; + bone[newBoneIndex] = newBone; + newBone->SetBoneRefs(bone[boneList->GetLocalFromGlobal(boneData->refIndex[0])]); + break; + } + case SKELBONE_HOSEROTBOTH: + { + skelBone_HoseRotBoth *newBone = new skelBone_HoseRotBoth; + bone[newBoneIndex] = newBone; + newBone->SetBoneRefs(bone[boneList->GetLocalFromGlobal(boneData->refIndex[0])]); + break; + } + case SKELBONE_HOSEROTPARENT: + { + skelBone_HoseRotParent *newBone = new skelBone_HoseRotParent; + bone[newBoneIndex] = newBone; + newBone->SetBoneRefs(bone[boneList->GetLocalFromGlobal(boneData->refIndex[0])]); + break; + } + default: + break; + } - bone[ newBoneIndex ]->SetBaseValue( boneData ); + bone[newBoneIndex]->SetBaseValue(boneData); - if( newBoneParent < 0 ) - { - parentBone = &skeletor_c::m_worldBone; - } - else - { - parentBone = bone[ newBoneParent ]; - } + if (newBoneParent < 0) { + parentBone = &skeletor_c::m_worldBone; + } else { + parentBone = bone[newBoneParent]; + } - bone[ newBoneIndex ]->SetParent( parentBone ); - } + bone[newBoneIndex]->SetParent(parentBone); + } } - -void SkeletorLoadBonesFromBuffer( skelChannelList_c *boneList, skelHeaderGame_t *buffer, skelBone_Base **bone ) +void SkeletorLoadBonesFromBuffer(skelChannelList_c *boneList, skelHeaderGame_t *buffer, skelBone_Base **bone) { - int boneNum; + int boneNum; - for( boneNum = 0; boneNum < buffer->numBones; boneNum++ ) - { - SkeletorLoadBoneFromBuffer( boneList, &buffer->pBones[ boneNum ], bone ); - } + for (boneNum = 0; boneNum < buffer->numBones; boneNum++) { + SkeletorLoadBoneFromBuffer(boneList, &buffer->pBones[boneNum], bone); + } } - -float *DecodeRLEValue( skanChannelHdr *channelFrames, int desiredFrameNum ) +float *DecodeRLEValue(skanChannelHdr *channelFrames, int desiredFrameNum) { - skanGameFrame *foundFrame = channelFrames->ary_frames; - int i; + skanGameFrame *foundFrame = channelFrames->ary_frames; + int i; - for( i = 0; i < channelFrames->nFramesInChannel; i++ ) - { - if( foundFrame->nFrameNum >= desiredFrameNum ) - { - break; - } + for (i = 0; i < channelFrames->nFramesInChannel; i++) { + if (foundFrame->nFrameNum >= desiredFrameNum) { + break; + } - foundFrame++; - } + foundFrame++; + } - if( foundFrame->nFrameNum > desiredFrameNum ) - { - foundFrame = &channelFrames->ary_frames[ foundFrame->nPrevFrameIndex ]; - } + if (foundFrame->nFrameNum > desiredFrameNum) { + foundFrame = &channelFrames->ary_frames[foundFrame->nPrevFrameIndex]; + } - return foundFrame->pChannelData; + return foundFrame->pChannelData; } -SkelQuat skelAnimStoreFrameList_c::GetSlerpValue( int globalChannelNum ) const +SkelQuat skelAnimStoreFrameList_c::GetSlerpValue(int globalChannelNum) const { - SkelQuat actionQuat, movementQuat; - SkelQuat outQuat; - float totalWeight; - SkelQuat *pIncomingQuat; - float incomingWeight; - int localChannelNum; - float channelActionWeight; - //float movementWeight; - int nTotal; - int i; - const skanBlendInfo *pFrame; - float t; + SkelQuat actionQuat, movementQuat; + SkelQuat outQuat; + float totalWeight; + SkelQuat *pIncomingQuat; + float incomingWeight; + int localChannelNum; + float channelActionWeight; + //float movementWeight; + int nTotal; + int i; + const skanBlendInfo *pFrame; + float t; - actionQuat.Set( 0, 0, 0, 0 ); - movementQuat.Set( 0, 0, 0, 0 ); + actionQuat.Set(0, 0, 0, 0); + movementQuat.Set(0, 0, 0, 0); - nTotal = 0; - totalWeight = 0.0; + nTotal = 0; + totalWeight = 0.0; - if( actionWeight > 0.001 ) - { - for( i = 0; i < numActionFrames; i++ ) - { - pFrame = &m_blendInfo[ i + 32 ]; + if (actionWeight > 0.001) { + for (i = 0; i < numActionFrames; i++) { + pFrame = &m_blendInfo[i + 32]; - localChannelNum = pFrame->pAnimationData->channelList.GetLocalFromGlobal( globalChannelNum ); - if( localChannelNum >= 0 ) - { - incomingWeight = pFrame->weight; - if( incomingWeight == 0.0 ) { - continue; - } - pIncomingQuat = ( SkelQuat * )DecodeRLEValue( &pFrame->pAnimationData->ary_channels[ localChannelNum ], pFrame->frame ); - totalWeight += incomingWeight; - nTotal++; + localChannelNum = pFrame->pAnimationData->channelList.GetLocalFromGlobal(globalChannelNum); + if (localChannelNum >= 0) { + incomingWeight = pFrame->weight; + if (incomingWeight == 0.0) { + continue; + } + pIncomingQuat = + (SkelQuat *)DecodeRLEValue(&pFrame->pAnimationData->ary_channels[localChannelNum], pFrame->frame); + totalWeight += incomingWeight; + nTotal++; - if( DotProduct4( *pIncomingQuat, actionQuat ) >= 0.0 ) - { - actionQuat.x += pIncomingQuat->x * incomingWeight; - actionQuat.y += pIncomingQuat->y * incomingWeight; - actionQuat.z += pIncomingQuat->z * incomingWeight; - actionQuat.w += pIncomingQuat->w * incomingWeight; - } - else - { - actionQuat.x -= pIncomingQuat->x * incomingWeight; - actionQuat.y -= pIncomingQuat->y * incomingWeight; - actionQuat.z -= pIncomingQuat->z * incomingWeight; - actionQuat.w -= pIncomingQuat->w * incomingWeight; - } - } - } - } + if (DotProduct4(*pIncomingQuat, actionQuat) >= 0.0) { + actionQuat.x += pIncomingQuat->x * incomingWeight; + actionQuat.y += pIncomingQuat->y * incomingWeight; + actionQuat.z += pIncomingQuat->z * incomingWeight; + actionQuat.w += pIncomingQuat->w * incomingWeight; + } else { + actionQuat.x -= pIncomingQuat->x * incomingWeight; + actionQuat.y -= pIncomingQuat->y * incomingWeight; + actionQuat.z -= pIncomingQuat->z * incomingWeight; + actionQuat.w -= pIncomingQuat->w * incomingWeight; + } + } + } + } - if( nTotal ) - { - channelActionWeight = actionWeight; - if( nTotal > 1 ) { - t = 1.0 / actionQuat.Length(); - } else { - t = 1.0 / totalWeight; - } + if (nTotal) { + channelActionWeight = actionWeight; + if (nTotal > 1) { + t = 1.0 / actionQuat.Length(); + } else { + t = 1.0 / totalWeight; + } - actionQuat.x = actionQuat.x * t; - actionQuat.y = actionQuat.y * t; - actionQuat.z = actionQuat.z * t; - actionQuat.w = actionQuat.w * t; - } else { - channelActionWeight = 0.0; - } + actionQuat.x = actionQuat.x * t; + actionQuat.y = actionQuat.y * t; + actionQuat.z = actionQuat.z * t; + actionQuat.w = actionQuat.w * t; + } else { + channelActionWeight = 0.0; + } - nTotal = 0; - totalWeight = 0.0; + nTotal = 0; + totalWeight = 0.0; - if( channelActionWeight < 0.999 ) - { - for( i = 0; i < numMovementFrames; i++ ) - { - pFrame = &m_blendInfo[ i ]; + if (channelActionWeight < 0.999) { + for (i = 0; i < numMovementFrames; i++) { + pFrame = &m_blendInfo[i]; - localChannelNum = pFrame->pAnimationData->channelList.GetLocalFromGlobal( globalChannelNum ); - if( localChannelNum >= 0 ) - { - incomingWeight = pFrame->weight; - if( incomingWeight == 0.0 ) { - continue; - } - pIncomingQuat = ( SkelQuat * )DecodeRLEValue( &pFrame->pAnimationData->ary_channels[ localChannelNum ], pFrame->frame ); - totalWeight += incomingWeight; - nTotal++; + localChannelNum = pFrame->pAnimationData->channelList.GetLocalFromGlobal(globalChannelNum); + if (localChannelNum >= 0) { + incomingWeight = pFrame->weight; + if (incomingWeight == 0.0) { + continue; + } + pIncomingQuat = + (SkelQuat *)DecodeRLEValue(&pFrame->pAnimationData->ary_channels[localChannelNum], pFrame->frame); + totalWeight += incomingWeight; + nTotal++; - if( DotProduct4( *pIncomingQuat, movementQuat ) >= 0.0 ) - { - movementQuat.x += pIncomingQuat->x * incomingWeight; - movementQuat.y += pIncomingQuat->y * incomingWeight; - movementQuat.z += pIncomingQuat->z * incomingWeight; - movementQuat.w += pIncomingQuat->w * incomingWeight; - } - else - { - movementQuat.x -= pIncomingQuat->x * incomingWeight; - movementQuat.y -= pIncomingQuat->y * incomingWeight; - movementQuat.z -= pIncomingQuat->z * incomingWeight; - movementQuat.w -= pIncomingQuat->w * incomingWeight; - } - } - } - } + if (DotProduct4(*pIncomingQuat, movementQuat) >= 0.0) { + movementQuat.x += pIncomingQuat->x * incomingWeight; + movementQuat.y += pIncomingQuat->y * incomingWeight; + movementQuat.z += pIncomingQuat->z * incomingWeight; + movementQuat.w += pIncomingQuat->w * incomingWeight; + } else { + movementQuat.x -= pIncomingQuat->x * incomingWeight; + movementQuat.y -= pIncomingQuat->y * incomingWeight; + movementQuat.z -= pIncomingQuat->z * incomingWeight; + movementQuat.w -= pIncomingQuat->w * incomingWeight; + } + } + } + } - if( nTotal ) - { - if( nTotal > 1 ) { - t = 1.0 / movementQuat.Length(); - } else { - t = 1.0 / totalWeight; - } + if (nTotal) { + if (nTotal > 1) { + t = 1.0 / movementQuat.Length(); + } else { + t = 1.0 / totalWeight; + } - movementQuat.x = movementQuat.x * t; - movementQuat.y = movementQuat.y * t; - movementQuat.z = movementQuat.z * t; - movementQuat.w = movementQuat.w * t; - } - else { - movementQuat.w = 1.0; - } + movementQuat.x = movementQuat.x * t; + movementQuat.y = movementQuat.y * t; + movementQuat.z = movementQuat.z * t; + movementQuat.w = movementQuat.w * t; + } else { + movementQuat.w = 1.0; + } - if( channelActionWeight < 0.001 ) - { - outQuat.x = movementQuat.x; - outQuat.y = movementQuat.y; - outQuat.z = movementQuat.z; - outQuat.w = movementQuat.w; - return outQuat; - } - else if( channelActionWeight >= 0.999 ) - { - outQuat.x = actionQuat.x; - outQuat.y = actionQuat.y; - outQuat.z = actionQuat.z; - outQuat.w = actionQuat.w; - return outQuat; - } + if (channelActionWeight < 0.001) { + outQuat.x = movementQuat.x; + outQuat.y = movementQuat.y; + outQuat.z = movementQuat.z; + outQuat.w = movementQuat.w; + return outQuat; + } else if (channelActionWeight >= 0.999) { + outQuat.x = actionQuat.x; + outQuat.y = actionQuat.y; + outQuat.z = actionQuat.z; + outQuat.w = actionQuat.w; + return outQuat; + } - t = 1.0 - channelActionWeight; + t = 1.0 - channelActionWeight; - if( DotProduct4( actionQuat, movementQuat ) >= 0.0 ) - { - outQuat.x = movementQuat.x * t + actionQuat.x * channelActionWeight; - outQuat.y = movementQuat.y * t + actionQuat.y * channelActionWeight; - outQuat.z = movementQuat.z * t + actionQuat.z * channelActionWeight; - outQuat.w = movementQuat.w * t + actionQuat.w * channelActionWeight; - } - else - { - outQuat.x = movementQuat.x * t - actionQuat.x * channelActionWeight; - outQuat.y = movementQuat.y * t - actionQuat.y * channelActionWeight; - outQuat.z = movementQuat.z * t - actionQuat.z * channelActionWeight; - outQuat.w = movementQuat.w * t - actionQuat.w * channelActionWeight; - } + if (DotProduct4(actionQuat, movementQuat) >= 0.0) { + outQuat.x = movementQuat.x * t + actionQuat.x * channelActionWeight; + outQuat.y = movementQuat.y * t + actionQuat.y * channelActionWeight; + outQuat.z = movementQuat.z * t + actionQuat.z * channelActionWeight; + outQuat.w = movementQuat.w * t + actionQuat.w * channelActionWeight; + } else { + outQuat.x = movementQuat.x * t - actionQuat.x * channelActionWeight; + outQuat.y = movementQuat.y * t - actionQuat.y * channelActionWeight; + outQuat.z = movementQuat.z * t - actionQuat.z * channelActionWeight; + outQuat.w = movementQuat.w * t - actionQuat.w * channelActionWeight; + } - t = 1.0 / outQuat.Length(); - outQuat.x = outQuat.x * t; - outQuat.y = outQuat.y * t; - outQuat.z = outQuat.z * t; - outQuat.w = outQuat.w * t; + t = 1.0 / outQuat.Length(); + outQuat.x = outQuat.x * t; + outQuat.y = outQuat.y * t; + outQuat.z = outQuat.z * t; + outQuat.w = outQuat.w * t; - return outQuat; + return outQuat; } -void skelAnimStoreFrameList_c::GetLerpValue3( int globalChannelNum, SkelVec3 *outVec ) const +void skelAnimStoreFrameList_c::GetLerpValue3(int globalChannelNum, SkelVec3 *outVec) const { - float totalWeight; - SkelVec3 incomingVec; - float incomingWeight; - int localChannelNum; - vec3_t result; - float t; - float channelActionWeight; - int i; - const skanBlendInfo *pFrame; + float totalWeight; + SkelVec3 incomingVec; + float incomingWeight; + int localChannelNum; + vec3_t result; + float t; + float channelActionWeight; + int i; + const skanBlendInfo *pFrame; - totalWeight = 0.0; + totalWeight = 0.0; - if( actionWeight > 0.001 ) - { - VectorClear( result ); + if (actionWeight > 0.001) { + VectorClear(result); - for( i = 0; i < numActionFrames; i++ ) - { - pFrame = &m_blendInfo[ i + 32 ]; + for (i = 0; i < numActionFrames; i++) { + pFrame = &m_blendInfo[i + 32]; - localChannelNum = pFrame->pAnimationData->channelList.GetLocalFromGlobal( globalChannelNum ); - if( localChannelNum >= 0 ) - { - incomingWeight = pFrame->weight; - incomingVec = DecodeRLEValue( &pFrame->pAnimationData->ary_channels[ localChannelNum ], pFrame->frame ); - totalWeight += incomingWeight; - result[ 0 ] += incomingVec[ 0 ] * incomingWeight; - result[ 1 ] += incomingVec[ 1 ] * incomingWeight; - result[ 2 ] += incomingVec[ 2 ] * incomingWeight; - } - } - } + localChannelNum = pFrame->pAnimationData->channelList.GetLocalFromGlobal(globalChannelNum); + if (localChannelNum >= 0) { + incomingWeight = pFrame->weight; + incomingVec = DecodeRLEValue(&pFrame->pAnimationData->ary_channels[localChannelNum], pFrame->frame); + totalWeight += incomingWeight; + result[0] += incomingVec[0] * incomingWeight; + result[1] += incomingVec[1] * incomingWeight; + result[2] += incomingVec[2] * incomingWeight; + } + } + } - if( totalWeight != 0.0 ) - { - t = 1.0 / totalWeight; - VectorScale( result, t, *outVec ); - channelActionWeight = actionWeight; - } - else - { - VectorClear( *outVec ); - channelActionWeight = 0.0; - } + if (totalWeight != 0.0) { + t = 1.0 / totalWeight; + VectorScale(result, t, *outVec); + channelActionWeight = actionWeight; + } else { + VectorClear(*outVec); + channelActionWeight = 0.0; + } - if( channelActionWeight >= 0.999 || !numMovementFrames ) { - return; - } + if (channelActionWeight >= 0.999 || !numMovementFrames) { + return; + } - totalWeight = 0.0; - VectorClear( result ); + totalWeight = 0.0; + VectorClear(result); - for( i = 0; i < numMovementFrames; i++ ) - { - pFrame = &m_blendInfo[ i ]; + for (i = 0; i < numMovementFrames; i++) { + pFrame = &m_blendInfo[i]; - localChannelNum = pFrame->pAnimationData->channelList.GetLocalFromGlobal( globalChannelNum ); - if( localChannelNum >= 0 ) - { - incomingWeight = pFrame->weight; - incomingVec = DecodeRLEValue( &pFrame->pAnimationData->ary_channels[ localChannelNum ], pFrame->frame ); - totalWeight += incomingWeight; - result[ 0 ] += incomingVec[ 0 ] * incomingWeight; - result[ 1 ] += incomingVec[ 1 ] * incomingWeight; - result[ 2 ] += incomingVec[ 2 ] * incomingWeight; - } - } + localChannelNum = pFrame->pAnimationData->channelList.GetLocalFromGlobal(globalChannelNum); + if (localChannelNum >= 0) { + incomingWeight = pFrame->weight; + incomingVec = DecodeRLEValue(&pFrame->pAnimationData->ary_channels[localChannelNum], pFrame->frame); + totalWeight += incomingWeight; + result[0] += incomingVec[0] * incomingWeight; + result[1] += incomingVec[1] * incomingWeight; + result[2] += incomingVec[2] * incomingWeight; + } + } - if( totalWeight != 0.0 ) - { - t = 1.0 / totalWeight * ( 1.0 - channelActionWeight ); - outVec->x = outVec->x * channelActionWeight + result[ 0 ] * t; - outVec->y = outVec->y * channelActionWeight + result[ 1 ] * t; - outVec->z = outVec->z * channelActionWeight + result[ 2 ] * t; - } + if (totalWeight != 0.0) { + t = 1.0 / totalWeight * (1.0 - channelActionWeight); + outVec->x = outVec->x * channelActionWeight + result[0] * t; + outVec->y = outVec->y * channelActionWeight + result[1] * t; + outVec->z = outVec->z * channelActionWeight + result[2] * t; + } } skelBone_Base::skelBone_Base() { - m_parent = NULL; - m_isDirty = true; - m_controller = NULL; + m_parent = NULL; + m_isDirty = true; + m_controller = NULL; } -skelBone_Base::~skelBone_Base() +skelBone_Base::~skelBone_Base() {} + +int skelBone_Base::GetNumChannels(boneType_t boneType) { + switch (boneType) { + case SKELBONE_ROTATION: + return 1; + case SKELBONE_POSROT: + case SKELBONE_IKWRIST: + return 2; + default: + return 0; + } } -int skelBone_Base::GetNumChannels( boneType_t boneType ) +int skelBone_Base::GetNumBoneRefs(boneType_t boneType) { - switch( boneType ) - { - case SKELBONE_ROTATION: - return 1; - case SKELBONE_POSROT: - case SKELBONE_IKWRIST: - return 2; - default: - return 0; - } + switch (boneType) { + case SKELBONE_AVROT: + return 2; + case SKELBONE_IKELBOW: + case SKELBONE_IKWRIST: + case SKELBONE_HOSEROT: + case SKELBONE_HOSEROTBOTH: + case SKELBONE_HOSEROTPARENT: + return 1; + default: + return 0; + } } -int skelBone_Base::GetNumBoneRefs( boneType_t boneType ) +SkelMat4& skelBone_Base::GetTransform(const skelAnimStoreFrameList_c *frames) { - switch( boneType ) - { - case SKELBONE_AVROT: - return 2; - case SKELBONE_IKELBOW: - case SKELBONE_IKWRIST: - case SKELBONE_HOSEROT: - case SKELBONE_HOSEROTBOTH: - case SKELBONE_HOSEROTPARENT: - return 1; - default: - return 0; - } + if (m_isDirty) { + return GetDirtyTransform(frames); + } else { + return m_cachedValue; + } } -SkelMat4 &skelBone_Base::GetTransform( const skelAnimStoreFrameList_c *frames ) +void skelBone_Base::SetParent(skelBone_Base *parent) { - if( m_isDirty ) - { - return GetDirtyTransform( frames ); - } - else - { - return m_cachedValue; - } + m_parent = parent; } -void skelBone_Base::SetParent( skelBone_Base *parent ) +void skelBone_Base::SetBaseValue(boneData_t *boneData) {} + +int skelBone_Base::GetChannelIndex(int num) { - m_parent = parent; + return 0; } -void skelBone_Base::SetBaseValue( boneData_t *boneData ) +skelBone_Base *skelBone_Base::GetBoneRef(int num) { -} - -int skelBone_Base::GetChannelIndex( int num ) -{ - return 0; -} - -skelBone_Base *skelBone_Base::GetBoneRef( int num ) -{ - return NULL; + return NULL; } skelBone_Base *skelBone_Base::Parent() const { - return m_parent; + return m_parent; } -SkelMat4 &skelBone_Zero::GetDirtyTransform( const skelAnimStoreFrameList_c *frames ) +SkelMat4& skelBone_Zero::GetDirtyTransform(const skelAnimStoreFrameList_c *frames) { - if( m_parent ) - { - m_cachedValue = m_parent->GetTransform( frames ); - } + if (m_parent) { + m_cachedValue = m_parent->GetTransform(frames); + } - m_isDirty = false; - return m_cachedValue; + m_isDirty = false; + return m_cachedValue; } -void skelBone_Zero::SetBaseValue( boneData_t *boneData ) +void skelBone_Zero::SetBaseValue(boneData_t *boneData) {} + +int skelBone_Zero::GetChannelIndex(int num) { + return 0; } -int skelBone_Zero::GetChannelIndex( int num ) +skelBone_Base *skelBone_Zero::GetBoneRef(int num) { - return 0; + return NULL; } -skelBone_Base *skelBone_Zero::GetBoneRef( int num ) +SkelMat4& skelBone_Rotation::GetDirtyTransform(const skelAnimStoreFrameList_c *frames) { - return NULL; + SkelMat4 incomingValue; + SkelQuat incomingQuat; + + incomingQuat = frames->GetSlerpValue(m_quatChannel); + incomingQuat.GetMat4(incomingValue); + VectorCopy(m_baseValue, incomingValue[3]); + + if (m_parent) { + m_cachedValue.Multiply(incomingValue, m_parent->GetTransform(frames)); + } else { + m_cachedValue = incomingValue; + } + + if (m_controller) { + SkelMat3 m; + + incomingQuat.Set(m_controller); + incomingQuat.GetMat3(m); + m_cachedValue.RotateBy(m); + } + + m_isDirty = false; + + return m_cachedValue; } -SkelMat4 &skelBone_Rotation::GetDirtyTransform( const skelAnimStoreFrameList_c *frames ) +void skelBone_Rotation::SetChannels(int num) { - SkelMat4 incomingValue; - SkelQuat incomingQuat; - - incomingQuat = frames->GetSlerpValue( m_quatChannel ); - incomingQuat.GetMat4( incomingValue ); - VectorCopy( m_baseValue, incomingValue[ 3 ] ); - - if( m_parent ) - { - m_cachedValue.Multiply( incomingValue, m_parent->GetTransform( frames ) ); - } - else - { - m_cachedValue = incomingValue; - } - - if( m_controller ) - { - SkelMat3 m; - - incomingQuat.Set( m_controller ); - incomingQuat.GetMat3( m ); - m_cachedValue.RotateBy( m ); - } - - m_isDirty = false; - - return m_cachedValue; + m_quatChannel = num; } - -void skelBone_Rotation::SetChannels( int num ) +void skelBone_Rotation::SetBaseValue(boneData_t *data) { - m_quatChannel = num; + m_baseValue = data->offset; } -void skelBone_Rotation::SetBaseValue( boneData_t *data ) +int skelBone_Rotation::GetChannelIndex(int num) { - m_baseValue = data->offset; + return m_quatChannel; } -int skelBone_Rotation::GetChannelIndex( int num ) +skelBone_Base *skelBone_Rotation::GetBoneRef(int bone) { - return m_quatChannel; + return 0; } -skelBone_Base *skelBone_Rotation::GetBoneRef( int bone ) +SkelMat4& skelBone_PosRot::GetDirtyTransform(const skelAnimStoreFrameList_c *frames) { - return 0; + SkelVec3 incomingOffset; + SkelMat4 incomingValue; + SkelQuat incomingQuat; + + incomingQuat = frames->GetSlerpValue(m_quatChannel); + frames->GetLerpValue3(m_offsetChannel, &incomingOffset); + incomingQuat.GetMat4(incomingValue); + VectorCopy(incomingOffset, incomingValue[3]); + + if (m_parent) { + m_cachedValue.Multiply(incomingValue, m_parent->GetTransform(frames)); + } else { + m_cachedValue = incomingValue; + } + + if (m_controller) { + SkelMat3 m; + + incomingQuat.Set(m_controller); + incomingQuat.GetMat3(m); + m_cachedValue.RotateBy(m); + } + + m_isDirty = false; + + return m_cachedValue; } -SkelMat4 &skelBone_PosRot::GetDirtyTransform( const skelAnimStoreFrameList_c *frames ) +void skelBone_PosRot::SetChannels(int quatChannel, int offsetChannel) { - SkelVec3 incomingOffset; - SkelMat4 incomingValue; - SkelQuat incomingQuat; - - incomingQuat = frames->GetSlerpValue( m_quatChannel ); - frames->GetLerpValue3( m_offsetChannel, &incomingOffset ); - incomingQuat.GetMat4( incomingValue ); - VectorCopy( incomingOffset, incomingValue[ 3 ] ); - - if( m_parent ) - { - m_cachedValue.Multiply( incomingValue, m_parent->GetTransform( frames ) ); - } - else - { - m_cachedValue = incomingValue; - } - - if( m_controller ) - { - SkelMat3 m; - - incomingQuat.Set( m_controller ); - incomingQuat.GetMat3( m ); - m_cachedValue.RotateBy( m ); - } - - m_isDirty = false; - - return m_cachedValue; + m_quatChannel = quatChannel; + m_offsetChannel = offsetChannel; } -void skelBone_PosRot::SetChannels( int quatChannel, int offsetChannel ) +void skelBone_PosRot::SetBaseValue(boneData_t *boneData) {} + +int skelBone_PosRot::GetChannelIndex(int num) { - m_quatChannel = quatChannel; - m_offsetChannel = offsetChannel; + if (num) { + return m_quatChannel; + } else { + return m_offsetChannel; + } } -void skelBone_PosRot::SetBaseValue( boneData_t *boneData ) +skelBone_Base *skelBone_PosRot::GetBoneRef(int num) { + return NULL; } -int skelBone_PosRot::GetChannelIndex( int num ) +SkelMat4& skelBone_Root::GetDirtyTransform(const skelAnimStoreFrameList_c *frames) { - if( num ) - { - return m_quatChannel; - } - else - { - return m_offsetChannel; - } -} + SkelVec3 incomingOffset; + SkelMat4 incomingValue; + SkelQuat incomingQuat; -skelBone_Base *skelBone_PosRot::GetBoneRef( int num ) -{ - return NULL; -} + incomingQuat = frames->GetSlerpValue(m_quatChannel); + frames->GetLerpValue3(m_offsetChannel, &incomingOffset); + incomingQuat.GetMat4(incomingValue); + VectorCopy(incomingOffset, incomingValue[3]); -SkelMat4 &skelBone_Root::GetDirtyTransform( const skelAnimStoreFrameList_c *frames ) -{ - SkelVec3 incomingOffset; - SkelMat4 incomingValue; - SkelQuat incomingQuat; + if (m_parent) { + m_cachedValue.Multiply(incomingValue, m_parent->GetTransform(frames)); + } else { + m_cachedValue = incomingValue; + } - incomingQuat = frames->GetSlerpValue( m_quatChannel ); - frames->GetLerpValue3( m_offsetChannel, &incomingOffset ); - incomingQuat.GetMat4( incomingValue ); - VectorCopy( incomingOffset, incomingValue[ 3 ] ); + if (m_controller) { + SkelMat3 m; - if( m_parent ) - { - m_cachedValue.Multiply( incomingValue, m_parent->GetTransform( frames ) ); - } - else - { - m_cachedValue = incomingValue; - } + incomingQuat.Set(m_controller); + incomingQuat.GetMat3(m); + m_cachedValue.RotateBy(m); + } - if( m_controller ) - { - SkelMat3 m; + m_isDirty = false; - incomingQuat.Set( m_controller ); - incomingQuat.GetMat3( m ); - m_cachedValue.RotateBy( m ); - } - - m_isDirty = false; - - return m_cachedValue; + return m_cachedValue; } skelBone_IKshoulder::skelBone_IKshoulder() { - m_wrist = NULL; + m_wrist = NULL; } -SkelMat4 &skelBone_IKshoulder::GetDirtyTransform( const skelAnimStoreFrameList_c *frames ) +SkelMat4& skelBone_IKshoulder::GetDirtyTransform(const skelAnimStoreFrameList_c *frames) { - SkelMat4 baseMatrix, targetMatrix; - float desiredLength; - SkelVec3 newBaseY; - SkelVec3 newBaseZ; - SkelVec3 cross; - float cosUpperAngle; - float sinUpperAngle; - float maxLength; - float length; - float cosA; - float sinA; + SkelMat4 baseMatrix, targetMatrix; + float desiredLength; + SkelVec3 newBaseY; + SkelVec3 newBaseZ; + SkelVec3 cross; + float cosUpperAngle; + float sinUpperAngle; + float maxLength; + float length; + float cosA; + float sinA; - if( !m_wrist ) - { - m_cachedValue.MakeIdentity(); - return m_cachedValue; - } + if (!m_wrist) { + m_cachedValue.MakeIdentity(); + return m_cachedValue; + } - if( m_parent ) - { - baseMatrix = m_parent->GetTransform( frames ); - } + if (m_parent) { + baseMatrix = m_parent->GetTransform(frames); + } - baseMatrix[ 3 ][ 0 ] += m_baseValue[ 0 ] * baseMatrix[ 0 ][ 0 ] + m_baseValue[ 1 ] * baseMatrix[ 1 ][ 0 ] + m_baseValue[ 2 ] * baseMatrix[ 2 ][ 0 ]; - baseMatrix[ 3 ][ 1 ] += m_baseValue[ 0 ] * baseMatrix[ 0 ][ 1 ] + m_baseValue[ 1 ] * baseMatrix[ 1 ][ 1 ] + m_baseValue[ 2 ] * baseMatrix[ 2 ][ 1 ]; - baseMatrix[ 3 ][ 2 ] += m_baseValue[ 0 ] * baseMatrix[ 0 ][ 2 ] + m_baseValue[ 1 ] * baseMatrix[ 1 ][ 2 ] + m_baseValue[ 2 ] * baseMatrix[ 2 ][ 2 ]; - baseMatrix.InvertAxis( 0 ); - baseMatrix.InvertAxis( 2 ); + baseMatrix[3][0] += + m_baseValue[0] * baseMatrix[0][0] + m_baseValue[1] * baseMatrix[1][0] + m_baseValue[2] * baseMatrix[2][0]; + baseMatrix[3][1] += + m_baseValue[0] * baseMatrix[0][1] + m_baseValue[1] * baseMatrix[1][1] + m_baseValue[2] * baseMatrix[2][1]; + baseMatrix[3][2] += + m_baseValue[0] * baseMatrix[0][2] + m_baseValue[1] * baseMatrix[1][2] + m_baseValue[2] * baseMatrix[2][2]; + baseMatrix.InvertAxis(0); + baseMatrix.InvertAxis(2); - m_wristAngle = frames->GetSlerpValue( m_wrist->m_quatChannel ); - m_wristAngle.GetMat4( targetMatrix ); + m_wristAngle = frames->GetSlerpValue(m_wrist->m_quatChannel); + m_wristAngle.GetMat4(targetMatrix); - frames->GetLerpValue3( m_wrist->m_offsetChannel, &m_wristPos ); - m_cachedValue = baseMatrix; - VectorCopy( m_wristPos, targetMatrix[ 3 ] ); - VectorSubtract( targetMatrix[ 3 ], baseMatrix[ 3 ], m_cachedValue[ 0 ] ); + frames->GetLerpValue3(m_wrist->m_offsetChannel, &m_wristPos); + m_cachedValue = baseMatrix; + VectorCopy(m_wristPos, targetMatrix[3]); + VectorSubtract(targetMatrix[3], baseMatrix[3], m_cachedValue[0]); - sinUpperAngle = VectorNormalize( m_cachedValue[ 0 ] ); + sinUpperAngle = VectorNormalize(m_cachedValue[0]); - newBaseY = baseMatrix[ 2 ]; - newBaseZ = m_cachedValue[ 0 ]; + newBaseY = baseMatrix[2]; + newBaseZ = m_cachedValue[0]; - CrossProduct( newBaseY, newBaseZ, cross ); - VectorCopy( cross, m_cachedValue[ 1 ] ); + CrossProduct(newBaseY, newBaseZ, cross); + VectorCopy(cross, m_cachedValue[1]); - newBaseY = targetMatrix[ 2 ]; - newBaseZ = m_cachedValue[ 0 ]; + newBaseY = targetMatrix[2]; + newBaseZ = m_cachedValue[0]; - CrossProduct( newBaseY, newBaseZ, cross ); - VectorAdd( m_cachedValue[ 1 ], cross, m_cachedValue[ 1 ] ); + CrossProduct(newBaseY, newBaseZ, cross); + VectorAdd(m_cachedValue[1], cross, m_cachedValue[1]); - desiredLength = VectorNormalize( m_cachedValue[ 1 ] ); + desiredLength = VectorNormalize(m_cachedValue[1]); - if( !desiredLength ) { - m_cachedValue[ 1 ][ 1 ] = 1.0; - } + if (!desiredLength) { + m_cachedValue[1][1] = 1.0; + } - newBaseY = m_cachedValue[ 0 ]; - newBaseZ = m_cachedValue[ 1 ]; + newBaseY = m_cachedValue[0]; + newBaseZ = m_cachedValue[1]; - CrossProduct( newBaseY, newBaseZ, cross ); - VectorCopy( cross, m_cachedValue[ 2 ] ); + CrossProduct(newBaseY, newBaseZ, cross); + VectorCopy(cross, m_cachedValue[2]); - cosUpperAngle = m_upperLength + m_lowerLength - 0.001; + cosUpperAngle = m_upperLength + m_lowerLength - 0.001; - if( sinUpperAngle > cosUpperAngle ) - { - sinUpperAngle = cosUpperAngle; + if (sinUpperAngle > cosUpperAngle) { + sinUpperAngle = cosUpperAngle; - m_wristPos = m_cachedValue[ 3 ]; + m_wristPos = m_cachedValue[3]; - m_wristPos[ 0 ] += m_cachedValue[ 0 ][ 0 ] * cosUpperAngle; - m_wristPos[ 1 ] += m_cachedValue[ 0 ][ 1 ] * cosUpperAngle; - m_wristPos[ 2 ] += m_cachedValue[ 0 ][ 2 ] * cosUpperAngle; - } + m_wristPos[0] += m_cachedValue[0][0] * cosUpperAngle; + m_wristPos[1] += m_cachedValue[0][1] * cosUpperAngle; + m_wristPos[2] += m_cachedValue[0][2] * cosUpperAngle; + } - maxLength = ( sinUpperAngle * sinUpperAngle + m_upperLength * m_upperLength - m_lowerLength * m_lowerLength ) - / ( sinUpperAngle * m_upperLength + sinUpperAngle * m_upperLength ); + maxLength = (sinUpperAngle * sinUpperAngle + m_upperLength * m_upperLength - m_lowerLength * m_lowerLength) + / (sinUpperAngle * m_upperLength + sinUpperAngle * m_upperLength); - if( maxLength > 1.0 ) { - maxLength = 1.0; - } + if (maxLength > 1.0) { + maxLength = 1.0; + } - m_cosElbowAngle = -( ( m_lowerLength * m_lowerLength + m_upperLength * m_upperLength - sinUpperAngle * sinUpperAngle ) / - ( m_upperLength * m_lowerLength + m_upperLength * m_lowerLength ) ); + m_cosElbowAngle = + -((m_lowerLength * m_lowerLength + m_upperLength * m_upperLength - sinUpperAngle * sinUpperAngle) + / (m_upperLength * m_lowerLength + m_upperLength * m_lowerLength)); - length = -sqrt( 1.0 - maxLength * maxLength ); + length = -sqrt(1.0 - maxLength * maxLength); - cosA = m_cachedValue[ 0 ][ 0 ]; - sinA = m_cachedValue[ 1 ][ 0 ]; - m_cachedValue[ 0 ][ 0 ] = cosA * maxLength - sinA * length; - m_cachedValue[ 1 ][ 0 ] = sinA * maxLength + cosA * length; + cosA = m_cachedValue[0][0]; + sinA = m_cachedValue[1][0]; + m_cachedValue[0][0] = cosA * maxLength - sinA * length; + m_cachedValue[1][0] = sinA * maxLength + cosA * length; - cosA = m_cachedValue[ 0 ][ 1 ]; - sinA = m_cachedValue[ 1 ][ 1 ]; - m_cachedValue[ 0 ][ 1 ] = cosA * maxLength - sinA * length; - m_cachedValue[ 1 ][ 1 ] = sinA * maxLength + cosA * length; + cosA = m_cachedValue[0][1]; + sinA = m_cachedValue[1][1]; + m_cachedValue[0][1] = cosA * maxLength - sinA * length; + m_cachedValue[1][1] = sinA * maxLength + cosA * length; - cosA = m_cachedValue[ 0 ][ 2 ]; - sinA = m_cachedValue[ 1 ][ 2 ]; - m_cachedValue[ 0 ][ 2 ] = cosA * maxLength - sinA * length; - m_cachedValue[ 1 ][ 2 ] = sinA * maxLength + cosA * length; + cosA = m_cachedValue[0][2]; + sinA = m_cachedValue[1][2]; + m_cachedValue[0][2] = cosA * maxLength - sinA * length; + m_cachedValue[1][2] = sinA * maxLength + cosA * length; - m_isDirty = false; + m_isDirty = false; - return m_cachedValue; + return m_cachedValue; } -void skelBone_IKshoulder::SetBaseValue( boneData_t *boneData ) +void skelBone_IKshoulder::SetBaseValue(boneData_t *boneData) { - m_baseValue = boneData->offset; + m_baseValue = boneData->offset; } -int skelBone_IKshoulder::GetChannelIndex( int num ) +int skelBone_IKshoulder::GetChannelIndex(int num) { - return -1; + return -1; } -skelBone_Base *skelBone_IKshoulder::GetBoneRef( int num ) +skelBone_Base *skelBone_IKshoulder::GetBoneRef(int num) { - return m_wrist; + return m_wrist; } -void skelBone_IKshoulder::SetElbowValue( float elbowOffset ) +void skelBone_IKshoulder::SetElbowValue(float elbowOffset) { - m_upperLength = elbowOffset; + m_upperLength = elbowOffset; } -void skelBone_IKshoulder::SetWristValue( float wristOffset ) +void skelBone_IKshoulder::SetWristValue(float wristOffset) { - m_lowerLength = wristOffset; + m_lowerLength = wristOffset; } -void skelBone_IKshoulder::SetWristBone( skelBone_IKwrist *wrist ) +void skelBone_IKshoulder::SetWristBone(skelBone_IKwrist *wrist) { - this->m_wrist = wrist; + this->m_wrist = wrist; } float skelBone_IKshoulder::GetUpperLength() { - return m_upperLength; + return m_upperLength; } float skelBone_IKshoulder::GetLowerLength() { - return m_lowerLength; + return m_lowerLength; } -SkelMat4 &skelBone_IKwrist::GetDirtyTransform( const skelAnimStoreFrameList_c *frames ) +SkelMat4& skelBone_IKwrist::GetDirtyTransform(const skelAnimStoreFrameList_c *frames) { - if( m_shoulder->m_isDirty ) { - m_shoulder->GetDirtyTransform( frames ); - } + if (m_shoulder->m_isDirty) { + m_shoulder->GetDirtyTransform(frames); + } - m_shoulder->m_wristAngle.GetMat4( m_cachedValue ); - VectorCopy( m_shoulder->m_wristPos, m_cachedValue[ 3 ] ); - m_isDirty = false; + m_shoulder->m_wristAngle.GetMat4(m_cachedValue); + VectorCopy(m_shoulder->m_wristPos, m_cachedValue[3]); + m_isDirty = false; - return m_cachedValue; + return m_cachedValue; } -void skelBone_IKwrist::SetChannels( int quatChannel, int offsetChannel ) +void skelBone_IKwrist::SetChannels(int quatChannel, int offsetChannel) { - m_quatChannel = quatChannel; - m_offsetChannel = offsetChannel; + m_quatChannel = quatChannel; + m_offsetChannel = offsetChannel; } -void skelBone_IKwrist::SetBoneRefs( skelBone_IKshoulder *shoulder ) +void skelBone_IKwrist::SetBoneRefs(skelBone_IKshoulder *shoulder) { - m_shoulder = shoulder; + m_shoulder = shoulder; } -void skelBone_IKwrist::SetBaseValue( boneData_t *boneData ) +void skelBone_IKwrist::SetBaseValue(boneData_t *boneData) { - m_shoulder->SetWristValue( boneData->length ); + m_shoulder->SetWristValue(boneData->length); } -int skelBone_IKwrist::GetChannelIndex( int num ) +int skelBone_IKwrist::GetChannelIndex(int num) { - return -1; + return -1; } -skelBone_Base *skelBone_IKwrist::GetBoneRef( int num ) +skelBone_Base *skelBone_IKwrist::GetBoneRef(int num) { - return m_shoulder; + return m_shoulder; } -SkelMat4 &skelBone_IKelbow::GetDirtyTransform( const skelAnimStoreFrameList_c *frames ) +SkelMat4& skelBone_IKelbow::GetDirtyTransform(const skelAnimStoreFrameList_c *frames) { - float fLength; - float cosA, sinA; + float fLength; + float cosA, sinA; - m_cachedValue = m_shoulder->GetTransform( frames ); + m_cachedValue = m_shoulder->GetTransform(frames); - m_cachedValue[ 3 ][ 0 ] += m_cachedValue[ 0 ][ 0 ] * m_shoulder->m_upperLength; - m_cachedValue[ 3 ][ 1 ] += m_cachedValue[ 0 ][ 1 ] * m_shoulder->m_upperLength; - m_cachedValue[ 3 ][ 2 ] += m_cachedValue[ 0 ][ 2 ] * m_shoulder->m_upperLength; + m_cachedValue[3][0] += m_cachedValue[0][0] * m_shoulder->m_upperLength; + m_cachedValue[3][1] += m_cachedValue[0][1] * m_shoulder->m_upperLength; + m_cachedValue[3][2] += m_cachedValue[0][2] * m_shoulder->m_upperLength; - fLength = sqrt( 1.0 - m_shoulder->m_cosElbowAngle * m_shoulder->m_cosElbowAngle ); + fLength = sqrt(1.0 - m_shoulder->m_cosElbowAngle * m_shoulder->m_cosElbowAngle); - cosA = m_cachedValue[ 0 ][ 0 ]; - sinA = m_cachedValue[ 1 ][ 0 ]; - m_cachedValue[ 0 ][ 0 ] = cosA * m_shoulder->m_cosElbowAngle - sinA * fLength; - m_cachedValue[ 1 ][ 0 ] = sinA * m_shoulder->m_cosElbowAngle + cosA * fLength; + cosA = m_cachedValue[0][0]; + sinA = m_cachedValue[1][0]; + m_cachedValue[0][0] = cosA * m_shoulder->m_cosElbowAngle - sinA * fLength; + m_cachedValue[1][0] = sinA * m_shoulder->m_cosElbowAngle + cosA * fLength; - cosA = m_cachedValue[ 0 ][ 1 ]; - sinA = m_cachedValue[ 1 ][ 1 ]; - m_cachedValue[ 0 ][ 1 ] = cosA * m_shoulder->m_cosElbowAngle - sinA * fLength; - m_cachedValue[ 1 ][ 1 ] = sinA * m_shoulder->m_cosElbowAngle + cosA * fLength; + cosA = m_cachedValue[0][1]; + sinA = m_cachedValue[1][1]; + m_cachedValue[0][1] = cosA * m_shoulder->m_cosElbowAngle - sinA * fLength; + m_cachedValue[1][1] = sinA * m_shoulder->m_cosElbowAngle + cosA * fLength; - cosA = m_cachedValue[ 0 ][ 2 ]; - sinA = m_cachedValue[ 1 ][ 2 ]; - m_cachedValue[ 0 ][ 2 ] = cosA * m_shoulder->m_cosElbowAngle - sinA * fLength; - m_cachedValue[ 1 ][ 2 ] = sinA * m_shoulder->m_cosElbowAngle + cosA * fLength; + cosA = m_cachedValue[0][2]; + sinA = m_cachedValue[1][2]; + m_cachedValue[0][2] = cosA * m_shoulder->m_cosElbowAngle - sinA * fLength; + m_cachedValue[1][2] = sinA * m_shoulder->m_cosElbowAngle + cosA * fLength; - m_isDirty = false; + m_isDirty = false; - return m_cachedValue; + return m_cachedValue; } -void skelBone_IKelbow::SetBoneRefs( skelBone_IKshoulder *shoulder ) +void skelBone_IKelbow::SetBoneRefs(skelBone_IKshoulder *shoulder) { - m_shoulder = shoulder; + m_shoulder = shoulder; } -void skelBone_IKelbow::SetBaseValue( boneData_t *boneData ) +void skelBone_IKelbow::SetBaseValue(boneData_t *boneData) { - m_shoulder->SetElbowValue( boneData->length ); + m_shoulder->SetElbowValue(boneData->length); } -int skelBone_IKelbow::GetChannelIndex( int num ) +int skelBone_IKelbow::GetChannelIndex(int num) { - return -1; + return -1; } -skelBone_Base *skelBone_IKelbow::GetBoneRef( int num ) +skelBone_Base *skelBone_IKelbow::GetBoneRef(int num) { - return m_shoulder; + return m_shoulder; } skelBone_AvRot::skelBone_AvRot() { - m_reference1 = NULL; - m_reference2 = NULL; + m_reference1 = NULL; + m_reference2 = NULL; } -SkelMat4 &skelBone_AvRot::GetDirtyTransform( const skelAnimStoreFrameList_c *frames ) +SkelMat4& skelBone_AvRot::GetDirtyTransform(const skelAnimStoreFrameList_c *frames) { - SkelQuat temp1, temp2; - SkelMat4 temp; + SkelQuat temp1, temp2; + SkelMat4 temp; - temp1 = m_reference1->GetTransform( frames ); - temp2 = m_reference2->GetTransform( frames ); + temp1 = m_reference1->GetTransform(frames); + temp2 = m_reference2->GetTransform(frames); - // lerp values - Slerp( temp1, temp2, m_bone2weight, &m_cachedQuat ); + // lerp values + Slerp(temp1, temp2, m_bone2weight, &m_cachedQuat); - VectorCopy( m_basePos, m_cachedValue[ 3 ] ); + VectorCopy(m_basePos, m_cachedValue[3]); - if( m_parent ) - { - temp.Multiply( m_cachedValue, m_parent->GetTransform( frames ) ); - m_cachedValue = temp; - } + if (m_parent) { + temp.Multiply(m_cachedValue, m_parent->GetTransform(frames)); + m_cachedValue = temp; + } - m_cachedQuat.GetMat4( m_cachedValue ); + m_cachedQuat.GetMat4(m_cachedValue); - m_isDirty = false; + m_isDirty = false; - return m_cachedValue; + return m_cachedValue; } -void skelBone_AvRot::SetBoneRefs( skelBone_Base *ref1, skelBone_Base *ref2 ) +void skelBone_AvRot::SetBoneRefs(skelBone_Base *ref1, skelBone_Base *ref2) { - m_reference1 = ref1; - m_reference2 = ref2; + m_reference1 = ref1; + m_reference2 = ref2; } -void skelBone_AvRot::SetBaseValue( boneData_t *boneData ) +void skelBone_AvRot::SetBaseValue(boneData_t *boneData) { - m_basePos = boneData->offset; - m_bone2weight = boneData->weight; + m_basePos = boneData->offset; + m_bone2weight = boneData->weight; } -int skelBone_AvRot::GetChannelIndex( int num ) +int skelBone_AvRot::GetChannelIndex(int num) { - return -1; + return -1; } -skelBone_Base *skelBone_AvRot::GetBoneRef( int num ) +skelBone_Base *skelBone_AvRot::GetBoneRef(int num) { - if( num ) - { - return m_reference2; - } - else - { - return m_reference1; - } + if (num) { + return m_reference2; + } else { + return m_reference1; + } } -SkelMat4 &skelBone_HoseRot::GetDirtyTransform( const skelAnimStoreFrameList_c *frames ) +SkelMat4& skelBone_HoseRot::GetDirtyTransform(const skelAnimStoreFrameList_c *frames) { - SkelMat4 mat; + SkelMat4 mat; - if( m_parent ) - { - mat = m_parent->GetTransform( frames ); - } + if (m_parent) { + mat = m_parent->GetTransform(frames); + } - return GetDirtyTransform( mat, m_target->GetTransform( frames ) ); + return GetDirtyTransform(mat, m_target->GetTransform(frames)); } -SkelMat4 &skelBone_HoseRot::GetDirtyTransform( SkelMat4& myParentTM, SkelMat4& targetTM ) +SkelMat4& skelBone_HoseRot::GetDirtyTransform(SkelMat4& myParentTM, SkelMat4& targetTM) { - SkelMat4 m; - SkelMat4 invParentTM; - SkelMat4 temp; - SkelVec3 rotaxis; - SkelVec3 targetup, targetaim; - SkelVec3 upaxis, aimaxis; - SkelVec3 tmp; - SkelQuat targetQuat; - float l, s, c; - float angle, vScale; + SkelMat4 m; + SkelMat4 invParentTM; + SkelMat4 temp; + SkelVec3 rotaxis; + SkelVec3 targetup, targetaim; + SkelVec3 upaxis, aimaxis; + SkelVec3 tmp; + SkelQuat targetQuat; + float l, s, c; + float angle, vScale; - aimaxis = myParentTM[ 0 ]; - targetaim = targetTM[ 0 ]; + aimaxis = myParentTM[0]; + targetaim = targetTM[0]; - CrossProduct( targetaim, aimaxis, rotaxis ); + CrossProduct(targetaim, aimaxis, rotaxis); - s = VectorLengthSquared( rotaxis ); + s = VectorLengthSquared(rotaxis); - if( s == 0.0 ) { - rotaxis.x = 1.0; - } else if( s != 1.0 ) { - l = 1.0 / sqrt( s ); - VectorScale( rotaxis, l, rotaxis ); - } + if (s == 0.0) { + rotaxis.x = 1.0; + } else if (s != 1.0) { + l = 1.0 / sqrt(s); + VectorScale(rotaxis, l, rotaxis); + } - s = DotProduct( aimaxis, targetaim ); - if( s < 1.0 ) { - if( s > -0.999 ) { - angle = acos( s ); - } else { - angle = 6.2831855f; - } - } else { - angle = 0.0; - } + s = DotProduct(aimaxis, targetaim); + if (s < 1.0) { + if (s > -0.999) { + angle = acos(s); + } else { + angle = 6.2831855f; + } + } else { + angle = 0.0; + } - vScale = angle * m_bendRatio; - if( vScale > m_bendMax ) { - vScale = m_bendMax; - } + vScale = angle * m_bendRatio; + if (vScale > m_bendMax) { + vScale = m_bendMax; + } - temp[ 0 ][ 0 ] = myParentTM[ 0 ][ 0 ]; - temp[ 0 ][ 1 ] = myParentTM[ 1 ][ 0 ]; - temp[ 0 ][ 2 ] = myParentTM[ 2 ][ 0 ]; - temp[ 1 ][ 0 ] = myParentTM[ 0 ][ 1 ]; - temp[ 1 ][ 1 ] = myParentTM[ 1 ][ 1 ]; - temp[ 1 ][ 2 ] = myParentTM[ 2 ][ 1 ]; - temp[ 2 ][ 0 ] = myParentTM[ 0 ][ 2 ]; - temp[ 2 ][ 1 ] = myParentTM[ 1 ][ 2 ]; - temp[ 2 ][ 2 ] = myParentTM[ 2 ][ 2 ]; - temp[ 3 ][ 0 ] = -( myParentTM[ 0 ][ 0 ] * myParentTM[ 3 ][ 0 ] + myParentTM[ 0 ][ 1 ] * myParentTM[ 3 ][ 1 ] + myParentTM[ 0 ][ 2 ] * myParentTM[ 3 ][ 2 ] ); - temp[ 3 ][ 1 ] = -( myParentTM[ 1 ][ 0 ] * myParentTM[ 3 ][ 0 ] + myParentTM[ 1 ][ 1 ] * myParentTM[ 3 ][ 1 ] + myParentTM[ 1 ][ 2 ] * myParentTM[ 3 ][ 2 ] ); - temp[ 3 ][ 2 ] = -( myParentTM[ 2 ][ 0 ] * myParentTM[ 3 ][ 0 ] + myParentTM[ 2 ][ 1 ] * myParentTM[ 3 ][ 1 ] + myParentTM[ 2 ][ 2 ] * myParentTM[ 3 ][ 2 ] ); + temp[0][0] = myParentTM[0][0]; + temp[0][1] = myParentTM[1][0]; + temp[0][2] = myParentTM[2][0]; + temp[1][0] = myParentTM[0][1]; + temp[1][1] = myParentTM[1][1]; + temp[1][2] = myParentTM[2][1]; + temp[2][0] = myParentTM[0][2]; + temp[2][1] = myParentTM[1][2]; + temp[2][2] = myParentTM[2][2]; + temp[3][0] = + -(myParentTM[0][0] * myParentTM[3][0] + myParentTM[0][1] * myParentTM[3][1] + + myParentTM[0][2] * myParentTM[3][2]); + temp[3][1] = + -(myParentTM[1][0] * myParentTM[3][0] + myParentTM[1][1] * myParentTM[3][1] + + myParentTM[1][2] * myParentTM[3][2]); + temp[3][2] = + -(myParentTM[2][0] * myParentTM[3][0] + myParentTM[2][1] * myParentTM[3][1] + + myParentTM[2][2] * myParentTM[3][2]); - m.Multiply( temp, myParentTM ); + m.Multiply(temp, myParentTM); - VectorCopy( rotaxis, tmp ); - rotaxis[ 0 ] = tmp[ 0 ] * temp[ 0 ][ 0 ] + tmp[ 1 ] * temp[ 1 ][ 0 ] + tmp[ 2 ] * temp[ 2 ][ 0 ]; - rotaxis[ 1 ] = tmp[ 0 ] * temp[ 0 ][ 1 ] + tmp[ 1 ] * temp[ 1 ][ 1 ] + tmp[ 2 ] * temp[ 2 ][ 1 ]; - rotaxis[ 2 ] = tmp[ 0 ] * temp[ 0 ][ 2 ] + tmp[ 1 ] * temp[ 1 ][ 2 ] + tmp[ 2 ] * temp[ 2 ][ 2 ]; + VectorCopy(rotaxis, tmp); + rotaxis[0] = tmp[0] * temp[0][0] + tmp[1] * temp[1][0] + tmp[2] * temp[2][0]; + rotaxis[1] = tmp[0] * temp[0][1] + tmp[1] * temp[1][1] + tmp[2] * temp[2][1]; + rotaxis[2] = tmp[0] * temp[0][2] + tmp[1] * temp[1][2] + tmp[2] * temp[2][2]; - targetaim.y = cos( vScale * 0.5 ); - targetup.y = rotaxis.x * targetaim.y; - targetup.z = rotaxis.y * targetaim.y; - targetaim.x = rotaxis.z * targetaim.y; + targetaim.y = cos(vScale * 0.5); + targetup.y = rotaxis.x * targetaim.y; + targetup.z = rotaxis.y * targetaim.y; + targetaim.x = rotaxis.z * targetaim.y; - c = cos( vScale * 0.5 ); - l = sqrt( 1.0 - c * c ); + c = cos(vScale * 0.5); + l = sqrt(1.0 - c * c); - m_cachedQuat[ 0 ] = rotaxis[ 0 ] * l; - m_cachedQuat[ 1 ] = rotaxis[ 1 ] * l; - m_cachedQuat[ 2 ] = rotaxis[ 2 ] * l; - m_cachedQuat[ 3 ] = c; + m_cachedQuat[0] = rotaxis[0] * l; + m_cachedQuat[1] = rotaxis[1] * l; + m_cachedQuat[2] = rotaxis[2] * l; + m_cachedQuat[3] = c; - if( m_spinRatio < 1.0 ) - { - m.Multiply( targetTM, temp ); - MatToQuat( m.val, targetQuat.val ); - Slerp( targetQuat, m_cachedQuat, m_spinRatio, &m_cachedQuat ); - } + if (m_spinRatio < 1.0) { + m.Multiply(targetTM, temp); + MatToQuat(m.val, targetQuat.val); + Slerp(targetQuat, m_cachedQuat, m_spinRatio, &m_cachedQuat); + } - m_cachedQuat.GetMat4( m_cachedValue ); - VectorCopy( m_basePos, m_cachedValue[ 3 ] ); + m_cachedQuat.GetMat4(m_cachedValue); + VectorCopy(m_basePos, m_cachedValue[3]); - m.Multiply( m_cachedValue, myParentTM ); - m_cachedValue = m; + m.Multiply(m_cachedValue, myParentTM); + m_cachedValue = m; - m_isDirty = false; + m_isDirty = false; - return m_cachedValue; + return m_cachedValue; } -void skelBone_HoseRot::SetBoneRefs( skelBone_Base *ref ) +void skelBone_HoseRot::SetBoneRefs(skelBone_Base *ref) { - m_target = ref; + m_target = ref; } -void skelBone_HoseRot::SetBaseValue( boneData_t *boneData ) +void skelBone_HoseRot::SetBaseValue(boneData_t *boneData) { - m_bendRatio = boneData->bendRatio; - m_bendMax = boneData->bendMax; - m_spinRatio = boneData->spinRatio; - m_basePos = boneData->offset; + m_bendRatio = boneData->bendRatio; + m_bendMax = boneData->bendMax; + m_spinRatio = boneData->spinRatio; + m_basePos = boneData->offset; } -int skelBone_HoseRot::GetChannelIndex( int num ) +int skelBone_HoseRot::GetChannelIndex(int num) { - return -1; + return -1; } -skelBone_Base *skelBone_HoseRot::GetBoneRef( int num ) +skelBone_Base *skelBone_HoseRot::GetBoneRef(int num) { - return m_target; + return m_target; } -SkelMat4 &skelBone_HoseRotBoth::GetDirtyTransform( const skelAnimStoreFrameList_c *frames ) +SkelMat4& skelBone_HoseRotBoth::GetDirtyTransform(const skelAnimStoreFrameList_c *frames) { - SkelMat4 myParentTM; - SkelMat4 targetTM; + SkelMat4 myParentTM; + SkelMat4 targetTM; - if( m_parent ) - { - myParentTM = m_parent->GetTransform( frames ); - targetTM = m_target->GetTransform( frames ); - } + if (m_parent) { + myParentTM = m_parent->GetTransform(frames); + targetTM = m_target->GetTransform(frames); + } - VectorInverse( targetTM[ 0 ] ); - VectorInverse( targetTM[ 2 ] ); - VectorInverse( myParentTM[ 0 ] ); - VectorInverse( myParentTM[ 2 ] ); + VectorInverse(targetTM[0]); + VectorInverse(targetTM[2]); + VectorInverse(myParentTM[0]); + VectorInverse(myParentTM[2]); - return skelBone_HoseRot::GetDirtyTransform( myParentTM, targetTM ); + return skelBone_HoseRot::GetDirtyTransform(myParentTM, targetTM); } -void skelBone_HoseRotBoth::SetBaseValue( boneData_t *boneData ) +void skelBone_HoseRotBoth::SetBaseValue(boneData_t *boneData) { - skelBone_HoseRot::SetBaseValue( boneData ); - m_basePos.x = -m_basePos.x; - m_basePos.z = -m_basePos.z; + skelBone_HoseRot::SetBaseValue(boneData); + m_basePos.x = -m_basePos.x; + m_basePos.z = -m_basePos.z; } -SkelMat4 &skelBone_HoseRotParent::GetDirtyTransform( const skelAnimStoreFrameList_c *frames ) +SkelMat4& skelBone_HoseRotParent::GetDirtyTransform(const skelAnimStoreFrameList_c *frames) { - SkelMat4 myParentTM; - SkelMat4 targetTM; + SkelMat4 myParentTM; + SkelMat4 targetTM; - if( m_parent ) - { - myParentTM = m_parent->GetTransform( frames ); - targetTM = m_target->GetTransform( frames ); - } + if (m_parent) { + myParentTM = m_parent->GetTransform(frames); + targetTM = m_target->GetTransform(frames); + } - VectorInverse( myParentTM[ 0 ] ); - VectorInverse( myParentTM[ 2 ] ); + VectorInverse(myParentTM[0]); + VectorInverse(myParentTM[2]); - return skelBone_HoseRot::GetDirtyTransform( myParentTM, targetTM ); + return skelBone_HoseRot::GetDirtyTransform(myParentTM, targetTM); } -void skelBone_HoseRotParent::SetBaseValue( boneData_t *boneData ) +void skelBone_HoseRotParent::SetBaseValue(boneData_t *boneData) { - skelBone_HoseRot::SetBaseValue( boneData ); - m_basePos.x = -m_basePos.x; - m_basePos.z = -m_basePos.z; + skelBone_HoseRot::SetBaseValue(boneData); + m_basePos.x = -m_basePos.x; + m_basePos.z = -m_basePos.z; } -SkelMat4 &skelBone_World::GetDirtyTransform( const skelAnimStoreFrameList_c *frames ) +SkelMat4& skelBone_World::GetDirtyTransform(const skelAnimStoreFrameList_c *frames) { - m_cachedValue.MakeIdentity(); - m_isDirty = false; - return m_cachedValue; + m_cachedValue.MakeIdentity(); + m_isDirty = false; + return m_cachedValue; } -void skelBone_World::SetBaseValue( boneData_t *boneData ) +void skelBone_World::SetBaseValue(boneData_t *boneData) {} + +int skelBone_World::GetChannelIndex(int num) { + return 0; } -int skelBone_World::GetChannelIndex( int num ) +skelBone_Base *skelBone_World::GetBoneRef(int num) { - return 0; -} - -skelBone_Base *skelBone_World::GetBoneRef( int num ) -{ - return NULL; + return NULL; } diff --git a/code/skeletor/tokenizer.cpp b/code/skeletor/tokenizer.cpp index 68c6b6f1..ea3e394e 100644 --- a/code/skeletor/tokenizer.cpp +++ b/code/skeletor/tokenizer.cpp @@ -1,6 +1,6 @@ /* =========================================================================== -Copyright (C) 2015 the OpenMoHAA team +Copyright (C) 2023 the OpenMoHAA team This file is part of OpenMoHAA source code. diff --git a/code/skeletor/tokenizer.h b/code/skeletor/tokenizer.h index 97cd6926..ff1e9018 100644 --- a/code/skeletor/tokenizer.h +++ b/code/skeletor/tokenizer.h @@ -1,6 +1,6 @@ /* =========================================================================== -Copyright (C) 2015 the OpenMoHAA team +Copyright (C) 2023 the OpenMoHAA team This file is part of OpenMoHAA source code. @@ -22,47 +22,46 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // tokenizer.h : Tokenizer -#ifndef __TOKENIZER_H__ -#define __TOKENIZER_H__ +#pragma once + +class Tokenizer +{ + char *pBuffer; + char *pEnd; + int iLength; + char *pCurrent; + int iLine; + int iError; + bool fTokenReady; + char szToken[256]; -class Tokenizer { - char *pBuffer; - char *pEnd; - int iLength; - char *pCurrent; - int iLine; - int iError; - bool fTokenReady; - char szToken[ 256 ]; public: - Tokenizer(); - Tokenizer( const char *pInputBuffer , int iBufferLength ); + Tokenizer(); + Tokenizer(const char *pInputBuffer, int iBufferLength); - void SetBuffer( const char *pInputBuffer, int iBufferLength); - void Reset(); - int GetLineNumber(); - bool HasError(); - int GetError(); - bool SkipToEOL(); - bool CheckOverflow(); - bool SkipWhiteSpace( bool fCrossLine ); - bool AtComment(); - void SkipNonToken( bool fCrossLine ); - bool TokenAvailable( bool fCrossLine ); - bool CommentAvailable( bool fCrossLine ); - void UnGetToken(); - bool AtString( bool fCrossLine ); - char *GetToken( bool fCrossLine ); - char *GetLine( bool fCrossLine ); - char *GetRaw(); - char *GetString( bool fCrossLine ); - bool GetSpecific( const char *szString ); - int GetInteger( bool fCrossLine ); - double GetDouble( bool fCrossLine ); - float GetFloat( bool fCrossLine ); - int LinesInFile(); - char *Token(); - char *GetCurrentPointer(); + void SetBuffer(const char *pInputBuffer, int iBufferLength); + void Reset(); + int GetLineNumber(); + bool HasError(); + int GetError(); + bool SkipToEOL(); + bool CheckOverflow(); + bool SkipWhiteSpace(bool fCrossLine); + bool AtComment(); + void SkipNonToken(bool fCrossLine); + bool TokenAvailable(bool fCrossLine); + bool CommentAvailable(bool fCrossLine); + void UnGetToken(); + bool AtString(bool fCrossLine); + char *GetToken(bool fCrossLine); + char *GetLine(bool fCrossLine); + char *GetRaw(); + char *GetString(bool fCrossLine); + bool GetSpecific(const char *szString); + int GetInteger(bool fCrossLine); + double GetDouble(bool fCrossLine); + float GetFloat(bool fCrossLine); + int LinesInFile(); + char *Token(); + char *GetCurrentPointer(); }; - -#endif // __TOKENIZER_H__