Basic structure for rotation
This commit is contained in:
parent
d6effd66f6
commit
0aa41b3d66
@ -2,6 +2,7 @@
|
||||
#define __PATHMOVE_H__
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
#include <vector>
|
||||
|
||||
struct PathMove {
|
||||
@ -11,14 +12,19 @@ struct PathMove {
|
||||
std::vector<glm::vec3> points;
|
||||
};
|
||||
|
||||
PathMove(double speed, Path path) : speed(speed), path(path) {}
|
||||
struct Views {
|
||||
Views(std::vector<glm::quat> views) : views(views) {}
|
||||
|
||||
std::vector<glm::quat> views;
|
||||
};
|
||||
|
||||
PathMove(double speed, Path path, Views views) : speed(speed), path(path), views(views) {}
|
||||
|
||||
double speed;
|
||||
|
||||
Path path;
|
||||
|
||||
float time_passed = 0.0;
|
||||
int current_point_index = 0;
|
||||
|
||||
float time_passed = 0.0;
|
||||
Path path;
|
||||
Views views;
|
||||
};
|
||||
#endif // __PATHMOVE_H__
|
@ -9,6 +9,8 @@
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
#include "glm/gtx/string_cast.hpp"
|
||||
|
||||
struct Transform {
|
||||
Transform() = default;
|
||||
|
||||
@ -35,6 +37,16 @@ struct Transform {
|
||||
translate(-difference);
|
||||
}
|
||||
|
||||
void set_rotation_from_quat(glm::quat quaternion) {
|
||||
// Remember translation
|
||||
glm::vec4 save = matrix[3];
|
||||
|
||||
matrix = glm::mat4_cast(quaternion);
|
||||
matrix[3] = save;
|
||||
|
||||
std::cout << glm::to_string(matrix) << std::endl;
|
||||
}
|
||||
|
||||
glm::vec3 getPosition() const {
|
||||
return matrix * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
|
@ -137,6 +137,11 @@ class PathMoveSystem : public EntitySystem, public EventSubscriber<InputEvent> {
|
||||
// Apply
|
||||
transform->set_position(point);
|
||||
|
||||
// Rotation
|
||||
// https://www.3dgep.com/understanding-quaternions/#SQUAD
|
||||
PathMove::Views views = pathmove->views;
|
||||
transform->set_rotation_from_quat(views.views[pathmove->current_point_index]);
|
||||
|
||||
// FIXME: Debugging output
|
||||
std::cout << point.x << ", " << point.y << ", " << point.z << std::endl;
|
||||
});
|
||||
|
24
main.cpp
24
main.cpp
@ -93,13 +93,23 @@ int main() {
|
||||
player->assign<Camera>(70.0f, 1280, 720, 0.1f, 100.0f);
|
||||
player->assign<PathMove>(10.0, PathMove::Path(std::vector<glm::vec3>{
|
||||
glm::vec3(0.0, 2.0, 0.0),
|
||||
glm::vec3(0.0, 2.0, 1.0),
|
||||
glm::vec3(2.0, 2.0, 2.0),
|
||||
glm::vec3(1.0, 3.0, 3.0),
|
||||
glm::vec3(-2.0, 2.0, 4.0),
|
||||
glm::vec3(2.0, 2.0, 4.0),
|
||||
glm::vec3(0.0, 2.0, 10.0)
|
||||
}));
|
||||
glm::vec3(0.0, 2.0, -1.0),
|
||||
glm::vec3(2.0, 2.0, -2.0),
|
||||
glm::vec3(1.0, 3.0, -3.0),
|
||||
glm::vec3(-2.0, 2.0, -4.0),
|
||||
glm::vec3(2.0, 2.0, -4.0),
|
||||
glm::vec3(0.0, 2.0, -10.0)
|
||||
}),
|
||||
PathMove::Views(std::vector<glm::quat>{
|
||||
glm::quat(0.0, 0.0, 0.0, 0.0),
|
||||
glm::angleAxis(glm::radians(10.f), glm::vec3(0.f, 1.f, 0.f)),
|
||||
glm::angleAxis(glm::radians(30.f), glm::vec3(0.f, 1.f, 0.f)),
|
||||
glm::angleAxis(glm::radians(40.f), glm::vec3(0.f, 1.f, 0.f)),
|
||||
glm::angleAxis(glm::radians(50.f), glm::vec3(0.f, 1.f, 0.f)),
|
||||
glm::angleAxis(glm::radians(70.f), glm::vec3(0.f, 1.f, 0.f)),
|
||||
glm::angleAxis(glm::radians(80.f), glm::vec3(0.f, 1.f, 0.f))
|
||||
})
|
||||
);
|
||||
player->get<Transform>()->translate(glm::vec3(0.0f, 1.0f, 2.0f));
|
||||
|
||||
Entity *monkey = world->create();
|
||||
|
Loading…
x
Reference in New Issue
Block a user