当前位置: 首页>>代码示例>>C#>>正文


C# Scene.CreateActor方法代码示例

本文整理汇总了C#中Scene.CreateActor方法的典型用法代码示例。如果您正苦于以下问题:C# Scene.CreateActor方法的具体用法?C# Scene.CreateActor怎么用?C# Scene.CreateActor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Scene的用法示例。


在下文中一共展示了Scene.CreateActor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FluidWithEmitterAndDrain

		public static PhysX.Fluid FluidWithEmitterAndDrain(Scene scene)
		{
			const int maximumParticles = 1000;

			var fluidEmitterDesc = new FluidEmitterDescription()
			{
				DimensionX = 0.5f,
				DimensionY = 0.5f,
				Rate = 15,
				RelativePose = 
					Matrix.RotationAxis(new Vector3(0, 1, 0), (float)Math.PI) *
					Matrix.Translation(-40, 10, -50),
				Shape = EmitterShape.Rectangular,
				Type = EmitterType.ConstantFlowRate,
				RandomAngle = 0.5f
			};
			fluidEmitterDesc.Flags |= (FluidEmitterFlag.Enabled | FluidEmitterFlag.Visualization);

			var fluidDesc = new FluidDescription()
			{
				Emitters = { fluidEmitterDesc },
				Flags = FluidFlag.Enabled | FluidFlag.Visualization,
				MaximumParticles = maximumParticles
			};
			fluidDesc.ParticleWriteData.AllocatePositionBuffer<Vector3>(maximumParticles);
			fluidDesc.ParticleWriteData.NumberOfParticles = maximumParticles;

			var fluid = scene.CreateFluid(fluidDesc);

			// Ledge
			{
				var boxShapeDesc = new BoxShapeDescription(5, 0.1f, 5);

				var drainActorDesc = new ActorDescription()
				{
					GlobalPose = Matrix.RotationX(-0.5f) * Matrix.Translation(-40, 5, -52),
					Shapes = { boxShapeDesc }
				};

				var drianActor = scene.CreateActor(drainActorDesc);
			}

			// Drain
			{
				var boxShapeDesc = new BoxShapeDescription(5, 0.1f, 5);
				boxShapeDesc.Flags |= ShapeFlag.FluidDrain;

				var drainActorDesc = new ActorDescription()
				{
					GlobalPose = Matrix.Translation(-40, 0, -55),
					Shapes = { boxShapeDesc }
				};

				var drianActor = scene.CreateActor(drainActorDesc);
			}

			return fluid;
		}
开发者ID:dkushner,项目名称:PhysX.NET,代码行数:58,代码来源:Fluid.cs

示例2: HeightfieldGrid

		public static PhysX.HeightField HeightfieldGrid(Scene scene)
		{
			int rows = 25;
			int columns = 25;

			var samples = new HeightFieldSample[rows * columns];
			for (int r = 0; r < rows; r++)
			{
				for (int c = 0; c < columns; c++)
				{
					// Put a z and x curve together
					double h = Math.Sin(c) * Math.Cos(r) * short.MaxValue;

					var sample = new HeightFieldSample()
					{
						Height = (short)h,
						MaterialIndex0 = 0,
						MaterialIndex1 = 1,
						TessellationFlag = 0
					};

					samples[r * columns + c] = sample;
				}
			}

			var heightFieldDesc = new HeightFieldDescription()
			{
				NumberOfRows = rows,
				NumberOfColumns = columns
			};
			heightFieldDesc.SetSamples(samples);

			var heightField = scene.Core.CreateHeightField(heightFieldDesc);

			//

			var heightFieldShapeDesc = new HeightFieldShapeDescription()
			{
				HeightField = heightField,
				HoleMaterial = 2,
				// The max height of our samples is short.MaxValue and we want it to be 1
				HeightScale = 1.0f / (float)short.MaxValue,
				RowScale = 3,
				ColumnScale = 3
			};
			heightFieldShapeDesc.LocalPosition = new Vector3(-0.5f * rows * 1 * heightFieldShapeDesc.RowScale, 0, -0.5f * columns * 1 * heightFieldShapeDesc.ColumnScale);

			var actorDesc = new ActorDescription()
			{
				GlobalPose = Matrix.Translation(100, 0, 0),
				Shapes = { heightFieldShapeDesc }
			};

			var actor = scene.CreateActor(actorDesc);

			return heightField;
		}
