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