Преглед изворни кода

Correctly initialize scene graph

Daniele Bartolini пре 12 година
родитељ
комит
4e25ee70db
4 измењених фајлова са 13 додато и 10 уклоњено
  1. 11 2
      engine/world/SceneGraph.cpp
  2. 1 1
      engine/world/SceneGraph.h
  3. 1 3
      engine/world/Unit.cpp
  4. 0 4
      engine/world/World.cpp

+ 11 - 2
engine/world/SceneGraph.cpp

@@ -52,7 +52,7 @@ SceneGraph::SceneGraph(Allocator& a, uint32_t index)
 }
 
 //-----------------------------------------------------------------------------
-void SceneGraph::create(uint32_t count, const StringId32* name, const Matrix4x4* local, int32_t* parent)
+void SceneGraph::create(const Matrix4x4& root, uint32_t count, const StringId32* name, const Matrix4x4* local, int32_t* parent)
 {
 	char* mem = (char*) m_allocator->allocate(count * (sizeof(uint8_t) + sizeof(Matrix4x4) + sizeof(Matrix4x4) + sizeof(int32_t) + sizeof(StringId32)));
 
@@ -64,11 +64,20 @@ void SceneGraph::create(uint32_t count, const StringId32* name, const Matrix4x4*
 	m_parents = (int32_t*) mem; mem += sizeof(int32_t) * count;
 	m_names = (StringId32*) mem; mem += sizeof(StringId32) * count;
 
-	memset(m_flags, (int) LOCAL_DIRTY, sizeof(uint8_t) * count);
+	memset(m_flags, (int) CLEAN, sizeof(uint8_t) * count);
 	memcpy(m_local_poses, local, sizeof(Matrix4x4) * count);
 	memcpy(m_parents, parent, sizeof(int32_t) * count);
 	memcpy(m_names, name, sizeof(StringId32) * count);
 
+	// Compute initial world poses
+	for (uint32_t i = 1; i < m_num_nodes; i++)
+	{
+		m_world_poses[i] = root * m_local_poses[i];
+	}
+
+	m_world_poses[0] = root;
+	m_flags[0] = WORLD_DIRTY;
+
 	update();
 }
 

+ 1 - 1
engine/world/SceneGraph.h

@@ -44,7 +44,7 @@ struct SceneGraph
 	/// @a name, @a local and @parent are the array containing the name of the nodes,
 	/// the local poses of the nodes and the links between the nodes respectively.
 	/// A parent of -1 means "no parent".
-	void			create(uint32_t count, const StringId32* name, const Matrix4x4* local, int32_t* parent);
+	void			create(const Matrix4x4& root, uint32_t count, const StringId32* name, const Matrix4x4* local, int32_t* parent);
 
 	/// Destroys the graph deallocating memory if necessary.
 	void			destroy();

+ 1 - 3
engine/world/Unit.cpp

@@ -84,10 +84,8 @@ const UnitResource*	Unit::resource() const
 void Unit::create_objects(const Matrix4x4& pose)
 {
 	// Create the scene graph
-	m_scene_graph.create(m_resource->num_scene_graph_nodes(), m_resource->scene_graph_names(),
+	m_scene_graph.create(pose, m_resource->num_scene_graph_nodes(), m_resource->scene_graph_names(),
 							m_resource->scene_graph_poses(), m_resource->scene_graph_parents());
-	// Set root node's pose
-	m_scene_graph.set_world_pose(0, pose);
 
 	create_camera_objects();
 	create_renderable_objects();

+ 0 - 4
engine/world/World.cpp

@@ -157,10 +157,6 @@ Camera* World::lookup_camera(CameraId camera)
 //-----------------------------------------------------------------------------
 void World::update(float dt)
 {
-	// Update scene graphs
-	m_scenegraph_manager.update();
-
-	// Update physics world
 	m_physics_world.update(dt);
 
 	m_scenegraph_manager.update();