开发者ID:flair2005,项目名称:PhysX.Net,代码行数:57,代码来源:Heightfield.cs

示例3: PrismaticJointWithLimit

		public static PrismaticJoint PrismaticJointWithLimit(Scene scene)
		{
			Actor actorA, actorB;
			{
				BoxShapeDescription boxShapeDesc = new BoxShapeDescription(3, 3, 3);

				BodyDescription bodyDesc = new BodyDescription(10.0f);
				bodyDesc.BodyFlags |= BodyFlag.Kinematic;

				ActorDescription actorDesc = new ActorDescription()
				{
					BodyDescription = bodyDesc,
					GlobalPose = Matrix.Translation(70, 25, -65),
					Shapes = { boxShapeDesc }
				};
				actorA = scene.CreateActor(actorDesc);
			}
			{
				BoxShapeDescription boxShapeDesc = new BoxShapeDescription(3, 3, 3);

				ActorDescription actorDesc = new ActorDescription()
				{
					BodyDescription = new BodyDescription(10.0f),
					GlobalPose = Matrix.Translation(70, 15, -65),
					Shapes = { boxShapeDesc }
				};
				actorB = scene.CreateActor(actorDesc);
			}

			PrismaticJointDescription prismaticJointDesc = new PrismaticJointDescription()
			{
				Actor1 = actorA,
				Actor2 = actorB,
			};
			prismaticJointDesc.SetGlobalAnchor(new Vector3(70, 20, -65));
			prismaticJointDesc.SetGlobalAxis(new Vector3(0, 1, 0));

			PrismaticJoint prismaticJoint = scene.CreateJoint(prismaticJointDesc) as PrismaticJoint;

			LimitPlane limitPlane = new LimitPlane(new Vector3(0, 1, 0), new Vector3(-30, 8, -30), 0);
			prismaticJoint.AddLimitPlane(limitPlane);

			return prismaticJoint;
		}
开发者ID:dkushner,项目名称:PhysX.NET,代码行数:44,代码来源:Joints.cs

示例4: LoadVehiclePhysics

		private void LoadVehiclePhysics(Scene scene)
		{
			// Create a 2 ton car with 4 wheels
			BodyDescription bodyDesc = new BodyDescription()
			{
				Mass = 2000
			};
			//bodyDesc.MassLocalPose = Matrix.CreateTranslation( 0, -1.5f, 0 ); // Seems not to be working

			ActorDescription actorDesc = new ActorDescription()
			{
				BodyDescription = bodyDesc,
				Shapes = { new BoxShapeDescription(5, 3, 7) },
				GlobalPose = Matrix.Translation(-50, 5, -70)
			};

			_vehicleBodyActor = scene.CreateActor(actorDesc);
			_vehicleBodyActor.SetCenterOfMassOffsetLocalPosition(new Vector3(0, -1.5f, 0)); // Move the COM to the bottom of the vehicle to stop it flipping over so much

			//

			WheelShapeDescription leftFrontDesc = new WheelShapeDescription()
			{
				Radius = 0.8f,
				SuspensionTravel = 1,
				LocalPosition = new Vector3(-2.5f, -1, 3)
			};

			WheelShapeDescription leftRearDesc = new WheelShapeDescription()
			{
				Radius = 0.8f,
				SuspensionTravel = 1,
				LocalPosition = new Vector3(-2.5f, -1, -3),
			};

			WheelShapeDescription rightFrontDesc = new WheelShapeDescription()
			{
				Radius = 0.8f,
				SuspensionTravel = 1,
				LocalPosition = new Vector3(2.5f, -1, 3)
			};

			WheelShapeDescription rightRearDesc = new WheelShapeDescription()
			{
				Radius = 0.8f,
				SuspensionTravel = 1,
				LocalPosition = new Vector3(2.5f, -1, -3)
			};

			this.LeftFront = _vehicleBodyActor.CreateShape(leftFrontDesc) as WheelShape;
			this.LeftRear = _vehicleBodyActor.CreateShape(leftRearDesc) as WheelShape;
			this.RightFront = _vehicleBodyActor.CreateShape(rightFrontDesc) as WheelShape;
			this.RightRear = _vehicleBodyActor.CreateShape(rightRearDesc) as WheelShape;
		}
