Explorar o código

Add position and rotation properties to actor shapes

Daniele Bartolini %!s(int64=11) %!d(string=hai) anos
pai
achega
50c0e63b1a

+ 12 - 5
engine/physics/Actor.cpp

@@ -51,18 +51,23 @@ using physx::PxCapsuleGeometry;
 using physx::PxConvexFlag;
 using physx::PxConvexMesh;
 using physx::PxConvexMeshDesc;
+using physx::PxConvexMeshGeometry;
 using physx::PxD6Axis;
 using physx::PxD6Joint;
 using physx::PxD6JointCreate;
 using physx::PxD6Motion;
+using physx::PxDefaultMemoryInputData;
+using physx::PxDefaultMemoryOutputStream;
 using physx::PxFilterData;
 using physx::PxForceMode;
 using physx::PxMat44;
 using physx::PxPlaneGeometry;
+using physx::PxQuat;
 using physx::PxReal;
 using physx::PxRigidActor;
 using physx::PxRigidBody;
 using physx::PxRigidBodyExt;
+using physx::PxRigidBodyFlag;
 using physx::PxRigidDynamic;
 using physx::PxRigidDynamicFlag;
 using physx::PxRigidStatic;
@@ -70,13 +75,9 @@ using physx::PxShape;
 using physx::PxShapeFlag;
 using physx::PxSphereGeometry;
 using physx::PxTransform;
-using physx::PxU32;
 using physx::PxU16;
+using physx::PxU32;
 using physx::PxVec3;
-using physx::PxDefaultMemoryOutputStream;
-using physx::PxDefaultMemoryInputData;
-using physx::PxConvexMeshGeometry;
-using physx::PxRigidBodyFlag;
 
 namespace crown
 {
@@ -192,6 +193,12 @@ void Actor::create_objects()
 			}
 		}
 
+		// Setup shape pose
+		px_shape->setLocalPose(PxTransform(
+								PxVec3(shape.position.x, shape.position.y, shape.position.z),
+								PxQuat(shape.rotation.x, shape.rotation.y, shape.rotation.z, shape.rotation.w)));
+
+		// Setup collision filters
 		PxFilterData filter_data;
 		filter_data.word0 = config->filter(shape_class.collision_filter).me;
 		filter_data.word1 = config->filter(shape_class.collision_filter).mask;

+ 2 - 0
engine/resource/PhysicsResource.cpp

@@ -104,6 +104,8 @@ void parse_shapes(JSONElement e, Array<PhysicsShape>& shapes)
 		ps.material = material.to_string_id();
 		DynamicString stype; type.to_string(stype);
 		ps.type = shape_type_to_enum(stype.c_str());
+		ps.position = shape.key("position").to_vector3();
+		ps.rotation = shape.key("rotation").to_quaternion();
 
 		switch (ps.type)
 		{

+ 2 - 0
engine/resource/PhysicsResource.h

@@ -96,6 +96,8 @@ struct PhysicsShape
 	StringId32 type;			// Type of the shape
 	StringId32 material;		// Material from global.physics_config
 	ResourceId resource;		// Resource such as .mesh or .heightmap
+	Vector3 position;			// In actor space
+	Quaternion rotation;		// In actor space
 	float data_0;
 	float data_1;
 	float data_2;