openrw/rwlib/source/data/Model.cpp

55 lines
981 B
C++
Raw Normal View History

#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()
{
2013-09-25 09:05:18 +01:00
}
2014-02-09 03:14:43 +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
}
Model::~Model()
{
for(auto mf : frames) {
delete mf;
}
}
float Model::getBoundingRadius() const
{
float mindist = std::numeric_limits<float>::min();
for (size_t g = 0; g < geometries.size(); g++)
{
RW::BSGeometryBounds& bounds = geometries[g]->geometryBounds;
mindist = std::max(mindist, glm::length(bounds.center) + bounds.radius);
}
return mindist;
}