开发者ID:flair2005,项目名称:PhysX.Net,代码行数:54,代码来源:LoadVehiclePhysics.cs

示例5: LoadConvexMesh

		public static Model LoadConvexMesh(Scene scene, Device device)
		{
			var torusModel = ColladaLoader.Load(@"Resources\Torus.DAE", device);

			var core = scene.Core;

			// Allocate memory for the points and triangles
			var convexMeshDesc = new ConvexMeshDescription()
			{
				PointCount = torusModel.VertexPositions.Length
			};
			convexMeshDesc.Flags |= ConvexFlag.ComputeConvex;
			convexMeshDesc.AllocatePoints<Vector3>(torusModel.VertexPositions.Length);

			// Write in the points and triangles
			// We only want the Position component of the vertex. Also scale down the mesh.
			foreach (var vertex in torusModel.VertexPositions)
			{
				var t = SlimDX.Matrix.Scaling(0.1f, 0.1f, 0.1f);
				var position = SlimDX.Vector3.TransformCoordinate(vertex, t);

				convexMeshDesc.PointsStream.Write(position);
			}

			//

			// Cook to memory or to a file
			ConvexMesh convexMesh;
			using (var stream = new MemoryStream())
			{
				//FileStream stream = new FileStream( @"Convex Mesh.cooked", FileMode.CreateNew );

				Cooking.InitializeCooking(new ConsoleOutputStream());
				Cooking.CookConvexMesh(convexMeshDesc, stream);
				Cooking.CloseCooking();

				stream.Position = 0;

				convexMesh = core.CreateConvexMesh(stream);
			}
			var convexShapeDesc = new ConvexShapeDescription(convexMesh);

			var actorDesc = new ActorDescription()
			{
				BodyDescription = new BodyDescription(10.0f),
				GlobalPose = Matrix.Translation(30, 30, 0)
			};
			actorDesc.Shapes.Add(convexShapeDesc);

			var actor = scene.CreateActor(actorDesc);

			return torusModel;
		}
开发者ID:dkushner,项目名称:PhysX.NET,代码行数:53,代码来源:Convex.cs

示例6: CreateContactReport

		public static void CreateContactReport(Scene scene, Actor groundActor)
		{
			// Contact report
			// When the capsule actor hits the ground make it bounce by using the conact report
			{
				CapsuleShapeDescription capsuleShapeDesc = new CapsuleShapeDescription(1, 5);

				ActorDescription actorDesc = new ActorDescription()
				{
					GlobalPose = Matrix.Translation(-30, 20, 0),
					BodyDescription = new BodyDescription(10.0f),
					Name = "Report Capsule",
					Shapes = { capsuleShapeDesc }
				};

				var contactReportActor = scene.CreateActor(actorDesc);

				scene.SetActorPairFlags(contactReportActor, groundActor, ContactPairFlag.All);

				scene.UserContactReport = new ContactReport(contactReportActor, groundActor);
			}

			// Trigger Reports
			{
				BoxShapeDescription boxShapeDesc = new BoxShapeDescription(15, 8, 15);
				boxShapeDesc.Flags |= (ShapeFlag.TriggerOnEnter | ShapeFlag.TriggerOnLeave);

				ActorDescription actorDesc = new ActorDescription()
				{
					GlobalPose = Matrix.Translation(-30, 4, 0),
					Shapes = { boxShapeDesc }
				};
				scene.CreateActor(actorDesc);

				scene.UserTriggerReport = new TriggerReport();
			}

			scene.UserNotify = new Notify();
		}
开发者ID:flair2005,项目名称:PhysX.Net,代码行数:39,代码来源:Report.cs

示例7: CreateBoxActor

        private static Actor CreateBoxActor( Scene scene, float sizeX, float sizeY, float sizeZ )
        {
            var actorDesc = new ActorDescription();
            var bodyDesc = new BodyDescription();

            var boxDesc = new BoxShapeDescription( sizeX, sizeY, sizeZ );

            actorDesc.Shapes.Add( boxDesc );

            actorDesc.BodyDescription = bodyDesc;
            actorDesc.Density = 10;

            return scene.CreateActor( actorDesc );
        }
开发者ID:werwolfby,项目名称:Managed-OpenGL,代码行数:14,代码来源:PhysXBox.cs

