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 Chunk::Pos &c, const Block::Pos &pos) noexcept {
54 void Entity::Position(const Block::Pos &pos) noexcept {
56 while (position.x >= Chunk::width) {
57 position.x -= Chunk::width;
60 while (position.x < 0) {
61 position.x += Chunk::width;
64 while (position.y >= Chunk::height) {
65 position.y -= Chunk::height;
68 while (position.y < 0) {
69 position.y += Chunk::height;
72 while (position.z >= Chunk::depth) {
73 position.z -= Chunk::depth;
76 while (position.z < 0) {
77 position.z += Chunk::depth;
82 void Entity::Move(const glm::vec3 &delta) noexcept {
83 Position(position + delta);
86 void Entity::AngularVelocity(const glm::quat &v) noexcept {
90 void Entity::Rotation(const glm::mat4 &rot) noexcept {
94 void Entity::Rotate(const glm::quat &delta) noexcept {
95 Rotation(rotation * glm::mat4_cast(delta));
98 glm::mat4 Entity::Transform(const Chunk::Pos &chunk_offset) const noexcept {
99 const glm::vec3 chunk_pos = (chunk - chunk_offset) * Chunk::Extent();
100 return glm::translate(position + chunk_pos) * rotation;
103 Ray Entity::Aim(const Chunk::Pos &chunk_offset) const noexcept {
104 glm::mat4 transform = Transform(chunk_offset);
105 glm::vec4 from = transform * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
107 glm::vec4 to = transform * glm::vec4(0.0f, 0.0f, -1.0f, 1.0f);
109 return Ray{ glm::vec3(from), glm::normalize(glm::vec3(to - from)) };
112 void Entity::Update(int dt) noexcept {
113 Move(velocity * float(dt));
114 Rotate(angular_velocity * float(dt));
118 void Entity::Draw() noexcept {