From d460d1db5025e041ceb8bd20c00b68f5d7e11cbd Mon Sep 17 00:00:00 2001 From: Dane Johnson Date: Wed, 20 Jan 2021 17:18:39 -0600 Subject: [PATCH] Added scaling --- core/Transform.cpp | 9 +++++++++ core/Transform.h | 2 ++ core/couch.cpp | 1 + demo/main.lua | 1 + 4 files changed, 13 insertions(+) diff --git a/core/Transform.cpp b/core/Transform.cpp index 8b2ca0d..271e404 100644 --- a/core/Transform.cpp +++ b/core/Transform.cpp @@ -3,13 +3,22 @@ Transform::Transform() { position = Vector3(0.0f); rotation = Vector3(0.0f); + scale = Vector3(1.0f, 1.0f, 1.0f); } Transform::Transform(Vector3 position, Vector3 rotation) { this->position = position; this->rotation = rotation; + this->scale = Vector3(1.0f, 1.0f, 1.0f); } +Transform::Transform(Vector3 position, Vector3 rotation, Vector3 scale) { + this->position = position; + this->rotation = rotation; + this->scale = scale; +} + + void Transform::Translate(cfloat x, cfloat y, cfloat z) { position = position + Vector3(x, y, z); } diff --git a/core/Transform.h b/core/Transform.h index 03a1407..811cb5d 100644 --- a/core/Transform.h +++ b/core/Transform.h @@ -8,8 +8,10 @@ struct Transform { Transform(); Transform(Vector3 position, Vector3 rotation); + Transform(Vector3 position, Vector3 rotation, Vector3 scale); Vector3 position; Vector3 rotation; + Vector3 scale; void Translate(cfloat x, cfloat y, cfloat z); Vector3 Forward(); }; diff --git a/core/couch.cpp b/core/couch.cpp index fc80afd..0173b3b 100644 --- a/core/couch.cpp +++ b/core/couch.cpp @@ -38,6 +38,7 @@ void render(Node *curr, Shader *shader, Matrix model) { model = glm::rotate(model, spatial->transform.rotation.y, Vector3(0.0f, 1.0f, 0.0f)); model = glm::rotate(model, spatial->transform.rotation.z, Vector3(0.0f, 0.0f, 1.0f)); model = glm::translate(model, spatial->transform.position); + model = glm::scale(model, spatial->transform.scale); shader->UpdateModel(model); } Mesh *mesh = dynamic_cast(curr); diff --git a/demo/main.lua b/demo/main.lua index e2eefb9..5a4b8d5 100644 --- a/demo/main.lua +++ b/demo/main.lua @@ -49,6 +49,7 @@ function init() trough = couch.TexturedMesh("trough.glb", "wood_lowres.png") couch.Node.GetRoot().children:Append(trough) trough.transform:Translate(10.0, 0.0, 0.0) + trough.transform.scale = trough.transform.scale * 3.0 scaffold = couch.TexturedMesh("scaffold.glb", "grate_floor_lowres.png", "railing.png") couch.Node.GetRoot().children:Append(scaffold)