/// <summary> /// Deactivate the buoyancy actor for the physics object this /// actor acts upon. /// </summary> private void DeactivateBuoyancy() { // If the buoyancy motor instance is existent, it is active so // go ahead and remove the pre-step Buoyancy action // and set the buoyancy motor to null if (m_buoyancyMotor != null) { PhysicsScene.BeforeStep -= Buoyancy; m_buoyancyMotor = null; } }
/// <summary> /// Activate the buoyancy of the physics actor to begin applying force /// upon the physical object to simulate buoyancy within the physics /// scene. /// </summary> private void ActivateBuoyancy() { // If the buoyancy motor is null, initialize an instance // of the PxFMotor (Float motor) if (m_buoyancyMotor == null) { // Initialize the PxFMotor with the position of the // physics object, and the infinite motor component // and a efficiency of 1.0f m_buoyancyMotor = new PxFMotor( PhysicsObject.Position.Z, PxMotor.Infinite, 1.0f); // Set the target as the water height within the physics scene // and the current value as the height of the physics object // to that the motor knows the current value and the target // value that it should be iterating up to m_buoyancyMotor.SetTarget(PhysicsScene.WaterHeight); m_buoyancyMotor.SetCurrent(PhysicsObject.Position.Z); // Add the buoyancy function to the before step within the scene // to ensure it is called before every simulation step PhysicsScene.BeforeStep += Buoyancy; } }
/// <summary> /// Constructor for the buoyancy actor, includes the physics scene, /// the physics object, and the name of this physics actor. /// </summary> /// <param name="physicsScene"> The physics scene that this actor will /// act within. </param> /// <param name="physicsObject"> The physics object that this actor will /// act upon. </param> /// <param name="actorName"> The physics actor name to identify /// the intent. <param> public PxActorBuoyancy(PxScene physicsScene, PxPhysObject physObject, string actorName) : base(physicsScene, physObject, actorName) { m_buoyancyMotor = null; }