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

pass PhysicsActor to Actor

mikymod пре 12 година
родитељ
комит
ac5efafbad
4 измењених фајлова са 27 додато и 22 уклоњено
  1. 14 12
      engine/physics/Actor.cpp
  2. 9 7
      engine/physics/Actor.h
  3. 2 2
      engine/physics/PhysicsWorld.cpp
  4. 2 1
      engine/physics/PhysicsWorld.h

+ 14 - 12
engine/physics/Actor.cpp

@@ -32,6 +32,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #include "Device.h"
 #include "Physics.h"
 #include "Log.h"
+#include "PhysicsResource.h"
 #include "SceneGraph.h"
 #include "PxPhysicsAPI.h"
 
@@ -58,17 +59,17 @@ namespace crown
 {
 	
 //-----------------------------------------------------------------------------
-Actor::Actor(PxScene* scene, SceneGraph& sg, int32_t node, ActorType::Enum type, const Vector3& pos, const Quaternion& rot)
-	: m_scene(scene)
+Actor::Actor(const PhysicsActor& resource, PxScene* scene, SceneGraph& sg, int32_t node, const Vector3& pos, const Quaternion& rot)
+	: m_resource(resource)
+	, m_scene(scene)
 	, m_scene_graph(sg)
 	, m_node(node)
-	, m_type(type)
 {
 	Matrix4x4 m = sg.world_pose(node);
 
 	PxMat44 pose((PxReal*)(m.to_float_ptr()));
 
-	switch (type)
+	switch (m_resource.type)
 	{
 		case ActorType::STATIC:
 		{
@@ -80,7 +81,7 @@ Actor::Actor(PxScene* scene, SceneGraph& sg, int32_t node, ActorType::Enum type,
 		{
 			m_actor = device()->physx()->createRigidDynamic(PxTransform(pose));
 
-			if (type == ActorType::DYNAMIC_KINEMATIC)
+			if (m_resource.type == ActorType::DYNAMIC_KINEMATIC)
 			{
 				static_cast<PxRigidDynamic*>(m_actor)->setRigidDynamicFlag(PxRigidDynamicFlag::eKINEMATIC, true);
 			}
@@ -98,7 +99,7 @@ Actor::Actor(PxScene* scene, SceneGraph& sg, int32_t node, ActorType::Enum type,
 	
 	create_box(Vector3(0, 0, 0), .5, .5, .5);
 
-	if (type == ActorType::DYNAMIC_PHYSICAL || type == ActorType::DYNAMIC_KINEMATIC)
+	if (m_resource.type == ActorType::DYNAMIC_PHYSICAL || m_resource.type == ActorType::DYNAMIC_KINEMATIC)
 	{
 		PxRigidBodyExt::setMassAndUpdateInertia(*static_cast<PxRigidDynamic*>(m_actor), 500.0f);
 
@@ -132,6 +133,7 @@ void Actor::create_sphere(const Vector3& position, float radius)
 //-----------------------------------------------------------------------------
 void Actor::create_box(const Vector3& position, float a, float b, float c)
 {
+	Log::i("x: %f, y: %f, z; %f", a, b, c);
 	m_actor->createShape(PxBoxGeometry(a, b, c), *m_mat);
 }
 
@@ -156,25 +158,25 @@ void Actor::disable_gravity()
 //-----------------------------------------------------------------------------
 bool Actor::is_static() const
 {
-	return m_type == ActorType::STATIC;
+	return m_resource.type == ActorType::STATIC;
 }
 
 //-----------------------------------------------------------------------------
 bool Actor::is_dynamic() const
 {
-	return m_type == ActorType::DYNAMIC_PHYSICAL || m_type == ActorType::DYNAMIC_KINEMATIC;
+	return m_resource.type == ActorType::DYNAMIC_PHYSICAL || m_resource.type == ActorType::DYNAMIC_KINEMATIC;
 }
 
 //-----------------------------------------------------------------------------
 bool Actor::is_kinematic() const
 {
-	return m_type == ActorType::DYNAMIC_KINEMATIC;
+	return m_resource.type == ActorType::DYNAMIC_KINEMATIC;
 }
 
 //-----------------------------------------------------------------------------
 bool Actor::is_physical() const
 {
-	return m_type == ActorType::DYNAMIC_PHYSICAL;
+	return m_resource.type == ActorType::DYNAMIC_PHYSICAL;
 }
 
 //-----------------------------------------------------------------------------
@@ -251,7 +253,7 @@ void Actor::update_pose()
 	const PxMat44 pose((PxReal*) (wp.to_float_ptr()));
 	const PxTransform world_transform(pose);
 
-	switch (m_type)
+	switch (m_resource.type)
 	{
 		case ActorType::STATIC:
 		{
@@ -274,7 +276,7 @@ void Actor::update_pose()
 void Actor::update(const Matrix4x4& pose)
 {
 
-	if (m_type == ActorType::DYNAMIC_PHYSICAL)
+	if (m_resource.type == ActorType::DYNAMIC_PHYSICAL)
 	{
 		m_scene_graph.set_world_pose(m_node, pose);
 	}

+ 9 - 7
engine/physics/Actor.h

@@ -43,6 +43,7 @@ using physx::PxScene;
 namespace crown
 {
 
+struct PhysicsActor;
 struct Quaternion;
 struct Matrix4x4;
 struct Unit;
@@ -50,7 +51,7 @@ class SceneGraph;
 
 struct Actor
 {
-						Actor(PxScene* scene, SceneGraph& sg, int32_t node, ActorType::Enum type, const Vector3& pos, const Quaternion& rot);
+						Actor(const PhysicsActor& resource, PxScene* scene, SceneGraph& sg, int32_t node, const Vector3& pos, const Quaternion& rot);
 						~Actor();
 
 	void				enable_gravity();
@@ -88,12 +89,13 @@ private:
 	
 public:
 
-	PxScene*			m_scene;
-	SceneGraph&			m_scene_graph;
-	int32_t				m_node;
-	PxRigidActor* 		m_actor;
-	PxMaterial* 		m_mat;
-	ActorType::Enum 	m_type;
+	const PhysicsActor&		m_resource;
+
+	PxScene*				m_scene;
+	SceneGraph&				m_scene_graph;
+	int32_t					m_node;
+	PxRigidActor* 			m_actor;
+	PxMaterial* 			m_mat;
 };
 
 } // namespace crown

+ 2 - 2
engine/physics/PhysicsWorld.cpp

@@ -104,9 +104,9 @@ PhysicsWorld::~PhysicsWorld()
 }
 
 //-----------------------------------------------------------------------------
-ActorId	PhysicsWorld::create_actor(SceneGraph& sg, int32_t node, ActorType::Enum type)
+ActorId	PhysicsWorld::create_actor(const PhysicsActor& resource, SceneGraph& sg, int32_t node)
 {
-	Actor* actor = CE_NEW(m_actors_pool, Actor)(m_scene, sg, node, type, Vector3::ZERO, Quaternion::IDENTITY);
+	Actor* actor = CE_NEW(m_actors_pool, Actor)(resource, m_scene, sg, node, Vector3::ZERO, Quaternion::IDENTITY);
 	return m_actors.create(actor);
 }
 

+ 2 - 1
engine/physics/PhysicsWorld.h

@@ -46,6 +46,7 @@ namespace crown
 {
 
 struct PhysicsResource;
+struct PhysicsActor;
 struct Controller;
 struct Vector3;
 struct Actor;
@@ -61,7 +62,7 @@ public:
 								PhysicsWorld();
 								~PhysicsWorld();
 
-	ActorId						create_actor(SceneGraph& sg, int32_t node, ActorType::Enum type);
+	ActorId						create_actor(const PhysicsActor& resource, SceneGraph& sg, int32_t node);
 	void						destroy_actor(ActorId id);
 
 	ControllerId				create_controller(const PhysicsResource* pr, SceneGraph& sg, int32_t node);