示例8: RevoluteJoint

		public static RevoluteJoint RevoluteJoint(Scene scene)
		{
			BoxShapeDescription boxShapeDescA = new BoxShapeDescription(3, 3, 3);
			BoxShapeDescription boxShapeDescB = new BoxShapeDescription(3, 3, 3);

			ActorDescription actorDescA = new ActorDescription()
			{
				BodyDescription = new BodyDescription(10.0f),
				GlobalPose = Matrix.Translation(75, 1.5f, -55),
				Shapes = { boxShapeDescA }
			};
			Actor actorA = scene.CreateActor(actorDescA);

			ActorDescription actorDescB = new ActorDescription()
			{
				BodyDescription = new BodyDescription(10.0f),
				GlobalPose = Matrix.Translation(70, 1.5f, -55),
				Shapes = { boxShapeDescB }
			};
			Actor actorB = scene.CreateActor(actorDescB);

			//

			RevoluteJointDescription revoluteJointDesc = new RevoluteJointDescription()
			{
				Actor1 = actorA,
				Actor2 = actorB,
				Motor = new MotorDescription(20, 20.1f, true)
			};
			revoluteJointDesc.Flags |= RevoluteJointFlag.MotorEnabled;
			revoluteJointDesc.SetGlobalAnchor(new Vector3(73.5f, 1.5f, -55));
			revoluteJointDesc.SetGlobalAxis(new Vector3(1, 0, 0));

			RevoluteJoint revoluteJoint = scene.CreateJoint(revoluteJointDesc) as RevoluteJoint;

			return revoluteJoint;
		}
开发者ID:dkushner,项目名称:PhysX.NET,代码行数:37,代码来源:Joints.cs

示例9: SimpleBoxes

		public static void SimpleBoxes(Scene scene)
		{
			for (int x = 0; x < 5; x++)
			{
				BoxShapeDescription boxShapeDesc = new BoxShapeDescription(2, 3, 8);

				ActorDescription actorDesc = new ActorDescription()
				{
					Name = String.Format("Box {0}", x),
					BodyDescription = new BodyDescription(10.0f),
					GlobalPose = Matrix.Translation(100, 15 + 3 * x, 20),
					Shapes = { boxShapeDesc }
				};

				Actor actor = scene.CreateActor(actorDesc);
			}
		}
开发者ID:dkushner,项目名称:PhysX.NET,代码行数:17,代码来源:RigidBodies.cs

示例10: CreateActor

        private Actor CreateActor(RigidBodyDescriptor descriptor, Scene scene)
        {
         
            var materialDesc = new MaterialDescription
            {
                DynamicFriction = 0.5f,
                StaticFriction = 0.5f,
                Restitution = 0.7f,
                FrictionCombineMode = CombineMode.Average,
                RestitutionCombineMode = CombineMode.Average
            };
            DefaultMaterial = scene.CreateMaterial(materialDesc);
            var boxDesc = new BoxShapeDescription
            {
                Material = DefaultMaterial,
                Dimensions = new Vector3(1, 1, 1)
            };
            ///////////////////////////////////////////////



            //resolve the motion type
            var rigidBodyDesc = descriptor.MotionType == MotionType.Static
                                    ? null
                                    : new BodyDescription();
            if (descriptor.MotionType == MotionType.Kinematic)
                rigidBodyDesc.BodyFlags = BodyFlag.Kinematic;

            HasDefaultShape = true;
            var actorDesc = new ActorDescription(boxDesc)
                                {
                                    BodyDescription = rigidBodyDesc,
                                    Density = 10.0f,
                                    GlobalPose = descriptor.Pose.ToPhysX(),
                                    UserData = descriptor.UserData
                                };
            return scene.CreateActor(actorDesc);
        }
开发者ID:sandygk,项目名称:System.Physics,代码行数:38,代码来源:RigidBody.cs

示例11: LoadPhysics


