Ejemplo n.º 1
0
        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>();
        }
Ejemplo n.º 2
0
        //    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;
        }
Ejemplo n.º 3
0
 internal override void CreateAndAddCollidableDescription(
     BepuPhysicsComponent physicsComponent,
     BepuSimulation xenkoSimulation,
     out TypedIndex shapeTypeIndex,
     out CollidableDescription collidableDescription)
 {
     CreateAndAddCollidableDescription <Sphere>(
         physicsComponent, xenkoSimulation, out shapeTypeIndex, out collidableDescription);
 }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 5
0
        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
                }
            });
        }
Ejemplo n.º 6
0
 public override void Start()
 {
     camera     = Entity.Get <CameraComponent>();
     simulation = this.GetBepuSimulation();
 }