protected override void OnSystemAdd() { physicsSystem = (Bepu2PhysicsSystem)Services.GetService <IBepuPhysicsSystem>(); if (physicsSystem == null) { physicsSystem = new Bepu2PhysicsSystem(Services); Services.AddService <IBepuPhysicsSystem>(physicsSystem); var gameSystems = Services.GetSafeServiceAs <IGameSystemCollection>(); gameSystems.Add(physicsSystem); } ((IReferencable)physicsSystem).AddReference(); // Check if PhysicsShapesRenderingService is created (and check if rendering is enabled with IGraphicsDeviceService) if (Services.GetService <IGraphicsDeviceService>() != null && Services.GetService <BepuPhysicsShapesRenderingService>() == null) { debugShapeRendering = new BepuPhysicsShapesRenderingService(Services); var gameSystems = Services.GetSafeServiceAs <IGameSystemCollection>(); gameSystems.Add(debugShapeRendering); } Simulation = physicsSystem.Create(this); sceneSystem = Services.GetSafeServiceAs <SceneSystem>(); }
// public override Vector3 Scaling // { // get => cachedScaling; // set // { // base.Scaling = value; // foreach (var colliderShape in colliderShapes) // { // colliderShape.Scaling = cachedScaling; // } // } // } internal override void CreateAndAddCollidableDescription( BepuPhysicsComponent physicsComponent, BepuSimulation xenkoSimulation, out TypedIndex shapeTypeIndex, out CollidableDescription collidableDescription) { //throw new System.NotImplementedException(); shapeTypeIndex = default; collidableDescription = default; }
internal override void CreateAndAddCollidableDescription( BepuPhysicsComponent physicsComponent, BepuSimulation xenkoSimulation, out TypedIndex shapeTypeIndex, out CollidableDescription collidableDescription) { CreateAndAddCollidableDescription <Sphere>( physicsComponent, xenkoSimulation, out shapeTypeIndex, out collidableDescription); }
void CreatePoint2PointConstraint() { cubeRigidBody.LinearFactor = Vector3.Zero; cubeRigidBody.AngularFactor = Vector3.Zero; sphereRigidBody.LinearFactor = new Vector3(1, 1, 1); sphereRigidBody.AngularFactor = new Vector3(1, 1, 1); currentConstraint = BepuSimulation.CreateConstraint(ConstraintTypes.Point2Point, cubeRigidBody, sphereRigidBody, Matrix.Identity, Matrix.Translation(new Vector3(4, 0, 0))); simulation.AddConstraint(currentConstraint); constraintNameBlock.Text = "Point to Point"; //there are no limits so the sphere will orbit once we apply this sphereRigidBody.ApplyImpulse(new Vector3(0, 0, 18)); }
public override void Start() { //simulation = this.GetSimulation(); simulation = SceneSystem.SceneInstance.GetProcessor <BepuPhysicsProcessor>()?.Simulation; simulation.Gravity = new Vector3(0, -9, 0); cubeRigidBody = cube.Get <BepuRigidbodyComponent>(); cubeRigidBody.CanSleep = false; sphereRigidBody = sphere.Get <BepuRigidbodyComponent>(); sphereRigidBody.CanSleep = false; // Create the UI constraintNameBlock = new TextBlock { Font = Font, TextSize = 55, TextColor = Color.White, }; constraintNameBlock.SetCanvasPinOrigin(new Vector3(0.5f, 0.5f, 0)); constraintNameBlock.SetCanvasRelativePosition(new Vector3(0.5f, 0.83f, 0)); Entity.Get <UIComponent>().Page = new UIPage { RootElement = new Canvas { Children = { constraintNameBlock, CreateButton("Next", Font, 1), CreateButton("Previous",Font, -1) } } }; // Create and initialize constraint PhysicsSampleList.Add(CreatePoint2PointConstraint); //PhysicsSampleList.Add(CreateHingeConstraint); //PhysicsSampleList.Add(CreateGearConstraint); //PhysicsSampleList.Add(CreateSliderConstraint); //PhysicsSampleList.Add(CreateConeTwistConstraint); //PhysicsSampleList.Add(CreateGeneric6DoFConstraint); RemoveConstraint(); PhysicsSampleList[constraintIndex](); //Add a script for the slider constraint, to apply an impulse on collision cubeRigidBody.ProcessCollisions = true; Script.AddTask(async() => { while (Game.IsRunning) { var collision = await cubeRigidBody.NewCollision(); //if (!(currentConstraint is SliderConstraint)) continue; if (collision.ColliderA != sphereRigidBody && collision.ColliderB != sphereRigidBody) { continue; } sphereRigidBody.LinearVelocity = Vector3.Zero; //clear any existing velocity sphereRigidBody.ApplyImpulse(new Vector3(-25, 0, 0)); //fire impulse } }); }
public override void Start() { camera = Entity.Get <CameraComponent>(); simulation = this.GetBepuSimulation(); }