//.........这里部分代码省略.........
				Vector3[] vertices =
				{
					new Vector3( size.X, -size.Y, -size.Z ),
					new Vector3( size.X, -size.Y, size.Z ),
					new Vector3( size.X, size.Y, -size.Z ),
					new Vector3( size.X,  size.Y,  size.Z ),
					new Vector3( -size.X, -size.Y, -size.Z ),
					new Vector3( -size.X, -size.Y, size.Z ),
					new Vector3( -size.X,  size.Y, -size.Z ),
					new Vector3( -size.X,  size.Y,  size.Z )
				};

				TriangleMeshDescription triangleMeshDesc = new TriangleMeshDescription();
				triangleMeshDesc.AllocateVertices<Vector3>(vertices.Length);
				triangleMeshDesc.AllocateTriangles<int>(indices.Length);

				triangleMeshDesc.VerticesStream.SetData(vertices);
				triangleMeshDesc.TriangleStream.SetData(indices);

				triangleMeshDesc.VertexCount = vertices.Length;
				triangleMeshDesc.TriangleCount = indices.Length / 3;

				ccdSkeletonForBox = scene.Core.CreateCCDSkeleton(triangleMeshDesc);

				// Enable CCD and CCD Visualization
				scene.Core.SetParameter(PhysicsParameter.ContinuousCollisionDetection, true);
				scene.Core.SetParameter(PhysicsParameter.VisualizeContinuousCollisionDetectionTests, true);
			}

			// Create a large 2 polygon triangle mesh plane
			// For CCD to work/be used many conditions must be met (check the docs for full list)
			// One of those conditions is that one of the objects must be a triangle mesh or a convex mesh (for static-dynamic)
			{
				Vector3[] vertices = 
				{
					new Vector3( -100, 5, -100 ),
					new Vector3( -100, 5, 100 ),
					new Vector3( 100, 5, -100 ),
					new Vector3( 100, 5, 100 ),
				};

				int[] indices =
				{
					0, 1, 2,
					1, 3, 2
				};

				TriangleMeshDescription triangleMeshDesc = new TriangleMeshDescription();
				triangleMeshDesc.TriangleCount = indices.Length / 3;
				triangleMeshDesc.VertexCount = vertices.Length;

				triangleMeshDesc.AllocateTriangles<int>(triangleMeshDesc.TriangleCount);
				triangleMeshDesc.AllocateVertices<Vector3>(triangleMeshDesc.VertexCount);

				triangleMeshDesc.TriangleStream.SetData(indices);
				triangleMeshDesc.VerticesStream.SetData(vertices);

				TriangleMesh triangleMesh;
				using (MemoryStream s = new MemoryStream())
				{
					Cooking.InitializeCooking();
					Cooking.CookTriangleMesh(triangleMeshDesc, s);
					Cooking.CloseCooking();

					s.Position = 0;
					triangleMesh = scene.Core.CreateTriangleMesh(s);
				}

				TriangleMeshShapeDescription triangleMeshShapeDesc = new TriangleMeshShapeDescription()
				{
					TriangleMesh = triangleMesh,
					Flags = ShapeFlag.Visualization
				};

				ActorDescription actorDesc = new ActorDescription()
				{
					Shapes = { triangleMeshShapeDesc }
				};

				Actor actor = scene.CreateActor(actorDesc);
			}

			// Make 20 boxes fall down
			for (int x = 0; x < 20; x++)
			{
				BoxShapeDescription boxShapeDesc = new BoxShapeDescription(2, 3, 8);
				// Assign the CCD Skeleton to the shape
				boxShapeDesc.CCDSkeleton = ccdSkeletonForBox;

				ActorDescription actorDesc = new ActorDescription()
				{
					Name = String.Format("Box {0}", x),
					BodyDescription = new BodyDescription(10.0f),
					GlobalPose = Matrix.Translation(0, 15 + 3 * x, 0),
					Shapes = { boxShapeDesc }
				};

				Actor actor = scene.CreateActor(actorDesc);
			}
		}
开发者ID:flair2005,项目名称:PhysX.Net,代码行数:101,代码来源:LoadPhysics.cs

