1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-07 03:12:36 +01:00
openrw/rwlib/source/data/Model.cpp

47 lines
1.1 KiB
C++
Raw Normal View History

#include "data/Model.hpp"
2014-02-09 04:14:43 +01:00
#include <iostream>
#include <glm/gtc/matrix_transform.hpp>
Model::Geometry::Geometry() : flags(0) {
2013-09-25 10:05:18 +02:00
}
Model::Geometry::~Geometry() {
2013-09-25 10:05:18 +02:00
}
2014-02-09 04:14:43 +01: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
}
void ModelFrame::reset() {
matrix = glm::translate(glm::mat4(), defaultTranslation) *
glm::mat4(defaultRotation);
2014-02-09 04:14:43 +01:00
}
void ModelFrame::addGeometry(size_t idx) {
geometries.push_back(idx);
2014-06-08 23:40:46 +02:00
}
Model::~Model() {
for (auto mf : frames) {
delete mf;
}
}
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);
}
}