Przeglądaj źródła

add support for capsules and meshes

mikymod 12 lat temu
rodzic
commit
ed4e69d52f

+ 24 - 2
engine/resource/PhysicsResource.cpp

@@ -110,11 +110,17 @@ void parse_shapes(JSONElement e, List<PhysicsShape>& shapes)
 			{
 				JSONElement radius = shape.key("radius");
 				ps.data_0 = radius.to_float();
+				
 				break;
 			}
 			case PhysicsShapeType::CAPSULE:
 			{
-				// TODO
+				JSONElement radius = shape.key("radius");
+				JSONElement half_height = shape.key("half_height");
+
+				ps.data_0 = radius.to_float();
+				ps.data_1 = half_height.to_float();
+
 				break;
 			}
 			case PhysicsShapeType::BOX:
@@ -131,7 +137,23 @@ void parse_shapes(JSONElement e, List<PhysicsShape>& shapes)
 			}
 			case PhysicsShapeType::PLANE:
 			{
-				// TODO
+				JSONElement n_x = shape.key("n_x");
+				JSONElement n_y = shape.key("n_y");
+				JSONElement n_z = shape.key("n_z");
+				JSONElement distance = shape.key("distance");
+
+				ps.data_0 = n_x.to_float();
+				ps.data_1 = n_y.to_float();
+				ps.data_2 = n_z.to_float();
+				ps.data_3 = distance.to_float();
+
+				break;
+			}
+			case PhysicsShapeType::CONVEX_MESH:
+			{
+				JSONElement resource = shape.key("mesh");
+				ps.resource = resource.to_string_id();
+
 				break;
 			}
 		}

+ 4 - 2
engine/resource/PhysicsResource.h

@@ -82,7 +82,8 @@ struct PhysicsShapeType
 		SPHERE,
 		CAPSULE,
 		BOX,
-		PLANE
+		PLANE,
+		CONVEX_MESH
 	};
 };
 
@@ -93,6 +94,7 @@ struct PhysicsShape
 	StringId32 shape_class;		// Shape class from global.physics_config
 	StringId32 type;			// Type of the shape
 	StringId32 material;		// Material from global.physics_config
+	StringId32 resource;		// Resource such as .mesh or .heightmap
 	float data_0;
 	float data_1;
 	float data_2;
@@ -256,7 +258,7 @@ struct PhysicsResource
 
 		const PhysicsHeader* ph = (PhysicsHeader*) this;
 		PhysicsJoint* joint = (PhysicsJoint*) (((char*) this) + ph->joints_offset);
-		return joint[i];		
+		return joint[i];
 	}
 
 private: