Make movement work with origin change

This commit is contained in:
karl 2020-10-02 22:47:10 +02:00
parent aef495a394
commit 2889a6fa8a
4 changed files with 10 additions and 6 deletions

View File

@ -10,7 +10,7 @@ struct Movement {
glm::vec3 speed;
glm::ivec3 moving;
glm::ivec3 moving = glm::ivec3(0, 0, 0);
glm::vec3 velocity;
};

View File

@ -41,6 +41,10 @@ struct Transform {
origin = position;
}
void add_to_origin(glm::vec3 addition) {
origin += addition;
}
void set_rotation_from_quat(glm::quat quaternion) {
// Remember translation
glm::vec4 save = matrix[3];

View File

@ -63,7 +63,7 @@ class KeyboardMovementSystem : public EntitySystem, public EventSubscriber<Input
void tick(World *pWorld, float deltaTime) override {
pWorld->each<Transform, Movement>(
[&](Entity *ent, ComponentHandle<Transform> transform, ComponentHandle<Movement> movement) {
transform->translate(glm::vec3(movement->moving) * movement->speed * deltaTime);
transform->add_to_origin(transform->matrix * glm::vec4((glm::vec3(movement->moving) * movement->speed * deltaTime), 0.0));
});
}

View File

@ -88,10 +88,10 @@ int main() {
Entity *player = world->create();
player->assign<Transform>();
//player->assign<Movement>(glm::vec3(2.f, 2.f, 2.f));
//player->assign<MouseLook>(0.1);
player->assign<Movement>(glm::vec3(2.f, 2.f, 2.f));
player->assign<MouseLook>(0.1);
player->assign<Camera>(70.0f, 1280, 720, 0.1f, 100.0f);
player->assign<PathMove>(10.0, PathMove::Path(std::vector<glm::vec3>{
/*player->assign<PathMove>(10.0, PathMove::Path(std::vector<glm::vec3>{
glm::vec3(0.0, 2.0, 0.0),
glm::vec3(-2.0, 2.0, -1.0),
glm::vec3(-1.0, 2.0, -2.0),
@ -109,7 +109,7 @@ int main() {
glm::angleAxis(glm::radians(120.f), glm::vec3(0.f, 1.f, 0.f)),
glm::angleAxis(glm::radians(180.f), glm::vec3(0.f, 1.f, 0.f))
})
);
);*/
Entity *monkey = world->create();
monkey->assign<Transform>();