]> git.localhorst.tv Git - blank.git/blobdiff - src/model/composite.cpp
random stuff
[blank.git] / src / model / composite.cpp
index ffb58572eae4bafaceea5f14978a8ec36e7b9089..f43b7264a57ef60463fc600997a7d71a7ff34ac5 100644 (file)
 namespace blank {
 
 CompositeModel::CompositeModel()
-: node_model(nullptr)
+: parent(nullptr)
+, node_model(nullptr)
+, id(0)
+, bounds{{ 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 0.0f }}
 , position(0.0f)
 , orientation(1.0f, 0.0f, 0.0f, 0.0f)
 , parts() {
@@ -114,31 +117,40 @@ Skeletons::~Skeletons() {
 
 void Skeletons::LoadHeadless() {
        skeletons.clear();
-       skeletons.reserve(3);
+       skeletons.reserve(4);
        {
-               AABB bounds{{ -0.25f, -0.5f, -0.25f }, { 0.25f, 0.5f, 0.25f }};
+               AABB bounds{{ -0.5f, -0.5f, -0.5f }, { 0.5f, 0.5f, 0.5f }};
                skeletons.emplace_back(new CompositeModel);
+               skeletons[0]->ID(1);
                skeletons[0]->Bounds(bounds);
        }
        {
                AABB bounds{{ -0.5f, -0.25f, -0.5f }, { 0.5f, 0.25f, 0.5f }};
                skeletons.emplace_back(new CompositeModel);
+               skeletons[1]->ID(2);
                skeletons[1]->Bounds(bounds);
        }
        {
-               AABB bounds{{ -0.5f, -0.5f, -0.5f }, { 0.5f, 0.5f, 0.5f }};
+               AABB bounds{{ -0.25f, -0.5f, -0.25f }, { 0.25f, 0.5f, 0.25f }};
                skeletons.emplace_back(new CompositeModel);
+               skeletons[2]->ID(3);
                skeletons[2]->Bounds(bounds);
        }
+       {
+               AABB bounds{{ -0.25f, -0.5f, -0.35f }, { 0.25f, 0.5f, 0.35f }};
+               skeletons.emplace_back(new CompositeModel);
+               skeletons[3]->ID(4);
+               skeletons[3]->Bounds(bounds);
+       }
 }
 
 void Skeletons::Load() {
        LoadHeadless();
-       models.resize(3);
+       models.resize(4);
        EntityModel::Buffer buf;
        {
                CuboidShape shape(skeletons[0]->Bounds());
-               shape.Vertices(buf, 1.0f);
+               shape.Vertices(buf, 3.0f);
                buf.colors.resize(shape.VertexCount(), { 1.0f, 1.0f, 0.0f });
                models[0].Update(buf);
                skeletons[0]->SetNodeModel(&models[0]);
@@ -146,7 +158,7 @@ void Skeletons::Load() {
        {
                CuboidShape shape(skeletons[1]->Bounds());
                buf.Clear();
-               shape.Vertices(buf, 2.0f);
+               shape.Vertices(buf, 0.0f);
                buf.colors.resize(shape.VertexCount(), { 0.0f, 1.0f, 1.0f });
                models[1].Update(buf);
                skeletons[1]->SetNodeModel(&models[1]);
@@ -154,11 +166,35 @@ void Skeletons::Load() {
        {
                StairShape shape(skeletons[2]->Bounds(), { 0.4f, 0.4f });
                buf.Clear();
-               shape.Vertices(buf, 3.0f);
+               shape.Vertices(buf, 1.0f);
                buf.colors.resize(shape.VertexCount(), { 1.0f, 0.0f, 1.0f });
                models[2].Update(buf);
                skeletons[2]->SetNodeModel(&models[2]);
        }
+       {
+               CuboidShape shape(skeletons[3]->Bounds());
+               buf.Clear();
+               shape.Vertices(buf, 2.0f);
+               buf.colors.resize(shape.VertexCount(), { 1.0f, 0.25f, 0.5f });
+               models[3].Update(buf);
+               skeletons[3]->SetNodeModel(&models[3]);
+       }
+}
+
+CompositeModel *Skeletons::ByID(std::uint16_t id) noexcept {
+       if (id == 0 || id > skeletons.size()) {
+               return nullptr;
+       } else {
+               return skeletons[id - 1].get();
+       }
+}
+
+const CompositeModel *Skeletons::ByID(std::uint16_t id) const noexcept {
+       if (id == 0 || id > skeletons.size()) {
+               return nullptr;
+       } else {
+               return skeletons[id - 1].get();
+       }
 }
 
 }