Added scaling

This commit is contained in:
Dane Johnson 2021-01-20 17:18:39 -06:00
parent 391060d9ba
commit 4955d77de8
4 changed files with 13 additions and 0 deletions

View File

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

View File

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

View File

@ -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<Mesh*>(curr);

View File

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