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.cs66
1 files changed, 28 insertions, 38 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
index 57d5726..19eb1e6 100644
--- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
+++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs
@@ -39,18 +39,16 @@ public class BSCharacter : BSPhysObject
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]";
41 41
42 private String _avName;
43 // private bool _stopped; 42 // private bool _stopped;
44 private OMV.Vector3 _size; 43 private OMV.Vector3 _size;
45 private OMV.Vector3 _scale; 44 private OMV.Vector3 _scale;
46 private PrimitiveBaseShape _pbs; 45 private PrimitiveBaseShape _pbs;
47 private uint _localID = 0;
48 private bool _grabbed; 46 private bool _grabbed;
49 private bool _selected; 47 private bool _selected;
50 private OMV.Vector3 _position; 48 private OMV.Vector3 _position;
51 private float _mass; 49 private float _mass;
52 public float _density; 50 private float _avatarDensity;
53 public float _avatarVolume; 51 private float _avatarVolume;
54 private OMV.Vector3 _force; 52 private OMV.Vector3 _force;
55 private OMV.Vector3 _velocity; 53 private OMV.Vector3 _velocity;
56 private OMV.Vector3 _torque; 54 private OMV.Vector3 _torque;
@@ -63,18 +61,12 @@ public class BSCharacter : BSPhysObject
63 private bool _setAlwaysRun; 61 private bool _setAlwaysRun;
64 private bool _throttleUpdates; 62 private bool _throttleUpdates;
65 private bool _isColliding; 63 private bool _isColliding;
66 private long _collidingStep;
67 private bool _collidingGround;
68 private long _collidingGroundStep;
69 private bool _collidingObj; 64 private bool _collidingObj;
70 private bool _floatOnWater; 65 private bool _floatOnWater;
71 private OMV.Vector3 _rotationalVelocity; 66 private OMV.Vector3 _rotationalVelocity;
72 private bool _kinematic; 67 private bool _kinematic;
73 private float _buoyancy; 68 private float _buoyancy;
74 69
75 private int _subscribedEventsMs = 0;
76 private int _nextCollisionOkTime = 0;
77
78 private OMV.Vector3 _PIDTarget; 70 private OMV.Vector3 _PIDTarget;
79 private bool _usePID; 71 private bool _usePID;
80 private float _PIDTau; 72 private float _PIDTau;
@@ -85,9 +77,7 @@ public class BSCharacter : BSPhysObject
85 77
86 public BSCharacter(uint localID, String avName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size, bool isFlying) 78 public BSCharacter(uint localID, String avName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size, bool isFlying)
87 { 79 {
88 base.BaseInitialize(parent_scene); 80 base.BaseInitialize(parent_scene, localID, avName);
89 _localID = localID;
90 _avName = avName;
91 _physicsActorType = (int)ActorTypes.Agent; 81 _physicsActorType = (int)ActorTypes.Agent;
92 _position = pos; 82 _position = pos;
93 _size = size; 83 _size = size;
@@ -95,14 +85,15 @@ public class BSCharacter : BSPhysObject
95 _orientation = OMV.Quaternion.Identity; 85 _orientation = OMV.Quaternion.Identity;
96 _velocity = OMV.Vector3.Zero; 86 _velocity = OMV.Vector3.Zero;
97 _buoyancy = ComputeBuoyancyFromFlying(isFlying); 87 _buoyancy = ComputeBuoyancyFromFlying(isFlying);
88
98 // The dimensions of the avatar capsule are kept in the scale. 89 // The dimensions of the avatar capsule are kept in the scale.
99 // Physics creates a unit capsule which is scaled by the physics engine. 90 // Physics creates a unit capsule which is scaled by the physics engine.
100 _scale = new OMV.Vector3(PhysicsScene.Params.avatarCapsuleRadius, PhysicsScene.Params.avatarCapsuleRadius, size.Z); 91 ComputeAvatarScale(_size);
101 _density = PhysicsScene.Params.avatarDensity; 92 _avatarDensity = PhysicsScene.Params.avatarDensity;
102 ComputeAvatarVolumeAndMass(); // set _avatarVolume and _mass based on capsule size, _density and _scale 93 ComputeAvatarVolumeAndMass(); // set _avatarVolume and _mass based on capsule size, _density and _scale
103 94
104 ShapeData shapeData = new ShapeData(); 95 ShapeData shapeData = new ShapeData();
105 shapeData.ID = _localID; 96 shapeData.ID = LocalID;
106 shapeData.Type = ShapeData.PhysicsShapeType.SHAPE_AVATAR; 97 shapeData.Type = ShapeData.PhysicsShapeType.SHAPE_AVATAR;
107 shapeData.Position = _position; 98 shapeData.Position = _position;
108 shapeData.Rotation = _orientation; 99 shapeData.Rotation = _orientation;
@@ -117,7 +108,7 @@ public class BSCharacter : BSPhysObject
117 // do actual create at taint time 108 // do actual create at taint time
118 PhysicsScene.TaintedObject("BSCharacter.create", delegate() 109 PhysicsScene.TaintedObject("BSCharacter.create", delegate()
119 { 110 {
120 DetailLog("{0},BSCharacter.create", _localID); 111 DetailLog("{0},BSCharacter.create,taint", LocalID);
121 BulletSimAPI.CreateObject(PhysicsScene.WorldID, shapeData); 112 BulletSimAPI.CreateObject(PhysicsScene.WorldID, shapeData);
122 113
123 // Set the buoyancy for flying. This will be refactored when all the settings happen in C# 114 // Set the buoyancy for flying. This will be refactored when all the settings happen in C#
@@ -135,7 +126,7 @@ public class BSCharacter : BSPhysObject
135 DetailLog("{0},BSCharacter.Destroy", LocalID); 126 DetailLog("{0},BSCharacter.Destroy", LocalID);
136 PhysicsScene.TaintedObject("BSCharacter.destroy", delegate() 127 PhysicsScene.TaintedObject("BSCharacter.destroy", delegate()
137 { 128 {
138 BulletSimAPI.DestroyObject(PhysicsScene.WorldID, _localID); 129 BulletSimAPI.DestroyObject(PhysicsScene.WorldID, LocalID);
139 }); 130 });
140 } 131 }
141 132
@@ -158,7 +149,7 @@ public class BSCharacter : BSPhysObject
158 // When an avatar's size is set, only the height is changed 149 // When an avatar's size is set, only the height is changed
159 // and that really only depends on the radius. 150 // and that really only depends on the radius.
160 _size = value; 151 _size = value;
161 _scale.Z = (_size.Z * 1.15f) - (_scale.X + _scale.Y); 152 ComputeAvatarScale(_size);
162 153
163 // TODO: something has to be done with the avatar's vertical position 154 // TODO: something has to be done with the avatar's vertical position
164 155
@@ -175,11 +166,6 @@ public class BSCharacter : BSPhysObject
175 set { _pbs = value; 166 set { _pbs = value;
176 } 167 }
177 } 168 }
178 public override uint LocalID {
179 set { _localID = value;
180 }
181 get { return _localID; }
182 }
183 public override bool Grabbed { 169 public override bool Grabbed {
184 set { _grabbed = value; 170 set { _grabbed = value;
185 } 171 }
@@ -223,7 +209,7 @@ public class BSCharacter : BSPhysObject
223 PhysicsScene.TaintedObject("BSCharacter.setPosition", delegate() 209 PhysicsScene.TaintedObject("BSCharacter.setPosition", delegate()
224 { 210 {
225 DetailLog("{0},BSCharacter.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); 211 DetailLog("{0},BSCharacter.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation);
226 BulletSimAPI.SetObjectTranslation(PhysicsScene.WorldID, _localID, _position, _orientation); 212 BulletSimAPI.SetObjectTranslation(PhysicsScene.WorldID, LocalID, _position, _orientation);
227 }); 213 });
228 } 214 }
229 } 215 }
@@ -261,7 +247,7 @@ public class BSCharacter : BSPhysObject
261 PhysicsScene.TaintedObject("BSCharacter.PositionSanityCheck", delegate() 247 PhysicsScene.TaintedObject("BSCharacter.PositionSanityCheck", delegate()
262 { 248 {
263 DetailLog("{0},BSCharacter.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, _position, _orientation); 249 DetailLog("{0},BSCharacter.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, _position, _orientation);
264 BulletSimAPI.SetObjectTranslation(PhysicsScene.WorldID, _localID, _position, _orientation); 250 BulletSimAPI.SetObjectTranslation(PhysicsScene.WorldID, LocalID, _position, _orientation);
265 }); 251 });
266 ret = true; 252 ret = true;
267 } 253 }
@@ -312,7 +298,7 @@ public class BSCharacter : BSPhysObject
312 PhysicsScene.TaintedObject("BSCharacter.setVelocity", delegate() 298 PhysicsScene.TaintedObject("BSCharacter.setVelocity", delegate()
313 { 299 {
314 DetailLog("{0},BSCharacter.setVelocity,taint,vel={1}", LocalID, _velocity); 300 DetailLog("{0},BSCharacter.setVelocity,taint,vel={1}", LocalID, _velocity);
315 BulletSimAPI.SetObjectVelocity(PhysicsScene.WorldID, _localID, _velocity); 301 BulletSimAPI.SetObjectVelocity(PhysicsScene.WorldID, LocalID, _velocity);
316 }); 302 });
317 } 303 }
318 } 304 }
@@ -338,7 +324,7 @@ public class BSCharacter : BSPhysObject
338 PhysicsScene.TaintedObject("BSCharacter.setOrientation", delegate() 324 PhysicsScene.TaintedObject("BSCharacter.setOrientation", delegate()
339 { 325 {
340 // _position = BulletSimAPI.GetObjectPosition(Scene.WorldID, _localID); 326 // _position = BulletSimAPI.GetObjectPosition(Scene.WorldID, _localID);
341 BulletSimAPI.SetObjectTranslation(PhysicsScene.WorldID, _localID, _position, _orientation); 327 BulletSimAPI.SetObjectTranslation(PhysicsScene.WorldID, LocalID, _position, _orientation);
342 }); 328 });
343 } 329 }
344 } 330 }
@@ -375,12 +361,12 @@ public class BSCharacter : BSPhysObject
375 set { _throttleUpdates = value; } 361 set { _throttleUpdates = value; }
376 } 362 }
377 public override bool IsColliding { 363 public override bool IsColliding {
378 get { return (_collidingStep == PhysicsScene.SimulationStep); } 364 get { return (CollidingStep == PhysicsScene.SimulationStep); }
379 set { _isColliding = value; } 365 set { _isColliding = value; }
380 } 366 }
381 public override bool CollidingGround { 367 public override bool CollidingGround {
382 get { return (_collidingGroundStep == PhysicsScene.SimulationStep); } 368 get { return (CollidingGroundStep == PhysicsScene.SimulationStep); }
383 set { _collidingGround = value; } 369 set { CollidingGround = value; }
384 } 370 }
385 public override bool CollidingObj { 371 public override bool CollidingObj {
386 get { return _collidingObj; } 372 get { return _collidingObj; }
@@ -466,6 +452,16 @@ public class BSCharacter : BSPhysObject
466 public override void SetMomentum(OMV.Vector3 momentum) { 452 public override void SetMomentum(OMV.Vector3 momentum) {
467 } 453 }
468 454
455 private void ComputeAvatarScale(OMV.Vector3 size)
456 {
457 _scale.X = PhysicsScene.Params.avatarCapsuleRadius;
458 _scale.Y = PhysicsScene.Params.avatarCapsuleRadius;
459
460 // The 1.15 came from ODE but it seems to cause the avatar to float off the ground
461 // _scale.Z = (_size.Z * 1.15f) - (_scale.X + _scale.Y);
462 _scale.Z = (_size.Z) - (_scale.X + _scale.Y);
463 }
464
469 // set _avatarVolume and _mass based on capsule size, _density and _scale 465 // set _avatarVolume and _mass based on capsule size, _density and _scale
470 private void ComputeAvatarVolumeAndMass() 466 private void ComputeAvatarVolumeAndMass()
471 { 467 {
@@ -480,7 +476,7 @@ public class BSCharacter : BSPhysObject
480 * Math.Min(_scale.X, _scale.Y) 476 * Math.Min(_scale.X, _scale.Y)
481 * _scale.Y // plus the volume of the capsule end caps 477 * _scale.Y // plus the volume of the capsule end caps
482 ); 478 );
483 _mass = _density * _avatarVolume; 479 _mass = _avatarDensity * _avatarVolume;
484 } 480 }
485 481
486 // The physics engine says that properties have updated. Update same and inform 482 // The physics engine says that properties have updated. Update same and inform
@@ -502,11 +498,5 @@ public class BSCharacter : BSPhysObject
502 DetailLog("{0},BSCharacter.UpdateProperties,call,pos={1},orient={2},vel={3},accel={4},rotVel={5},terrain={6}", 498 DetailLog("{0},BSCharacter.UpdateProperties,call,pos={1},orient={2},vel={3},accel={4},rotVel={5},terrain={6}",
503 LocalID, _position, _orientation, _velocity, _acceleration, _rotationalVelocity, heightHere); 499 LocalID, _position, _orientation, _velocity, _acceleration, _rotationalVelocity, heightHere);
504 } 500 }
505
506 // Invoke the detailed logger and output something if it's enabled.
507 private void DetailLog(string msg, params Object[] args)
508 {
509 PhysicsScene.PhysicsLogging.Write(msg, args);
510 }
511} 501}
512} 502}