ソースを参照

replace create_sphere/box/plane with create_shape in Actor

mikymod 12 年 前
コミット
7b854f07a0
2 ファイル変更35 行追加38 行削除
  1. 33 35
      engine/physics/Actor.cpp
  2. 2 3
      engine/physics/Actor.h

+ 33 - 35
engine/physics/Actor.cpp

@@ -120,31 +120,11 @@ Actor::Actor(const PhysicsResource* res, uint32_t index, PxPhysics* physics, PxS
 	uint32_t shape_index = m_resource->shape_index(m_index);
 	for (uint32_t i = 0; i < a.num_shapes; i++)
 	{
-		PhysicsShape shape = m_resource->shape(shape_index);
+		const PhysicsShape& shape = m_resource->shape(shape_index);
 		Vector3 pos = sg.world_position(node);
 
-		switch(shape.type)
-		{
-			case PhysicsShapeType::SPHERE:
-			{
-				create_sphere(pos, shape.data_0);
-				break;
-			}
-			case PhysicsShapeType::BOX:
-			{
-				create_box(pos, shape.data_0, shape.data_1, shape.data_2);
-				break;
-			}
-			case PhysicsShapeType::PLANE:
-			{
-				create_plane(pos, Vector3(shape.data_0, shape.data_1, shape.data_2));
-				break;
-			}
-			default:
-			{
-				CE_FATAL("Oops, unknown shape type");
-			}
-		}
+		create_shape(pos, shape);
+
 		shape_index++;
 	}
 
@@ -170,21 +150,39 @@ Actor::~Actor()
 }
 
 //-----------------------------------------------------------------------------
-void Actor::create_sphere(const Vector3& position, float radius)
+void Actor::create_shape(const Vector3& position, const PhysicsShape& s)
 {
-	m_actor->createShape(PxSphereGeometry(radius), *m_mat);
-}
+	PxShape* shape;
 
-//-----------------------------------------------------------------------------
-void Actor::create_box(const Vector3& position, float half_x, float half_y, float half_z)
-{
-	m_actor->createShape(PxBoxGeometry(half_x, half_y, half_z), *m_mat);
-}
+	switch(s.type)
+	{
+		case PhysicsShapeType::SPHERE:
+		{
+			shape = m_actor->createShape(PxSphereGeometry(s.data_0), *m_mat);
+			break;
+		}
+		case PhysicsShapeType::BOX:
+		{
+			shape = m_actor->createShape(PxBoxGeometry(s.data_0, s.data_1, s.data_2), *m_mat);
+			break;
+		}
+		case PhysicsShapeType::PLANE:
+		{
+			// FIXME
+			shape = m_actor->createShape(PxPlaneGeometry(), *m_mat);
+			break;
+		}
+		default:
+		{
+			CE_FATAL("Oops, unknown shape type");
+		}
+	}
 
-//-----------------------------------------------------------------------------
-void Actor::create_plane(const Vector3& position, const Vector3& /*normal*/)
-{
-	m_actor->createShape(PxPlaneGeometry(), *m_mat);
+	if (s.trigger)
+	{
+		shape->setFlag(PxShapeFlag::eSIMULATION_SHAPE, false);
+		shape->setFlag(PxShapeFlag::eTRIGGER_SHAPE, true);		
+	}
 }
 
 //-----------------------------------------------------------------------------

+ 2 - 3
engine/physics/Actor.h

@@ -49,6 +49,7 @@ struct PhysicsResource;
 struct Quaternion;
 struct Matrix4x4;
 struct Unit;
+struct PhysicsShape;
 class SceneGraph;
 
 struct Actor
@@ -97,9 +98,7 @@ struct Actor
 
 private:
 
-	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);
+	void				create_shape(const Vector3& position, const PhysicsShape& s);
 	
 public: