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


C# Scene.AddActor方法代码示例

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


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

示例1: LoadPhysics

		protected override void LoadPhysics(Scene scene)
		{
			var material = scene.Physics.CreateMaterial(0.7f, 0.7f, 0.1f);

			var boxA = scene.Physics.CreateRigidDynamic();
			boxA.Name = "Box A";
			boxA.GlobalPose = Matrix4x4.CreateTranslation(0, 50, 0);

			var shapeA = boxA.CreateShape(new BoxGeometry(2, 2, 2), material);

			scene.AddActor(boxA);

			//

			var boxB = scene.Physics.CreateRigidDynamic();
			boxB.Name = "Box B";
			boxB.GlobalPose = Matrix4x4.CreateTranslation(0, 4, 0);

			var shapeB = boxB.CreateShape(new BoxGeometry(2, 2, 2), material);

			scene.AddActor(boxB);

			//

			// Tell PhysX what to call when a contact/touch occurs
			var callback = new EventCallback(this);
			scene.SetSimulationEventCallback(callback, 0);
		}
开发者ID:flair2005,项目名称:PhysX.Net,代码行数:28,代码来源:EventsSample.cs

示例2: CreateFunnel

		private void CreateFunnel(Scene scene)
		{
			// Create two boxes that angle inwards to create a funnel

			var material = scene.Physics.CreateMaterial(0.1f, 0.1f, 0.1f);

			var rigidActor = scene.Physics.CreateRigidDynamic();

			var boxGeom = new BoxGeometry(10, 0.25f, 5);
			var boxShape = rigidActor.CreateShape(boxGeom, material);

			rigidActor.GlobalPose =
				Matrix4x4.CreateRotationX(0.2f) *
				Matrix4x4.CreateTranslation(0, 7, -5.1f);
			rigidActor.SetMassAndUpdateInertia(10);
			rigidActor.Flags = RigidDynamicFlags.Kinematic;

			scene.AddActor(rigidActor);

			//

			var rigidActor2 = scene.Physics.CreateRigidDynamic();

			var boxGeom2 = new BoxGeometry(10, 0.25f, 5);
			var boxShape2 = rigidActor2.CreateShape(boxGeom2, material);

			rigidActor2.GlobalPose =
				Matrix4x4.CreateRotationX(-0.2f) *
				Matrix4x4.CreateTranslation(0, 7, 5.1f);
			rigidActor2.SetMassAndUpdateInertia(10);
			rigidActor2.Flags = RigidDynamicFlags.Kinematic;

			scene.AddActor(rigidActor2);
		}
开发者ID:flair2005,项目名称:PhysX.Net,代码行数:34,代码来源:FluidSample.cs

示例3: LoadPhysics

		protected override void LoadPhysics(Scene scene)
		{
			var material = scene.Physics.CreateMaterial(0.7f, 0.7f, 0.1f);

			// Spherical Joint
			{
				// Actor 0
				var rigidActor0 = scene.Physics.CreateRigidDynamic();
				rigidActor0.CreateShape(new BoxGeometry(2, 2, 2), material);

				rigidActor0.GlobalPose = Matrix.Translation(0, 10, 0);
				rigidActor0.SetMassAndUpdateInertia(10);



				// Actor 1
				//var rigidActor1 = scene.Physics.CreateRigidDynamic();
				//rigidActor1.CreateShape(new BoxGeometry(2, 2, 2), material);

				//rigidActor1.GlobalPose = Matrix.Translation(-20, 10, 0);
				//rigidActor1.SetMassAndUpdateInertia(10);

				//rigidActor1.Flags = RigidDynamicFlags.Kinematic; // Pin this actor in space

				//scene.AddActor(rigidActor1);

				//

				var sphericalJoint = scene.CreateJoint<SphericalJoint>(rigidActor0, Matrix.Translation(0, 4, 0), null, Matrix.Translation(0, 15, 0));

				sphericalJoint.ConstraintFlag = ConstraintFlag.Visualization;

				scene.AddActor(rigidActor0);
			}
		}
开发者ID:zwagoth,项目名称:PhysX.net,代码行数:35,代码来源:JointsSample.cs

