Przeglądaj źródła

Add Actor::update()

Daniele Bartolini 12 lat temu
rodzic
commit
d402d2500d
2 zmienionych plików z 18 dodań i 14 usunięć
  1. 13 4
      engine/physics/Actor.cpp
  2. 5 10
      engine/physics/Actor.h

+ 13 - 4
engine/physics/Actor.cpp

@@ -51,8 +51,10 @@ namespace crown
 {
 	
 //-----------------------------------------------------------------------------
-Actor::Actor(ActorType::Enum type, const Vector3& pos, const Quaternion& rot)
-	: m_type(type)
+Actor::Actor(SceneGraph& sg, int32_t node, ActorType::Enum type, const Vector3& pos, const Quaternion& rot)
+	: m_scene_graph(sg)
+	, m_node(node)
+	, m_type(type)
 {
 	Matrix4x4 m(rot, pos);
 	m.transpose();
@@ -68,9 +70,10 @@ Actor::Actor(ActorType::Enum type, const Vector3& pos, const Quaternion& rot)
 		case ActorType::DYNAMIC_PHYSICAL:
 		case ActorType::DYNAMIC_KINEMATIC:
 		{
+			Log::d("Created dynamic");
 			m_actor = device()->physx()->createRigidDynamic(PxTransform(pose));
-			static_cast<PxRigidDynamic*>(m_actor)->setRigidDynamicFlag(PxRigidDynamicFlag::eKINEMATIC,
-																			type == ActorType::DYNAMIC_KINEMATIC);
+			//static_cast<PxRigidDynamic*>(m_actor)->setRigidDynamicFlag(PxRigidDynamicFlag::eKINEMATIC,
+			//																type == ActorType::DYNAMIC_KINEMATIC);
 			break;
 		}
 		default:
@@ -80,6 +83,7 @@ Actor::Actor(ActorType::Enum type, const Vector3& pos, const Quaternion& rot)
 		}
 	}
 
+	m_actor->userData = this;
 	m_mat = device()->physx()->createMaterial(0.5f, 0.5f, 0.5f);
 
 	// FIXME
@@ -215,5 +219,10 @@ void Actor::wake_up()
 	((PxRigidDynamic*)m_actor)->wakeUp();
 }
 
+//-----------------------------------------------------------------------------
+void Actor::update(const Matrix4x4& pose)
+{
+	m_scene_graph.set_world_pose(m_node, pose);
+}
 
 } // namespace crown

+ 5 - 10
engine/physics/Actor.h

@@ -50,22 +50,13 @@ class SceneGraph;
 
 struct Actor
 {
-						Actor(ActorType::Enum type, const Vector3& pos, const Quaternion& rot);
+						Actor(SceneGraph& sg, int32_t node, ActorType::Enum type, const Vector3& pos, const Quaternion& rot);
 						~Actor();
 
 	void				create_sphere(const Vector3& position, float radius);
 	void				create_box(const Vector3& position, float a, float b, float c);
 	void				create_plane(const Vector3& position, const Vector3& normal);
 
-	Matrix4x4 world_pose()
-	{
-		physx::PxTransform t = m_actor->getGlobalPose();
-
-		Vector3 pos(t.p.x, t.p.y, t.p.z);
-		Quaternion rot(t.q.x, t.q.y, t.q.z, t.q.w);
-		return Matrix4x4(rot, pos);
-	}
-
 	void				enable_gravity();
 	void				disable_gravity();
 
@@ -90,8 +81,12 @@ struct Actor
 	bool				is_sleeping();
 	void				wake_up();
 
+	void				update(const Matrix4x4& pose);
+
 public:
 
+	SceneGraph&			m_scene_graph;
+	int32_t				m_node;
 	PxRigidActor* 		m_actor;
 	PxMaterial* 		m_mat;
 	ActorType::Enum 	m_type;