]> git.localhorst.tv Git - blank.git/blobdiff - src/entity.cpp
drawable entity with angular velocity
[blank.git] / src / entity.cpp
index d72bd1cc20a2772019a9ab85fef51e6776579062..b24835030884be373db2d3a9adfcaeea2d8f42b5 100644 (file)
@@ -5,17 +5,39 @@
 #include <cmath>
 #include <glm/gtx/transform.hpp>
 
+namespace {
+
+blank::Model::Buffer model_buffer;
+
+}
 
 namespace blank {
 
 Entity::Entity()
-: velocity()
-, position()
+: shape(nullptr)
+, model()
+, velocity(0, 0, 0)
+, position(0, 0, 0)
+, chunk(0, 0, 0)
+, angular_velocity(1.0f, 0.0f, 0.0f, 0.0f)
 , rotation(1.0f) {
 
 }
 
 
+void Entity::SetShape(Shape *s, const glm::vec3 &color) {
+       shape = s;
+       model_buffer.Clear();
+       shape->Vertices(model_buffer.vertices, model_buffer.normals, model_buffer.indices);
+       model_buffer.colors.resize(shape->VertexCount(), color);
+       model.Update(model_buffer);
+}
+
+void Entity::SetShapeless() {
+       shape = nullptr;
+}
+
+
 void Entity::Velocity(const glm::vec3 &vel) {
        velocity = vel;
 }
@@ -52,10 +74,18 @@ void Entity::Move(const glm::vec3 &delta) {
        Position(position + delta);
 }
 
+void Entity::AngularVelocity(const glm::quat &v) {
+       angular_velocity = v;
+}
+
 void Entity::Rotation(const glm::mat4 &rot) {
        rotation = rot;
 }
 
+void Entity::Rotate(const glm::quat &delta) {
+       Rotation(rotation * glm::mat4_cast(delta));
+}
+
 glm::mat4 Entity::Transform(const Chunk::Pos &chunk_offset) const {
        const glm::vec3 chunk_pos = (chunk - chunk_offset) * Chunk::Extent();
        return glm::translate(position + chunk_pos) * rotation;
@@ -72,6 +102,12 @@ Ray Entity::Aim(const Chunk::Pos &chunk_offset) const {
 
 void Entity::Update(int dt) {
        Move(velocity * float(dt));
+       Rotate(angular_velocity * float(dt));
+}
+
+
+void Entity::Draw() {
+       model.Draw();
 }
 
 }