示例12: LoadPhysics

		protected override void LoadPhysics(Scene scene)
		{
			// Create a simple fluid description with fluids and visualization enabled
			FluidDescription fluidDesc = new FluidDescription()
			{
				Flags = FluidFlag.Enabled | FluidFlag.Visualization,
			};

			// Store our particle positions somewhere (as our particle generation function below generates and unknown number of particles at runtime we need a list instead of an array)
			var particlePositions = new List<Vector3>();

			// Move all the particles by this offset
			Vector3 position = new Vector3( 0, 20, 0 );

			// Number of particles in the x, y and z directions
			int sideNum = 10;
			float distance = 1f;

			float radius = sideNum * distance * 0.5f;

			for( int i = 0; i < sideNum; i++ )
			{
				for( int j = 0; j < sideNum; j++ )
				{
					for( int k = 0; k < sideNum; k++ )
					{
						Vector3 p = new Vector3( i * distance, j * distance, k * distance );

						if( ( p - new Vector3( radius, radius, radius ) ).Length() < radius )
						{
							p += position - new Vector3( radius, radius, radius );

							particlePositions.Add( p );
						}
					}
				}
			}

			// Allocate memory for the initial particle positions to be stored in
			// And then set the position buffer
			fluidDesc.InitialParticleData.AllocatePositionBuffer<Vector3>( particlePositions.Count );
			fluidDesc.InitialParticleData.NumberOfParticles = particlePositions.Count;
			fluidDesc.InitialParticleData.PositionBuffer.SetData( particlePositions.ToArray() );

			// Allocate memory for PhysX to store the position of each particle
			fluidDesc.ParticleWriteData.AllocatePositionBuffer<Vector3>( particlePositions.Count );
			fluidDesc.ParticleWriteData.NumberOfParticles = particlePositions.Count;

			Fluid fluid = scene.CreateFluid(fluidDesc);

			//

			// Make a basic box (ramp) for the particle to slide down
			ActorDescription rampDesc = new ActorDescription()
			{
				Shapes = { new BoxShapeDescription( 10, 0.2f, 10 ) },
				GlobalPose =
					Matrix.RotationZ( 0.3f ) *
					Matrix.Translation( 0, 5, 0 )
			};

			Actor ramp = scene.CreateActor(rampDesc);
		}
开发者ID:dkushner,项目名称:PhysX.NET,代码行数:63,代码来源:LoadPhysics.cs

示例13: FlagOfCloth

		public static PhysX.Cloth FlagOfCloth(Scene scene)
		{
			Core core = scene.Core;

			// Create a Grid of Points
			VertexGrid grid = VertexGrid.CreateGrid(10, 10);

			ClothMeshDescription clothMeshDesc = new ClothMeshDescription();
			clothMeshDesc.AllocateVertices<Vector3>(grid.Points.Length);
			clothMeshDesc.AllocateTriangles<int>(grid.Indices.Length / 3);

			clothMeshDesc.VertexCount = grid.Points.Length;
			clothMeshDesc.TriangleCount = grid.Indices.Length / 3;

			clothMeshDesc.VerticesStream.SetData(grid.Points);
			clothMeshDesc.TriangleStream.SetData(grid.Indices);

			// We are using 32 bit integers, so make sure the 16 bit flag is removed.
			// 32 bits are the default, so this isn't technically needed
			clothMeshDesc.Flags &= ~MeshFlag.Indices16Bit;

			// Write the cooked data to memory
			MemoryStream memoryStream = new MemoryStream();

			Cooking.InitializeCooking();
			Cooking.CookClothMesh(clothMeshDesc, memoryStream);
			Cooking.CloseCooking();

			// Need to reset the position of the stream to the beginning
			memoryStream.Position = 0;

			ClothMesh clothMesh = core.CreateClothMesh(memoryStream);

			//

			ClothDescription clothDesc = new ClothDescription()
			{
				ClothMesh = clothMesh,
				Flags = ClothFlag.Gravity | ClothFlag.Bending | ClothFlag.CollisionTwoway | ClothFlag.Visualization,
				GlobalPose =
					Matrix.RotationYawPitchRoll(0, (float)Math.PI / 2.0f, (float)Math.PI / 2.0f) *
					Matrix.Translation(0, 20, 0)
			};
			clothDesc.MeshData.AllocatePositions<Vector3>(grid.Points.Length);
			clothDesc.MeshData.AllocateIndices<int>(grid.Indices.Length);

			clothDesc.MeshData.MaximumVertices = grid.Points.Length;
			clothDesc.MeshData.MaximumIndices = grid.Indices.Length;

			clothDesc.MeshData.NumberOfVertices = grid.Points.Length;
			clothDesc.MeshData.NumberOfIndices = grid.Indices.Length;

			var flag = scene.CreateCloth(clothDesc);

			// Flag Pole
			ActorDescription flagPoleActorDesc = new ActorDescription()
			{
				GlobalPose = Matrix.Translation(0, 10, 0),
				Shapes = { new BoxShapeDescription(1.0f, 20.0f, 1.0f) }
			};

			Actor flagPoleActor = scene.CreateActor(flagPoleActorDesc);

			flag.AttachToShape(flagPoleActor.Shapes[0], 0);
			flag.WindAcceleration = new Vector3(10, 10, 10);
			flag.BendingStiffness = 0.1f;

			return flag;
		}
