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.
This commit is contained in:
Epicalert 2021-02-10 17:02:38 +08:00
parent dd6edb96f3
commit e56009c125
No known key found for this signature in database
GPG key ID: CAA46F858D0979BD
3 changed files with 28 additions and 3 deletions

View file

@ -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");

View file

@ -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) {

View file

@ -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);