/// <summary> /// Adds the object to the rendering system. /// </summary> /// <param name="o">Object to add.</param> /// <returns>Display object created from the object.</returns> public LineDisplayObjectBase Add(object o) { //Create the correct kind of display object for this line drawer. Type displayType; if (myDisplayTypes.TryGetValue(o.GetType(), out displayType)) { #if !WINDOWS LineDisplayObjectBase objectAdded = (LineDisplayObjectBase)displayType.GetConstructor( new Type[] { o.GetType(), typeof(LineDrawer) }) .Invoke(new object[] { o, this }); #else var objectAdded = (LineDisplayObjectBase)Activator.CreateInstance(displayType, new[] { o, this }); #endif displayObjects.Add(objectAdded); return(objectAdded); } if (o is SolverGroup) { //Solver groups are special. If no special type-specific display object //has been registered for a solver group, add every child individually. foreach (SolverUpdateable item in (o as SolverGroup).SolverUpdateables) { LineDisplayObjectBase objectAdded = Add(item); if (objectAdded != null) { objectAdded.IsDrawing = item.IsActiveInSolver; //Match the initial activity of the item. } } return(null); } return(null); //Don't have this type registered; don't know what to do with it. }
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; }