public CharacterCameraControlScheme(CharacterController character, Camera camera, DemosGame game)
     : base(camera, game)
 {
     Character = character;
     UseCameraSmoothing = true;
     StandingCameraOffset = 0.7f;
     CrouchingCameraOffset = 0.4f;
 }
        /// <summary>
        /// Constructs the character and internal physics character controller.
        /// </summary>
        /// <param name="owningSpace">Space to add the character to.</param>
        /// <param name="camera">Camera to attach to the character.</param>
        /// <param name="game">The running game.</param>
        public CharacterControllerInput(Space owningSpace, Camera camera, DemosGame game)
        {
            CharacterController = new CharacterController();
            Camera = camera;
            CameraControlScheme = new CharacterCameraControlScheme(CharacterController, camera, game);

            Space = owningSpace;
        }
Beispiel #3
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="game"></param>
		/// <param name="space"></param>
		public Characters ( Entity entity, World world,
 			float height = 1.7f, 
			float crouchingHeight = 1.19f, 
			float radius = 0.6f, 
			float margin = 0.1f, 
			float mass = 10f, 
			float maximumTractionSlope = 0.8f, 
			float maximumSupportSlope = 1.3f, 
			float standingSpeed = 8f, 
			float crouchingSpeed = 3f, 
			float tractionForce = 1000f, 
			float slidingSpeed = 6f, 
			float slidingForce = 50f, 
			float airSpeed = 1f, 
			float airForce = 250f, 
			float jumpSpeed = 6f, 
			float slidingJumpSpeed = 3f, 
			float maximumGlueForce = 5000f ) : base(entity,world)
		{
			this.space	=	((MPWorld)world).PhysSpace;

			var pos = MathConverter.Convert( entity.Position );

			controller = new CharacterController( pos, 
					height					, 
					crouchingHeight			, 
					radius					, 
					margin					, 
					mass					,
					maximumTractionSlope	, 
					maximumSupportSlope		, 
					standingSpeed			,
					crouchingSpeed			,
					tractionForce			, 
					slidingSpeed			,
					slidingForce			,
					airSpeed				,
					airForce				, 
					jumpSpeed				, 
					slidingJumpSpeed		,
					maximumGlueForce		);


			controller.StepManager.MaximumStepHeight	=	0.5f;
			controller.Body.Tag	=	entity;
			controller.Tag		=	entity;

			space.Add( controller );
		}
Beispiel #4
0
 public override void SpawnBody()
 {
     base.SpawnBody();
     NMTWOCBody = GenCharCon();
     NMTWOWorld.Add(NMTWOCBody);
 }
Beispiel #5
0
 public void SetMoveSpeed(CharacterController cc, UserInputSet uis)
 {
     float speedmod = (float)new Vector2(uis.XMove, uis.YMove).Length() * 2;
     speedmod *= (1f + uis.SprintOrWalk * 0.5f);
     if (Click)
     {
         ItemStack item = TheClient.GetItemForSlot(TheClient.QuickBarPos);
         bool has = item.SharedAttributes.ContainsKey("charge");
         BooleanTag bt = has ? BooleanTag.TryFor(item.SharedAttributes["charge"]) : null;
         if (bt != null && bt.Internal && item.SharedAttributes.ContainsKey("cspeedm"))
         {
             NumberTag nt = NumberTag.TryFor(item.SharedAttributes["cspeedm"]);
             if (nt != null)
             {
                 speedmod *= (float)nt.Internal;
             }
         }
     }
     RigidTransform transf = new RigidTransform(Vector3.Zero, Body.Orientation);
     BoundingBox box;
     cc.Body.CollisionInformation.Shape.GetBoundingBox(ref transf, out box);
     Location pos = new Location(cc.Body.Position) + new Location(0, 0, box.Min.Z);
     Material mat = TheRegion.GetBlockMaterial(pos + new Location(0, 0, -0.05f));
     speedmod *= (float)mat.GetSpeedMod();
     cc.StandingSpeed = CBStandSpeed * speedmod;
     cc.CrouchingSpeed = CBCrouchSpeed * speedmod;
     float frictionmod = 1f;
     frictionmod *= (float)mat.GetFrictionMod();
     cc.SlidingForce = CBSlideForce * frictionmod * Mass;
     cc.AirForce = CBAirForce * frictionmod * Mass;
     cc.TractionForce = CBTractionForce * frictionmod * Mass;
     cc.VerticalMotionConstraint.MaximumGlueForce = CBGlueForce * Mass;
 }
