aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs')
-rw-r--r--OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs206
1 files changed, 123 insertions, 83 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
index 623ac8f..4c195e1 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
@@ -34,7 +34,7 @@ using OpenSim.Region.Physics.Manager;
34 34
35namespace OpenSim.Region.Physics.BulletSPlugin 35namespace OpenSim.Region.Physics.BulletSPlugin
36{ 36{
37public class BSCharacter : BSPhysObject 37public sealed class BSCharacter : BSPhysObject
38{ 38{
39 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 39 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
40 private static readonly string LogHeader = "[BULLETS CHAR]"; 40 private static readonly string LogHeader = "[BULLETS CHAR]";
@@ -78,11 +78,17 @@ public class BSCharacter : BSPhysObject
78 private float _PIDHoverTao; 78 private float _PIDHoverTao;
79 79
80 public BSCharacter(uint localID, String avName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size, bool isFlying) 80 public BSCharacter(uint localID, String avName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size, bool isFlying)
81 : base(parent_scene, localID, avName, "BSCharacter")
81 { 82 {
82 base.BaseInitialize(parent_scene, localID, avName, "BSCharacter");
83 _physicsActorType = (int)ActorTypes.Agent; 83 _physicsActorType = (int)ActorTypes.Agent;
84 _position = pos; 84 _position = pos;
85
86 // Old versions of ScenePresence passed only the height. If width and/or depth are zero,
87 // replace with the default values.
85 _size = size; 88 _size = size;
89 if (_size.X == 0f) _size.X = PhysicsScene.Params.avatarCapsuleDepth;
90 if (_size.Y == 0f) _size.Y = PhysicsScene.Params.avatarCapsuleWidth;
91
86 _flying = isFlying; 92 _flying = isFlying;
87 _orientation = OMV.Quaternion.Identity; 93 _orientation = OMV.Quaternion.Identity;
88 _velocity = OMV.Vector3.Zero; 94 _velocity = OMV.Vector3.Zero;
@@ -97,28 +103,14 @@ public class BSCharacter : BSPhysObject
97 // set _avatarVolume and _mass based on capsule size, _density and Scale 103 // set _avatarVolume and _mass based on capsule size, _density and Scale
98 ComputeAvatarVolumeAndMass(); 104 ComputeAvatarVolumeAndMass();
99 DetailLog("{0},BSCharacter.create,call,size={1},scale={2},density={3},volume={4},mass={5}", 105 DetailLog("{0},BSCharacter.create,call,size={1},scale={2},density={3},volume={4},mass={5}",
100 LocalID, _size, Scale, _avatarDensity, _avatarVolume, MassRaw); 106 LocalID, _size, Scale, _avatarDensity, _avatarVolume, RawMass);
101
102 ShapeData shapeData = new ShapeData();
103 shapeData.ID = LocalID;
104 shapeData.Type = ShapeData.PhysicsShapeType.SHAPE_AVATAR;
105 shapeData.Position = _position;
106 shapeData.Rotation = _orientation;
107 shapeData.Velocity = _velocity;
108 shapeData.Size = Scale;
109 shapeData.Scale = Scale;
110 shapeData.Mass = _mass;
111 shapeData.Buoyancy = _buoyancy;
112 shapeData.Static = ShapeData.numericFalse;
113 shapeData.Friction = PhysicsScene.Params.avatarStandingFriction;
114 shapeData.Restitution = PhysicsScene.Params.avatarRestitution;
115 107
116 // do actual create at taint time 108 // do actual create at taint time
117 PhysicsScene.TaintedObject("BSCharacter.create", delegate() 109 PhysicsScene.TaintedObject("BSCharacter.create", delegate()
118 { 110 {
119 DetailLog("{0},BSCharacter.create,taint", LocalID); 111 DetailLog("{0},BSCharacter.create,taint", LocalID);
120 // New body and shape into BSBody and BSShape 112 // New body and shape into PhysBody and PhysShape
121 PhysicsScene.Shapes.GetBodyAndShape(true, PhysicsScene.World, this, shapeData, null, null, null); 113 PhysicsScene.Shapes.GetBodyAndShape(true, PhysicsScene.World, this, null, null);
122 114
123 SetPhysicalProperties(); 115 SetPhysicalProperties();
124 }); 116 });
@@ -131,41 +123,50 @@ public class BSCharacter : BSPhysObject
131 DetailLog("{0},BSCharacter.Destroy", LocalID); 123 DetailLog("{0},BSCharacter.Destroy", LocalID);
132 PhysicsScene.TaintedObject("BSCharacter.destroy", delegate() 124 PhysicsScene.TaintedObject("BSCharacter.destroy", delegate()
133 { 125 {
134 PhysicsScene.Shapes.DereferenceBody(BSBody, true, null); 126 PhysicsScene.Shapes.DereferenceBody(PhysBody, true, null);
135 PhysicsScene.Shapes.DereferenceShape(BSShape, true, null); 127 PhysicsScene.Shapes.DereferenceShape(PhysShape, true, null);
136 }); 128 });
137 } 129 }
138 130
139 private void SetPhysicalProperties() 131 private void SetPhysicalProperties()
140 { 132 {
141 BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, BSBody.ptr); 133 BulletSimAPI.RemoveObjectFromWorld2(PhysicsScene.World.ptr, PhysBody.ptr);
142 134
143 ZeroMotion(); 135 ZeroMotion(true);
144 ForcePosition = _position; 136 ForcePosition = _position;
145 // Set the velocity and compute the proper friction 137 // Set the velocity and compute the proper friction
146 ForceVelocity = _velocity; 138 ForceVelocity = _velocity;
147 BulletSimAPI.SetRestitution2(BSBody.ptr, PhysicsScene.Params.avatarRestitution); 139
148 BulletSimAPI.SetLocalScaling2(BSShape.ptr, Scale); 140 // This will enable or disable the flying buoyancy of the avatar.
149 BulletSimAPI.SetContactProcessingThreshold2(BSBody.ptr, PhysicsScene.Params.contactProcessingThreshold); 141 // Needs to be reset especially when an avatar is recreated after crossing a region boundry.
142 Flying = _flying;
143
144 BulletSimAPI.SetRestitution2(PhysBody.ptr, PhysicsScene.Params.avatarRestitution);
145 BulletSimAPI.SetMargin2(PhysShape.ptr, PhysicsScene.Params.collisionMargin);
146 BulletSimAPI.SetLocalScaling2(PhysShape.ptr, Scale);
147 BulletSimAPI.SetContactProcessingThreshold2(PhysBody.ptr, PhysicsScene.Params.contactProcessingThreshold);
150 if (PhysicsScene.Params.ccdMotionThreshold > 0f) 148 if (PhysicsScene.Params.ccdMotionThreshold > 0f)
151 { 149 {
152 BulletSimAPI.SetCcdMotionThreshold2(BSBody.ptr, PhysicsScene.Params.ccdMotionThreshold); 150 BulletSimAPI.SetCcdMotionThreshold2(PhysBody.ptr, PhysicsScene.Params.ccdMotionThreshold);
153 BulletSimAPI.SetCcdSweepSphereRadius2(BSBody.ptr, PhysicsScene.Params.ccdSweptSphereRadius); 151 BulletSimAPI.SetCcdSweptSphereRadius2(PhysBody.ptr, PhysicsScene.Params.ccdSweptSphereRadius);
154 } 152 }
155 153
156 OMV.Vector3 localInertia = BulletSimAPI.CalculateLocalInertia2(BSShape.ptr, MassRaw); 154 UpdatePhysicalMassProperties(RawMass);
157 BulletSimAPI.SetMassProps2(BSBody.ptr, MassRaw, localInertia); 155
156 // Make so capsule does not fall over
157 BulletSimAPI.SetAngularFactorV2(PhysBody.ptr, OMV.Vector3.Zero);
158 158
159 BulletSimAPI.AddToCollisionFlags2(BSBody.ptr, CollisionFlags.CF_CHARACTER_OBJECT); 159 BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.CF_CHARACTER_OBJECT);
160 160
161 BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, BSBody.ptr); 161 BulletSimAPI.AddObjectToWorld2(PhysicsScene.World.ptr, PhysBody.ptr);
162 162
163 BulletSimAPI.ForceActivationState2(BSBody.ptr, ActivationState.ACTIVE_TAG); 163 // BulletSimAPI.ForceActivationState2(BSBody.ptr, ActivationState.ACTIVE_TAG);
164 BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, BSBody.ptr); 164 BulletSimAPI.ForceActivationState2(PhysBody.ptr, ActivationState.DISABLE_DEACTIVATION);
165 BulletSimAPI.UpdateSingleAabb2(PhysicsScene.World.ptr, PhysBody.ptr);
165 166
166 // Do this after the object has been added to the world 167 // Do this after the object has been added to the world
167 BulletSimAPI.SetCollisionFilterMask2(BSBody.ptr, 168 BulletSimAPI.SetCollisionFilterMask2(PhysBody.ptr,
168 (uint)CollisionFilterGroups.AvatarFilter, 169 (uint)CollisionFilterGroups.AvatarFilter,
169 (uint)CollisionFilterGroups.AvatarMask); 170 (uint)CollisionFilterGroups.AvatarMask);
170 } 171 }
171 172
@@ -175,6 +176,7 @@ public class BSCharacter : BSPhysObject
175 } 176 }
176 // No one calls this method so I don't know what it could possibly mean 177 // No one calls this method so I don't know what it could possibly mean
177 public override bool Stopped { get { return false; } } 178 public override bool Stopped { get { return false; } }
179
178 public override OMV.Vector3 Size { 180 public override OMV.Vector3 Size {
179 get 181 get
180 { 182 {
@@ -187,23 +189,29 @@ public class BSCharacter : BSPhysObject
187 _size = value; 189 _size = value;
188 ComputeAvatarScale(_size); 190 ComputeAvatarScale(_size);
189 ComputeAvatarVolumeAndMass(); 191 ComputeAvatarVolumeAndMass();
190 DetailLog("{0},BSCharacter.setSize,call,scale={1},density={2},volume={3},mass={4}", 192 DetailLog("{0},BSCharacter.setSize,call,size={1},scale={2},density={3},volume={4},mass={5}",
191 LocalID, Scale, _avatarDensity, _avatarVolume, MassRaw); 193 LocalID, _size, Scale, _avatarDensity, _avatarVolume, RawMass);
192 194
193 PhysicsScene.TaintedObject("BSCharacter.setSize", delegate() 195 PhysicsScene.TaintedObject("BSCharacter.setSize", delegate()
194 { 196 {
195 BulletSimAPI.SetLocalScaling2(BSShape.ptr, Scale); 197 BulletSimAPI.SetLocalScaling2(PhysShape.ptr, Scale);
196 OMV.Vector3 localInertia = BulletSimAPI.CalculateLocalInertia2(BSShape.ptr, MassRaw); 198 UpdatePhysicalMassProperties(RawMass);
197 BulletSimAPI.SetMassProps2(BSBody.ptr, MassRaw, localInertia);
198 }); 199 });
199 200
200 } 201 }
201 } 202 }
203
202 public override OMV.Vector3 Scale { get; set; } 204 public override OMV.Vector3 Scale { get; set; }
205
203 public override PrimitiveBaseShape Shape 206 public override PrimitiveBaseShape Shape
204 { 207 {
205 set { BaseShape = value; } 208 set { BaseShape = value; }
206 } 209 }
210 // I want the physics engine to make an avatar capsule
211 public override BSPhysicsShapeType PreferredPhysicalShape
212 {
213 get {return BSPhysicsShapeType.SHAPE_CAPSULE; }
214 }
207 215
208 public override bool Grabbed { 216 public override bool Grabbed {
209 set { _grabbed = value; } 217 set { _grabbed = value; }
@@ -219,23 +227,42 @@ public class BSCharacter : BSPhysObject
219 // Do it to the properties so the values get set in the physics engine. 227 // Do it to the properties so the values get set in the physics engine.
220 // Push the setting of the values to the viewer. 228 // Push the setting of the values to the viewer.
221 // Called at taint time! 229 // Called at taint time!
222 public override void ZeroMotion() 230 public override void ZeroMotion(bool inTaintTime)
223 { 231 {
224 _velocity = OMV.Vector3.Zero; 232 _velocity = OMV.Vector3.Zero;
225 _acceleration = OMV.Vector3.Zero; 233 _acceleration = OMV.Vector3.Zero;
226 _rotationalVelocity = OMV.Vector3.Zero; 234 _rotationalVelocity = OMV.Vector3.Zero;
227 235
228 // Zero some other properties directly into the physics engine 236 // Zero some other properties directly into the physics engine
229 BulletSimAPI.SetLinearVelocity2(BSBody.ptr, OMV.Vector3.Zero); 237 PhysicsScene.TaintedObject(inTaintTime, "BSCharacter.ZeroMotion", delegate()
230 BulletSimAPI.SetAngularVelocity2(BSBody.ptr, OMV.Vector3.Zero); 238 {
231 BulletSimAPI.SetInterpolationVelocity2(BSBody.ptr, OMV.Vector3.Zero, OMV.Vector3.Zero); 239 BulletSimAPI.ClearAllForces2(PhysBody.ptr);
232 BulletSimAPI.ClearForces2(BSBody.ptr); 240 });
233 } 241 }
242 public override void ZeroAngularMotion(bool inTaintTime)
243 {
244 _rotationalVelocity = OMV.Vector3.Zero;
245
246 PhysicsScene.TaintedObject(inTaintTime, "BSCharacter.ZeroMotion", delegate()
247 {
248 BulletSimAPI.SetInterpolationAngularVelocity2(PhysBody.ptr, OMV.Vector3.Zero);
249 BulletSimAPI.SetAngularVelocity2(PhysBody.ptr, OMV.Vector3.Zero);
250 // The next also get rid of applied linear force but the linear velocity is untouched.
251 BulletSimAPI.ClearForces2(PhysBody.ptr);
252 });
253 }
254
234 255
235 public override void LockAngularMotion(OMV.Vector3 axis) { return; } 256 public override void LockAngularMotion(OMV.Vector3 axis) { return; }
236 257
258 public override OMV.Vector3 RawPosition
259 {
260 get { return _position; }
261 set { _position = value; }
262 }
237 public override OMV.Vector3 Position { 263 public override OMV.Vector3 Position {
238 get { 264 get {
265 // Don't refetch the position because this function is called a zillion times
239 // _position = BulletSimAPI.GetObjectPosition2(Scene.World.ptr, LocalID); 266 // _position = BulletSimAPI.GetObjectPosition2(Scene.World.ptr, LocalID);
240 return _position; 267 return _position;
241 } 268 }
@@ -246,30 +273,30 @@ public class BSCharacter : BSPhysObject
246 PhysicsScene.TaintedObject("BSCharacter.setPosition", delegate() 273 PhysicsScene.TaintedObject("BSCharacter.setPosition", delegate()
247 { 274 {
248 DetailLog("{0},BSCharacter.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); 275 DetailLog("{0},BSCharacter.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation);
249 BulletSimAPI.SetTranslation2(BSBody.ptr, _position, _orientation); 276 BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation);
250 }); 277 });
251 } 278 }
252 } 279 }
253 public override OMV.Vector3 ForcePosition { 280 public override OMV.Vector3 ForcePosition {
254 get { 281 get {
255 _position = BulletSimAPI.GetPosition2(BSBody.ptr); 282 _position = BulletSimAPI.GetPosition2(PhysBody.ptr);
256 return _position; 283 return _position;
257 } 284 }
258 set { 285 set {
259 _position = value; 286 _position = value;
260 PositionSanityCheck(); 287 PositionSanityCheck();
261 BulletSimAPI.SetTranslation2(BSBody.ptr, _position, _orientation); 288 BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation);
262 } 289 }
263 } 290 }
264 291
265 292
266 // Check that the current position is sane and, if not, modify the position to make it so. 293 // Check that the current position is sane and, if not, modify the position to make it so.
267 // Check for being below terrain and being out of bounds. 294 // Check for being below terrain or on water.
268 // Returns 'true' of the position was made sane by some action. 295 // Returns 'true' of the position was made sane by some action.
269 private bool PositionSanityCheck() 296 private bool PositionSanityCheck()
270 { 297 {
271 bool ret = false; 298 bool ret = false;
272 299
273 // If below the ground, move the avatar up 300 // If below the ground, move the avatar up
274 float terrainHeight = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(_position); 301 float terrainHeight = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(_position);
275 if (Position.Z < terrainHeight) 302 if (Position.Z < terrainHeight)
@@ -302,15 +329,11 @@ public class BSCharacter : BSPhysObject
302 { 329 {
303 // The new position value must be pushed into the physics engine but we can't 330 // The new position value must be pushed into the physics engine but we can't
304 // just assign to "Position" because of potential call loops. 331 // just assign to "Position" because of potential call loops.
305 BSScene.TaintCallback sanityOperation = delegate() 332 PhysicsScene.TaintedObject(inTaintTime, "BSCharacter.PositionSanityCheck", delegate()
306 { 333 {
307 DetailLog("{0},BSCharacter.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, _position, _orientation); 334 DetailLog("{0},BSCharacter.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, _position, _orientation);
308 BulletSimAPI.SetTranslation2(BSBody.ptr, _position, _orientation); 335 BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation);
309 }; 336 });
310 if (inTaintTime)
311 sanityOperation();
312 else
313 PhysicsScene.TaintedObject("BSCharacter.PositionSanityCheck", sanityOperation);
314 ret = true; 337 ret = true;
315 } 338 }
316 return ret; 339 return ret;
@@ -319,7 +342,14 @@ public class BSCharacter : BSPhysObject
319 public override float Mass { get { return _mass; } } 342 public override float Mass { get { return _mass; } }
320 343
321 // used when we only want this prim's mass and not the linkset thing 344 // used when we only want this prim's mass and not the linkset thing
322 public override float MassRaw { get {return _mass; } } 345 public override float RawMass {
346 get {return _mass; }
347 }
348 public override void UpdatePhysicalMassProperties(float physMass)
349 {
350 OMV.Vector3 localInertia = BulletSimAPI.CalculateLocalInertia2(PhysShape.ptr, physMass);
351 BulletSimAPI.SetMassProps2(PhysBody.ptr, physMass, localInertia);
352 }
323 353
324 public override OMV.Vector3 Force { 354 public override OMV.Vector3 Force {
325 get { return _force; } 355 get { return _force; }
@@ -329,13 +359,13 @@ public class BSCharacter : BSPhysObject
329 PhysicsScene.TaintedObject("BSCharacter.SetForce", delegate() 359 PhysicsScene.TaintedObject("BSCharacter.SetForce", delegate()
330 { 360 {
331 DetailLog("{0},BSCharacter.setForce,taint,force={1}", LocalID, _force); 361 DetailLog("{0},BSCharacter.setForce,taint,force={1}", LocalID, _force);
332 BulletSimAPI.SetObjectForce2(BSBody.ptr, _force); 362 BulletSimAPI.SetObjectForce2(PhysBody.ptr, _force);
333 }); 363 });
334 } 364 }
335 } 365 }
336 366
337 // Avatars don't do vehicles 367 // Avatars don't do vehicles
338 public override int VehicleType { get { return 0; } set { return; } } 368 public override int VehicleType { get { return (int)Vehicle.TYPE_NONE; } set { return; } }
339 public override void VehicleFloatParam(int param, float value) { } 369 public override void VehicleFloatParam(int param, float value) { }
340 public override void VehicleVectorParam(int param, OMV.Vector3 value) {} 370 public override void VehicleVectorParam(int param, OMV.Vector3 value) {}
341 public override void VehicleRotationParam(int param, OMV.Quaternion rotation) { } 371 public override void VehicleRotationParam(int param, OMV.Quaternion rotation) { }
@@ -368,7 +398,7 @@ public class BSCharacter : BSPhysObject
368 if (_currentFriction != PhysicsScene.Params.avatarStandingFriction) 398 if (_currentFriction != PhysicsScene.Params.avatarStandingFriction)
369 { 399 {
370 _currentFriction = PhysicsScene.Params.avatarStandingFriction; 400 _currentFriction = PhysicsScene.Params.avatarStandingFriction;
371 BulletSimAPI.SetFriction2(BSBody.ptr, _currentFriction); 401 BulletSimAPI.SetFriction2(PhysBody.ptr, _currentFriction);
372 } 402 }
373 } 403 }
374 else 404 else
@@ -376,15 +406,15 @@ public class BSCharacter : BSPhysObject
376 if (_currentFriction != PhysicsScene.Params.avatarFriction) 406 if (_currentFriction != PhysicsScene.Params.avatarFriction)
377 { 407 {
378 _currentFriction = PhysicsScene.Params.avatarFriction; 408 _currentFriction = PhysicsScene.Params.avatarFriction;
379 BulletSimAPI.SetFriction2(BSBody.ptr, _currentFriction); 409 BulletSimAPI.SetFriction2(PhysBody.ptr, _currentFriction);
380 } 410 }
381 } 411 }
382 _velocity = value; 412 _velocity = value;
383 // Remember the set velocity so we can suppress the reduction by friction, ... 413 // Remember the set velocity so we can suppress the reduction by friction, ...
384 _appliedVelocity = value; 414 _appliedVelocity = value;
385 415
386 BulletSimAPI.SetLinearVelocity2(BSBody.ptr, _velocity); 416 BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, _velocity);
387 BulletSimAPI.Activate2(BSBody.ptr, true); 417 BulletSimAPI.Activate2(PhysBody.ptr, true);
388 } 418 }
389 } 419 }
390 public override OMV.Vector3 Torque { 420 public override OMV.Vector3 Torque {
@@ -401,6 +431,11 @@ public class BSCharacter : BSPhysObject
401 get { return _acceleration; } 431 get { return _acceleration; }
402 set { _acceleration = value; } 432 set { _acceleration = value; }
403 } 433 }
434 public override OMV.Quaternion RawOrientation
435 {
436 get { return _orientation; }
437 set { _orientation = value; }
438 }
404 public override OMV.Quaternion Orientation { 439 public override OMV.Quaternion Orientation {
405 get { return _orientation; } 440 get { return _orientation; }
406 set { 441 set {
@@ -409,22 +444,22 @@ public class BSCharacter : BSPhysObject
409 PhysicsScene.TaintedObject("BSCharacter.setOrientation", delegate() 444 PhysicsScene.TaintedObject("BSCharacter.setOrientation", delegate()
410 { 445 {
411 // _position = BulletSimAPI.GetPosition2(BSBody.ptr); 446 // _position = BulletSimAPI.GetPosition2(BSBody.ptr);
412 BulletSimAPI.SetTranslation2(BSBody.ptr, _position, _orientation); 447 BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation);
413 }); 448 });
414 } 449 }
415 } 450 }
416 // Go directly to Bullet to get/set the value. 451 // Go directly to Bullet to get/set the value.
417 public override OMV.Quaternion ForceOrientation 452 public override OMV.Quaternion ForceOrientation
418 { 453 {
419 get 454 get
420 { 455 {
421 _orientation = BulletSimAPI.GetOrientation2(BSBody.ptr); 456 _orientation = BulletSimAPI.GetOrientation2(PhysBody.ptr);
422 return _orientation; 457 return _orientation;
423 } 458 }
424 set 459 set
425 { 460 {
426 _orientation = value; 461 _orientation = value;
427 BulletSimAPI.SetTranslation2(BSBody.ptr, _position, _orientation); 462 BulletSimAPI.SetTranslation2(PhysBody.ptr, _position, _orientation);
428 } 463 }
429 } 464 }
430 public override int PhysicsActorType { 465 public override int PhysicsActorType {
@@ -478,14 +513,14 @@ public class BSCharacter : BSPhysObject
478 set { _collidingObj = value; } 513 set { _collidingObj = value; }
479 } 514 }
480 public override bool FloatOnWater { 515 public override bool FloatOnWater {
481 set { 516 set {
482 _floatOnWater = value; 517 _floatOnWater = value;
483 PhysicsScene.TaintedObject("BSCharacter.setFloatOnWater", delegate() 518 PhysicsScene.TaintedObject("BSCharacter.setFloatOnWater", delegate()
484 { 519 {
485 if (_floatOnWater) 520 if (_floatOnWater)
486 CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(BSBody.ptr, CollisionFlags.BS_FLOATS_ON_WATER); 521 CurrentCollisionFlags = BulletSimAPI.AddToCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_FLOATS_ON_WATER);
487 else 522 else
488 CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(BSBody.ptr, CollisionFlags.BS_FLOATS_ON_WATER); 523 CurrentCollisionFlags = BulletSimAPI.RemoveFromCollisionFlags2(PhysBody.ptr, CollisionFlags.BS_FLOATS_ON_WATER);
489 }); 524 });
490 } 525 }
491 } 526 }
@@ -518,7 +553,7 @@ public class BSCharacter : BSPhysObject
518 DetailLog("{0},BSCharacter.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy); 553 DetailLog("{0},BSCharacter.setForceBuoyancy,taint,buoy={1}", LocalID, _buoyancy);
519 // Buoyancy is faked by changing the gravity applied to the object 554 // Buoyancy is faked by changing the gravity applied to the object
520 float grav = PhysicsScene.Params.gravity * (1f - _buoyancy); 555 float grav = PhysicsScene.Params.gravity * (1f - _buoyancy);
521 BulletSimAPI.SetGravity2(BSBody.ptr, new OMV.Vector3(0f, 0f, grav)); 556 BulletSimAPI.SetGravity2(PhysBody.ptr, new OMV.Vector3(0f, 0f, grav));
522 } 557 }
523 } 558 }
524 559
@@ -564,7 +599,7 @@ public class BSCharacter : BSPhysObject
564 PhysicsScene.TaintedObject("BSCharacter.AddForce", delegate() 599 PhysicsScene.TaintedObject("BSCharacter.AddForce", delegate()
565 { 600 {
566 DetailLog("{0},BSCharacter.setAddForce,taint,addedForce={1}", LocalID, _force); 601 DetailLog("{0},BSCharacter.setAddForce,taint,addedForce={1}", LocalID, _force);
567 BulletSimAPI.SetObjectForce2(BSBody.ptr, _force); 602 BulletSimAPI.SetObjectForce2(PhysBody.ptr, _force);
568 }); 603 });
569 } 604 }
570 else 605 else
@@ -584,14 +619,19 @@ public class BSCharacter : BSPhysObject
584 // The 'size' given by the simulator is the mid-point of the avatar 619 // The 'size' given by the simulator is the mid-point of the avatar
585 // and X and Y are unspecified. 620 // and X and Y are unspecified.
586 621
587 OMV.Vector3 newScale = OMV.Vector3.Zero; 622 OMV.Vector3 newScale = size;
588 newScale.X = PhysicsScene.Params.avatarCapsuleRadius; 623 // newScale.X = PhysicsScene.Params.avatarCapsuleWidth;
589 newScale.Y = PhysicsScene.Params.avatarCapsuleRadius; 624 // newScale.Y = PhysicsScene.Params.avatarCapsuleDepth;
625
626 // From the total height, remove the capsule half spheres that are at each end
627 // The 1.15f came from ODE. Not sure what this factors in.
628 // newScale.Z = (size.Z * 1.15f) - (newScale.X + newScale.Y);
629
630 // The total scale height is the central cylindar plus the caps on the two ends.
631 newScale.Z = size.Z + (Math.Min(size.X, size.Y) * 2f);
590 632
591 // From the total height, remote the capsule half spheres that are at each end 633 // Convert diameters to radii and height to half height -- the way Bullet expects it.
592 newScale.Z = (size.Z * 2f) - Math.Min(newScale.X, newScale.Y); 634 Scale = newScale / 2f;
593 // newScale.Z = (size.Z * 2f);
594 Scale = newScale;
595 } 635 }
596 636
597 // set _avatarVolume and _mass based on capsule size, _density and Scale 637 // set _avatarVolume and _mass based on capsule size, _density and Scale
@@ -633,10 +673,10 @@ public class BSCharacter : BSPhysObject
633 // That's just the way they are defined. 673 // That's just the way they are defined.
634 OMV.Vector3 avVel = new OMV.Vector3(_appliedVelocity.X, _appliedVelocity.Y, entprop.Velocity.Z); 674 OMV.Vector3 avVel = new OMV.Vector3(_appliedVelocity.X, _appliedVelocity.Y, entprop.Velocity.Z);
635 _velocity = avVel; 675 _velocity = avVel;
636 BulletSimAPI.SetLinearVelocity2(BSBody.ptr, avVel); 676 BulletSimAPI.SetLinearVelocity2(PhysBody.ptr, avVel);
637 } 677 }
638 678
639 // Tell the linkset about this 679 // Tell the linkset about value changes
640 Linkset.UpdateProperties(this); 680 Linkset.UpdateProperties(this);
641 681
642 // Avatars don't report their changes the usual way. Changes are checked for in the heartbeat loop. 682 // Avatars don't report their changes the usual way. Changes are checked for in the heartbeat loop.