示例4: CreateBoxActor

		protected RigidDynamic CreateBoxActor(Scene scene, Vector3 size, Vector3 position)
		{
			var material = scene.Physics.CreateMaterial(0.5f, 0.5f, 0.1f);

			var rigid = scene.Physics.CreateRigidDynamic();

			var shape = rigid.CreateShape(new BoxGeometry(size / 2), material);

			rigid.GlobalPose = Matrix.Translation(position);

			scene.AddActor(rigid);

			return rigid;
		}
开发者ID:zwagoth,项目名称:PhysX.net,代码行数:14,代码来源:Test.cs

示例5: CreateCloth

		private Cloth CreateCloth(Scene scene)
		{
			// Create a grid of triangles to be our cloth
			var clothGrid = new VertexGrid(25, 25);

			// Setup the grid for cooking
			var clothMeshDesc = new ClothMeshDesc()
			{
				Points = clothGrid.Points,
				Triangles = clothGrid.Indices
			};

			// Cook
			var clothFabricStream = new MemoryStream();

			using (var cooking = scene.Physics.CreateCooking())
			{
				bool result = cooking.CookClothFabric(clothMeshDesc, new Vector3(0, -1, 0), clothFabricStream);

				if (!result)
					throw new Exception("Failed to cook deformable mesh");
			}

			// Reset the seek position of the stream so we can read it form the beginning
			clothFabricStream.Position = 0;

			var clothFabric = scene.Physics.CreateClothFabric(clothFabricStream);

			var collisionData = new ClothCollisionData();

			var particles = from p in clothGrid.Points
							select new ClothParticle()
							{
								Position = p,
								InverseWeight = 0.1f
							};

			// Create the cloth mesh from the cooked stream
			var cloth = scene.Physics.CreateCloth(
				Matrix.Identity,
				clothFabric,
				particles.ToArray(),
				collisionData,
				0);

			scene.AddActor(cloth);

			return cloth;
		}
开发者ID:zwagoth,项目名称:PhysX.net,代码行数:49,代码来源:ClothSample.cs

示例6: CreateSpheres

		private static void CreateSpheres(Scene scene, Material material)
		{
			for (int i = 0; i < 10; i++)
			{
				var rigidActor = scene.Physics.CreateRigidDynamic();

				var sphereGeom = new SphereGeometry(radius: 2);
				var boxShape = rigidActor.CreateShape(sphereGeom, material);

				rigidActor.GlobalPose = Matrix.Translation(-10, 30 + i * (sphereGeom.Radius * 2 + 0.5f), 0);
				rigidActor.SetMassAndUpdateInertia(10);

				scene.AddActor(rigidActor);
			}
		}
开发者ID:kpko,项目名称:PhysX.Net,代码行数:15,代码来源:RigidBodiesSample.cs

示例7: CreateBoxes

		private static void CreateBoxes(Scene scene, Material material)
		{
			for (int i = 0; i < 10; i++)
			{
				var rigidActor = scene.Physics.CreateRigidDynamic();

				var boxGeom = new BoxGeometry(2, 2, 2);
				var boxShape = rigidActor.CreateShape(boxGeom, material);

				rigidActor.GlobalPose = Matrix.Translation(-20, 10 + i * (boxGeom.Size.Y + 0.5f), 0);
				rigidActor.SetMassAndUpdateInertia(10);

				scene.AddActor(rigidActor);
			}
		}
开发者ID:zwagoth,项目名称:PhysX.net,代码行数:15,代码来源:RigidBodiesSample.cs

示例8: StackOfBoxes

		public static void StackOfBoxes(Scene scene)
		{
			for (int i = 0; i < 10; i++)
			{
				var rigidActor = scene.Physics.CreateRigidDynamic();

				var material = scene.Physics.CreateMaterial(0.7f, 0.7f, 0.1f);

				var boxGeom = new BoxGeometry(2, 2, 2);
				var boxShape = rigidActor.CreateShape(boxGeom, material);

				rigidActor.GlobalPose = Matrix.Translation(0, 10 + i * boxGeom.Size.Y, 0);
				rigidActor.SetMassAndUpdateInertia(10);

				scene.AddActor(rigidActor);
			}
		}
