File size: 973 Bytes
8be366a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#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);
	}
}