Beispiel #6
0
 public void SetBodyMovement(CharacterController cc, UserInputSet uis)
 {
     Vector2 movement = InVehicle ? Vector2.Zero : new Vector2(uis.XMove, uis.YMove);
     if (movement.LengthSquared() > 0)
     {
         movement.Normalize();
     }
     cc.ViewDirection = Utilities.ForwardVector_Deg(uis.Direction.Yaw, uis.Direction.Pitch).ToBVector();
     cc.HorizontalMotionConstraint.MovementDirection = movement;
     if (uis.Downward)
     {
         cc.StanceManager.DesiredStance = Stance.Crouching;
     }
     else
     {
         cc.StanceManager.DesiredStance = DesiredStance;
     }
 }
Beispiel #7
0
 public void FlyForth(CharacterController cc, UserInputSet uis, double delta)
 {
     if (IsFlying)
     {
         Location move = new Location(-cc.HorizontalMotionConstraint.MovementDirection.Y, cc.HorizontalMotionConstraint.MovementDirection.X, 0);
         if (uis.Upward)
         {
             move.Z = 1;
             move = move.Normalize();
         }
         else if (uis.Downward)
         {
             move.Z = -1;
             move = move.Normalize();
         }
         Location forw = Utilities.RotateVector(move, Direction.Yaw * Utilities.PI180, Direction.Pitch * Utilities.PI180);
         cc.Body.Position += (forw * delta * CBStandSpeed * 4 * (new Vector2(uis.XMove, uis.YMove).Length())).ToBVector();
         cc.HorizontalMotionConstraint.MovementDirection = Vector2.Zero;
         cc.Body.LinearVelocity = new Vector3(0, 0, 0);
     }
 }
        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public CharacterStressTestDemo(DemosGame game)
            : base(game)
        {
            //Load in mesh data and create the group.
            Vector3[] staticTriangleVertices;
            int[] staticTriangleIndices;

            var playgroundModel = game.Content.Load<Model>("playground");
            //This is a little convenience method used to extract vertices and indices from a model.
            //It doesn't do anything special; any approach that gets valid vertices and indices will work.
            ModelDataExtractor.GetVerticesAndIndicesFromModel(playgroundModel, out staticTriangleVertices, out staticTriangleIndices);
            var meshShape = new InstancedMeshShape(staticTriangleVertices, staticTriangleIndices);
            var meshes = new List<Collidable>();

            var xSpacing = 400;
            var ySpacing = 400;
            var xCount = 11;
            var yCount = 11;
            for (int i = 0; i < xCount; i++)
            {
                for (int j = 0; j < yCount; j++)
                {
                    var staticMesh = new InstancedMesh(meshShape, new AffineTransform(Matrix3x3.Identity, new Vector3(-xSpacing * (xCount - 1) / 2 + i * xSpacing, 0, -ySpacing * (yCount - 1) / 2 + j * ySpacing)));
                    staticMesh.Sidedness = TriangleSidedness.Counterclockwise;
                    Space.Add(staticMesh);
                    //meshes.Add(staticMesh);
                    game.ModelDrawer.Add(staticMesh);
                }
            }
            //var group = new StaticGroup(meshes);
            //Space.Add(group);



            //Now drop the characters on it!
            var numColumns = 16;
            var numRows = 16;
            var numHigh = 8;
            float separation = 64;

            for (int i = 0; i < numRows; i++)
                for (int j = 0; j < numColumns; j++)
                    for (int k = 0; k < numHigh; k++)
                    {
                        var character = new CharacterController();
                        character.Body.Position =
                            new Vector3(
                            separation * i - numRows * separation / 2,
                            40f + k * separation,
                            separation * j - numColumns * separation / 2);

                        characters.Add(character);

                        Space.Add(character);
                    }

            //Now drop the ball-characters on it!
            numColumns = 16;
            numRows = 16;
            numHigh = 8;
            separation = 64;
            for (int i = 0; i < numRows; i++)
                for (int j = 0; j < numColumns; j++)
                    for (int k = 0; k < numHigh; k++)
                    {
                        var character = new SphereCharacterController();
                        character.Body.Position =
                            new Vector3(
                            separation * i - numRows * separation / 2,
                            48f + k * separation,
                            separation * j - numColumns * separation / 2);

                        sphereCharacters.Add(character);

                        Space.Add(character);
                    }


            game.Camera.Position = new Vector3(0, 10, 40);

            //Dump some boxes on top of the characters for fun.
            numColumns = 16;
            numRows = 16;
            numHigh = 8;
            separation = 64;
            for (int i = 0; i < numRows; i++)
                for (int j = 0; j < numColumns; j++)
                    for (int k = 0; k < numHigh; k++)
                    {
                        var toAdd = new Box(
                            new Vector3(
                            separation * i - numRows * separation / 2,
                            52f + k * separation,
                            separation * j - numColumns * separation / 2),
                            0.8f, 0.8f, 0.8f, 15);
                        toAdd.PositionUpdateMode = BEPUphysics.PositionUpdating.PositionUpdateMode.Continuous;

                        Space.Add(toAdd);
                    }
        }
