3 #include "../model/Shape.hpp"
6 #include <glm/gtx/transform.hpp>
10 blank::Model::Buffer model_buffer;
16 Entity::Entity() noexcept
24 , angular_velocity(1.0f, 0.0f, 0.0f, 0.0f)
26 , world_collision(false) {
31 void Entity::SetShape(const Shape *s, const glm::vec3 &color) {
34 shape->Vertices(model_buffer.vertices, model_buffer.normals, model_buffer.indices);
35 model_buffer.colors.resize(shape->VertexCount(), color);
36 model.Update(model_buffer);
39 void Entity::SetShapeless() noexcept {
44 void Entity::Velocity(const glm::vec3 &vel) noexcept {
48 void Entity::Position(const Block::Pos &pos) noexcept {
50 while (position.x >= Chunk::width) {
51 position.x -= Chunk::width;
54 while (position.x < 0) {
55 position.x += Chunk::width;
58 while (position.y >= Chunk::height) {
59 position.y -= Chunk::height;
62 while (position.y < 0) {
63 position.y += Chunk::height;
66 while (position.z >= Chunk::depth) {
67 position.z -= Chunk::depth;
70 while (position.z < 0) {
71 position.z += Chunk::depth;
76 void Entity::Move(const glm::vec3 &delta) noexcept {
77 Position(position + delta);
80 void Entity::AngularVelocity(const glm::quat &v) noexcept {
84 void Entity::Rotation(const glm::mat4 &rot) noexcept {
88 void Entity::Rotate(const glm::quat &delta) noexcept {
89 Rotation(rotation * glm::mat4_cast(delta));
92 glm::mat4 Entity::Transform(const Chunk::Pos &chunk_offset) const noexcept {
93 const glm::vec3 chunk_pos = (chunk - chunk_offset) * Chunk::Extent();
94 return glm::translate(position + chunk_pos) * rotation;
97 Ray Entity::Aim(const Chunk::Pos &chunk_offset) const noexcept {
98 glm::mat4 transform = Transform(chunk_offset);
99 glm::vec4 from = transform * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
101 glm::vec4 to = transform * glm::vec4(0.0f, 0.0f, -1.0f, 1.0f);
103 return Ray{ glm::vec3(from), glm::normalize(glm::vec3(to - from)) };
106 void Entity::Update(int dt) noexcept {
107 Move(velocity * float(dt));
108 Rotate(angular_velocity * float(dt));
112 void Entity::Draw() noexcept {