static mesh finish

This commit is contained in:
h4570
2022-07-18 21:42:11 +02:00
parent f249936981
commit 34c553af04
15 changed files with 213 additions and 146 deletions
+44 -5
View File
@@ -13,14 +13,53 @@
namespace Tyra {
Mesh::Mesh(const u8& isMother) {
id = rand() % 1000000;
_isMother = isMother;
translation.translate(Vec4(0.0F, 0.0F, 0.0F, 1.0F));
Mesh::Mesh(const MeshBuilderData& data) {
init();
TYRA_ASSERT(data.materialsCount > 0,
"Materials count must be greater than 0");
materialsCount = data.materialsCount;
materials = new MeshMaterial*[materialsCount];
for (u32 i = 0; i < materialsCount; i++) {
materials[i] = new MeshMaterial(data, i);
}
_isMother = true;
}
Mesh::Mesh(const Mesh& mesh) {
init();
materialsCount = mesh.materialsCount;
materials = new MeshMaterial*[materialsCount];
for (u32 i = 0; i < materialsCount; i++) {
materials[i] = new MeshMaterial(*mesh.materials[i]);
}
_isMother = false;
}
M4x4 Mesh::getModelMatrix() const { return translation * rotation * scale; }
Mesh::~Mesh() {}
Mesh::~Mesh() {
for (u32 i = 0; i < materialsCount; i++) {
delete materials[i];
}
delete[] materials;
}
void Mesh::init() {
id = rand() % 1000000;
materialsCount = 0;
translation.translate(Vec4(0.0F, 0.0F, 0.0F, 1.0F));
}
void Mesh::setPosition(const Vec4& v) {
TYRA_ASSERT(v.w == 1.0F, "Vec4 must be homogeneous");
reinterpret_cast<Vec4*>(&translation.data[3 * 4])->set(v);
}
} // namespace Tyra