Beispiel #9
0
 public override void SpawnBody()
 {
     if (CBody != null)
     {
         DestroyBody();
     }
     CBody = GenCharCon();
     Body = CBody.Body;
     Shape = CBody.Body.CollisionInformation.Shape;
     TheRegion.PhysicsWorld.Add(CBody);
     Jetpack = new JetpackMotionConstraint(this);
     TheRegion.PhysicsWorld.Add(Jetpack);
 }
Beispiel #10
0
 public CharacterController GenCharCon()
 {
     // TODO: Better variable control! (Server should command every detail!)
     CharacterController cb = new CharacterController(GetPosition().ToBVector(), CBHHeight * 2f * mod_scale, CBHHeight * 1.1f * mod_scale,
         CBHHeight * 1f * mod_scale, CBRadius * mod_scale, CBMargin, Mass, CBMaxTractionSlope, CBMaxSupportSlope, CBStandSpeed, CBCrouchSpeed, CBProneSpeed,
         CBTractionForce * Mass, CBSlideSpeed, CBSlideForce * Mass, CBAirSpeed, CBAirForce * Mass, CBJumpSpeed, CBSlideJumpSpeed, CBGlueForce * Mass);
     cb.StanceManager.DesiredStance = Stance.Standing;
     cb.ViewDirection = new Vector3(1f, 0f, 0f);
     cb.Down = new Vector3(0f, 0f, -1f);
     cb.Tag = this;
     BEPUphysics.Entities.Prefabs.Cylinder tb = cb.Body;
     tb.Tag = this;
     tb.AngularDamping = 1.0f;
     tb.CollisionInformation.CollisionRules.Group = CGroup;
     cb.StepManager.MaximumStepHeight = CBStepHeight;
     cb.StepManager.MinimumDownStepHeight = CBDownStepHeight;
     return cb;
 }
