6 #include <glm/gtx/transform.hpp>
19 void Entity::Velocity(const glm::vec3 &vel) {
23 void Entity::Position(const glm::vec3 &pos) {
25 while (position.x >= Chunk::Width()) {
26 position.x -= Chunk::Width();
29 while (position.x < 0) {
30 position.x += Chunk::Width();
33 while (position.y >= Chunk::Height()) {
34 position.y -= Chunk::Height();
37 while (position.y < 0) {
38 position.y += Chunk::Height();
41 while (position.z >= Chunk::Depth()) {
42 position.z -= Chunk::Depth();
45 while (position.z < 0) {
46 position.z += Chunk::Depth();
51 void Entity::Move(const glm::vec3 &delta) {
52 Position(position + delta);
55 void Entity::Rotation(const glm::mat4 &rot) {
59 glm::mat4 Entity::Transform(const glm::tvec3<int> &chunk_offset) const {
60 const glm::vec3 chunk_pos = glm::vec3(chunk - chunk_offset) * Chunk::Extent();
61 return glm::translate(position + chunk_pos) * rotation;
64 Ray Entity::Aim(const glm::tvec3<int> &chunk_offset) const {
65 glm::mat4 transform = Transform(chunk_offset);
66 glm::vec4 from = transform * glm::vec4(0.0f, 0.0f, 1.0f, 1.0f);
68 glm::vec4 to = transform * glm::vec4(0.0f, 0.0f, -1.0f, 1.0f);
70 return Ray{ glm::vec3(from), glm::normalize(glm::vec3(to - from)) };
73 void Entity::Update(int dt) {
74 Move(velocity * float(dt));