From e56009c125b598998a455512733d0e76cd585a4f Mon Sep 17 00:00:00 2001 From: Epicalert Date: Wed, 10 Feb 2021 17:02:38 +0800 Subject: [PATCH] Add scale and rotation factor Model parts can now have different scale and rotation factors, so all parts do not need to rotate and scale with the head. --- src/model.cpp | 13 ++++++++++++- src/modelpart.cpp | 12 ++++++++++-- src/modelpart.hpp | 6 ++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/model.cpp b/src/model.cpp index 0075c60..6f65fe0 100644 --- a/src/model.cpp +++ b/src/model.cpp @@ -9,7 +9,7 @@ #define BUFFER_SIZE_TEXTURE 16777220 // 16 MiB #define SUPPORTED_MODEL_MAJOR 0 -#define SUPPORTED_MODEL_MINOR 1 +#define SUPPORTED_MODEL_MINOR 2 void textureFromArchive(zip_t* archive, const char* path, ModelPart* part, size_t slot, std::string triggerName) { zip_file_t* textureFile = zip_fopen(archive, path, 0); @@ -118,6 +118,17 @@ Model::Model(const char* path) { } } + // rotation and scale factor + auto rotFacResult = partsVec[i].getDouble("rot_factor"); + auto scaleFacResult = partsVec[i].getDouble("scale_factor"); + + if (rotFacResult.first) { + newPart.setRotationFactor((float)rotFacResult.second); + } + if (scaleFacResult.first) { + newPart.setScaleFactor((float)scaleFacResult.second); + } + // texture auto textureSingle = partsVec[i].getString("texture"); diff --git a/src/modelpart.cpp b/src/modelpart.cpp index 74f46d1..2b0092b 100644 --- a/src/modelpart.cpp +++ b/src/modelpart.cpp @@ -44,10 +44,18 @@ void ModelPart::setFollowFactor(float followFactor) { factor = followFactor; } +void ModelPart::setRotationFactor(float rotationFactor) { + rotFactor = rotationFactor; +} + +void ModelPart::setScaleFactor(float scaleFac) { + scaleFactor = scaleFac; +} + void ModelPart::setTransform(glm::vec2 position, float rotation, float scale) { transMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(position.x, -position.y, 0.0f)); - transMatrix = glm::rotate(transMatrix, rotation, glm::vec3(0.0f, 0.0f, 1.0f)); - transMatrix = glm::scale(transMatrix, glm::vec3(scale, scale, scale)); + transMatrix = glm::rotate(transMatrix, rotation * rotFactor, glm::vec3(0.0f, 0.0f, 1.0f)); + transMatrix = glm::scale(transMatrix, glm::vec3(1,1,1) + (scale - 1) * scaleFactor); } void ModelPart::processFaceData(struct FaceData faceData) { diff --git a/src/modelpart.hpp b/src/modelpart.hpp index 90c9612..750ff2d 100644 --- a/src/modelpart.hpp +++ b/src/modelpart.hpp @@ -28,6 +28,9 @@ class ModelPart { int follow = BIND_NULL; float factor = 0.0f; //default factor of 0 so part will not follow a null by default + float rotFactor = 1.0f; + float scaleFactor = 1.0f; + bool empty = true; public: @@ -39,6 +42,9 @@ class ModelPart { void setFollowTarget(std::string followString); void setFollowFactor(float followFactor); + void setRotationFactor(float rotationFactor); + void setScaleFactor(float scaleFactor); + void setTransform(glm::vec2 position, float rotation, float scale); void processFaceData(struct FaceData faceData);