1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-12 22:02:49 +01:00
openrw/rwlib/source/data/Model.cpp
Daniel Evans 3e9b0c64e4 Re-implement object rendering using a depth-sorted approach.
This moves the object rendering logic into ObjectRenderer. This makes
GameRenderer a bit smaller.

There are some rendering logic decisions that haven't been brought
back yet since they may be better placed elsewhere.
2016-04-19 01:20:54 +01:00

54 lines
973 B
C++

#include "data/Model.hpp"
#include <iostream>
#include <glm/gtc/matrix_transform.hpp>
Model::Geometry::Geometry()
: flags(0)
{
}
Model::Geometry::~Geometry()
{
}
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();
}
void ModelFrame::reset()
{
matrix = glm::translate(glm::mat4(), defaultTranslation) * glm::mat4(defaultRotation);
}
void ModelFrame::addGeometry(size_t idx)
{
geometries.push_back(idx);
}
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);
}
}