private void showButton_Click(object sender, EventArgs e) { try { FillParameters(); _parameters.ValidateParameters(); } catch (ArgumentOutOfRangeException exception) { MessageBox.Show( "Введенные параметры выходят за границы доступного диапазона значений", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } catch (ArgumentException argumentException) { MessageBox.Show(argumentException.Message); return; } var modelDrawer = new ModelDrawer(_parameters, picture); modelDrawer.DrawPicture(); }
protected override void OnRender(DrawingContext drawingContext) { drawingContext.DrawRectangle(Brushes.Black, new Pen(), new Rect(new Point(0, 0), new Size(ActualWidth, ActualHeight))); var drawer = new ModelDrawer(_model, drawingContext, ActualWidth, ActualHeight); drawer.Draw(); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { //Set up drawers ModelDrawer = new InstancedModelDrawer(this); //Create the space itself Space = new Space(); var parallelLooper = new ParallelLooper(); //This section lets the engine know that it can make use of multithreaded systems //by adding threads to its thread pool. if (Environment.ProcessorCount > 1) { for (int i = 0; i < Environment.ProcessorCount; i++) { parallelLooper.AddThread(); } } Space = new Space(parallelLooper); Space.ForceUpdater.Gravity = new Vector3(0, -9.81f, 0); Space.Add(new Box(Vector3.Zero, 30, 1, 30)); //Create a bunch of boxes randomly. Random random = new Random(); int boxCount = 100; BoundingBox spawnVolume = new BoundingBox(new Vector3(-10, 10, -10), new Vector3(10, 30, 10)); for (int i = 0; i < boxCount; i++) { Vector3 position = new Vector3((float)(random.NextDouble() - 0.5f) * (spawnVolume.Max.X - spawnVolume.Min.X), (float)(random.NextDouble() - 0.5f) * (spawnVolume.Max.Y - spawnVolume.Min.Y), (float)(random.NextDouble() - 0.5f) * (spawnVolume.Max.Z - spawnVolume.Min.Z)) + (spawnVolume.Min + spawnVolume.Max) / 2; Space.Add(new Box(position, 1, 1, 1, 1)); } #region DisplayObject creation foreach (Entity e in Space.Entities) { if ((string)e.Tag != "noDisplayObject") { ModelDrawer.Add(e); } else//Remove the now unnecessary tag. { e.Tag = null; } } #endregion }
public PhysicsRenderManager(QSGame game) : base(game) { // By default physics rendering is disabled. this.Enabled = false; this.Game.Services.AddService(typeof(PhysicsRenderManager), this); this.modelDrawer = new InstancedModelDrawer(game); this.modelDrawer.IsWireframe = true; }
protected override void Initialize() { cam.Initialize(Vector3.Up, (float)(70f * Math.PI / 180), GraphicsDevice.Viewport.AspectRatio, 0.01f, 140 * 5, Vector3.Zero, Vector3.Forward); Input.Create(this); Input.Get().Update(); modelDrawer = new InstancedModelDrawer(this); base.Initialize(); }
protected override void Initialize() { ModelDrawer = new InstancedModelDrawer(this); ConstraintDrawer = new LineDrawer(this); ConstraintDrawer.DisplayTypes.Add(typeof(GrabSpring), typeof(DisplayGrabSpring)); ConstraintDrawer.DisplayTypes.Add(typeof(MotorizedGrabSpring), typeof(DisplayMotorizedGrabSpring)); ContactDrawer = new ContactDrawer(this); BoundingBoxDrawer = new BoundingBoxDrawer(this); SimulationIslandDrawer = new SimulationIslandDrawer(this); base.Initialize(); }
public BEPUPhysicsRenderer(IManagerServiceProvider sceneInterface) { _sceneInterface = sceneInterface; ManagerProcessOrder = 100; ModelDrawer = new InstancedModelDrawer(Application.Instance); ContactDrawer = new ContactDrawer(Application.Instance); BoundingBoxDrawer = new BoundingBoxDrawer(Application.Instance); SimulationIslandDrawer = new SimulationIslandDrawer(Application.Instance); LineDrawer = new BasicEffect(Application.Graphics.GraphicsDevice); Visible = true; }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { //Set up drawers modelDrawer = new InstancedModelDrawer(this); //Create the space and tell it that it should keep track of buffered states. This will let the //positions/orientations of entities be interpolated, producing a cleaner appearance. Space = new Space(); Space.BufferedStates.Enabled = true; Space.ForceUpdater.Gravity = new Vector3(0, -9.81f, 0); Space.Add(new Box(Vector3.Zero, 30, 1, 30)); //Make the ground //Create a bunch of boxes randomly. Random random = new Random(); int boxCount = 50; var spawnVolume = new BoundingBox(new Vector3(-5, 15, -5), new Vector3(5, 25, 5)); for (int i = 0; i < boxCount; i++) { var position = new Vector3((float)(random.NextDouble() - 0.5f) * (spawnVolume.Max.X - spawnVolume.Min.X), (float)(random.NextDouble() - 0.5f) * (spawnVolume.Max.Y - spawnVolume.Min.Y), (float)(random.NextDouble() - 0.5f) * (spawnVolume.Max.Z - spawnVolume.Min.Z)) + (spawnVolume.Min + spawnVolume.Max) / 2; Space.Add(new Box(position, 1, 1, 1, 1)); } //Start up the physics loop. physicsThread = new Thread(PhysicsLoop); physicsThread.IsBackground = true; physicsThread.Start(); #region DisplayObject creation foreach (Entity e in Space.Entities) { if ((string)e.Tag != "noDisplayObject") { modelDrawer.Add(e); } else//Remove the now unnecessary tag. { e.Tag = null; } } #endregion }
void FillSpace(Space space, ModelDrawer modelDrawer = null) { Entity ground = new MorphableEntity(new BoxShape(50, 1, 50)); space.Add(ground); space.ForceUpdater.Gravity = new Vector3(0, -10, 0); ModelDataExtractor.GetVerticesAndIndicesFromModel(Game.Content.Load <Model>("playground"), out Vector3[] vertices, out int[] indices); var mesh = new StaticMesh(vertices, indices, new AffineTransform(new Vector3(50, -20, 0))); space.Add(mesh); modelDrawer?.Add(mesh); for (int i = 0; i < 100; i++) { Entity e = new Box(new Vector3(.1f * i, 1 * i + 1, 0), 1, 1, 1, 1); //Entity e = new Capsule(new Vector3(.1f * i, 1 * i + 1, 0), .5f, .5f, 1); //Entity e = new Sphere(new Vector3(.1f * i, 1 * i + 1, 0), .5f, 1); e.ActivityInformation.IsAlwaysActive = true; e.CollisionInformation.Tag = i; space.Add(e); } for (int i = 0; i < 200; i++) { //Entity e = new Box(new Vector3(.1f * i, 1 * i + 1, 2), 1, 1, 1, 1); Entity e = new Capsule(new Vector3(.1f * i, 1 * i + 1, 2), .5f, .5f, 1); //Entity e = new Sphere(new Vector3(.1f * i, 1 * i + 1, 2), .5f, 1); e.ActivityInformation.IsAlwaysActive = true; e.CollisionInformation.Tag = i; space.Add(e); } for (int i = 0; i < 300; i++) { //Entity e = new Box(new Vector3(.1f * i, 1 * i + 1, 4), 1, 1, 1, 1); //Entity e = new Capsule(new Vector3(.1f * i, 1 * i + 1, 4), .5f, .5f, 1); Entity e = new Sphere(new Vector3(.1f * i, 1 * i + 1, 4), .5f, 1); e.ActivityInformation.IsAlwaysActive = true; e.CollisionInformation.Tag = i; space.Add(e); } if (modelDrawer != null) { for (int i = 0; i < space.Entities.Count; ++i) { modelDrawer.Add(space.Entities[i]); } } }
protected override void Initialize() { if (GraphicsDevice.GraphicsProfile == GraphicsProfile.HiDef) ModelDrawer = new InstancedModelDrawer(this); else ModelDrawer = new BruteModelDrawer(this); ConstraintDrawer = new LineDrawer(this); ConstraintDrawer.DisplayTypes.Add(typeof(GrabSpring), typeof(DisplayGrabSpring)); ConstraintDrawer.DisplayTypes.Add(typeof(MotorizedGrabSpring), typeof(DisplayMotorizedGrabSpring)); ContactDrawer = new ContactDrawer(this); BoundingBoxDrawer = new BoundingBoxDrawer(this); SimulationIslandDrawer = new SimulationIslandDrawer(this); base.Initialize(); }
public override void InitialiseLevel() { base.InitialiseLevel(); BEPUDebugDrawer = new ModelDrawer(vxEngine.Game); //Starts BEPU with multiple Cores BEPUParallelLooper = new ParallelLooper(); if (Environment.ProcessorCount > 1) { for (int i = 0; i < Environment.ProcessorCount; i++) { BEPUParallelLooper.AddThread(); } } BEPUPhyicsSpace = new Space(BEPUParallelLooper); BEPUPhyicsSpace.ForceUpdater.Gravity = new Vector3(0, -9.81f, 0); vxConsole.WriteLine("Starting Physics vxEngine using " + BEPUPhyicsSpace.ParallelLooper.ThreadCount + " Processors"); }
/// <summary> /// Constructs the front end and the internal physics representation of the Vehicle. /// </summary> /// <param name="position">Position of the Vehicle.</param> /// <param name="owningSpace">Space to add the Vehicle to.</param> /// <param name="cameraToUse">Camera to attach to the Vehicle.</param> /// <param name="drawer">Drawer used to draw the Vehicle.</param> /// <param name="wheelModel">Model of the wheels.</param> /// <param name="wheelTexture">Texture to use for the wheels.</param> public VehicleInput(Vector3 position, Space owningSpace, Camera cameraToUse, ModelDrawer drawer, Model wheelModel, Texture2D wheelTexture) { var bodies = new List <CompoundShapeEntry>() { new CompoundShapeEntry(new BoxShape(2.5f, .75f, 4.5f), new Vector3(0, 0, 0), 60), new CompoundShapeEntry(new BoxShape(2.5f, .3f, 2f), new Vector3(0, .75f / 2 + .3f / 2, .5f), 1) }; var body = new CompoundBody(bodies, 61); body.CollisionInformation.LocalPosition = new Vector3(0, .5f, 0); body.Position = (position); //At first, just keep it out of the way. Vehicle = new Vehicle(body); #region RaycastWheelShapes //The wheel model used is not aligned initially with how a wheel would normally look, so rotate them. Matrix wheelGraphicRotation = Matrix.CreateFromAxisAngle(Vector3.Forward, MathHelper.PiOver2); Vehicle.AddWheel(new Wheel( new RaycastWheelShape(.375f, wheelGraphicRotation), new WheelSuspension(2000, 100f, Vector3.Down, .8f, new Vector3(-1.1f, 0, 1.8f)), new WheelDrivingMotor(2.5f, 30000, 10000), new WheelBrake(1.5f, 2, .02f), new WheelSlidingFriction(4, 5))); Vehicle.AddWheel(new Wheel( new RaycastWheelShape(.375f, wheelGraphicRotation), new WheelSuspension(2000, 100f, Vector3.Down, .8f, new Vector3(-1.1f, 0, -1.8f)), new WheelDrivingMotor(2.5f, 30000, 10000), new WheelBrake(1.5f, 2, .02f), new WheelSlidingFriction(4, 5))); Vehicle.AddWheel(new Wheel( new RaycastWheelShape(.375f, wheelGraphicRotation), new WheelSuspension(2000, 100f, Vector3.Down, .8f, new Vector3(1.1f, 0, 1.8f)), new WheelDrivingMotor(2.5f, 30000, 10000), new WheelBrake(1.5f, 2, .02f), new WheelSlidingFriction(4, 5))); Vehicle.AddWheel(new Wheel( new RaycastWheelShape(.375f, wheelGraphicRotation), new WheelSuspension(2000, 100f, Vector3.Down, .8f, new Vector3(1.1f, 0, -1.8f)), new WheelDrivingMotor(2.5f, 30000, 10000), new WheelBrake(1.5f, 2, .02f), new WheelSlidingFriction(4, 5))); #endregion foreach (Wheel wheel in Vehicle.Wheels) { //This is a cosmetic setting that makes it looks like the car doesn't have antilock brakes. wheel.Shape.FreezeWheelsWhileBraking = true; //By default, wheels use as many iterations as the space. By lowering it, //performance can be improved at the cost of a little accuracy. //However, because the suspension and friction are not really rigid, //the lowered accuracy is not so much of a problem. wheel.Suspension.SolverSettings.MaximumIterations = 1; wheel.Brake.SolverSettings.MaximumIterations = 1; wheel.SlidingFriction.SolverSettings.MaximumIterations = 1; wheel.DrivingMotor.SolverSettings.MaximumIterations = 1; } Space = owningSpace; Space.Add(Vehicle); ModelDrawer = drawer; DisplayModel model; WheelModels = new List <DisplayModel>(); for (int k = 0; k < 4; k++) { Vehicle.Wheels[k].Shape.Detector.Tag = "noDisplayObject"; model = new DisplayModel(wheelModel, ModelDrawer); ModelDrawer.Add(model); WheelModels.Add(model); model.Texture = wheelTexture; } Camera = cameraToUse; }
public DynamicVisualizer(LinearDynamic dynamic, ModelDrawer modelDrawer) { Dynamic = dynamic; DisplayCollidable = new DisplayEntityCollidable(modelDrawer, new ConvexCollidable <BoxShape>(new BoxShape(0.5f, 0.5f, 0.5f))); modelDrawer.Add(DisplayCollidable); }
/// <summary> /// Constructs the front end and the internal physics representation of the vehicle. /// </summary> /// <param name="position">Position of the tank.</param> /// <param name="owningSpace">Space to add the vehicle to.</param> /// <param name="cameraToUse">Camera to attach to the vehicle.</param> /// <param name="drawer">Drawer used to draw the tank.</param> /// <param name="wheelModel">Model to use for the 'wheels' of the tank.</param> /// <param name="wheelTexture">Texture of the wheels on the tank.</param> public TankInput(Vector3 position, Space owningSpace, Camera cameraToUse, ModelDrawer drawer, Model wheelModel, Texture2D wheelTexture) { var bodies = new List <CompoundShapeEntry>() { new CompoundShapeEntry(new BoxShape(4f, 1, 8), new Vector3(0, 0, 0), 500), new CompoundShapeEntry(new BoxShape(3, .7f, 4f), new Vector3(0, .5f + .35f, .5f), 1) }; var body = new CompoundBody(bodies, 501); body.CollisionInformation.LocalPosition = new Vector3(0, -.5f, 0); body.Position = (position); //At first, just keep it out of the way. Vehicle = new Vehicle(body); #region RaycastWheelShapes //The wheel model used is not aligned initially with how a wheel would normally look, so rotate them. MaximumDriveForce = 1800; BaseSlidingFriction = 7; Matrix wheelGraphicRotation = Matrix.CreateFromAxisAngle(Vector3.Forward, MathHelper.PiOver2); for (int i = 0; i < 6; i++) { var toAdd = new Wheel( new RaycastWheelShape(.375f, wheelGraphicRotation), new WheelSuspension(2000, 300f, Vector3.Down, 1.3f, new Vector3(-1.9f, 0, -2.9f + i * 1.15f)), new WheelDrivingMotor(10, MaximumDriveForce, MaximumDriveForce), new WheelBrake(BaseSlidingFriction, BaseSlidingFriction, 1.0f), new WheelSlidingFriction(3.5f, 3.5f)); Vehicle.AddWheel(toAdd); leftTrack.Add(toAdd); } for (int i = 0; i < 6; i++) { var toAdd = new Wheel( new RaycastWheelShape(.375f, wheelGraphicRotation), new WheelSuspension(2000, 300f, Vector3.Down, 1.3f, new Vector3(1.9f, 0, -2.9f + i * 1.15f)), new WheelDrivingMotor(10, 2000, 1000), new WheelBrake(BaseSlidingFriction, BaseSlidingFriction, 1.0f), new WheelSlidingFriction(3.5f, 3.5f)); Vehicle.AddWheel(toAdd); rightTrack.Add(toAdd); } #endregion foreach (Wheel wheel in Vehicle.Wheels) { //This is a cosmetic setting that makes it looks like the car doesn't have antilock brakes. wheel.Shape.FreezeWheelsWhileBraking = true; //By default, wheels use as many iterations as the space. By lowering it, //performance can be improved at the cost of a little accuracy. wheel.Suspension.SolverSettings.MaximumIterations = 1; wheel.Brake.SolverSettings.MaximumIterations = 1; wheel.SlidingFriction.SolverSettings.MaximumIterations = 1; wheel.DrivingMotor.SolverSettings.MaximumIterations = 1; } Space = owningSpace; Space.Add(Vehicle); ModelDrawer = drawer; DisplayModel model; WheelModels = new List <DisplayModel>(); for (int k = 0; k < Vehicle.Wheels.Count; k++) { Vehicle.Wheels[k].Shape.Detector.Tag = "noDisplayObject"; model = new DisplayModel(wheelModel, ModelDrawer); ModelDrawer.Add(model); WheelModels.Add(model); model.Texture = wheelTexture; } Camera = cameraToUse; }
protected ModelDisplayObject(ModelDrawer drawer, T displayedObject) : base(drawer) { DisplayedObject = displayedObject; }
/// <summary> /// Constructs the front end and the internal physics representation of the Vehicle. /// </summary> /// <param name="position">Position of the Vehicle.</param> /// <param name="space">Space to add the Vehicle to.</param> /// <param name="camera">Camera to attach to the Vehicle.</param> /// <param name="game">The running game.</param> /// <param name="drawer">Drawer used to draw the Vehicle.</param> /// <param name="wheelModel">Model of the wheels.</param> /// <param name="wheelTexture">Texture to use for the wheels.</param> public VehicleInput(Vector3 position, Space space, Camera camera, DemosGame game, ModelDrawer drawer, Model wheelModel, Texture2D wheelTexture) { var bodies = new List <CompoundShapeEntry> { new CompoundShapeEntry(new BoxShape((Fix64)2.5m, (Fix64).75m, (Fix64)4.5m), new Vector3(0, 0, 0), 60), new CompoundShapeEntry(new BoxShape((Fix64)2.5m, (Fix64).3m, (Fix64)2f), new Vector3(0, (Fix64).75m / 2 + (Fix64).3m / 2, (Fix64).5m), 1) }; var body = new CompoundBody(bodies, 61); body.CollisionInformation.LocalPosition = new Vector3(0, (Fix64).5m, 0); body.Position = position; //At first, just keep it out of the way. Vehicle = new Vehicle(body); var localWheelRotation = Quaternion.CreateFromAxisAngle(new Vector3(0, 0, 1), MathHelper.PiOver2); //The wheel model used is not aligned initially with how a wheel would normally look, so rotate them. Matrix wheelGraphicRotation = Matrix.CreateFromAxisAngle(Vector3.Forward, MathHelper.PiOver2); Vehicle.AddWheel(new Wheel( new CylinderCastWheelShape((Fix64).375m, (Fix64)0.2m, localWheelRotation, wheelGraphicRotation, false), new WheelSuspension(2000, 100, Vector3.Down, (Fix64)0.325m, new Vector3((Fix64)(-1.1m), (Fix64)(-0.1m), (Fix64)1.8m)), new WheelDrivingMotor((Fix64)2.5m, 30000, 10000), new WheelBrake((Fix64)1.5m, 2, (Fix64).02m), new WheelSlidingFriction(4, 5))); Vehicle.AddWheel(new Wheel( new CylinderCastWheelShape((Fix64).375m, (Fix64)0.2m, localWheelRotation, wheelGraphicRotation, false), new WheelSuspension(2000, 100, Vector3.Down, (Fix64)0.325m, new Vector3((Fix64)(-1.1m), (Fix64)(-0.1m), (Fix64)(-1.8m))), new WheelDrivingMotor((Fix64)2.5m, 30000, 10000), new WheelBrake((Fix64)1.5m, 2, (Fix64).02m), new WheelSlidingFriction(4, 5))); Vehicle.AddWheel(new Wheel( new CylinderCastWheelShape((Fix64).375m, (Fix64)0.2m, localWheelRotation, wheelGraphicRotation, false), new WheelSuspension(2000, 100, Vector3.Down, (Fix64)0.325m, new Vector3((Fix64)1.1m, (Fix64)(-0.1m), (Fix64)1.8m)), new WheelDrivingMotor((Fix64)2.5m, 30000, 10000), new WheelBrake((Fix64)1.5m, 2, (Fix64).02m), new WheelSlidingFriction(4, 5))); Vehicle.AddWheel(new Wheel( new CylinderCastWheelShape((Fix64).375m, (Fix64)0.2m, localWheelRotation, wheelGraphicRotation, false), new WheelSuspension(2000, 100, Vector3.Down, (Fix64)0.325m, new Vector3((Fix64)1.1m, (Fix64)(-0.1m), (Fix64)(-1.8m))), new WheelDrivingMotor((Fix64)2.5m, 30000, 10000), new WheelBrake((Fix64)1.5m, 2, (Fix64).02m), new WheelSlidingFriction(4, 5))); foreach (Wheel wheel in Vehicle.Wheels) { //This is a cosmetic setting that makes it looks like the car doesn't have antilock brakes. wheel.Shape.FreezeWheelsWhileBraking = true; //By default, wheels use as many iterations as the space. By lowering it, //performance can be improved at the cost of a little accuracy. //However, because the suspension and friction are not really rigid, //the lowered accuracy is not so much of a problem. wheel.Suspension.SolverSettings.MaximumIterationCount = 1; wheel.Brake.SolverSettings.MaximumIterationCount = 1; wheel.SlidingFriction.SolverSettings.MaximumIterationCount = 1; wheel.DrivingMotor.SolverSettings.MaximumIterationCount = 1; } Space = space; Space.Add(Vehicle); ModelDrawer = drawer; DisplayModel model; WheelModels = new List <DisplayModel>(); for (int k = 0; k < 4; k++) { Vehicle.Wheels[k].Shape.Detector.Tag = "noDisplayObject"; model = new DisplayModel(wheelModel, ModelDrawer); ModelDrawer.Add(model); WheelModels.Add(model); model.Texture = wheelTexture; } CameraControlScheme = new ChaseCameraControlScheme(Vehicle.Body, new Vector3(0, (Fix64)0.6m, 0), true, 10, camera, game); }
protected SelfDrawingModelDisplayObject(ModelDrawer modelDrawer) { ModelDrawer = modelDrawer; }