diff --git a/Source/Contents/Models/ModelAnimation.h b/Source/Contents/Models/ModelAnimation.h index c7587e7df..9fa2474f2 100644 --- a/Source/Contents/Models/ModelAnimation.h +++ b/Source/Contents/Models/ModelAnimation.h @@ -15,12 +15,14 @@ public: class LegacyRotationTrack : public std::vector { public: using std::vector::operator=; + void Add(int frame, float x, float y, float z, float angle); void Sample(int frame, matrix& output) const; }; class LegacyScaleTrack : public std::vector { public: using std::vector::operator=; + void Add(int frame, float scaleX, float scaleY, float scaleZ, float x, float y, float z, float angle); void Sample(int frame, matrix& output) const; }; diff --git a/Source/Contents/Models/ModelKeyframes.cpp b/Source/Contents/Models/ModelKeyframes.cpp index e7d28426a..9f1662247 100644 --- a/Source/Contents/Models/ModelKeyframes.cpp +++ b/Source/Contents/Models/ModelKeyframes.cpp @@ -1,3 +1,4 @@ +#include "Contents/Models/ModelAnimation.h" #include "Resource/Models/ModelResource.h" #include "Utility/Math/AffineMatrix.h" @@ -19,14 +20,6 @@ struct ModelVectorKey { static_assert(sizeof(ModelVectorKey) == 20); -struct ModelRotationKeys : std::vector { - void Add(int frame, float x, float y, float z, float angle); -}; - -struct ModelScaleKeys : std::vector { - void Add(int frame, float scaleX, float scaleY, float scaleZ, float x, float y, float z, float angle); -}; - struct ModelPositionKeysV2 : std::vector { ModelPositionKeysV2& operator=(const ModelPositionKeysV2& other); }; @@ -46,7 +39,7 @@ ModelQuaternionKey::ModelQuaternionKey() : frame(0), rotation{0.0f, 0.0f, 0.0f, // OFFSET: 0x0053FFE0 // FUNCTION: fn_01716 -void ModelRotationKeys::Add(int frame, float x, float y, float z, float angle) { +void LegacyRotationTrack::Add(int frame, float x, float y, float z, float angle) { angle *= 0.5f; const float sine = ClientSin(angle); ModelRotationKey key; @@ -60,7 +53,7 @@ void ModelRotationKeys::Add(int frame, float x, float y, float z, float angle) { // OFFSET: 0x00540120 // FUNCTION: fn_01717 -void ModelScaleKeys::Add(int frame, float scaleX, float scaleY, float scaleZ, float x, float y, float z, float angle) { +void LegacyScaleTrack::Add(int frame, float scaleX, float scaleY, float scaleZ, float x, float y, float z, float angle) { angle *= 0.5f; const float sine = ClientSin(angle); ModelScaleKey key; diff --git a/Source/Contents/Models/ModelNode.cpp b/Source/Contents/Models/ModelNode.cpp index e7e81f0c8..d83a69a29 100644 --- a/Source/Contents/Models/ModelNode.cpp +++ b/Source/Contents/Models/ModelNode.cpp @@ -62,15 +62,13 @@ void C3dNodeV1::Initialize(const ModelNode& base) { this->alpha = static_cast(resource.alpha) / 255.0f; if (this->scaleKeys.size() == 0) { - this->scaleKeys.push_back({0, {resource.scale[0], resource.scale[1], resource.scale[2]}, {0, 0, 0, 1}}); + this->scaleKeys.Add(0, resource.scale[0], resource.scale[1], resource.scale[2], 1.0f, 0.0f, 0.0f, 0.0f); } this->rotationKeys = resource.rotationKeys; if (this->rotationKeys.size() == 0) { - const float halfAngle = resource.angle * 0.5f; - const float sine = ClientSin(halfAngle); - this->rotationKeys.push_back({0, {sine * resource.axis[0], sine * resource.axis[1], sine * resource.axis[2], ClientCos(halfAngle)}}); + this->rotationKeys.Add(0, resource.axis[0], resource.axis[1], resource.axis[2], resource.angle); } this->positionKeys = resource.legacyPositionKeys; @@ -79,12 +77,12 @@ void C3dNodeV1::Initialize(const ModelNode& base) { this->positionKeys.push_back({0, {resource.position[0], resource.position[1], resource.position[2]}}); } - for (const ModelNode* resourceChild : resource.children) { + for (auto it = resource.children.begin(); it != resource.children.end(); ++it) { auto* child = new C3dNodeV1; this->children.push_back(child); child->model = this->model; child->parent = this; - child->Initialize(*resourceChild); + child->Initialize(**it); } this->faceState.resize(this->mesh->faceCount);