/// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public InverseKinematicsTestDemo(DemosGame game)
            : base(game)
        {
            cameraControl = new FreeCameraControlScheme(10, game.Camera, game);
            whitePixel = game.Content.Load<Texture2D>("whitePixel");
            game.Camera.Position = new Vector3(0, 3, 5);
            Box ground = new Box(new Vector3(0, 0, 0), 30, 1, 30);
            Space.Add(ground);
            Space.ForceUpdater.Gravity = new Vector3(0, -9.81f, 0);

            stateControlGroup = new StateControlGroup(game.Camera, controls);

            drawer = new InstancedModelDrawer(game);

            solver.ActiveSet.UseAutomass = true;
            solver.AutoscaleControlImpulses = true;
            solver.AutoscaleControlMaximumForce = float.MaxValue;
            solver.TimeStepDuration = .1f;
            solver.ControlIterationCount = 100;
            solver.FixerIterationCount = 10;
            solver.VelocitySubiterationCount = 3;

            BuildChain(new Vector3(-5, 2, 0));

            BuildStick(new Vector3(-10, 2, 0));

            BuildActionFigure(new Vector3(5, 6, -8));
            BuildActionFigure(new Vector3(5, 6, -3));
            BuildActionFigure(new Vector3(5, 6, 3));
            BuildActionFigure(new Vector3(5, 6, 8));

            BuildCyclicMesh(new Vector3(-5, 5, -5));

            //BuildJointTest(new Vector3(0, 5, 0));
            //BuildTinyTest(new Vector3(0, 15, 0));

            BuildRoboArmThing(new Vector3(0, 5, 0));

            BuildRing(new Vector3(0, 10, 8));

            //Create the display objects.
            Model cylinder = game.Content.Load<Model>("cylinder");
            for (int i = 0; i < bones.Count; i++)
            {
                var displayBone = new DisplayModel(cylinder, drawer);
                var completedBone = bones[i];
                completedBone.DisplayBone = displayBone;
                bones[i] = completedBone;
                drawer.Add(displayBone);
            }
        }
Exemple #2
0
        public StandardDemo(DemosGame game)
            : base(game)
        {
            freeCameraControlScheme = new FreeCameraControlScheme(10, game.Camera, game);

            //Creates the player character (C).
            character = new CharacterControllerInput(Space, game.Camera, game);

            //Creates the drivable vehicle (V).
            var wheelModel   = game.Content.Load <Model>("carWheel");
            var wheelTexture = game.Content.Load <Texture2D>("wheel");

            whitePixel = game.Content.Load <Texture2D>("whitePixel");
            vehicle    = new VehicleInput(new Vector3(10000, 0, 0), Space, game.Camera, game, game.ModelDrawer, wheelModel, wheelTexture);
            Space.ForceUpdater.Gravity = new Vector3(0, (Fix64)(-9.81m), 0); //If left unset, the default value is (0,0,0).

            //Create the tossable ball.
            kapow      = new Sphere(new Vector3(11000, 0, 0), (Fix64).6m, 20);
            kapowMaker = new Explosion(Vector3.Zero, 400, 15, Space);
            //Create the right-click grab spring.
            grabber                  = new MotorizedGrabSpring();
            grabberGraphic           = game.ConstraintDrawer.Add(grabber);
            grabberGraphic.IsDrawing = false;
            Space.Add(grabber);
            Space.Add(kapow);


            //IMPORTANT PERFORMANCE NOTE:
            //  BEPUphysics uses an iterative system to solve constraints.  You can tell it to do more or less iterations.
            //  Less iterations is faster; more iterations makes the result more accurate.
            //
            //  The amount of iterations needed for a simulation varies.  The "Wall" and "Pyramid" simulations are each fairly
            //  solver intensive, but as few as 4 iterations can be used with acceptable results.
            //  The "Jenga" simulation usually needs a few more iterations for stability; 7-9 is a good minimum.
            //
            //  The Dogbot demo shows how accuracy can smoothly increase with more iterations.
            //  With very few iterations (1-3), it has slightly jaggier movement, as if the parts used to construct it were a little cheap.
            //  As you give it a few more iterations, the motors and constraints get more and more robust.
            //
            //  Many simulations can work perfectly fine with very few iterations,
            //  and using a low number of iterations can substantially improve performance.
            //
            //  To change the number of iterations used, uncomment and change the following line (10 iterations is the default):

            //Space.Solver.IterationLimit = 10;

            rayCastFilter = RayCastFilter;
        }
        public StandardDemo(DemosGame game)
            : base(game)
        {
            freeCameraControlScheme = new FreeCameraControlScheme(10, game.Camera, game);

            //Creates the player character (C).
            character = new CharacterControllerInput(Space, game.Camera, game);

            //Creates the drivable vehicle (V).
            var wheelModel = game.Content.Load<Model>("carWheel");
            var wheelTexture = game.Content.Load<Texture2D>("wheel");
            whitePixel = game.Content.Load<Texture2D>("whitePixel");
            vehicle = new VehicleInput(new Vector3(10000, 0, 0), Space, game.Camera, game, game.ModelDrawer, wheelModel, wheelTexture);
            Space.ForceUpdater.Gravity = new Vector3(0, -9.81f, 0f); //If left unset, the default value is (0,0,0).

            //Create the tossable ball.
            kapow = new Sphere(new Vector3(11000, 0, 0), .6f, 20);
            kapowMaker = new Explosion(Vector3.Zero, 400, 15, Space);
            //Create the right-click grab spring.
            grabber = new MotorizedGrabSpring();
            grabberGraphic = game.ConstraintDrawer.Add(grabber);
            grabberGraphic.IsDrawing = false;
            Space.Add(grabber);
            Space.Add(kapow);


            //IMPORTANT PERFORMANCE NOTE:
            //  BEPUphysics uses an iterative system to solve constraints.  You can tell it to do more or less iterations.
            //  Less iterations is faster; more iterations makes the result more accurate.
            //
            //  The amount of iterations needed for a simulation varies.  The "Wall" and "Pyramid" simulations are each fairly
            //  solver intensive, but as few as 4 iterations can be used with acceptable results.
            //  The "Jenga" simulation usually needs a few more iterations for stability; 7-9 is a good minimum.
            //
            //  The Dogbot demo shows how accuracy can smoothly increase with more iterations.
            //  With very few iterations (1-3), it has slightly jaggier movement, as if the parts used to construct it were a little cheap.
            //  As you give it a few more iterations, the motors and constraints get more and more robust.
            //  
            //  Many simulations can work perfectly fine with very few iterations, 
            //  and using a low number of iterations can substantially improve performance.
            //
            //  To change the number of iterations used, uncomment and change the following line (10 iterations is the default):

            //Space.Solver.IterationLimit = 10;

            rayCastFilter = RayCastFilter;
        }