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); }
public void CreateHeightfieldTest() { int rows = 25; int columns = 25; HeightFieldSample[] 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; HeightFieldSample sample = new HeightFieldSample() { Height = (short)h, MaterialIndex0 = 0, MaterialIndex1 = 1, TessellationFlag = 0 }; samples[ r * columns + c ] = sample; } } HeightFieldDescription heightFieldDesc = new HeightFieldDescription() { NumberOfRows = rows, NumberOfColumns = columns }; heightFieldDesc.SetSamples( samples ); using (CreateCoreAndScene()) { HeightField heightField = this.Core.CreateHeightField(heightFieldDesc); // HeightFieldShapeDescription 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); ActorDescription actorDesc = new ActorDescription() { GlobalPose = Matrix.Translation(100, 0, 0), Shapes = { heightFieldShapeDesc } }; Actor actor = this.Scene.CreateActor(actorDesc); } }
Actor CreateActorFromHeightmap(float[] heightmap) { HeightFieldSample[] samples = new HeightFieldSample[heightmap.Length]; float min = float.MaxValue, max = float.MinValue; for(int i=0;i<heightmap.Length;i++) { if(heightmap[i] > max) max = heightmap[i]; if(heightmap[i] < min) min = heightmap[i]; } for(int i=0;i<heightmap.Length;i++) { short normValue = (short) ((float) ((heightmap[i] - min)/(max - min))*(float) short.MaxValue); samples[i] = new HeightFieldSample(); samples[i].Height = normValue; samples[i].MaterialIndex0 = 0; samples[i].MaterialIndex1 = 1; samples[i].TessellationFlag = 0; // Might be important? } HeightFieldDescription heightFieldDescription = new HeightFieldDescription(); // Might cause fun with MegaRegions heightFieldDescription.NumberOfRows = (int) Constants.RegionSize; heightFieldDescription.NumberOfColumns = (int) Constants.RegionSize; HeightField heightField = physicsCore.CreateHeightField(heightFieldDescription); HeightFieldShapeDescription heightFieldShapeDescription = new HeightFieldShapeDescription() { HeightField = heightField, HoleMaterial = 2, HeightScale = (max - min), RowScale = 1.0f, ColumnScale = 1.0f }; heightFieldShapeDescription.LocalPosition = new Vector3(0, 0, min); // May need to move to ActorDescription.GlobalPos? ActorDescription actorDescription = new ActorDescription() { Shapes = {heightFieldShapeDescription} }; Actor actor = physicsScene.CreateActor(actorDescription); return actor; }
/// <summary> /// Creates a height field object in the world /// </summary> /// <param name="heightFieldDescription"> </param> /// <returns></returns> public IWorldObject CreateHeightField(HeightFieldDescription heightFieldDescription) { lock (this) { var heightField = new QuantumHeightField(heightFieldDescription.WidthX, heightFieldDescription.WidthZ, heightFieldDescription.Heights, heightFieldDescription.Position); return(new QuantumRigidbody(heightField) { Position = heightFieldDescription.Position, Rotation = Quaternion.Identity }); } }
/// <summary> /// Creates a height field object in the world /// </summary> /// <param name="heightFieldDescription"> </param> /// <returns></returns> public IWorldObject CreateHeightField(HeightFieldDescription heightFieldDescription) { lock (this) { var heightField = new RuneHeightField(heightFieldDescription.WidthX, heightFieldDescription.WidthZ, heightFieldDescription.Heights); var rigidBody = new RuneRigidbody(heightField) { Pose = new Pose(heightFieldDescription.Position.ToRuneVector(), QuaternionF.Identity), }; rigidBody.CollisionObject.CollisionGroup = CollisionGroupObject; rigidBody.MotionType = MotionType.Static; this.simulation.RigidBodies.Add(rigidBody); return(rigidBody); } }
/// <summary> /// Creates a height field object in the world /// </summary> /// <param name="heightFieldDescription"> </param> /// <returns></returns> public IHeightField CreateHeightField(HeightFieldDescription heightFieldDescription) { var position = heightFieldDescription.Position; var terrain = new Terrain(heightFieldDescription.Heights, new AffineTransform(new Vector3(position.X, position.Y, position.Z))) { CollisionRules = { Group = this.staticGroup }, Material = this.frictionlessMaterial, Thickness = 10, }; //var terrain = new BEPUTerrain(heights, position) {CollisionRules = {Group = this.terrainGroup}}; this.space.Add(terrain); return(null); }
public void LoadPhysics() { Core _core = this.Core; Scene _scene = this.Scene; #region Some Boxes 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); } #endregion //#region Cloth (Flag) //{ // // 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.CreateFromYawPitchRoll( 0, (float)Math.PI / 2.0f, (float)Math.PI / 2.0f ) * // Matrix.CreateTranslation( 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; // _flag = _scene.CreateCloth( clothDesc ); // // Flag Pole // ActorDescription flagPoleActorDesc = new ActorDescription() // { // GlobalPose = Matrix.CreateTranslation( 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; //} //#endregion #region Revolute Joint { 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; } #endregion #region Prismatic Joint with Limit { 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); } #endregion #region Fluid { const int maximumParticles = 1000; FluidEmitterDescription fluidEmitterDesc = new FluidEmitterDescription() { DimensionX = 0.5f, DimensionY = 0.5f, Rate = 15, RelativePose = Matrix.Translation(-40, 10, 50), Shape = EmitterShape.Rectangular, Type = EmitterType.ConstantFlowRate, RandomAngle = 0.5f }; fluidEmitterDesc.Flags |= (FluidEmitterFlag.Enabled | FluidEmitterFlag.Visualization); FluidDescription fluidDesc = new FluidDescription() { Emitters = { fluidEmitterDesc }, Flags = FluidFlag.Enabled | FluidFlag.Visualization, MaximumParticles = maximumParticles }; fluidDesc.ParticleWriteData.AllocatePositionBuffer <Vector3>(maximumParticles); fluidDesc.ParticleWriteData.NumberOfParticles = maximumParticles; Fluid fluid = _scene.CreateFluid(fluidDesc); // Ledge { BoxShapeDescription boxShapeDesc = new BoxShapeDescription(5, 0.1f, 5); ActorDescription drainActorDesc = new ActorDescription() { GlobalPose = Matrix.RotationX(0.5f) * Matrix.Translation(-40, 5, 52), Shapes = { boxShapeDesc } }; Actor drianActor = _scene.CreateActor(drainActorDesc); } // Drain { BoxShapeDescription boxShapeDesc = new BoxShapeDescription(5, 0.1f, 5); boxShapeDesc.Flags |= ShapeFlag.FluidDrain; ActorDescription drainActorDesc = new ActorDescription() { GlobalPose = Matrix.Translation(-40, 0, 55), Shapes = { boxShapeDesc } }; Actor drianActor = _scene.CreateActor(drainActorDesc); } } #endregion #region Force Field { BoxForceFieldShapeDescription boxForceFieldShapeDesc = new BoxForceFieldShapeDescription() { Size = new Vector3(10, 10, 10) }; ForceFieldLinearKernelDescription kernelDesc = new ForceFieldLinearKernelDescription() { Constant = new Vector3(0, 100.0f, 0) }; ForceFieldLinearKernel kernel = _scene.CreateForceFieldLinearKernel(kernelDesc); ForceFieldShapeGroupDescription shapeGroupDesc = new ForceFieldShapeGroupDescription() { Shapes = { boxForceFieldShapeDesc } }; ForceFieldShapeGroup shapeGroup = _scene.CreateForceFieldShapeGroup(shapeGroupDesc); BoxForceFieldShape boxForceFieldShape = shapeGroup.CreateShape(boxForceFieldShapeDesc) as BoxForceFieldShape; boxForceFieldShape.Pose = Matrix.Translation(30, 5, 0); ForceFieldDescription forceFieldDesc = new ForceFieldDescription() { Kernel = kernel, ShapeGroups = { shapeGroup } }; ForceField forceField = _scene.CreateForceField(forceFieldDesc); } #endregion #region Heightfield { int rows = 25; int columns = 25; HeightFieldSample[] 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; HeightFieldSample sample = new HeightFieldSample() { Height = (short)h, MaterialIndex0 = 0, MaterialIndex1 = 1, TessellationFlag = 0 }; samples[r * columns + c] = sample; } } HeightFieldDescription heightFieldDesc = new HeightFieldDescription() { NumberOfRows = rows, NumberOfColumns = columns }; heightFieldDesc.SetSamples(samples); HeightField heightField = _core.CreateHeightField(heightFieldDesc); // HeightFieldShapeDescription 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); ActorDescription actorDesc = new ActorDescription() { GlobalPose = Matrix.Translation(100, 0, 0), Shapes = { heightFieldShapeDesc } }; Actor actor = _scene.CreateActor(actorDesc); } #endregion //#region Convex Mesh //{ // ModelMesh mesh = _torusModel.Meshes.First(); // Matrix[] transforms = new Matrix[ _torusModel.Bones.Count ]; // _torusModel.CopyAbsoluteBoneTransformsTo( transforms ); // // Gets the vertices from the mesh // VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[ mesh.MeshParts[ 0 ].NumVertices ]; // mesh.VertexBuffer.GetData<VertexPositionNormalTexture>( vertices ); // // // // Allocate memory for the points and triangles // var convexMeshDesc = new ConvexMeshDescription() // { // PointCount = vertices.Length // }; // convexMeshDesc.Flags |= ConvexFlag.ComputeConvex; // convexMeshDesc.AllocatePoints<Vector3>( vertices.Length ); // // Write in the points and triangles // // We only want the Position component of the vertex. Also scale down the mesh // foreach( VertexPositionNormalTexture vertex in vertices ) // { // Vector3 position = Vector3.Transform( vertex.Position, Matrix.CreateScale( 0.1f, 0.1f, 0.1f ) * transforms[ 0 ] ); // convexMeshDesc.PointsStream.Write( position ); // } // // // // Cook to memory or to a file // MemoryStream 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 convexMesh = _core.CreateConvexMesh( stream ); // ConvexShapeDescription convexShapeDesc = new ConvexShapeDescription( convexMesh ); // ActorDescription actorDesc = new ActorDescription() // { // BodyDescription = new BodyDescription( 10.0f ), // GlobalPose = Matrix.CreateTranslation( 30, 30, 0 ) // }; // actorDesc.Shapes.Add( convexShapeDesc ); // _torusActor = _scene.CreateActor( actorDesc ); //} //#endregion //#region SoftBody //if( false ) // Enable to view soft bodies, they run slowly //{ // XmlDocument doc = new XmlDocument(); // doc.Load( "Teapot.xml" ); // // Not how NxuStream are meant to used but what ever :S // Vector3[] vertices = ReadVertices( doc.SelectSingleNode( "/NXUSTREAM2/NxuPhysicsCollection/NxSoftBodyMeshDesc/vertices" ) ); // int[] tetrahedraSingles = ReadTetrahedra( doc.SelectSingleNode( "/NXUSTREAM2/NxuPhysicsCollection/NxSoftBodyMeshDesc/tetrahedra" ) ); // var softBodyMeshDesc = new SoftBodyMeshDescription() // { // VertexCount = vertices.Length, // TetrahedraCount = tetrahedraSingles.Length / 4 // Tetrahedras come in quadruples of ints // }; // softBodyMeshDesc.AllocateVertices<Vector3>( softBodyMeshDesc.VertexCount ); // softBodyMeshDesc.AllocateTetrahedra<int>( softBodyMeshDesc.TetrahedraCount ); // Note: T is an int. T is the type of each point // softBodyMeshDesc.VertexStream.SetData( vertices ); // softBodyMeshDesc.TetrahedraStream.SetData( tetrahedraSingles ); // MemoryStream memoryStream = new MemoryStream(); // Cooking.InitializeCooking(); // Cooking.CookSoftBodyMesh( softBodyMeshDesc, memoryStream ); // Cooking.CloseCooking(); // memoryStream.Position = 0; // SoftBodyMesh softBodyMesh = _core.CreateSoftBodyMesh( memoryStream ); // SoftBodyDescription desc = new SoftBodyDescription() // { // GlobalPose = Matrix.CreateTranslation( -30, 20, -30 ), // SoftBodyMesh = softBodyMesh // }; // desc.Flags |= SoftBodyFlag.Visualization; // desc.MeshData.AllocatePositions<Vector3>( vertices.Length ); // desc.MeshData.AllocateIndices<int>( tetrahedraSingles.Length ); // SoftBody softBody = _scene.CreateSoftBody( desc ); //} //#endregion //#region Reports //// 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.CreateTranslation( -30, 20, 0 ), // BodyDescription = new BodyDescription( 10.0f ), // Name = "Report Capsule", // Shapes = { capsuleShapeDesc } // }; // _contactReportActor = _scene.CreateActor( actorDesc ); // _scene.SetActorPairFlags( _contactReportActor, _groundActor, ContactPairFlag.All ); // _scene.UserContactReport = new ContactReport( this ); //} //// Trigger Reports //{ // BoxShapeDescription boxShapeDesc = new BoxShapeDescription( 15, 8, 15 ); // boxShapeDesc.Flags |= ( ShapeFlag.TriggerOnEnter | ShapeFlag.TriggerOnLeave ); // ActorDescription actorDesc = new ActorDescription() // { // GlobalPose = Matrix.CreateTranslation( -30, 4, 0 ), // Shapes = { boxShapeDesc } // }; // _scene.CreateActor( actorDesc ); // _scene.UserTriggerReport = new TriggerReport( this ); //} //_scene.UserNotify = new Notify( this ); //#endregion //#region Wheel //{ // _basicVehicle = new Vehicle( this ); //} //#endregion #region Controller { ControllerManager manager = _scene.CreateControllerManager(); CapsuleControllerDescription capsuleControllerDesc = new CapsuleControllerDescription(4, 3); CapsuleController capsuleController = manager.CreateController <CapsuleController>(capsuleControllerDesc); capsuleController.Position = new Vector3(0, 1.5f + 2, -15); capsuleController.Actor.Name = "BoxController"; capsuleController.SetCollisionEnabled(true); } #endregion }
public void Run() { var worldBounds = new Bounds() { Min = new Vector3(0, -5000, 0), Max = new Vector3(2000, 5000, 1600) }; var serialNumber = @"tgCcAQADXEY+784BLMKfsg8O0AEnACNQcmF2ZWVuIFB1dmFuYXNpbmdhbSMxIzEjTm9uQ29tbWVyY2lhbECDssOQzVFUBAMB/A9Wt80a70/+9vKHaeL+Sj8kTFNIChTkCbzgKeebsjGh6Gx5YhufqQqjlT4HHZLRuk8="; var physics = new RunePhysicsWorld(worldBounds, serialNumber); var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", "map0.map"); float[,] heights; using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read)) { var buffer = new byte[sizeof(int)]; stream.Read(buffer, 0, buffer.Length); var c = BitConverter.ToInt32(buffer, 0); buffer = new byte[sizeof(int)]; stream.Read(buffer, 0, buffer.Length); var r = BitConverter.ToInt32(buffer, 0); heights = new float[c, r]; for (var z = 0; z < r; z++) { for (var x = 0; x < c; x++) { buffer = new byte[sizeof(float)]; stream.Read(buffer, 0, sizeof(float)); heights[x, z] = BitConverter.ToSingle(buffer, 0); } } } var heightFieldDescription = new HeightFieldDescription() { Heights = heights, Position = Vector3.Zero, WidthX = 2000, WidthZ = 1600, }; physics.CreateHeightField(heightFieldDescription); var boxDescription = new BoxDescription() { Position = new Vector3(1, 100, 1), Rotation = Quaternion.Identity, Size = new Vector3(1, 1, 1) }; physics.CreateWorldObject(boxDescription, CollisionHelper.AvatarObjectColliderDescription); var rnd = new Random(); var characterControllerDescription = new CharacterControllerDescription() { Height = 2f, Radius = .5f, SkinWidth = .03f, SlopeLimit = 45, StepOffset = .3f, Position = new Vector3(200, 20, 200), }; var controller = physics.CreateCharacterController(characterControllerDescription); controller.Position = new Vector3(rnd.Next(1, 1999), 100, rnd.Next(1, 1599)); controller.LocalVelocity = new Vector3(0, 0, 5); var body = new RigidBody(new BoxShape(10, 10, 1)) { MotionType = MotionType.Static, }; body.CollisionObject.Type = CollisionObjectType.Trigger; Console.WriteLine("simulation stated..."); try { var timer2 = Stopwatch.StartNew(); timer2.Start(); while (true) { Thread.Sleep(60); controller.LocalVelocity = new Vector3(0, 0, timer2.ElapsedMilliseconds / 60f); Console.WriteLine(controller.Position); timer2.Restart(); } } finally { Console.WriteLine("simulation ended..."); } }
public void LoadPhysics() { Core _core = this.Core; Scene _scene = this.Scene; #region Some Boxes 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 ); } #endregion //#region Cloth (Flag) //{ // // 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.CreateFromYawPitchRoll( 0, (float)Math.PI / 2.0f, (float)Math.PI / 2.0f ) * // Matrix.CreateTranslation( 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; // _flag = _scene.CreateCloth( clothDesc ); // // Flag Pole // ActorDescription flagPoleActorDesc = new ActorDescription() // { // GlobalPose = Matrix.CreateTranslation( 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; //} //#endregion #region Revolute Joint { 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; } #endregion #region Prismatic Joint with Limit { 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 ); } #endregion #region Fluid { const int maximumParticles = 1000; FluidEmitterDescription fluidEmitterDesc = new FluidEmitterDescription() { DimensionX = 0.5f, DimensionY = 0.5f, Rate = 15, RelativePose = Matrix.Translation( -40, 10, 50 ), Shape = EmitterShape.Rectangular, Type = EmitterType.ConstantFlowRate, RandomAngle = 0.5f }; fluidEmitterDesc.Flags |= ( FluidEmitterFlag.Enabled | FluidEmitterFlag.Visualization ); FluidDescription fluidDesc = new FluidDescription() { Emitters = { fluidEmitterDesc }, Flags = FluidFlag.Enabled | FluidFlag.Visualization, MaximumParticles = maximumParticles }; fluidDesc.ParticleWriteData.AllocatePositionBuffer<Vector3>( maximumParticles ); fluidDesc.ParticleWriteData.NumberOfParticles = maximumParticles; Fluid fluid = _scene.CreateFluid( fluidDesc ); // Ledge { BoxShapeDescription boxShapeDesc = new BoxShapeDescription( 5, 0.1f, 5 ); ActorDescription drainActorDesc = new ActorDescription() { GlobalPose = Matrix.RotationX( 0.5f ) * Matrix.Translation( -40, 5, 52 ), Shapes = { boxShapeDesc } }; Actor drianActor = _scene.CreateActor( drainActorDesc ); } // Drain { BoxShapeDescription boxShapeDesc = new BoxShapeDescription( 5, 0.1f, 5 ); boxShapeDesc.Flags |= ShapeFlag.FluidDrain; ActorDescription drainActorDesc = new ActorDescription() { GlobalPose = Matrix.Translation( -40, 0, 55 ), Shapes = { boxShapeDesc } }; Actor drianActor = _scene.CreateActor( drainActorDesc ); } } #endregion #region Force Field { BoxForceFieldShapeDescription boxForceFieldShapeDesc = new BoxForceFieldShapeDescription() { Size = new Vector3( 10, 10, 10 ) }; ForceFieldLinearKernelDescription kernelDesc = new ForceFieldLinearKernelDescription() { Constant = new Vector3( 0, 100.0f, 0 ) }; ForceFieldLinearKernel kernel = _scene.CreateForceFieldLinearKernel( kernelDesc ); ForceFieldShapeGroupDescription shapeGroupDesc = new ForceFieldShapeGroupDescription() { Shapes = { boxForceFieldShapeDesc } }; ForceFieldShapeGroup shapeGroup = _scene.CreateForceFieldShapeGroup( shapeGroupDesc ); BoxForceFieldShape boxForceFieldShape = shapeGroup.CreateShape( boxForceFieldShapeDesc ) as BoxForceFieldShape; boxForceFieldShape.Pose = Matrix.Translation( 30, 5, 0 ); ForceFieldDescription forceFieldDesc = new ForceFieldDescription() { Kernel = kernel, ShapeGroups = { shapeGroup } }; ForceField forceField = _scene.CreateForceField( forceFieldDesc ); } #endregion #region Heightfield { int rows = 25; int columns = 25; HeightFieldSample[] 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; HeightFieldSample sample = new HeightFieldSample() { Height = (short)h, MaterialIndex0 = 0, MaterialIndex1 = 1, TessellationFlag = 0 }; samples[ r * columns + c ] = sample; } } HeightFieldDescription heightFieldDesc = new HeightFieldDescription() { NumberOfRows = rows, NumberOfColumns = columns }; heightFieldDesc.SetSamples( samples ); HeightField heightField = _core.CreateHeightField( heightFieldDesc ); // HeightFieldShapeDescription 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 ); ActorDescription actorDesc = new ActorDescription() { GlobalPose = Matrix.Translation( 100, 0, 0 ), Shapes = { heightFieldShapeDesc } }; Actor actor = _scene.CreateActor( actorDesc ); } #endregion //#region Convex Mesh //{ // ModelMesh mesh = _torusModel.Meshes.First(); // Matrix[] transforms = new Matrix[ _torusModel.Bones.Count ]; // _torusModel.CopyAbsoluteBoneTransformsTo( transforms ); // // Gets the vertices from the mesh // VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[ mesh.MeshParts[ 0 ].NumVertices ]; // mesh.VertexBuffer.GetData<VertexPositionNormalTexture>( vertices ); // // // // Allocate memory for the points and triangles // var convexMeshDesc = new ConvexMeshDescription() // { // PointCount = vertices.Length // }; // convexMeshDesc.Flags |= ConvexFlag.ComputeConvex; // convexMeshDesc.AllocatePoints<Vector3>( vertices.Length ); // // Write in the points and triangles // // We only want the Position component of the vertex. Also scale down the mesh // foreach( VertexPositionNormalTexture vertex in vertices ) // { // Vector3 position = Vector3.Transform( vertex.Position, Matrix.CreateScale( 0.1f, 0.1f, 0.1f ) * transforms[ 0 ] ); // convexMeshDesc.PointsStream.Write( position ); // } // // // // Cook to memory or to a file // MemoryStream 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 convexMesh = _core.CreateConvexMesh( stream ); // ConvexShapeDescription convexShapeDesc = new ConvexShapeDescription( convexMesh ); // ActorDescription actorDesc = new ActorDescription() // { // BodyDescription = new BodyDescription( 10.0f ), // GlobalPose = Matrix.CreateTranslation( 30, 30, 0 ) // }; // actorDesc.Shapes.Add( convexShapeDesc ); // _torusActor = _scene.CreateActor( actorDesc ); //} //#endregion //#region SoftBody //if( false ) // Enable to view soft bodies, they run slowly //{ // XmlDocument doc = new XmlDocument(); // doc.Load( "Teapot.xml" ); // // Not how NxuStream are meant to used but what ever :S // Vector3[] vertices = ReadVertices( doc.SelectSingleNode( "/NXUSTREAM2/NxuPhysicsCollection/NxSoftBodyMeshDesc/vertices" ) ); // int[] tetrahedraSingles = ReadTetrahedra( doc.SelectSingleNode( "/NXUSTREAM2/NxuPhysicsCollection/NxSoftBodyMeshDesc/tetrahedra" ) ); // var softBodyMeshDesc = new SoftBodyMeshDescription() // { // VertexCount = vertices.Length, // TetrahedraCount = tetrahedraSingles.Length / 4 // Tetrahedras come in quadruples of ints // }; // softBodyMeshDesc.AllocateVertices<Vector3>( softBodyMeshDesc.VertexCount ); // softBodyMeshDesc.AllocateTetrahedra<int>( softBodyMeshDesc.TetrahedraCount ); // Note: T is an int. T is the type of each point // softBodyMeshDesc.VertexStream.SetData( vertices ); // softBodyMeshDesc.TetrahedraStream.SetData( tetrahedraSingles ); // MemoryStream memoryStream = new MemoryStream(); // Cooking.InitializeCooking(); // Cooking.CookSoftBodyMesh( softBodyMeshDesc, memoryStream ); // Cooking.CloseCooking(); // memoryStream.Position = 0; // SoftBodyMesh softBodyMesh = _core.CreateSoftBodyMesh( memoryStream ); // SoftBodyDescription desc = new SoftBodyDescription() // { // GlobalPose = Matrix.CreateTranslation( -30, 20, -30 ), // SoftBodyMesh = softBodyMesh // }; // desc.Flags |= SoftBodyFlag.Visualization; // desc.MeshData.AllocatePositions<Vector3>( vertices.Length ); // desc.MeshData.AllocateIndices<int>( tetrahedraSingles.Length ); // SoftBody softBody = _scene.CreateSoftBody( desc ); //} //#endregion //#region Reports //// 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.CreateTranslation( -30, 20, 0 ), // BodyDescription = new BodyDescription( 10.0f ), // Name = "Report Capsule", // Shapes = { capsuleShapeDesc } // }; // _contactReportActor = _scene.CreateActor( actorDesc ); // _scene.SetActorPairFlags( _contactReportActor, _groundActor, ContactPairFlag.All ); // _scene.UserContactReport = new ContactReport( this ); //} //// Trigger Reports //{ // BoxShapeDescription boxShapeDesc = new BoxShapeDescription( 15, 8, 15 ); // boxShapeDesc.Flags |= ( ShapeFlag.TriggerOnEnter | ShapeFlag.TriggerOnLeave ); // ActorDescription actorDesc = new ActorDescription() // { // GlobalPose = Matrix.CreateTranslation( -30, 4, 0 ), // Shapes = { boxShapeDesc } // }; // _scene.CreateActor( actorDesc ); // _scene.UserTriggerReport = new TriggerReport( this ); //} //_scene.UserNotify = new Notify( this ); //#endregion //#region Wheel //{ // _basicVehicle = new Vehicle( this ); //} //#endregion #region Controller { ControllerManager manager = _scene.CreateControllerManager(); CapsuleControllerDescription capsuleControllerDesc = new CapsuleControllerDescription( 4, 3 ); CapsuleController capsuleController = manager.CreateController<CapsuleController>( capsuleControllerDesc ); capsuleController.Position = new Vector3( 0, 1.5f + 2, -15 ); capsuleController.Actor.Name = "BoxController"; capsuleController.SetCollisionEnabled( true ); } #endregion }
protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory ,IContentManager contentManager) { PhysxPhysicWorld PhysxPhysicWorld = World.PhysicWorld as PhysxPhysicWorld; base.LoadContent(GraphicInfo, factory, contentManager); Texture2D tMap = factory.GetTexture2D("Textures//hmap_10243"); QuadTerrain q = new PloobsEngine.Material.QuadTerrain(factory, tMap, 33, 513, 10, 3f); ForwardTerrainMaterial mat = new ForwardTerrainMaterial(q); //Set various terrain stats. mat.diffuseScale = q.flatScale / 4; mat.detailScale = q.flatScale / 100; mat.detailMapStrength = 2; mat.textureBlend = factory.GetTexture2D("Textures//hmap_256blend"); mat.textureDetail = factory.GetTexture2D("Textures//coolgrass2DOT3"); mat.textureRed = factory.GetTexture2D("Textures//TexR"); mat.textureGreen = factory.GetTexture2D("Textures//TexG"); mat.textureBlue = factory.GetTexture2D("Textures//TexB"); mat.textureBlack = factory.GetTexture2D("Textures//TexBase"); mat.sunlightVector = Vector3.Normalize(new Vector3(.5f, .5f, .8f)); mat.sunlightColour = new Vector3(2.3f, 2f, 1.8f); float[,] f = q.getHeightMap(); int v = 513; var samples = new HeightFieldSample[v * v]; for (int r = 0; r < v; r++) { for (int c = 0; c < v ; c++) { var sample = new HeightFieldSample() { Height = (short)f[r, c], //Height = 5, TessellationFlag = 1, MaterialIndex0 = 1, MaterialIndex1 = 0 }; samples[r * v + c] = sample; } } var heightFieldDesc = new HeightFieldDescription() { NumberOfRows = v, NumberOfColumns = v, ConvexEdgeThreshold = 0f, }; heightFieldDesc.SetSamples(samples); var heightField = PhysxPhysicWorld.Core.CreateHeightField(heightFieldDesc); heightFieldDesc.Dispose(); var heightFieldShapeDesc = new HeightFieldShapeDescription() { HeightField = heightField, HeightScale = 1.0f, RowScale = 1, ColumnScale = 1, }; heightFieldShapeDesc.LocalPose = StillDesign.PhysX.MathPrimitives.Matrix.Identity; var actorDesc = new ActorDescription() { GlobalPose = Matrix.Identity.AsPhysX(), Shapes = { heightFieldShapeDesc }, }; actor = PhysxPhysicWorld.Scene.CreateActor(actorDesc); IObject obj3 = new IObject(mat, null, new PhysxGhostObject()); this.World.AddObject(obj3); BallThrowPhysx28 BallThrowBullet = new BallThrowPhysx28(this.World, GraphicFactory); this.AttachCleanUpAble(BallThrowBullet); CameraFirstPerson CameraFirstPerson = new CameraFirstPerson(GraphicInfo); CameraFirstPerson.FarPlane = 20000; this.World.CameraManager.AddCamera(CameraFirstPerson); }
protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager) { PhysxPhysicWorld PhysxPhysicWorld = World.PhysicWorld as PhysxPhysicWorld; base.LoadContent(GraphicInfo, factory, contentManager); Texture2D tMap = factory.GetTexture2D("Textures//hmap_10243"); QuadTerrain q = new PloobsEngine.Material.QuadTerrain(factory, tMap, 33, 513, 10, 3f); ForwardTerrainMaterial mat = new ForwardTerrainMaterial(q); //Set various terrain stats. mat.diffuseScale = q.flatScale / 4; mat.detailScale = q.flatScale / 100; mat.detailMapStrength = 2; mat.textureBlend = factory.GetTexture2D("Textures//hmap_256blend"); mat.textureDetail = factory.GetTexture2D("Textures//coolgrass2DOT3"); mat.textureRed = factory.GetTexture2D("Textures//TexR"); mat.textureGreen = factory.GetTexture2D("Textures//TexG"); mat.textureBlue = factory.GetTexture2D("Textures//TexB"); mat.textureBlack = factory.GetTexture2D("Textures//TexBase"); mat.sunlightVector = Vector3.Normalize(new Vector3(.5f, .5f, .8f)); mat.sunlightColour = new Vector3(2.3f, 2f, 1.8f); float[,] f = q.getHeightMap(); int v = 513; var samples = new HeightFieldSample[v * v]; for (int r = 0; r < v; r++) { for (int c = 0; c < v; c++) { var sample = new HeightFieldSample() { Height = (short)f[r, c], //Height = 5, TessellationFlag = 1, MaterialIndex0 = 1, MaterialIndex1 = 0 }; samples[r * v + c] = sample; } } var heightFieldDesc = new HeightFieldDescription() { NumberOfRows = v, NumberOfColumns = v, ConvexEdgeThreshold = 0f, }; heightFieldDesc.SetSamples(samples); var heightField = PhysxPhysicWorld.Core.CreateHeightField(heightFieldDesc); heightFieldDesc.Dispose(); var heightFieldShapeDesc = new HeightFieldShapeDescription() { HeightField = heightField, HeightScale = 1.0f, RowScale = 1, ColumnScale = 1, }; heightFieldShapeDesc.LocalPose = StillDesign.PhysX.MathPrimitives.Matrix.Identity; var actorDesc = new ActorDescription() { GlobalPose = Matrix.Identity.AsPhysX(), Shapes = { heightFieldShapeDesc }, }; actor = PhysxPhysicWorld.Scene.CreateActor(actorDesc); IObject obj3 = new IObject(mat, null, new PhysxGhostObject()); this.World.AddObject(obj3); BallThrowPhysx28 BallThrowBullet = new BallThrowPhysx28(this.World, GraphicFactory); this.AttachCleanUpAble(BallThrowBullet); CameraFirstPerson CameraFirstPerson = new CameraFirstPerson(GraphicInfo); CameraFirstPerson.FarPlane = 20000; this.World.CameraManager.AddCamera(CameraFirstPerson); }
/// <summary> /// Creates a new instance of the <see cref="MmoZone"/> class. /// </summary> /// <param name="world"> The world </param> /// <param name="name"> The name of the <see cref="MmoZone"/>. Does not have to be unique, this will be sent to the client. </param> /// <param name="id"> A unique id used to distinguish between other <see cref="MmoZone"/>s. Must be unique in order to avoid id conflicts. </param> /// <param name="tileDimentions"> </param> /// <param name="zoneDescription"> The zone data which contains data of the current zone </param> /// <param name="bounds"> </param> /// <param name="configuration"> </param> /// <remarks> /// The <see cref="MmoZone"/> uses an actual coordinate system, meaning x is right, z is forward and y is up always. /// </remarks> internal MmoZone(MmoWorld world, short id, string name, Bounds bounds, Vector3 tileDimentions, ZoneDescription zoneDescription, GameConfig configuration) : base(bounds, tileDimentions) { this.world = world; this.name = name; this.id = id; this.objectCache = new WorldObjectCache(PeerSettings.MaxLockWaitTime); this.dynamicObjectPool = new ObjectPool <short, Dynamic>(); this.localChatChannel = Chat.MmoChat.INVALID_CHAT_CHANNEL; this.tradeChatChannel = Chat.MmoChat.INVALID_CHAT_CHANNEL; var physicsEngineConfig = configuration.physics.engine; switch (physicsEngineConfig.type.ToLower()) { case "digitalrune": this.physics = new RunePhysicsWorld(Bounds, physicsEngineConfig.userObject); break; default: this.physics = new QuantumPhysicsWorld(Bounds, this); break; } var terrainWidthX = zoneDescription.TerrainWidthX; var terrainWidthZ = zoneDescription.TerrainWidthZ; var heights = new float[terrainWidthX, terrainWidthZ]; for (var z = 0; z < terrainWidthZ; z++) { for (var x = 0; x < terrainWidthX; x++) { // we need to load it in reverse order heights[x, z] = zoneDescription.Heights[z * terrainWidthX + x]; } } var heightFieldDescription = new HeightFieldDescription { Heights = heights, Position = Vector3.Zero, WidthX = terrainWidthX, WidthZ = terrainWidthZ }; this.heightField = physics.CreateHeightField(heightFieldDescription).Shape as IHeightField; if (heightField == null) { throw new NullReferenceException("heightField"); } // loading all box colliders var boxColliders = zoneDescription.Colliders.BoxColliders; if (boxColliders != null) { foreach (var boxCollider in boxColliders) { physics.CreateWorldObject(boxCollider, CollisionHelper.WorldObjectColliderDescription); } } // loading all sphere colliders var sphereColliders = zoneDescription.Colliders.SphereColliders; if (sphereColliders != null) { foreach (var sphereCollider in sphereColliders) { physics.CreateWorldObject(sphereCollider, CollisionHelper.WorldObjectColliderDescription); } } // loading all capsule colliders var capsuleColliders = zoneDescription.Colliders.CapsuleColliders; if (capsuleColliders != null) { foreach (var capsuleCollider in capsuleColliders) { physics.CreateWorldObject(capsuleCollider, CollisionHelper.WorldObjectColliderDescription); } } #if USE_PHYSICS // setting up the physics thread new Thread(o => { var timer = System.Diagnostics.Stopwatch.StartNew(); timer.Start(); while (true) { // sleeping for 16 ms ~ 1 / 60 s Thread.Sleep(16); // updating the physics engine this.physics.Update(timer.Elapsed); timer.Restart(); } }) { Priority = ThreadPriority.AboveNormal, IsBackground = true }.Start(this); #endif // load all npc, objects, items, quest, loot, etc this.PrimaryFiber.Enqueue(LoadZone); #if MMO_DEBUG Utils.Logger.DebugFormat("Zone (Name={0}:Min={1}:Max={2}) created in World (Min={3}:Max={4}", this.Name, Bounds.Min, Bounds.Max, World.Bounds.Min, World.Bounds.Max); #endif }