@@ -13,16 +13,58 @@ int main()
1313 std::shared_ptr<GameObject> room = engine.CreateGameObject ();
1414 room->loadMesh (" assets/models/viking_room.obj" );
1515 room->bindMatToMesh (0 , room_texture);
16- room->setPosition ({ 3 .0f , 0 .0f , 0 .0f });
16+ room->setPosition ({ 3 .0f , 0 .0f , 3 .0f });
1717
1818 std::shared_ptr<Material> room2_texture = engine.CreateMaterial (TSHADER::NO_TEXTURE);
1919 std::shared_ptr<GameObject> room2 = engine.CreateGameObject ();
2020 room2->loadMesh (" assets/models/viking_room.obj" );
2121 room2->bindMatToMesh (0 , room2_texture);
2222 room2->setPosition ({ 6 .0f , 0 .0f , 0 .0f });
2323
24+ std::shared_ptr<Material> cube_texture = engine.CreateMaterial (TSHADER::NO_TEXTURE);
25+ std::shared_ptr<GameObject> cube = engine.CreateCube ({ 2 .0f , .0f , .0f }, 1 .f , {1 .f , .0f , .0f });
26+ cube->bindMatToMesh (0 , cube_texture);
27+
28+ const float half_size = 1 .f / 2 .f ;
29+ Geometry voxel;
30+
31+ // vertices
32+ uint32_t index_0 = voxel.addVertex ({ 0 .f - half_size, 0 .f - half_size, -2 .f - half_size }, { 0 .f , 1 .f , 0 .f }, { .0f , .0f });
33+ uint32_t index_1 = voxel.addVertex ({ 0 .f + half_size, 0 .f - half_size, -2 .f - half_size }, { 0 .f , 1 .f , 0 .f }, { .0f , 2 .0f });
34+ uint32_t index_2 = voxel.addVertex ({ 0 .f - half_size, 0 .f + half_size, -2 .f - half_size }, { 0 .f , 1 .f , 0 .f }, { 2 .0f , .0f });
35+ uint32_t index_3 = voxel.addVertex ({ 0 .f + half_size, 0 .f + half_size, -2 .f - half_size }, { 0 .f , 1 .f , 0 .f }, { 2 .0f , .0f });
36+ uint32_t index_4 = voxel.addVertex ({ 0 .f - half_size, 0 .f - half_size, -2 .f + half_size }, { 0 .f , 1 .f , 0 .f }, { .0f , .0f });
37+ uint32_t index_5 = voxel.addVertex ({ 0 .f + half_size, 0 .f - half_size, -2 .f + half_size }, { 0 .f , 1 .f , 0 .f }, { .0f , 2 .0f });
38+ uint32_t index_6 = voxel.addVertex ({ 0 .f - half_size, 0 .f + half_size, -2 .f + half_size }, { 0 .f , 1 .f , 0 .f }, { 2 .0f , .0f });
39+ uint32_t index_7 = voxel.addVertex ({ 0 .f + half_size, 0 .f + half_size, -2 .f + half_size }, { 0 .f , 1 .f , 0 .f }, { 2 .0f , 2 .0f });
40+
41+ // indices
42+ voxel.addIndices (index_0, index_2, index_1);
43+ voxel.addIndices (index_1, index_2, index_3);
44+
45+ voxel.addIndices (index_5, index_7, index_4);
46+ voxel.addIndices (index_4, index_7, index_6);
47+
48+ voxel.addIndices (index_1, index_3, index_5);
49+ voxel.addIndices (index_5, index_3, index_7);
50+
51+ voxel.addIndices (index_4, index_6, index_0);
52+ voxel.addIndices (index_0, index_6, index_2);
53+
54+ voxel.addIndices (index_2, index_6, index_3);
55+ voxel.addIndices (index_3, index_6, index_7);
56+
57+ voxel.addIndices (index_4, index_0, index_5);
58+ voxel.addIndices (index_5, index_0, index_1);
59+
60+ cube->LoadMesh (voxel.vertices , voxel.indices );
61+
62+ cube->bindMatToMesh (1 , cube_texture);
63+
2464 std::shared_ptr<Scene> scene = std::make_shared<Scene>();
2565 scene->addGameObject (room);
66+ scene->addGameObject (room2);
67+ scene->addGameObject (cube);
2668
2769 engine.setScene (scene);
2870
@@ -45,9 +87,17 @@ int main()
4587 // running loop
4688 do
4789 {
48- if (init++ == 30000 )
90+ // cube->setPosition(cube->getPosition() + glm::vec3{0.0001f, 0.f, 0.f});
91+
92+ if (init++ == 10000 )
4993 {
50- scene->addGameObject (room2);
94+ Geometry v;
95+ v.vertices = cube->GetVertices (1 );
96+ v.indices = cube->GetIndices (1 );
97+ v.vertices [0 ].color = { .0f , .0f , 1 .0f };
98+
99+ cube->UpdateMesh (1 , v.vertices , v.indices );
100+ scene->Update ();
51101 }
52102
53103 engine.update ();
0 commit comments