2016-04-07 02:13:46 +02:00
|
|
|
#include "data/Model.hpp"
|
2014-02-09 04:14:43 +01:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include <glm/gtc/matrix_transform.hpp>
|
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
Model::Geometry::Geometry() : flags(0) {
|
2013-09-25 10:05:18 +02:00
|
|
|
}
|
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
Model::Geometry::~Geometry() {
|
2013-09-25 10:05:18 +02:00
|
|
|
}
|
2014-02-09 04:14:43 +01:00
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
ModelFrame::ModelFrame(unsigned int index, ModelFrame* parent, glm::mat3 dR,
|
|
|
|
glm::vec3 dT)
|
|
|
|
: index(index)
|
|
|
|
, defaultRotation(dR)
|
|
|
|
, defaultTranslation(dT)
|
|
|
|
, parentFrame(parent) {
|
|
|
|
if (parent != nullptr) {
|
|
|
|
parent->childs.push_back(this);
|
|
|
|
}
|
|
|
|
reset();
|
2014-02-09 04:14:43 +01:00
|
|
|
}
|
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
void ModelFrame::reset() {
|
|
|
|
matrix = glm::translate(glm::mat4(), defaultTranslation) *
|
|
|
|
glm::mat4(defaultRotation);
|
2014-02-09 04:14:43 +01:00
|
|
|
}
|
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
void ModelFrame::addGeometry(size_t idx) {
|
|
|
|
geometries.push_back(idx);
|
2014-06-08 23:40:46 +02:00
|
|
|
}
|
2014-08-04 23:21:01 +02:00
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
Model::~Model() {
|
|
|
|
for (auto mf : frames) {
|
|
|
|
delete mf;
|
|
|
|
}
|
2014-08-04 23:21:01 +02:00
|
|
|
}
|
2015-04-06 05:06:35 +02:00
|
|
|
|
2016-09-09 22:13:21 +02:00
|
|
|
void Model::recalculateMetrics() {
|
|
|
|
boundingRadius = std::numeric_limits<float>::min();
|
|
|
|
for (size_t g = 0; g < geometries.size(); g++) {
|
|
|
|
RW::BSGeometryBounds& bounds = geometries[g]->geometryBounds;
|
|
|
|
boundingRadius = std::max(boundingRadius,
|
|
|
|
glm::length(bounds.center) + bounds.radius);
|
|
|
|
}
|
2015-04-06 05:06:35 +02:00
|
|
|
}
|