From d1ede1df3a04428c83a9937059a0df00d7f3e281 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Tue, 25 Dec 2012 23:55:25 -0800 Subject: BulletSim: make llBuoyancy work. For some reason, Bullet resets an object's individual gravity to the world gravity when the object is added to the physical world. --- OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs') diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs index 159f79f..0d13096 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSPrim.cs @@ -422,20 +422,24 @@ public sealed class BSPrim : BSPhysObject BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, PhysBody.ptr); } - float grav = PhysicsScene.Params.gravity * (1f - _buoyancy); - BulletSimAPI.SetGravity2(PhysBody.ptr, new OMV.Vector3(0f, 0f, grav)); - Inertia = BulletSimAPI.CalculateLocalInertia2(PhysShape.ptr, physMass); BulletSimAPI.SetMassProps2(PhysBody.ptr, physMass, Inertia); BulletSimAPI.UpdateInertiaTensor2(PhysBody.ptr); + // center of mass is at the zero of the object // DEBUG DEBUG BulletSimAPI.SetCenterOfMassByPosRot2(PhysBody.ptr, ForcePosition, ForceOrientation); - DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2}", LocalID, physMass, Inertia); + DetailLog("{0},BSPrim.UpdateMassProperties,mass={1},localInertia={2},inWorld={3}", LocalID, physMass, Inertia, inWorld); if (inWorld) { BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, PhysBody.ptr); } + + // Must set gravity after it has been added to the world because, for unknown reasons, + // adding the object resets the object's gravity to world gravity + OMV.Vector3 grav = PhysicsScene.DefaultGravity * (1f - Buoyancy); + BulletSimAPI.SetGravity2(PhysBody.ptr, grav); + } } } -- cgit v1.1