diff options
author | Robert Adams | 2012-08-29 09:20:09 -0700 |
---|---|---|
committer | Robert Adams | 2012-08-31 11:41:28 -0700 |
commit | ae852bb8738c7bce60c8fee9fbf6038288bd9363 (patch) | |
tree | c729bdaa28bc827f0729f7c5a4882b351bf64996 /OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs | |
parent | BulletSim: fix line endings. (diff) | |
download | opensim-SC-ae852bb8738c7bce60c8fee9fbf6038288bd9363.zip opensim-SC-ae852bb8738c7bce60c8fee9fbf6038288bd9363.tar.gz opensim-SC-ae852bb8738c7bce60c8fee9fbf6038288bd9363.tar.bz2 opensim-SC-ae852bb8738c7bce60c8fee9fbf6038288bd9363.tar.xz |
BulletSim: clean up some variable naming for consistancy.
Update DLL API for new terrain and shape/body pattern methods.
Terrain creation and modification uses new shape/body pattern.
Move debug logging callback set to initialization call so logging
is per physics engine.
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs | 78 |
1 files changed, 37 insertions, 41 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index e76d8a4..fa21233 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs | |||
@@ -39,8 +39,7 @@ 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 BSScene _scene; | 42 | public BSScene Scene { get; private set; } |
43 | public BSScene Scene { get { return _scene; } } | ||
44 | private String _avName; | 43 | private String _avName; |
45 | // private bool _stopped; | 44 | // private bool _stopped; |
46 | private Vector3 _size; | 45 | private Vector3 _size; |
@@ -92,7 +91,7 @@ public class BSCharacter : BSPhysObject | |||
92 | { | 91 | { |
93 | _localID = localID; | 92 | _localID = localID; |
94 | _avName = avName; | 93 | _avName = avName; |
95 | _scene = parent_scene; | 94 | Scene = parent_scene; |
96 | _position = pos; | 95 | _position = pos; |
97 | _size = size; | 96 | _size = size; |
98 | _flying = isFlying; | 97 | _flying = isFlying; |
@@ -101,11 +100,11 @@ public class BSCharacter : BSPhysObject | |||
101 | _buoyancy = ComputeBuoyancyFromFlying(isFlying); | 100 | _buoyancy = ComputeBuoyancyFromFlying(isFlying); |
102 | // The dimensions of the avatar capsule are kept in the scale. | 101 | // The dimensions of the avatar capsule are kept in the scale. |
103 | // Physics creates a unit capsule which is scaled by the physics engine. | 102 | // Physics creates a unit capsule which is scaled by the physics engine. |
104 | _scale = new Vector3(_scene.Params.avatarCapsuleRadius, _scene.Params.avatarCapsuleRadius, size.Z); | 103 | _scale = new Vector3(Scene.Params.avatarCapsuleRadius, Scene.Params.avatarCapsuleRadius, size.Z); |
105 | _density = _scene.Params.avatarDensity; | 104 | _density = Scene.Params.avatarDensity; |
106 | ComputeAvatarVolumeAndMass(); // set _avatarVolume and _mass based on capsule size, _density and _scale | 105 | ComputeAvatarVolumeAndMass(); // set _avatarVolume and _mass based on capsule size, _density and _scale |
107 | 106 | ||
108 | Linkset = new BSLinkset(_scene, this); | 107 | Linkset = new BSLinkset(Scene, this); |
109 | 108 | ||
110 | ShapeData shapeData = new ShapeData(); | 109 | ShapeData shapeData = new ShapeData(); |
111 | shapeData.ID = _localID; | 110 | shapeData.ID = _localID; |
@@ -117,19 +116,19 @@ public class BSCharacter : BSPhysObject | |||
117 | shapeData.Mass = _mass; | 116 | shapeData.Mass = _mass; |
118 | shapeData.Buoyancy = _buoyancy; | 117 | shapeData.Buoyancy = _buoyancy; |
119 | shapeData.Static = ShapeData.numericFalse; | 118 | shapeData.Static = ShapeData.numericFalse; |
120 | shapeData.Friction = _scene.Params.avatarFriction; | 119 | shapeData.Friction = Scene.Params.avatarFriction; |
121 | shapeData.Restitution = _scene.Params.avatarRestitution; | 120 | shapeData.Restitution = Scene.Params.avatarRestitution; |
122 | 121 | ||
123 | // do actual create at taint time | 122 | // do actual create at taint time |
124 | _scene.TaintedObject("BSCharacter.create", delegate() | 123 | Scene.TaintedObject("BSCharacter.create", delegate() |
125 | { | 124 | { |
126 | DetailLog("{0},BSCharacter.create", _localID); | 125 | DetailLog("{0},BSCharacter.create", _localID); |
127 | BulletSimAPI.CreateObject(parent_scene.WorldID, shapeData); | 126 | BulletSimAPI.CreateObject(Scene.WorldID, shapeData); |
128 | 127 | ||
129 | // Set the buoyancy for flying. This will be refactored when all the settings happen in C# | 128 | // Set the buoyancy for flying. This will be refactored when all the settings happen in C# |
130 | BulletSimAPI.SetObjectBuoyancy(_scene.WorldID, LocalID, _buoyancy); | 129 | BulletSimAPI.SetObjectBuoyancy(Scene.WorldID, LocalID, _buoyancy); |
131 | 130 | ||
132 | Body = new BulletBody(LocalID, BulletSimAPI.GetBodyHandle2(_scene.World.Ptr, LocalID)); | 131 | Body = new BulletBody(LocalID, BulletSimAPI.GetBodyHandle2(Scene.World.Ptr, LocalID)); |
133 | // avatars get all collisions no matter what (makes walking on ground and such work) | 132 | // avatars get all collisions no matter what (makes walking on ground and such work) |
134 | BulletSimAPI.AddToCollisionFlags2(Body.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); | 133 | BulletSimAPI.AddToCollisionFlags2(Body.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); |
135 | }); | 134 | }); |
@@ -141,9 +140,9 @@ public class BSCharacter : BSPhysObject | |||
141 | public override void Destroy() | 140 | public override void Destroy() |
142 | { | 141 | { |
143 | DetailLog("{0},BSCharacter.Destroy", LocalID); | 142 | DetailLog("{0},BSCharacter.Destroy", LocalID); |
144 | _scene.TaintedObject("BSCharacter.destroy", delegate() | 143 | Scene.TaintedObject("BSCharacter.destroy", delegate() |
145 | { | 144 | { |
146 | BulletSimAPI.DestroyObject(_scene.WorldID, _localID); | 145 | BulletSimAPI.DestroyObject(Scene.WorldID, _localID); |
147 | }); | 146 | }); |
148 | } | 147 | } |
149 | 148 | ||
@@ -172,9 +171,9 @@ public class BSCharacter : BSPhysObject | |||
172 | 171 | ||
173 | ComputeAvatarVolumeAndMass(); | 172 | ComputeAvatarVolumeAndMass(); |
174 | 173 | ||
175 | _scene.TaintedObject("BSCharacter.setSize", delegate() | 174 | Scene.TaintedObject("BSCharacter.setSize", delegate() |
176 | { | 175 | { |
177 | BulletSimAPI.SetObjectScaleMass(_scene.WorldID, LocalID, _scale, _mass, true); | 176 | BulletSimAPI.SetObjectScaleMass(Scene.WorldID, LocalID, _scale, _mass, true); |
178 | }); | 177 | }); |
179 | 178 | ||
180 | } | 179 | } |
@@ -203,17 +202,17 @@ public class BSCharacter : BSPhysObject | |||
203 | 202 | ||
204 | public override Vector3 Position { | 203 | public override Vector3 Position { |
205 | get { | 204 | get { |
206 | // _position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID); | 205 | // _position = BulletSimAPI.GetObjectPosition(Scene.WorldID, _localID); |
207 | return _position; | 206 | return _position; |
208 | } | 207 | } |
209 | set { | 208 | set { |
210 | _position = value; | 209 | _position = value; |
211 | PositionSanityCheck(); | 210 | PositionSanityCheck(); |
212 | 211 | ||
213 | _scene.TaintedObject("BSCharacter.setPosition", delegate() | 212 | Scene.TaintedObject("BSCharacter.setPosition", delegate() |
214 | { | 213 | { |
215 | DetailLog("{0},BSCharacter.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); | 214 | DetailLog("{0},BSCharacter.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); |
216 | BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation); | 215 | BulletSimAPI.SetObjectTranslation(Scene.WorldID, _localID, _position, _orientation); |
217 | }); | 216 | }); |
218 | } | 217 | } |
219 | } | 218 | } |
@@ -229,10 +228,8 @@ public class BSCharacter : BSPhysObject | |||
229 | float terrainHeight = Scene.TerrainManager.GetTerrainHeightAtXYZ(_position); | 228 | float terrainHeight = Scene.TerrainManager.GetTerrainHeightAtXYZ(_position); |
230 | if (Position.Z < terrainHeight) | 229 | if (Position.Z < terrainHeight) |
231 | { | 230 | { |
232 | DetailLog("{0},BSCharacter.PositionAdjustUnderGround,call,pos={1},terrain={2}", LocalID, _position, terrainHeight); | 231 | DetailLog("{0},BSCharacter.PositionAdjustUnderGround,call,pos={1},terrain={2}", LocalID, _position, terrainHeight); |
233 | Vector3 newPos = _position; | 232 | _position.Z = terrainHeight + 2.0f; |
234 | newPos.Z = terrainHeight + 2.0f; | ||
235 | _position = newPos; | ||
236 | ret = true; | 233 | ret = true; |
237 | } | 234 | } |
238 | 235 | ||
@@ -250,10 +247,10 @@ public class BSCharacter : BSPhysObject | |||
250 | { | 247 | { |
251 | // The new position value must be pushed into the physics engine but we can't | 248 | // The new position value must be pushed into the physics engine but we can't |
252 | // just assign to "Position" because of potential call loops. | 249 | // just assign to "Position" because of potential call loops. |
253 | _scene.TaintedObject("BSCharacter.PositionSanityCheck", delegate() | 250 | Scene.TaintedObject("BSCharacter.PositionSanityCheck", delegate() |
254 | { | 251 | { |
255 | DetailLog("{0},BSCharacter.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, _position, _orientation); | 252 | DetailLog("{0},BSCharacter.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, _position, _orientation); |
256 | BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation); | 253 | BulletSimAPI.SetObjectTranslation(Scene.WorldID, _localID, _position, _orientation); |
257 | }); | 254 | }); |
258 | ret = true; | 255 | ret = true; |
259 | } | 256 | } |
@@ -301,10 +298,10 @@ public class BSCharacter : BSPhysObject | |||
301 | set { | 298 | set { |
302 | _velocity = value; | 299 | _velocity = value; |
303 | // m_log.DebugFormat("{0}: set velocity = {1}", LogHeader, _velocity); | 300 | // m_log.DebugFormat("{0}: set velocity = {1}", LogHeader, _velocity); |
304 | _scene.TaintedObject("BSCharacter.setVelocity", delegate() | 301 | Scene.TaintedObject("BSCharacter.setVelocity", delegate() |
305 | { | 302 | { |
306 | DetailLog("{0},BSCharacter.setVelocity,taint,vel={1}", LocalID, _velocity); | 303 | DetailLog("{0},BSCharacter.setVelocity,taint,vel={1}", LocalID, _velocity); |
307 | BulletSimAPI.SetObjectVelocity(_scene.WorldID, _localID, _velocity); | 304 | BulletSimAPI.SetObjectVelocity(Scene.WorldID, _localID, _velocity); |
308 | }); | 305 | }); |
309 | } | 306 | } |
310 | } | 307 | } |
@@ -327,10 +324,10 @@ public class BSCharacter : BSPhysObject | |||
327 | set { | 324 | set { |
328 | _orientation = value; | 325 | _orientation = value; |
329 | // m_log.DebugFormat("{0}: set orientation to {1}", LogHeader, _orientation); | 326 | // m_log.DebugFormat("{0}: set orientation to {1}", LogHeader, _orientation); |
330 | _scene.TaintedObject("BSCharacter.setOrientation", delegate() | 327 | Scene.TaintedObject("BSCharacter.setOrientation", delegate() |
331 | { | 328 | { |
332 | // _position = BulletSimAPI.GetObjectPosition(_scene.WorldID, _localID); | 329 | // _position = BulletSimAPI.GetObjectPosition(Scene.WorldID, _localID); |
333 | BulletSimAPI.SetObjectTranslation(_scene.WorldID, _localID, _position, _orientation); | 330 | BulletSimAPI.SetObjectTranslation(Scene.WorldID, _localID, _position, _orientation); |
334 | }); | 331 | }); |
335 | } | 332 | } |
336 | } | 333 | } |
@@ -367,11 +364,11 @@ public class BSCharacter : BSPhysObject | |||
367 | set { _throttleUpdates = value; } | 364 | set { _throttleUpdates = value; } |
368 | } | 365 | } |
369 | public override bool IsColliding { | 366 | public override bool IsColliding { |
370 | get { return (_collidingStep == _scene.SimulationStep); } | 367 | get { return (_collidingStep == Scene.SimulationStep); } |
371 | set { _isColliding = value; } | 368 | set { _isColliding = value; } |
372 | } | 369 | } |
373 | public override bool CollidingGround { | 370 | public override bool CollidingGround { |
374 | get { return (_collidingGroundStep == _scene.SimulationStep); } | 371 | get { return (_collidingGroundStep == Scene.SimulationStep); } |
375 | set { _collidingGround = value; } | 372 | set { _collidingGround = value; } |
376 | } | 373 | } |
377 | public override bool CollidingObj { | 374 | public override bool CollidingObj { |
@@ -393,10 +390,10 @@ public class BSCharacter : BSPhysObject | |||
393 | public override float Buoyancy { | 390 | public override float Buoyancy { |
394 | get { return _buoyancy; } | 391 | get { return _buoyancy; } |
395 | set { _buoyancy = value; | 392 | set { _buoyancy = value; |
396 | _scene.TaintedObject("BSCharacter.setBuoyancy", delegate() | 393 | Scene.TaintedObject("BSCharacter.setBuoyancy", delegate() |
397 | { | 394 | { |
398 | DetailLog("{0},BSCharacter.setBuoyancy,taint,buoy={1}", LocalID, _buoyancy); | 395 | DetailLog("{0},BSCharacter.setBuoyancy,taint,buoy={1}", LocalID, _buoyancy); |
399 | BulletSimAPI.SetObjectBuoyancy(_scene.WorldID, LocalID, _buoyancy); | 396 | BulletSimAPI.SetObjectBuoyancy(Scene.WorldID, LocalID, _buoyancy); |
400 | }); | 397 | }); |
401 | } | 398 | } |
402 | } | 399 | } |
@@ -440,7 +437,7 @@ public class BSCharacter : BSPhysObject | |||
440 | _force.Y += force.Y; | 437 | _force.Y += force.Y; |
441 | _force.Z += force.Z; | 438 | _force.Z += force.Z; |
442 | // m_log.DebugFormat("{0}: AddForce. adding={1}, newForce={2}", LogHeader, force, _force); | 439 | // m_log.DebugFormat("{0}: AddForce. adding={1}, newForce={2}", LogHeader, force, _force); |
443 | _scene.TaintedObject("BSCharacter.AddForce", delegate() | 440 | Scene.TaintedObject("BSCharacter.AddForce", delegate() |
444 | { | 441 | { |
445 | DetailLog("{0},BSCharacter.setAddForce,taint,addedForce={1}", LocalID, _force); | 442 | DetailLog("{0},BSCharacter.setAddForce,taint,addedForce={1}", LocalID, _force); |
446 | BulletSimAPI.AddObjectForce2(Body.Ptr, _force); | 443 | BulletSimAPI.AddObjectForce2(Body.Ptr, _force); |
@@ -524,10 +521,9 @@ public class BSCharacter : BSPhysObject | |||
524 | // Do some sanity checking for the avatar. Make sure it's above ground and inbounds. | 521 | // Do some sanity checking for the avatar. Make sure it's above ground and inbounds. |
525 | PositionSanityCheck2(); | 522 | PositionSanityCheck2(); |
526 | 523 | ||
527 | float heightHere = Scene.TerrainManager.GetTerrainHeightAtXYZ(_position); // just for debug | 524 | float heightHere = Scene.TerrainManager.GetTerrainHeightAtXYZ(_position); // only for debug |
528 | DetailLog("{0},BSCharacter.UpdateProperties,call,pos={1},orient={2},vel={3},accel={4},rotVel={5},terrain={6}", | 525 | DetailLog("{0},BSCharacter.UpdateProperties,call,pos={1},orient={2},vel={3},accel={4},rotVel={5},terrain={6}", |
529 | LocalID, entprop.Position, entprop.Rotation, entprop.Velocity, | 526 | LocalID, _position, _orientation, _velocity, _acceleration, _rotationalVelocity, heightHere); |
530 | entprop.Acceleration, entprop.RotationalVelocity, heightHere); | ||
531 | } | 527 | } |
532 | 528 | ||
533 | // Called by the scene when a collision with this object is reported | 529 | // Called by the scene when a collision with this object is reported |
@@ -539,16 +535,16 @@ public class BSCharacter : BSPhysObject | |||
539 | // m_log.DebugFormat("{0}: Collide: ms={1}, id={2}, with={3}", LogHeader, _subscribedEventsMs, LocalID, collidingWith); | 535 | // m_log.DebugFormat("{0}: Collide: ms={1}, id={2}, with={3}", LogHeader, _subscribedEventsMs, LocalID, collidingWith); |
540 | 536 | ||
541 | // The following makes IsColliding() and IsCollidingGround() work | 537 | // The following makes IsColliding() and IsCollidingGround() work |
542 | _collidingStep = _scene.SimulationStep; | 538 | _collidingStep = Scene.SimulationStep; |
543 | if (collidingWith == BSScene.TERRAIN_ID || collidingWith == BSScene.GROUNDPLANE_ID) | 539 | if (collidingWith == BSScene.TERRAIN_ID || collidingWith == BSScene.GROUNDPLANE_ID) |
544 | { | 540 | { |
545 | _collidingGroundStep = _scene.SimulationStep; | 541 | _collidingGroundStep = Scene.SimulationStep; |
546 | } | 542 | } |
547 | // DetailLog("{0},BSCharacter.Collison,call,with={1}", LocalID, collidingWith); | 543 | // DetailLog("{0},BSCharacter.Collison,call,with={1}", LocalID, collidingWith); |
548 | 544 | ||
549 | // throttle collisions to the rate specified in the subscription | 545 | // throttle collisions to the rate specified in the subscription |
550 | if (_subscribedEventsMs != 0) { | 546 | if (_subscribedEventsMs != 0) { |
551 | int nowTime = _scene.SimulationNowTime; | 547 | int nowTime = Scene.SimulationNowTime; |
552 | if (nowTime >= _nextCollisionOkTime) { | 548 | if (nowTime >= _nextCollisionOkTime) { |
553 | _nextCollisionOkTime = nowTime + _subscribedEventsMs; | 549 | _nextCollisionOkTime = nowTime + _subscribedEventsMs; |
554 | 550 | ||