3 #include "../model/Shape.hpp"
6 #include <glm/gtx/transform.hpp>
10 blank::EntityModel::Buffer model_buffer;
16 Entity::Entity() noexcept
24 , angular_velocity(1.0f, 0.0f, 0.0f, 0.0f)
26 , world_collision(false)
32 void Entity::SetShape(const Shape *s, const glm::vec3 &color) {
35 shape->Vertices(model_buffer.vertices, model_buffer.normals, model_buffer.indices);
36 model_buffer.colors.resize(shape->VertexCount(), color);
37 model.Update(model_buffer);
40 void Entity::SetShapeless() noexcept {
45 void Entity::Velocity(const glm::vec3 &vel) noexcept {
49 void Entity::Position(const Block::Pos &pos) noexcept {
51 while (position.x >= Chunk::width) {
52 position.x -= Chunk::width;
55 while (position.x < 0) {
56 position.x += Chunk::width;
59 while (position.y >= Chunk::height) {
60 position.y -= Chunk::height;
63 while (position.y < 0) {
64 position.y += Chunk::height;
67 while (position.z >= Chunk::depth) {
68 position.z -= Chunk::depth;
71 while (position.z < 0) {
72 position.z += Chunk::depth;
77 void Entity::Move(const glm::vec3 &delta) noexcept {
78 Position(position + delta);
81 void Entity::AngularVelocity(const glm::quat &v) noexcept {
85 void Entity::Rotation(const glm::mat4 &rot) noexcept {
89 void Entity::Rotate(const glm::quat &delta) noexcept {
90 Rotation(rotation * glm::mat4_cast(delta));
93 glm::mat4 Entity::Transform(const Chunk::Pos &chunk_offset) const noexcept {
94 const glm::vec3 chunk_pos = (chunk - chunk_offset) * Chunk::Extent();
95 return glm::translate(position + chunk_pos) * rotation;
98 Ray Entity::Aim(const Chunk::Pos &chunk_offset) const noexcept {
99 glm::mat4 transform = Transform(chunk_offset);
100 glm::vec4 from = transform * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
102 glm::vec4 to = transform * glm::vec4(0.0f, 0.0f, -1.0f, 1.0f);
104 return Ray{ glm::vec3(from), glm::normalize(glm::vec3(to - from)) };
107 void Entity::Update(int dt) noexcept {
108 Move(velocity * float(dt));
109 Rotate(angular_velocity * float(dt));
113 void Entity::Draw() noexcept {