开发者ID:dkushner,项目名称:PhysX.NET,代码行数:69,代码来源:Cloth.cs

示例14: LoadPhysics


//.........这里部分代码省略.........
				clothMeshDesc.AllocateTriangles<int>(indices / 3);

				clothMeshDesc.VertexCount = vertices;
				clothMeshDesc.TriangleCount = indices / 3;

				clothMeshDesc.VerticesStream.SetData(grid.Points);
				clothMeshDesc.TriangleStream.SetData(grid.Indices);

				// We are using 32 bit integers for our indices, so make sure the 16 bit flag is removed.
				// 32 bits are the default, so this isn't technically needed, but it's good to show in a sample
				clothMeshDesc.Flags &= ~MeshFlag.Indices16Bit;
				clothMeshDesc.Flags |= (MeshFlag)((int)clothMeshDesc.Flags | (int)ClothMeshFlag.Tearable);

				// Write the cooked data to memory
				using (var memoryStream = new MemoryStream())
				{
					Cooking.InitializeCooking();
					Cooking.CookClothMesh(clothMeshDesc, memoryStream);
					Cooking.CloseCooking();

					// Need to reset the position of the stream to the beginning
					memoryStream.Position = 0;

					clothMesh = Engine.Core.CreateClothMesh(memoryStream);
				}
			}

			//

			int j = vertices * 2;
			int k = indices * 3;

			var clothDesc = new ClothDescription()
			{
				ClothMesh = clothMesh,
				GlobalPose =
					Matrix.Translation(-hw, 0, -hh) *
					Matrix.Translation(p),
				Flags = ClothFlag.Gravity | ClothFlag.Bending | ClothFlag.CollisionTwoway | ClothFlag.Visualization | ClothFlag.Tearable,
				BendingStiffness = 0.1f,
				TearFactor = 1.5f
			};
			clothDesc.MeshData.AllocatePositions<Vector3>(j);
			clothDesc.MeshData.AllocateIndices<int>(k);
			clothDesc.MeshData.AllocateNormals<Vector3>(j);

			clothDesc.MeshData.MaximumVertices = j;
			clothDesc.MeshData.MaximumIndices = k;

			clothDesc.MeshData.NumberOfVertices = vertices;
			clothDesc.MeshData.NumberOfIndices = indices;

			_cloth = scene.CreateCloth(clothDesc);

			//

			// Four corner boxes to hold it in place
			var positions = new[]
			{
				new Vector3(0, 0, -hh), // Back
				new Vector3(0, 0, hh), // Front
				new Vector3(-hw, 0, 0), // Left
				new Vector3(hw, 0, 0), // Right
			};

			var sizes = new[]
			{
				new Vector3(w, 1, 1), // Back
				new Vector3(w, 1, 1), // Front
				new Vector3(1, 1, h), // Left
				new Vector3(1, 1, h), //Right
			};

			for (int i = 0; i < 4; i++)
			{
				var actorDesc = new ActorDescription()
				{
					GlobalPose = Matrix.Translation(positions[i] + p),
					Shapes = { new BoxShapeDescription(sizes[i]) }
				};

				var actor = scene.CreateActor(actorDesc);

				_cloth.AttachToShape(actor.Shapes.First(), (ClothAttachmentFlag)0);
			}

			//

			// Something to drop on it
			{
				var actorDesc = new ActorDescription()
				{
					GlobalPose = Matrix.Translation(0, 100, 0),
					Shapes = { new SphereShapeDescription(2) },
					BodyDescription = new BodyDescription(50)
				};

				var actor = scene.CreateActor(actorDesc);
			}
		}
开发者ID:dkushner,项目名称:PhysX.NET,代码行数:101,代码来源:TearingCloth.cs

示例15: LoadPhysics