开发者ID:zwagoth,项目名称:PhysX.net,代码行数:17,代码来源:RigidActorsSample.cs

示例9: CreateBoxes

		private static void CreateBoxes(Scene scene, Material material)
		{
			for (int i = 0; i < 10; i++)
			{
				var rigidActor = scene.Physics.CreateRigidDynamic();

				var boxGeom = new BoxGeometry(2, 2, 2);
				var boxShape = rigidActor.CreateShape(boxGeom, material);

				rigidActor.GlobalPose = Matrix.Translation(-20, 10 + i * (boxGeom.Size.Y + 0.5f), 0);
				rigidActor.SetMassAndUpdateInertia(10);

				scene.AddActor(rigidActor);

				// Spin the cube
				rigidActor.AddTorque(new Vector3(0, 50000, 0), ForceMode.Acceleration, true);
			}
		}
开发者ID:kpko,项目名称:PhysX.Net,代码行数:18,代码来源:RigidBodiesSample.cs

示例10: CreateFluidBlob

		private static void CreateFluidBlob(Scene scene)
		{
			// The number of particles we want along one of the three dimensions
			const int d = 15;

			// Create the particle fluid
			var particleFluid = scene.Physics.CreateParticleFluid(d * d * d);

			particleFluid.RestParticleDistance *= 10.5f;

			//

			// Create an array to hold the positions of the particles
			var particlePositions = new Vector3[particleFluid.MaximumParticles];

			var blobOffset = -new Vector3(d) * 0.5f;

			int i = 0;
			for (int x = 0; x < d; x++)
			{
				for (int y = 0; y < d; y++)
				{
					for (int z = 0; z < d; z++)
					{
						// Compute the location in a grid of particles + move the grid back so its center is at 0, 0, 0
						particlePositions[i++] = new Vector3(x, 20 + y, z) + blobOffset;
					}
				}
			}

			// Add the particles
			var particleCreateDesc = new ParticleCreationData()
			{
				NumberOfParticles = particleFluid.MaximumParticles,
				PositionBuffer = particlePositions,
				IndexBuffer = Enumerable.Range(0, particlePositions.Length).ToArray()
			};

			int numCreated = particleFluid.CreateParticles(particleCreateDesc);

			scene.AddActor(particleFluid);
		}
开发者ID:flair2005,项目名称:PhysX.Net,代码行数:42,代码来源:FluidSample.cs

示例11: OnAdd

        public override void OnAdd(Scene scene)
        {
            base.OnAdd(scene);

            scene.AddActor(this);

            PhysicsSystem world = scene.GetPhysicsEngine();

            Vector3 pos = Vector3.Up * 256 + 15*(new Vector3((float)RandomHelper.RandomGen.NextDouble(), (float)RandomHelper.RandomGen.NextDouble(), (float)RandomHelper.RandomGen.NextDouble())*2-Vector3.One);
            //pos.X += (scene.MainTerrain as TerrainHeightmap).GetWidth()*0.5f;
            //pos.Z += (scene.MainTerrain as TerrainHeightmap).GetDepth() * 0.5f;
            Vector3 normal = Vector3.Up;
            //scene.MainTerrain.GenerateRandomTransform(RandomHelper.RandomGen, out pos, out normal);
            //pos = pos + Vector3.Up * 5;

            body = new CharacterBody();
            collision = new CollisionSkin(body);

            standCapsule = new Capsule(Vector3.Zero, Matrix.CreateRotationX(MathHelper.PiOver2), 1.0f, 1.778f);
            crouchCapsule = new Capsule(Vector3.Zero, Matrix.CreateRotationX(MathHelper.PiOver2), 1.0f, 1.0f);
            SetupPosture(false);
            collision.AddPrimitive(standCapsule, (int)MaterialTable.MaterialID.NormalRough);
            body.CollisionSkin = collision;
            Vector3 com = PhysicsHelper.SetMass(75.0f, body, collision);

            body.MoveTo(pos + com, Matrix.Identity);
            collision.ApplyLocalTransform(new JigLibX.Math.Transform(-com, Matrix.Identity));

            body.SetBodyInvInertia(0.0f, 0.0f, 0.0f);

            body.AllowFreezing = false;
            body.EnableBody();
            Transformation = new Transform(body);

            ResetState();
        }
