ICT290 / src / engine / object.cpp
object.cpp
Raw
#include "object.h"
#include <algorithm>
#include "../glIncludes.h"

Object::Object(std::string name_,
               glm::vec3 location_,
               glm::vec3 rotation_,
               glm::vec3 scale_)
    : name(std::move(name_)),
      location(location_),
      rotation(rotation_),
      scale(scale_) {}

Object::Object(std::string name_,
               std::shared_ptr<Model>& model_,
               glm::vec3 location_,
               glm::vec3 rotation_,
               glm::vec3 scale_)
    : name(std::move(name_)),
      model(model_),
      location(location_),
      rotation(rotation_),
      scale(scale_) {}

void Object::draw() const {
    glPushMatrix();
    glTranslatef(location.x, location.y, location.z);
    glRotatef(rotation.x, 1, 0, 0);
    glRotatef(rotation.y, 0, 1, 0);
    glRotatef(rotation.z, 0, 0, 1);
    glScalef(scale.x, scale.y, scale.z);
    if (model != nullptr) {
        model->draw();
    }
    glPopMatrix();
}