6 #include <glm/gtx/transform.hpp>
10 blank::Model::Buffer model_buffer;
22 , angular_velocity(1.0f, 0.0f, 0.0f, 0.0f)
28 void Entity::SetShape(Shape *s, const glm::vec3 &color) {
31 shape->Vertices(model_buffer.vertices, model_buffer.normals, model_buffer.indices);
32 model_buffer.colors.resize(shape->VertexCount(), color);
33 model.Update(model_buffer);
36 void Entity::SetShapeless() {
41 void Entity::Velocity(const glm::vec3 &vel) {
45 void Entity::Position(const Block::Pos &pos) {
47 while (position.x >= Chunk::Width()) {
48 position.x -= Chunk::Width();
51 while (position.x < 0) {
52 position.x += Chunk::Width();
55 while (position.y >= Chunk::Height()) {
56 position.y -= Chunk::Height();
59 while (position.y < 0) {
60 position.y += Chunk::Height();
63 while (position.z >= Chunk::Depth()) {
64 position.z -= Chunk::Depth();
67 while (position.z < 0) {
68 position.z += Chunk::Depth();
73 void Entity::Move(const glm::vec3 &delta) {
74 Position(position + delta);
77 void Entity::AngularVelocity(const glm::quat &v) {
81 void Entity::Rotation(const glm::mat4 &rot) {
85 void Entity::Rotate(const glm::quat &delta) {
86 Rotation(rotation * glm::mat4_cast(delta));
89 glm::mat4 Entity::Transform(const Chunk::Pos &chunk_offset) const {
90 const glm::vec3 chunk_pos = (chunk - chunk_offset) * Chunk::Extent();
91 return glm::translate(position + chunk_pos) * rotation;
94 Ray Entity::Aim(const Chunk::Pos &chunk_offset) const {
95 glm::mat4 transform = Transform(chunk_offset);
96 glm::vec4 from = transform * glm::vec4(0.0f, 0.0f, 1.0f, 1.0f);
98 glm::vec4 to = transform * glm::vec4(0.0f, 0.0f, -1.0f, 1.0f);
100 return Ray{ glm::vec3(from), glm::normalize(glm::vec3(to - from)) };
103 void Entity::Update(int dt) {
104 Move(velocity * float(dt));
105 Rotate(angular_velocity * float(dt));
109 void Entity::Draw() {