Beispiel #11
0
 public override void DestroyBody()
 {
     if (CBody == null)
     {
         return;
     }
     if (Jetpack != null)
     {
         TheRegion.PhysicsWorld.Remove(Jetpack);
         Jetpack = null;
     }
     TheRegion.PhysicsWorld.Remove(CBody);
     CBody = null;
     Body = null;
 }
        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public CharacterStressierTestDemo(DemosGame game)
            : base(game)
        {
            //Load in mesh data and create the group.
            Vector3[] staticTriangleVertices;
            int[] staticTriangleIndices;

            var playgroundModel = game.Content.Load<Model>("playground");
            //This is a little convenience method used to extract vertices and indices from a model.
            //It doesn't do anything special; any approach that gets valid vertices and indices will work.
            ModelDataExtractor.GetVerticesAndIndicesFromModel(playgroundModel, out staticTriangleVertices, out staticTriangleIndices);
            var meshShape = new InstancedMeshShape(staticTriangleVertices, staticTriangleIndices);
            var meshes = new List<Collidable>();

            var xSpacing = 400;
            var ySpacing = 400;
            var xCount = 11;
            var yCount = 11;
            for (int i = 0; i < xCount; i++)
            {
                for (int j = 0; j < yCount; j++)
                {
                    var staticMesh = new InstancedMesh(meshShape, new AffineTransform(Matrix3x3.Identity, new Vector3(-xSpacing * (xCount - 1) / 2 + i * xSpacing, 0, -ySpacing * (yCount - 1) / 2 + j * ySpacing)));
                    staticMesh.Sidedness = TriangleSidedness.Counterclockwise;
                    Space.Add(staticMesh);
                    //meshes.Add(staticMesh);
                    game.ModelDrawer.Add(staticMesh);
                }
            }
            //var group = new StaticGroup(meshes);
            //Space.Add(group);

            //To demonstrate, we'll be creating a set of static objects and giving them to a group to manage.
            var collidables = new List<Collidable>();

            //Start with a whole bunch of boxes.  These are entity collidables, but without entities!
            xSpacing = 25;
            ySpacing = 16;
            float zSpacing = 25;

            xCount = 25;
            yCount = 7;
            int zCount = 25;


            var random = new Random();
            for (int i = 0; i < xCount; i++)
            {
                for (int j = 0; j < yCount; j++)
                {
                    for (int k = 0; k < zCount; k++)
                    {
                        //Create a transform and the instance of the mesh.
                        var collidable = new ConvexCollidable<BoxShape>(new BoxShape((float)random.NextDouble() * 25 + 5.5f, (float)random.NextDouble() * 25 + 5.5f, (float)random.NextDouble() * 25 + 5.5f));

                        //This EntityCollidable isn't associated with an entity, so we must manually tell it where to sit by setting the WorldTransform.
                        //This also updates its bounding box.
                        collidable.WorldTransform = new RigidTransform(
                            new Vector3(i * xSpacing - xCount * xSpacing * .5f, j * ySpacing + -50, k * zSpacing - zCount * zSpacing * .5f),
                            Quaternion.CreateFromAxisAngle(Vector3.Normalize(new Vector3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble())), (float)random.NextDouble() * 100));

                        collidables.Add(collidable);
                        game.ModelDrawer.Add(collidable);
                    }
                }
            }
            var group = new StaticGroup(collidables);
            Space.Add(group);

           
            //Now drop the characters on it!
            var numColumns = 16;
            var numRows = 16;
            var numHigh = 16;
            float separation = 24;

            for (int i = 0; i < numRows; i++)
                for (int j = 0; j < numColumns; j++)
                    for (int k = 0; k < numHigh; k++)
                    {
                        var character = new CharacterController();
                        character.Body.Position =
                            new Vector3(
                            separation * i - numRows * separation / 2,
                            50f + k * separation,
                            separation * j - numColumns * separation / 2);

                        characters.Add(character);

                        Space.Add(character);
                    }

           

            game.Camera.Position = new Vector3(0, 10, 40);

            //Dump some boxes on top of the characters for fun.
            numColumns = 16;
            numRows = 16;
            numHigh = 8;
            separation = 24;
            for (int i = 0; i < numRows; i++)
                for (int j = 0; j < numColumns; j++)
                    for (int k = 0; k < numHigh; k++)
                    {
                        var toAdd = new Box(
                            new Vector3(
                            separation * i - numRows * separation / 2,
                            52f + k * separation,
                            separation * j - numColumns * separation / 2),
                            0.8f, 0.8f, 0.8f, 15);
                        toAdd.PositionUpdateMode = BEPUphysics.PositionUpdating.PositionUpdateMode.Continuous;

                        Space.Add(toAdd);
                    }
        }
Beispiel #13
0
 public override void SpawnBody()
 {
     MinZ = CBHHeight;
     if (CBody != null)
     {
         DestroyBody();
     }
     // TODO: Better variable control! (Server should command every detail!)
     CBody = new CharacterController(WorldTransform.Translation, CBHHeight * 2f * mod_scale, CBHHeight * 1.1f * mod_scale,
         CBHHeight * 1f * mod_scale, CBRadius * mod_scale, CBMargin, Mass, CBMaxTractionSlope, CBMaxSupportSlope, CBStandSpeed, CBCrouchSpeed, CBProneSpeed,
         CBTractionForce * Mass, CBSlideSpeed, CBSlideForce * Mass, CBAirSpeed, CBAirForce * Mass, CBJumpSpeed, CBSlideJumpSpeed, CBGlueForce * Mass);
     CBody.StanceManager.DesiredStance = Stance.Standing;
     CBody.ViewDirection = new Vector3(1f, 0f, 0f);
     CBody.Down = new Vector3(0f, 0f, -1f);
     CBody.Tag = this;
     Body = CBody.Body;
     Body.Tag = this;
     Body.AngularDamping = 1.0f;
     Shape = CBody.Body.CollisionInformation.Shape;
     Body.CollisionInformation.CollisionRules.Group = CGroup;
     CBody.StepManager.MaximumStepHeight = CBStepHeight;
     CBody.StepManager.MinimumDownStepHeight = CBDownStepHeight;
     TheRegion.PhysicsWorld.Add(CBody);
     RigidTransform transf = new RigidTransform(Vector3.Zero, Body.Orientation);
     BoundingBox box;
     Body.CollisionInformation.Shape.GetBoundingBox(ref transf, out box);
     MinZ = box.Min.Z;
 }