开发者ID:MattVitelli,项目名称:IslandAdventure,代码行数:36,代码来源:Actor.cs

示例12: LoadPhysics

		protected override void LoadPhysics(Scene scene)
		{
			var material = scene.Physics.CreateMaterial(0.7f, 0.7f, 0.1f);

			// Spherical Joint
			{
				var box = scene.Physics.CreateRigidDynamic();
				box.CreateShape(new BoxGeometry(2, 2, 2), material);
				box.GlobalPose = Matrix4x4.CreateTranslation(0, 10, 0);
				box.SetMassAndUpdateInertia(10);

				//

				var sphericalJoint = scene.CreateJoint<SphericalJoint>(box, Matrix4x4.CreateTranslation(0, 4, 0), null, Matrix4x4.CreateTranslation(0, 15, 0));
				sphericalJoint.ConstraintFlag = ConstraintFlag.Visualization;

				scene.AddActor(box);
			}

			// Revolute Joint
			{
				var box = scene.Physics.CreateRigidDynamic();
				box.CreateShape(new BoxGeometry(2, 2, 2), material);
				box.GlobalPose = Matrix4x4.CreateTranslation(-10, 10, 0);
				box.SetMassAndUpdateInertia(10);

				//

				var revoluteJoint = scene.CreateJoint<RevoluteJoint>(box, Matrix4x4.CreateTranslation(0, 4, 0), null, Matrix4x4.CreateTranslation(-10, 15, 0));
				revoluteJoint.ConstraintFlag = ConstraintFlag.Visualization;

				scene.AddActor(box);
			}

			// Breakable Revolute Joint
			{
				var box = scene.Physics.CreateRigidDynamic();
				box.CreateShape(new BoxGeometry(2, 2, 2), material);
				box.GlobalPose = Matrix4x4.CreateTranslation(10, 10, 0);
				box.SetMassAndUpdateInertia(10);

				//

				var revoluteJoint = scene.CreateJoint<RevoluteJoint>(box, Matrix4x4.CreateTranslation(0, 4, 0), null, Matrix4x4.CreateTranslation(10, 15, 0));
				revoluteJoint.ConstraintFlag = ConstraintFlag.Visualization;
				revoluteJoint.BreakForce = 0.001f;

				scene.AddActor(box);
			}

			// Distance Joint
			{
				var box = scene.Physics.CreateRigidDynamic();
				box.CreateShape(new BoxGeometry(2, 2, 2), material);
				box.GlobalPose = Matrix4x4.CreateTranslation(-20, 10, 0);
				box.SetMassAndUpdateInertia(10);

				//

				var distanceJoint = scene.CreateJoint<DistanceJoint>(box, Matrix4x4.CreateTranslation(0, 4, 0), null, Matrix4x4.CreateTranslation(-20, 15, 0));
				distanceJoint.ConstraintFlag = ConstraintFlag.Visualization;
				distanceJoint.MinimumDistance = 1;
				distanceJoint.MaximumDistance = 3;

				scene.AddActor(box);
			}

			// Fixed Joint
			{
				var box = scene.Physics.CreateRigidDynamic();
				box.CreateShape(new BoxGeometry(2, 2, 2), material);
				box.GlobalPose = Matrix4x4.CreateTranslation(-30, 15, 0);
				box.SetMassAndUpdateInertia(10);

				//

				var fixedJoint = scene.CreateJoint<FixedJoint>(box, Matrix4x4.Identity, null, Matrix4x4.CreateTranslation(-30, 15, 0));
				fixedJoint.ConstraintFlag = ConstraintFlag.Visualization;

				scene.AddActor(box);
			}

			// Prismatic Joint
			{
				var box = scene.Physics.CreateRigidDynamic();
				box.CreateShape(new BoxGeometry(2, 2, 2), material);
				box.GlobalPose = Matrix4x4.CreateTranslation(-40, 15, 0);
				box.SetMassAndUpdateInertia(10);

				//

				var prismaticJoint = scene.CreateJoint<PrismaticJoint>(box, Matrix4x4.Identity, null, Matrix4x4.CreateTranslation(-40, 15, 0));
				prismaticJoint.ConstraintFlag = ConstraintFlag.Visualization;

				scene.AddActor(box);
			}

			// D6 Joint
			{
				var box = scene.Physics.CreateRigidDynamic();
//.........这里部分代码省略.........
开发者ID:flair2005,项目名称:PhysX.Net,代码行数:101,代码来源:JointsSample.cs

示例13: CreateHeightField

		private void CreateHeightField(Scene scene, Material material)
		{
			const int rows = 25, columns = 25;
			const float scale = 3;

			var samples = CreateSampleGrid(rows, columns);

			var heightFieldDesc = new HeightFieldDesc()
			{
				NumberOfRows = rows,
				NumberOfColumns = columns,
				Samples = samples
			};

			HeightField heightField = scene.Physics.CreateHeightField(heightFieldDesc);

			//

			var rigidActor = scene.Physics.CreateRigidStatic();

			var heightFieldGeom = new HeightFieldGeometry(heightField, MeshGeometryFlag.DoubleSided, 1, scale, scale);

			rigidActor.CreateShape(heightFieldGeom, material);

			rigidActor.GlobalPose = Matrix.Translation(30, 30, -32.5f);

			scene.AddActor(rigidActor);
		}
开发者ID:kpko,项目名称:PhysX.Net,代码行数:28,代码来源:RigidBodiesSample.cs

示例14: CreateCapsules

		private static void CreateCapsules(Scene scene, Material material)
		{
			for (int i = 0; i < 10; i++)
			{
				var rigidActor = scene.Physics.CreateRigidDynamic();

				var capsuleGeom = new CapsuleGeometry(radius: 2, halfHeight: 2);
				var boxShape = rigidActor.CreateShape(capsuleGeom, material);

				rigidActor.GlobalPose = Matrix.Translation(0, 30 + i * (capsuleGeom.HalfHeight + capsuleGeom.Radius + 0.5f), 0);
				rigidActor.SetMassAndUpdateInertia(10);

				scene.AddActor(rigidActor);
			}
		}
开发者ID:kpko,项目名称:PhysX.Net,代码行数:15,代码来源:RigidBodiesSample.cs

示例15: CreateConvexMesh

		private void CreateConvexMesh(Scene scene, Material material)
		{
			var colladaLoader = new ColladaLoader();
			var bunny = colladaLoader.Load(@"Teapot.DAE", this.Engine.GraphicsDevice);

			var convexMeshDesc = new ConvexMeshDesc()
			{
				Flags = ConvexFlag.ComputeConvex
			};
			convexMeshDesc.SetPositions(bunny.VertexPositions);
			convexMeshDesc.SetTriangles(bunny.Indices);

			var cooking = scene.Physics.CreateCooking();

			var stream = new MemoryStream();
			var cookResult = cooking.CookConvexMesh(convexMeshDesc, stream);

			stream.Position = 0;

			var convexMesh = scene.Physics.CreateConvexMesh(stream);

			var convexMeshGeom = new ConvexMeshGeometry(convexMesh)
			{
				Scale = new MeshScale(new Vector3(0.3f, 0.3f, 0.3f), Quaternion.Identity)
			};

			var rigidActor = scene.Physics.CreateRigidDynamic();

			// TODO: The Shape created here is now also an owner of the ConvexMesh object,
			// this needs to be incorp into the ObjectTable ownership logic
			rigidActor.CreateShape(convexMeshGeom, material);

			rigidActor.GlobalPose =
				Matrix.RotationX(-(float)System.Math.PI / 2) *
				Matrix.Translation(0, 80, 0);

			scene.AddActor(rigidActor);
		}
开发者ID:kpko,项目名称:PhysX.Net,代码行数:38,代码来源:RigidBodiesSample.cs


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