From 22322d50fd7e52aa2e01afbefaff58aecbd5336f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20=E2=80=98Touky=E2=80=99=20Huet?= Date: Thu, 23 Apr 2015 05:00:03 +0000 Subject: [PATCH] Scene::AddPrimitive now only supports Primitive because why not --- doc/samples/meshviewer/meshviewer.cpp | 14 +++++++------- doc/samples/physicobject.h | 4 ++-- doc/tutorial/05_easymesh.cpp | 2 +- src/mesh/mesh.cpp | 6 ++++++ src/mesh/mesh.h | 2 ++ src/scene.cpp | 10 ---------- src/scene.h | 1 - 7 files changed, 18 insertions(+), 21 deletions(-) diff --git a/doc/samples/meshviewer/meshviewer.cpp b/doc/samples/meshviewer/meshviewer.cpp index 117a33a2..674a4dfd 100644 --- a/doc/samples/meshviewer/meshviewer.cpp +++ b/doc/samples/meshviewer/meshviewer.cpp @@ -101,7 +101,7 @@ void EasyMeshViewerObject::TickDraw(float seconds, Scene &scene) switch (m_mesh.GetMeshState().ToScalar()) { case MeshRender::NeedConvert: { m_mesh.MeshConvert(); break; } - case MeshRender::CanRender: { scene.AddPrimitive(m_mesh, mat4::identity/*TODO:FIX THAT*/); break; } + case MeshRender::CanRender: { m_mesh.Render(scene, mat4::identity/*TODO:FIX THAT*/); break; } default: break; } } @@ -1030,12 +1030,12 @@ void MeshViewer::Draw(float seconds, Scene &scene) //Camera projection mat4 new_proj = mat_obj_offset * mat_count_offset * mat_align * mat_count_scale * save_proj; m_camera->SetProjection(new_proj); - scene.AddPrimitive(*m_meshes[i].m1, m_mat); + m_meshes[i].m1->Render(scene, m_mat); g_renderer->Clear(ClearMask::Depth); } m_camera->SetProjection(save_proj); #else - scene.AddPrimitive(*m_meshes[i].m1, m_mat); + m_meshes[i].m1->Render(scene, m_mat); #endif //ALL_FEATURES } } @@ -1045,7 +1045,7 @@ void MeshViewer::Draw(float seconds, Scene &scene) { m_camera->SetProjection(mat_gizmo); if (m_ssetup->m_show_gizmo) - scene.AddPrimitive(*m_gizmos[GZ_Editor], m_mat); + m_gizmos[GZ_Editor]->Render(scene, m_mat); if (m_ssetup->m_show_lights) { @@ -1057,12 +1057,12 @@ void MeshViewer::Draw(float seconds, Scene &scene) //dir light if (ltmp->GetType() == LightType::Directional) { - scene.AddPrimitive(*m_gizmos[GZ_LightPos], m_mat * inverse(local)); - scene.AddPrimitive(*m_gizmos[GZ_LightDir], inverse(world) * inverse(mat4::lookat(vec3::zero, -ltmp->GetPosition(), vec3::axis_y))); + m_gizmos[GZ_LightPos]->Render(scene, m_mat * inverse(local)); + m_gizmos[GZ_LightDir]->Render(scene, inverse(world) * inverse(mat4::lookat(vec3::zero, -ltmp->GetPosition(), vec3::axis_y))); } else //point light { - scene.AddPrimitive(*m_gizmos[GZ_LightPos], m_mat * local); + m_gizmos[GZ_LightPos]->Render(scene, m_mat * local); } } } diff --git a/doc/samples/physicobject.h b/doc/samples/physicobject.h index af50fa8d..e1c9cfe6 100644 --- a/doc/samples/physicobject.h +++ b/doc/samples/physicobject.h @@ -334,9 +334,9 @@ protected: else if (m_should_render) { if (m_is_character) - scene.AddPrimitive(m_mesh, m_character->GetTransform()); + m_mesh.Render(scene, m_character->GetTransform()); else - scene.AddPrimitive(m_mesh, m_physics->GetTransform()); + m_mesh.Render(scene, m_physics->GetTransform()); } } } diff --git a/doc/tutorial/05_easymesh.cpp b/doc/tutorial/05_easymesh.cpp index 2fad7bd4..10e79a9d 100644 --- a/doc/tutorial/05_easymesh.cpp +++ b/doc/tutorial/05_easymesh.cpp @@ -146,7 +146,7 @@ public: for (int i = 0; i < m_gears.Count(); i++) { - scene.AddPrimitive(m_gears[i].m1, m_mat * m_gears[i].m2); + m_gears[i].m1.Render(scene, m_mat * m_gears[i].m2); } } diff --git a/src/mesh/mesh.cpp b/src/mesh/mesh.cpp index 4c40ba8f..14894e77 100644 --- a/src/mesh/mesh.cpp +++ b/src/mesh/mesh.cpp @@ -28,6 +28,12 @@ Mesh::~Mesh() { } +void Mesh::Render(Scene& scene, mat4 const &matrix) +{ + for (int i = 0; i < m_submeshes.Count(); ++i) + scene.AddPrimitive(new PrimitiveMesh(m_submeshes[i], matrix)); +} + void Mesh::Render() { for (int i = 0; i < m_submeshes.Count(); ++i) diff --git a/src/mesh/mesh.h b/src/mesh/mesh.h index 1fe544b1..a25aaaee 100644 --- a/src/mesh/mesh.h +++ b/src/mesh/mesh.h @@ -59,6 +59,8 @@ public: * may behave differently between submeshes. */ void SetMaterial(Shader *shader); + //TODO: Not sure about the name + void Render(Scene& scene, mat4 const &matrix); protected: void Render(); diff --git a/src/scene.cpp b/src/scene.cpp index aec95d2d..2834a2e1 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -254,16 +254,6 @@ void Scene::Reset() data->m_primitives.Empty(); } -//----------------------------------------------------------------------------- -/*TODO: SAM/TOUKY: Change that*/ -void Scene::AddPrimitive(Mesh const &mesh, mat4 const &matrix) -{ - for (int i = 0; i < mesh.m_submeshes.Count(); ++i) - { - AddPrimitive(new PrimitiveMesh(mesh.m_submeshes[i], matrix)); - } -} - //----------------------------------------------------------------------------- void Scene::AddPrimitive(Primitive* primitive) { diff --git a/src/scene.h b/src/scene.h index 0d998443..84e289e3 100644 --- a/src/scene.h +++ b/src/scene.h @@ -93,7 +93,6 @@ public: void Reset(); /* New scenegraph */ - void AddPrimitive(Mesh const &mesh, mat4 const &matrix); void AddPrimitive(Primitive* primitive); void AddPrimitive(Entity* entity, Primitive* primitive);