This commit is contained in:
Dane Johnson 2021-01-13 20:08:39 -06:00
parent 3c652884c2
commit e9a669eebe
4 changed files with 12 additions and 3 deletions

View File

@ -4,8 +4,9 @@ Transform::Transform() {
position = Vector3(0.0f);
}
Transform::Transform(Vector3 position) {
Transform::Transform(Vector3 position, Vector3 rotation) {
this->position = position;
this->rotation = rotation;
}
void Transform::Translate(cfloat x, cfloat y, cfloat z) {

View File

@ -5,8 +5,9 @@
struct Transform {
Transform();
Transform(Vector3 position);
Transform(Vector3 position, Vector3 rotation);
Vector3 position;
Vector3 rotation;
void Translate(cfloat x, cfloat y, cfloat z);
};

View File

@ -113,6 +113,9 @@ int main() {
for (Mesh *mesh : meshes) {
Matrix model(1.0f);
model = glm::translate(model, mesh->transform.position);
model = glm::rotate(model, mesh->transform.rotation.x, Vector3(1.0f, 0.0f, 0.0f));
model = glm::rotate(model, mesh->transform.rotation.y, Vector3(0.0f, 1.0f, 0.0f));
model = glm::rotate(model, mesh->transform.rotation.z, Vector3(0.0f, 0.0f, 1.0f));
shader.UpdateModel(model);
mesh->Draw();
}

View File

@ -14,6 +14,7 @@ local ballvy = -1.0
function init()
camera = couch.Camera()
camera:MakeCurrent()
camera.transform:Translate(0.0, 0.0, 10.0)
ball = couch.Ball()
ball:SetupMesh()
couch.AddMeshToList(ball)
@ -33,7 +34,10 @@ function update(delta)
elseif loc.y < 2.0 then
ballvy = 1.0
end
ball1.transform:Translate(0.0, ballvy * delta, 0.0)
ball1.transform.position.y = ball1.transform.position.y + ballvy * delta
ball.transform.rotation.z = ball.transform.rotation.z + 1.0 * delta;
ball.transform.rotation.x = ball.transform.rotation.x + 1.0 * delta;
end
function onkey(key, code, action, mod)