//.........这里部分代码省略.........
            {
                ClothMesh = clothMesh,
                GlobalPose =
                    Matrix.RotationX((float)Math.PI / 2.0F) *
                    Matrix.Translation(-w - 1, 0, 0) *
                    Matrix.Translation(p),
                Flags = ClothFlag.Gravity | ClothFlag.Bending | ClothFlag.CollisionTwoway | ClothFlag.Visualization,
                BendingStiffness = 0.1f,
                TearFactor = 1.5f,
                WindAcceleration = new Vector3(windX, windY, windZ)
            };
            clothDesc.MeshData.AllocatePositions<Vector3>(j);
            clothDesc.MeshData.AllocateIndices<int>(k);
            clothDesc.MeshData.AllocateNormals<Vector3>(j);

            clothDesc.MeshData.MaximumVertices = j;
            clothDesc.MeshData.MaximumIndices = k;

            clothDesc.MeshData.NumberOfVertices = vertices;
            clothDesc.MeshData.NumberOfIndices = indices;

            _clothL = scene.CreateCloth(clothDesc);

            var clothDesc2 = new ClothDescription()
            {
                ClothMesh = clothMesh,
                GlobalPose =
                    Matrix.RotationX((float)Math.PI / 2.0F) *
                    Matrix.Translation(1, 0, 0) *
                    Matrix.Translation(p),
                Flags = ClothFlag.Gravity | ClothFlag.Bending | ClothFlag.CollisionTwoway | ClothFlag.Visualization,
                BendingStiffness = 0.1f,
                TearFactor = 1.5f,
                WindAcceleration = new Vector3(windX, windY, windZ)
            };
            clothDesc2.MeshData.AllocatePositions<Vector3>(j);
            clothDesc2.MeshData.AllocateIndices<int>(k);
            clothDesc2.MeshData.AllocateNormals<Vector3>(j);

            clothDesc2.MeshData.MaximumVertices = j;
            clothDesc2.MeshData.MaximumIndices = k;

            clothDesc2.MeshData.NumberOfVertices = vertices;
            clothDesc2.MeshData.NumberOfIndices = indices;

            _clothR = scene.CreateCloth(clothDesc2);
            //

            for (int i = 0; i <= w; i += 2)
            {
                var actorDesc = new ActorDescription()
                {
                    GlobalPose = Matrix.Translation(new Vector3(i - w - 1, 0, 0) + p),
                    Shapes = { new SphereShapeDescription(0.3F) },
                    BodyDescription = new BodyDescription(3)
                };
                var actor = scene.CreateActor(actorDesc);
                AnchorActorsL.Add(actor);
                _clothL.AttachToShape(actor.Shapes.First(), (ClothAttachmentFlag)0);
            }
            for (int i = 0; i <= w; i += 2)
            {
                var actorDesc = new ActorDescription()
                {
                    GlobalPose = Matrix.Translation(new Vector3(-i + w + 1, 0, 0) + p),
                    Shapes = { new SphereShapeDescription(0.3F) },
                    BodyDescription = new BodyDescription(3)
                };
                var actor = scene.CreateActor(actorDesc);
                AnchorActorsR.Add(actor);
                _clothR.AttachToShape(actor.Shapes.First(), (ClothAttachmentFlag)0);
            }
            for (int i = 0; i <= 1; i++)
            {
                var actorDesc = new ActorDescription()
                {
                    GlobalPose = Matrix.Translation(new Vector3(0, -1,  0.2F * (float)Math.Pow(-1, i)) + p),
                    Shapes = { new BoxShapeDescription(new Vector3(2 * w + 4, 0.001F, 0.1F)) }
                };
                scene.CreateActor(actorDesc);
            }
            for (int i = 0; i <= 1; i++)
            {
                var actorDesc = new ActorDescription()
                {
                    GlobalPose = Matrix.Translation(new Vector3(0, -1, 0.4F * (float)Math.Pow(-1, i)) + p),
                    Shapes = { new BoxShapeDescription(new Vector3(2 * w + 4, 1, 0.1F)) }
                };
                scene.CreateActor(actorDesc);
            }
            for (int i = 0; i <= 1; i++)
            {
                var actorDesc = new ActorDescription()
                {
                    GlobalPose = Matrix.Translation(new Vector3((w + 2.1F) * (float)Math.Pow(-1, i), -1, 0) + p),
                    Shapes = { new BoxShapeDescription(new Vector3(0.1F, 1, 1)) }
                };
                scene.CreateActor(actorDesc);
            }
        }
开发者ID:kurema,项目名称:CurtainSimulator,代码行数:101,代码来源:TearingCloth.cs


注:本文中的Scene.CreateActor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。