Rotation
This commit is contained in:
parent
3c652884c2
commit
e9a669eebe
@ -4,8 +4,9 @@ Transform::Transform() {
|
|||||||
position = Vector3(0.0f);
|
position = Vector3(0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
Transform::Transform(Vector3 position) {
|
Transform::Transform(Vector3 position, Vector3 rotation) {
|
||||||
this->position = position;
|
this->position = position;
|
||||||
|
this->rotation = rotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Transform::Translate(cfloat x, cfloat y, cfloat z) {
|
void Transform::Translate(cfloat x, cfloat y, cfloat z) {
|
||||||
|
@ -5,8 +5,9 @@
|
|||||||
|
|
||||||
struct Transform {
|
struct Transform {
|
||||||
Transform();
|
Transform();
|
||||||
Transform(Vector3 position);
|
Transform(Vector3 position, Vector3 rotation);
|
||||||
Vector3 position;
|
Vector3 position;
|
||||||
|
Vector3 rotation;
|
||||||
void Translate(cfloat x, cfloat y, cfloat z);
|
void Translate(cfloat x, cfloat y, cfloat z);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -113,6 +113,9 @@ int main() {
|
|||||||
for (Mesh *mesh : meshes) {
|
for (Mesh *mesh : meshes) {
|
||||||
Matrix model(1.0f);
|
Matrix model(1.0f);
|
||||||
model = glm::translate(model, mesh->transform.position);
|
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);
|
shader.UpdateModel(model);
|
||||||
mesh->Draw();
|
mesh->Draw();
|
||||||
}
|
}
|
||||||
|
6
main.lua
6
main.lua
@ -14,6 +14,7 @@ local ballvy = -1.0
|
|||||||
function init()
|
function init()
|
||||||
camera = couch.Camera()
|
camera = couch.Camera()
|
||||||
camera:MakeCurrent()
|
camera:MakeCurrent()
|
||||||
|
camera.transform:Translate(0.0, 0.0, 10.0)
|
||||||
ball = couch.Ball()
|
ball = couch.Ball()
|
||||||
ball:SetupMesh()
|
ball:SetupMesh()
|
||||||
couch.AddMeshToList(ball)
|
couch.AddMeshToList(ball)
|
||||||
@ -33,7 +34,10 @@ function update(delta)
|
|||||||
elseif loc.y < 2.0 then
|
elseif loc.y < 2.0 then
|
||||||
ballvy = 1.0
|
ballvy = 1.0
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
function onkey(key, code, action, mod)
|
function onkey(key, code, action, mod)
|
||||||
|
Loading…
Reference in New Issue
Block a user