Basic structure for rotation
This commit is contained in:
parent
d6effd66f6
commit
0aa41b3d66
@ -2,6 +2,7 @@
|
|||||||
#define __PATHMOVE_H__
|
#define __PATHMOVE_H__
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
#include <glm/gtx/quaternion.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
struct PathMove {
|
struct PathMove {
|
||||||
@ -11,14 +12,19 @@ struct PathMove {
|
|||||||
std::vector<glm::vec3> points;
|
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;
|
double speed;
|
||||||
|
float time_passed = 0.0;
|
||||||
Path path;
|
|
||||||
|
|
||||||
int current_point_index = 0;
|
int current_point_index = 0;
|
||||||
|
|
||||||
float time_passed = 0.0;
|
Path path;
|
||||||
|
Views views;
|
||||||
};
|
};
|
||||||
#endif // __PATHMOVE_H__
|
#endif // __PATHMOVE_H__
|
@ -9,6 +9,8 @@
|
|||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
|
|
||||||
|
#include "glm/gtx/string_cast.hpp"
|
||||||
|
|
||||||
struct Transform {
|
struct Transform {
|
||||||
Transform() = default;
|
Transform() = default;
|
||||||
|
|
||||||
@ -35,6 +37,16 @@ struct Transform {
|
|||||||
translate(-difference);
|
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 {
|
glm::vec3 getPosition() const {
|
||||||
return matrix * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
|
return matrix * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
@ -137,6 +137,11 @@ class PathMoveSystem : public EntitySystem, public EventSubscriber<InputEvent> {
|
|||||||
// Apply
|
// Apply
|
||||||
transform->set_position(point);
|
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
|
// FIXME: Debugging output
|
||||||
std::cout << point.x << ", " << point.y << ", " << point.z << std::endl;
|
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<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(0.0, 2.0, 0.0),
|
||||||
glm::vec3(0.0, 2.0, 1.0),
|
glm::vec3(0.0, 2.0, -1.0),
|
||||||
glm::vec3(2.0, 2.0, 2.0),
|
glm::vec3(2.0, 2.0, -2.0),
|
||||||
glm::vec3(1.0, 3.0, 3.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(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, -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));
|
player->get<Transform>()->translate(glm::vec3(0.0f, 1.0f, 2.0f));
|
||||||
|
|
||||||
Entity *monkey = world->create();
|
Entity *monkey = world->create();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user