aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
diff options
context:
space:
mode:
authorRobert Adams2012-10-17 08:30:10 -0700
committerRobert Adams2012-10-19 10:52:23 -0700
commite87a179c893ef246dae8338e0f56c3fe20458fbc (patch)
tree1699e1fc26a47ba000bbd2392df894dc3247f956 /OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
parentBulletSim: remove code in ShapeCollection that hinted at shape sharing. (diff)
downloadopensim-SC_OLD-e87a179c893ef246dae8338e0f56c3fe20458fbc.zip
opensim-SC_OLD-e87a179c893ef246dae8338e0f56c3fe20458fbc.tar.gz
opensim-SC_OLD-e87a179c893ef246dae8338e0f56c3fe20458fbc.tar.bz2
opensim-SC_OLD-e87a179c893ef246dae8338e0f56c3fe20458fbc.tar.xz
BulletSim: change nonimal physics frame rate to 55 to give same numbers as ODE.
Change character scaling to represent size of capsule (diameter rather than radius) Modify create capsule call to pass radius and height. Eliminate errors when calculating shape inertia (should have some type checking).
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs46
1 files changed, 26 insertions, 20 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
index 8e1171a..e7bff6e 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
@@ -89,13 +89,15 @@ public class BSCharacter : BSPhysObject
89 _appliedVelocity = OMV.Vector3.Zero; 89 _appliedVelocity = OMV.Vector3.Zero;
90 _buoyancy = ComputeBuoyancyFromFlying(isFlying); 90 _buoyancy = ComputeBuoyancyFromFlying(isFlying);
91 _currentFriction = PhysicsScene.Params.avatarStandingFriction; 91 _currentFriction = PhysicsScene.Params.avatarStandingFriction;
92 _avatarDensity = PhysicsScene.Params.avatarDensity;
92 93
93 // The dimensions of the avatar capsule are kept in the scale. 94 // The dimensions of the avatar capsule are kept in the scale.
94 // Physics creates a unit capsule which is scaled by the physics engine. 95 // Physics creates a unit capsule which is scaled by the physics engine.
95 ComputeAvatarScale(_size); 96 ComputeAvatarScale(_size);
96 _avatarDensity = PhysicsScene.Params.avatarDensity;
97 // set _avatarVolume and _mass based on capsule size, _density and Scale 97 // set _avatarVolume and _mass based on capsule size, _density and Scale
98 ComputeAvatarVolumeAndMass(); 98 ComputeAvatarVolumeAndMass();
99 DetailLog("{0},BSCharacter.create,call,size={1},scale={2},density={3},volume={4},mass={5}",
100 LocalID, _size, Scale, _avatarDensity, _avatarVolume, MassRaw);
99 101
100 ShapeData shapeData = new ShapeData(); 102 ShapeData shapeData = new ShapeData();
101 shapeData.ID = LocalID; 103 shapeData.ID = LocalID;
@@ -103,6 +105,7 @@ public class BSCharacter : BSPhysObject
103 shapeData.Position = _position; 105 shapeData.Position = _position;
104 shapeData.Rotation = _orientation; 106 shapeData.Rotation = _orientation;
105 shapeData.Velocity = _velocity; 107 shapeData.Velocity = _velocity;
108 shapeData.Size = Scale;
106 shapeData.Scale = Scale; 109 shapeData.Scale = Scale;
107 shapeData.Mass = _mass; 110 shapeData.Mass = _mass;
108 shapeData.Buoyancy = _buoyancy; 111 shapeData.Buoyancy = _buoyancy;
@@ -114,8 +117,9 @@ public class BSCharacter : BSPhysObject
114 PhysicsScene.TaintedObject("BSCharacter.create", delegate() 117 PhysicsScene.TaintedObject("BSCharacter.create", delegate()
115 { 118 {
116 DetailLog("{0},BSCharacter.create,taint", LocalID); 119 DetailLog("{0},BSCharacter.create,taint", LocalID);
117 PhysicsScene.Shapes.GetBodyAndShape(true, PhysicsScene.World, this, shapeData, null, null, null); 120 // New body and shape into BSBody and BSShape
118 121 PhysicsScene.Shapes.GetBodyAndShape(true, PhysicsScene.World, this, shapeData, null, null, null);
122
119 SetPhysicalProperties(); 123 SetPhysicalProperties();
120 }); 124 });
121 return; 125 return;
@@ -138,7 +142,7 @@ public class BSCharacter : BSPhysObject
138 142
139 ZeroMotion(); 143 ZeroMotion();
140 144
141 OMV.Vector3 localInertia = BulletSimAPI.CalculateLocalInertia2(BSShape.ptr, MassRaw); 145 OMV.Vector3 localInertia = BulletSimAPI.CalculateLocalInertia2(BSShape.ptr, MassRaw);
142 BulletSimAPI.SetMassProps2(BSBody.ptr, MassRaw, localInertia); 146 BulletSimAPI.SetMassProps2(BSBody.ptr, MassRaw, localInertia);
143 147
144 ForcePosition = _position; 148 ForcePosition = _position;
@@ -151,13 +155,13 @@ public class BSCharacter : BSPhysObject
151 { 155 {
152 BulletSimAPI.SetCcdMotionThreshold2(BSBody.ptr, PhysicsScene.Params.ccdMotionThreshold); 156 BulletSimAPI.SetCcdMotionThreshold2(BSBody.ptr, PhysicsScene.Params.ccdMotionThreshold);
153 BulletSimAPI.SetCcdSweepSphereRadius2(BSBody.ptr, PhysicsScene.Params.ccdSweptSphereRadius); 157 BulletSimAPI.SetCcdSweepSphereRadius2(BSBody.ptr, PhysicsScene.Params.ccdSweptSphereRadius);
154 } 158 }
155 159
156 BulletSimAPI.AddToCollisionFlags2(BSBody.ptr, CollisionFlags.CF_CHARACTER_OBJECT); 160 BulletSimAPI.AddToCollisionFlags2(BSBody.ptr, CollisionFlags.CF_CHARACTER_OBJECT);
157 161
158 BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, BSBody.ptr); 162 BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, BSBody.ptr);
159 163
160 BulletSimAPI.ForceActivationState2(BSBody.ptr, ActivationState.DISABLE_DEACTIVATION); 164 BulletSimAPI.ForceActivationState2(BSBody.ptr, ActivationState.ACTIVE_TAG);
161 BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, BSBody.ptr); 165 BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, BSBody.ptr);
162 166
163 // Do this after the object has been added to the world 167 // Do this after the object has been added to the world
@@ -176,7 +180,7 @@ public class BSCharacter : BSPhysObject
176 get 180 get
177 { 181 {
178 // Avatar capsule size is kept in the scale parameter. 182 // Avatar capsule size is kept in the scale parameter.
179 return new OMV.Vector3(Scale.X * 2, Scale.Y * 2, Scale.Z); 183 return _size;
180 } 184 }
181 185
182 set { 186 set {
@@ -184,11 +188,13 @@ public class BSCharacter : BSPhysObject
184 _size = value; 188 _size = value;
185 ComputeAvatarScale(_size); 189 ComputeAvatarScale(_size);
186 ComputeAvatarVolumeAndMass(); 190 ComputeAvatarVolumeAndMass();
191 DetailLog("{0},BSCharacter.setSize,call,scale={1},density={2},volume={3},mass={4}",
192 LocalID, Scale, _avatarDensity, _avatarVolume, MassRaw);
187 193
188 PhysicsScene.TaintedObject("BSCharacter.setSize", delegate() 194 PhysicsScene.TaintedObject("BSCharacter.setSize", delegate()
189 { 195 {
190 BulletSimAPI.SetLocalScaling2(BSShape.ptr, Scale); 196 BulletSimAPI.SetLocalScaling2(BSShape.ptr, Scale);
191 OMV.Vector3 localInertia = BulletSimAPI.CalculateLocalInertia2(BSBody.ptr, MassRaw); 197 OMV.Vector3 localInertia = BulletSimAPI.CalculateLocalInertia2(BSShape.ptr, MassRaw);
192 BulletSimAPI.SetMassProps2(BSBody.ptr, MassRaw, localInertia); 198 BulletSimAPI.SetMassProps2(BSBody.ptr, MassRaw, localInertia);
193 }); 199 });
194 200
@@ -578,13 +584,13 @@ public class BSCharacter : BSPhysObject
578 private void ComputeAvatarScale(OMV.Vector3 size) 584 private void ComputeAvatarScale(OMV.Vector3 size)
579 { 585 {
580 OMV.Vector3 newScale = OMV.Vector3.Zero; 586 OMV.Vector3 newScale = OMV.Vector3.Zero;
581 newScale.X = PhysicsScene.Params.avatarCapsuleRadius; 587 // Scale wants the diameter so mult radius by two
582 newScale.Y = PhysicsScene.Params.avatarCapsuleRadius; 588 newScale.X = PhysicsScene.Params.avatarCapsuleRadius * 2f;
589 newScale.Y = PhysicsScene.Params.avatarCapsuleRadius * 2f;
583 590
584 // The 1.15 came from ODE but it seems to cause the avatar to float off the ground 591 // From the total height, add the capsule half spheres that are at each end
585 // Scale.Z = (_size.Z * 1.15f) - (Scale.X + Scale.Y); 592 // newScale.Z = (size.Z) - Math.Min(newScale.X, newScale.Y);
586 // From the total height, remove the capsule half spheres that are at each end 593 newScale.Z = (size.Z * 2f);
587 newScale.Z = (size.Z) - (Math.Min(newScale.X, newScale.Y) * 2f);
588 Scale = newScale; 594 Scale = newScale;
589 } 595 }
590 596
@@ -593,14 +599,14 @@ public class BSCharacter : BSPhysObject
593 { 599 {
594 _avatarVolume = (float)( 600 _avatarVolume = (float)(
595 Math.PI 601 Math.PI
596 * Scale.X 602 * (Scale.X / 2f)
597 * Scale.Y // the area of capsule cylinder 603 * (Scale.Y / 2f) // the area of capsule cylinder
598 * Scale.Z // times height of capsule cylinder 604 * Scale.Z // times height of capsule cylinder
599 + 1.33333333f 605 + 1.33333333f
600 * Math.PI 606 * Math.PI
601 * Scale.X 607 * (Scale.X / 2f)
602 * Math.Min(Scale.X, Scale.Y) 608 * (Math.Min(Scale.X, Scale.Y) / 2f)
603 * Scale.Y // plus the volume of the capsule end caps 609 * (Scale.Y / 2f) // plus the volume of the capsule end caps
604 ); 610 );
605 _mass = _avatarDensity * _avatarVolume; 611 _mass = _avatarDensity * _avatarVolume;
606 } 612 }