diff options
author | Robert Adams | 2012-09-18 08:39:52 -0700 |
---|---|---|
committer | Robert Adams | 2012-09-27 22:01:11 -0700 |
commit | ee7cda261cbbc9dcd558c35eabc070cc0bf45644 (patch) | |
tree | f30f9c9baf15ef6988983e53bf3141749eab75f9 /OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs | |
parent | Comment out unused RestPlugins text in OpenSimDefaults.ini (diff) | |
download | opensim-SC-ee7cda261cbbc9dcd558c35eabc070cc0bf45644.zip opensim-SC-ee7cda261cbbc9dcd558c35eabc070cc0bf45644.tar.gz opensim-SC-ee7cda261cbbc9dcd558c35eabc070cc0bf45644.tar.bz2 opensim-SC-ee7cda261cbbc9dcd558c35eabc070cc0bf45644.tar.xz |
BulletSim: move a bunch of common logic out of BSPrim and BSCharacter
and into the parent class BSPhysObject.
Rework collision logic to enable extra collision after done colliding.
Rename 'Scene' to 'PhysicsScene' to differentiate it from the simulator 'Scene'.
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs | 238 |
1 files changed, 82 insertions, 156 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs index 526dbad..57d5726 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSCharacter.cs | |||
@@ -28,7 +28,7 @@ using System; | |||
28 | using System.Collections.Generic; | 28 | using System.Collections.Generic; |
29 | using System.Reflection; | 29 | using System.Reflection; |
30 | using log4net; | 30 | using log4net; |
31 | using OpenMetaverse; | 31 | using OMV = OpenMetaverse; |
32 | using OpenSim.Framework; | 32 | using OpenSim.Framework; |
33 | using OpenSim.Region.Physics.Manager; | 33 | using OpenSim.Region.Physics.Manager; |
34 | 34 | ||
@@ -39,25 +39,24 @@ 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 | public BSScene Scene { get; private set; } | ||
43 | private String _avName; | 42 | private String _avName; |
44 | // private bool _stopped; | 43 | // private bool _stopped; |
45 | private Vector3 _size; | 44 | private OMV.Vector3 _size; |
46 | private Vector3 _scale; | 45 | private OMV.Vector3 _scale; |
47 | private PrimitiveBaseShape _pbs; | 46 | private PrimitiveBaseShape _pbs; |
48 | private uint _localID = 0; | 47 | private uint _localID = 0; |
49 | private bool _grabbed; | 48 | private bool _grabbed; |
50 | private bool _selected; | 49 | private bool _selected; |
51 | private Vector3 _position; | 50 | private OMV.Vector3 _position; |
52 | private float _mass; | 51 | private float _mass; |
53 | public float _density; | 52 | public float _density; |
54 | public float _avatarVolume; | 53 | public float _avatarVolume; |
55 | private Vector3 _force; | 54 | private OMV.Vector3 _force; |
56 | private Vector3 _velocity; | 55 | private OMV.Vector3 _velocity; |
57 | private Vector3 _torque; | 56 | private OMV.Vector3 _torque; |
58 | private float _collisionScore; | 57 | private float _collisionScore; |
59 | private Vector3 _acceleration; | 58 | private OMV.Vector3 _acceleration; |
60 | private Quaternion _orientation; | 59 | private OMV.Quaternion _orientation; |
61 | private int _physicsActorType; | 60 | private int _physicsActorType; |
62 | private bool _isPhysical; | 61 | private bool _isPhysical; |
63 | private bool _flying; | 62 | private bool _flying; |
@@ -69,18 +68,14 @@ public class BSCharacter : BSPhysObject | |||
69 | private long _collidingGroundStep; | 68 | private long _collidingGroundStep; |
70 | private bool _collidingObj; | 69 | private bool _collidingObj; |
71 | private bool _floatOnWater; | 70 | private bool _floatOnWater; |
72 | private Vector3 _rotationalVelocity; | 71 | private OMV.Vector3 _rotationalVelocity; |
73 | private bool _kinematic; | 72 | private bool _kinematic; |
74 | private float _buoyancy; | 73 | private float _buoyancy; |
75 | 74 | ||
76 | public override BulletBody BSBody { get; set; } | ||
77 | public override BulletShape BSShape { get; set; } | ||
78 | public override BSLinkset Linkset { get; set; } | ||
79 | |||
80 | private int _subscribedEventsMs = 0; | 75 | private int _subscribedEventsMs = 0; |
81 | private int _nextCollisionOkTime = 0; | 76 | private int _nextCollisionOkTime = 0; |
82 | 77 | ||
83 | private Vector3 _PIDTarget; | 78 | private OMV.Vector3 _PIDTarget; |
84 | private bool _usePID; | 79 | private bool _usePID; |
85 | private float _PIDTau; | 80 | private float _PIDTau; |
86 | private bool _useHoverPID; | 81 | private bool _useHoverPID; |
@@ -88,26 +83,24 @@ public class BSCharacter : BSPhysObject | |||
88 | private PIDHoverType _PIDHoverType; | 83 | private PIDHoverType _PIDHoverType; |
89 | private float _PIDHoverTao; | 84 | private float _PIDHoverTao; |
90 | 85 | ||
91 | public BSCharacter(uint localID, String avName, BSScene parent_scene, Vector3 pos, Vector3 size, bool isFlying) | 86 | public BSCharacter(uint localID, String avName, BSScene parent_scene, OMV.Vector3 pos, OMV.Vector3 size, bool isFlying) |
92 | { | 87 | { |
88 | base.BaseInitialize(parent_scene); | ||
93 | _localID = localID; | 89 | _localID = localID; |
94 | _avName = avName; | 90 | _avName = avName; |
95 | Scene = parent_scene; | ||
96 | _physicsActorType = (int)ActorTypes.Agent; | 91 | _physicsActorType = (int)ActorTypes.Agent; |
97 | _position = pos; | 92 | _position = pos; |
98 | _size = size; | 93 | _size = size; |
99 | _flying = isFlying; | 94 | _flying = isFlying; |
100 | _orientation = Quaternion.Identity; | 95 | _orientation = OMV.Quaternion.Identity; |
101 | _velocity = Vector3.Zero; | 96 | _velocity = OMV.Vector3.Zero; |
102 | _buoyancy = ComputeBuoyancyFromFlying(isFlying); | 97 | _buoyancy = ComputeBuoyancyFromFlying(isFlying); |
103 | // The dimensions of the avatar capsule are kept in the scale. | 98 | // The dimensions of the avatar capsule are kept in the scale. |
104 | // Physics creates a unit capsule which is scaled by the physics engine. | 99 | // Physics creates a unit capsule which is scaled by the physics engine. |
105 | _scale = new Vector3(Scene.Params.avatarCapsuleRadius, Scene.Params.avatarCapsuleRadius, size.Z); | 100 | _scale = new OMV.Vector3(PhysicsScene.Params.avatarCapsuleRadius, PhysicsScene.Params.avatarCapsuleRadius, size.Z); |
106 | _density = Scene.Params.avatarDensity; | 101 | _density = PhysicsScene.Params.avatarDensity; |
107 | ComputeAvatarVolumeAndMass(); // set _avatarVolume and _mass based on capsule size, _density and _scale | 102 | ComputeAvatarVolumeAndMass(); // set _avatarVolume and _mass based on capsule size, _density and _scale |
108 | 103 | ||
109 | Linkset = new BSLinkset(Scene, this); | ||
110 | |||
111 | ShapeData shapeData = new ShapeData(); | 104 | ShapeData shapeData = new ShapeData(); |
112 | shapeData.ID = _localID; | 105 | shapeData.ID = _localID; |
113 | shapeData.Type = ShapeData.PhysicsShapeType.SHAPE_AVATAR; | 106 | shapeData.Type = ShapeData.PhysicsShapeType.SHAPE_AVATAR; |
@@ -118,19 +111,19 @@ public class BSCharacter : BSPhysObject | |||
118 | shapeData.Mass = _mass; | 111 | shapeData.Mass = _mass; |
119 | shapeData.Buoyancy = _buoyancy; | 112 | shapeData.Buoyancy = _buoyancy; |
120 | shapeData.Static = ShapeData.numericFalse; | 113 | shapeData.Static = ShapeData.numericFalse; |
121 | shapeData.Friction = Scene.Params.avatarFriction; | 114 | shapeData.Friction = PhysicsScene.Params.avatarFriction; |
122 | shapeData.Restitution = Scene.Params.avatarRestitution; | 115 | shapeData.Restitution = PhysicsScene.Params.avatarRestitution; |
123 | 116 | ||
124 | // do actual create at taint time | 117 | // do actual create at taint time |
125 | Scene.TaintedObject("BSCharacter.create", delegate() | 118 | PhysicsScene.TaintedObject("BSCharacter.create", delegate() |
126 | { | 119 | { |
127 | DetailLog("{0},BSCharacter.create", _localID); | 120 | DetailLog("{0},BSCharacter.create", _localID); |
128 | BulletSimAPI.CreateObject(Scene.WorldID, shapeData); | 121 | BulletSimAPI.CreateObject(PhysicsScene.WorldID, shapeData); |
129 | 122 | ||
130 | // Set the buoyancy for flying. This will be refactored when all the settings happen in C# | 123 | // Set the buoyancy for flying. This will be refactored when all the settings happen in C# |
131 | BulletSimAPI.SetObjectBuoyancy(Scene.WorldID, LocalID, _buoyancy); | 124 | BulletSimAPI.SetObjectBuoyancy(PhysicsScene.WorldID, LocalID, _buoyancy); |
132 | 125 | ||
133 | BSBody = new BulletBody(LocalID, BulletSimAPI.GetBodyHandle2(Scene.World.Ptr, LocalID)); | 126 | BSBody = new BulletBody(LocalID, BulletSimAPI.GetBodyHandle2(PhysicsScene.World.Ptr, LocalID)); |
134 | }); | 127 | }); |
135 | 128 | ||
136 | return; | 129 | return; |
@@ -140,9 +133,9 @@ public class BSCharacter : BSPhysObject | |||
140 | public override void Destroy() | 133 | public override void Destroy() |
141 | { | 134 | { |
142 | DetailLog("{0},BSCharacter.Destroy", LocalID); | 135 | DetailLog("{0},BSCharacter.Destroy", LocalID); |
143 | Scene.TaintedObject("BSCharacter.destroy", delegate() | 136 | PhysicsScene.TaintedObject("BSCharacter.destroy", delegate() |
144 | { | 137 | { |
145 | BulletSimAPI.DestroyObject(Scene.WorldID, _localID); | 138 | BulletSimAPI.DestroyObject(PhysicsScene.WorldID, _localID); |
146 | }); | 139 | }); |
147 | } | 140 | } |
148 | 141 | ||
@@ -154,11 +147,11 @@ public class BSCharacter : BSPhysObject | |||
154 | public override bool Stopped { | 147 | public override bool Stopped { |
155 | get { return false; } | 148 | get { return false; } |
156 | } | 149 | } |
157 | public override Vector3 Size { | 150 | public override OMV.Vector3 Size { |
158 | get | 151 | get |
159 | { | 152 | { |
160 | // Avatar capsule size is kept in the scale parameter. | 153 | // Avatar capsule size is kept in the scale parameter. |
161 | return new Vector3(_scale.X * 2, _scale.Y * 2, _scale.Z); | 154 | return new OMV.Vector3(_scale.X * 2, _scale.Y * 2, _scale.Z); |
162 | } | 155 | } |
163 | 156 | ||
164 | set { | 157 | set { |
@@ -171,9 +164,9 @@ public class BSCharacter : BSPhysObject | |||
171 | 164 | ||
172 | ComputeAvatarVolumeAndMass(); | 165 | ComputeAvatarVolumeAndMass(); |
173 | 166 | ||
174 | Scene.TaintedObject("BSCharacter.setSize", delegate() | 167 | PhysicsScene.TaintedObject("BSCharacter.setSize", delegate() |
175 | { | 168 | { |
176 | BulletSimAPI.SetObjectScaleMass(Scene.WorldID, LocalID, _scale, _mass, true); | 169 | BulletSimAPI.SetObjectScaleMass(PhysicsScene.WorldID, LocalID, _scale, _mass, true); |
177 | }); | 170 | }); |
178 | 171 | ||
179 | } | 172 | } |
@@ -198,9 +191,27 @@ public class BSCharacter : BSPhysObject | |||
198 | public override void CrossingFailure() { return; } | 191 | public override void CrossingFailure() { return; } |
199 | public override void link(PhysicsActor obj) { return; } | 192 | public override void link(PhysicsActor obj) { return; } |
200 | public override void delink() { return; } | 193 | public override void delink() { return; } |
201 | public override void LockAngularMotion(Vector3 axis) { return; } | ||
202 | 194 | ||
203 | public override Vector3 Position { | 195 | // Set motion values to zero. |
196 | // Do it to the properties so the values get set in the physics engine. | ||
197 | // Push the setting of the values to the viewer. | ||
198 | // Called at taint time! | ||
199 | public override void ZeroMotion() | ||
200 | { | ||
201 | _velocity = OMV.Vector3.Zero; | ||
202 | _acceleration = OMV.Vector3.Zero; | ||
203 | _rotationalVelocity = OMV.Vector3.Zero; | ||
204 | |||
205 | // Zero some other properties directly into the physics engine | ||
206 | BulletSimAPI.SetLinearVelocity2(BSBody.Ptr, OMV.Vector3.Zero); | ||
207 | BulletSimAPI.SetAngularVelocity2(BSBody.Ptr, OMV.Vector3.Zero); | ||
208 | BulletSimAPI.SetInterpolationVelocity2(BSBody.Ptr, OMV.Vector3.Zero, OMV.Vector3.Zero); | ||
209 | BulletSimAPI.ClearForces2(BSBody.Ptr); | ||
210 | } | ||
211 | |||
212 | public override void LockAngularMotion(OMV.Vector3 axis) { return; } | ||
213 | |||
214 | public override OMV.Vector3 Position { | ||
204 | get { | 215 | get { |
205 | // _position = BulletSimAPI.GetObjectPosition(Scene.WorldID, _localID); | 216 | // _position = BulletSimAPI.GetObjectPosition(Scene.WorldID, _localID); |
206 | return _position; | 217 | return _position; |
@@ -209,10 +220,10 @@ public class BSCharacter : BSPhysObject | |||
209 | _position = value; | 220 | _position = value; |
210 | PositionSanityCheck(); | 221 | PositionSanityCheck(); |
211 | 222 | ||
212 | Scene.TaintedObject("BSCharacter.setPosition", delegate() | 223 | PhysicsScene.TaintedObject("BSCharacter.setPosition", delegate() |
213 | { | 224 | { |
214 | DetailLog("{0},BSCharacter.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); | 225 | DetailLog("{0},BSCharacter.SetPosition,taint,pos={1},orient={2}", LocalID, _position, _orientation); |
215 | BulletSimAPI.SetObjectTranslation(Scene.WorldID, _localID, _position, _orientation); | 226 | BulletSimAPI.SetObjectTranslation(PhysicsScene.WorldID, _localID, _position, _orientation); |
216 | }); | 227 | }); |
217 | } | 228 | } |
218 | } | 229 | } |
@@ -225,7 +236,7 @@ public class BSCharacter : BSPhysObject | |||
225 | bool ret = false; | 236 | bool ret = false; |
226 | 237 | ||
227 | // If below the ground, move the avatar up | 238 | // If below the ground, move the avatar up |
228 | float terrainHeight = Scene.TerrainManager.GetTerrainHeightAtXYZ(_position); | 239 | float terrainHeight = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(_position); |
229 | if (Position.Z < terrainHeight) | 240 | if (Position.Z < terrainHeight) |
230 | { | 241 | { |
231 | DetailLog("{0},BSCharacter.PositionAdjustUnderGround,call,pos={1},terrain={2}", LocalID, _position, terrainHeight); | 242 | DetailLog("{0},BSCharacter.PositionAdjustUnderGround,call,pos={1},terrain={2}", LocalID, _position, terrainHeight); |
@@ -247,10 +258,10 @@ public class BSCharacter : BSPhysObject | |||
247 | { | 258 | { |
248 | // The new position value must be pushed into the physics engine but we can't | 259 | // The new position value must be pushed into the physics engine but we can't |
249 | // just assign to "Position" because of potential call loops. | 260 | // just assign to "Position" because of potential call loops. |
250 | Scene.TaintedObject("BSCharacter.PositionSanityCheck", delegate() | 261 | PhysicsScene.TaintedObject("BSCharacter.PositionSanityCheck", delegate() |
251 | { | 262 | { |
252 | DetailLog("{0},BSCharacter.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, _position, _orientation); | 263 | DetailLog("{0},BSCharacter.PositionSanityCheck,taint,pos={1},orient={2}", LocalID, _position, _orientation); |
253 | BulletSimAPI.SetObjectTranslation(Scene.WorldID, _localID, _position, _orientation); | 264 | BulletSimAPI.SetObjectTranslation(PhysicsScene.WorldID, _localID, _position, _orientation); |
254 | }); | 265 | }); |
255 | ret = true; | 266 | ret = true; |
256 | } | 267 | } |
@@ -266,15 +277,15 @@ public class BSCharacter : BSPhysObject | |||
266 | // used when we only want this prim's mass and not the linkset thing | 277 | // used when we only want this prim's mass and not the linkset thing |
267 | public override float MassRaw { get {return _mass; } } | 278 | public override float MassRaw { get {return _mass; } } |
268 | 279 | ||
269 | public override Vector3 Force { | 280 | public override OMV.Vector3 Force { |
270 | get { return _force; } | 281 | get { return _force; } |
271 | set { | 282 | set { |
272 | _force = value; | 283 | _force = value; |
273 | // m_log.DebugFormat("{0}: Force = {1}", LogHeader, _force); | 284 | // m_log.DebugFormat("{0}: Force = {1}", LogHeader, _force); |
274 | Scene.TaintedObject("BSCharacter.SetForce", delegate() | 285 | PhysicsScene.TaintedObject("BSCharacter.SetForce", delegate() |
275 | { | 286 | { |
276 | DetailLog("{0},BSCharacter.setForce,taint,force={1}", LocalID, _force); | 287 | DetailLog("{0},BSCharacter.setForce,taint,force={1}", LocalID, _force); |
277 | BulletSimAPI.SetObjectForce(Scene.WorldID, LocalID, _force); | 288 | BulletSimAPI.SetObjectForce(PhysicsScene.WorldID, LocalID, _force); |
278 | }); | 289 | }); |
279 | } | 290 | } |
280 | } | 291 | } |
@@ -284,28 +295,28 @@ public class BSCharacter : BSPhysObject | |||
284 | set { return; } | 295 | set { return; } |
285 | } | 296 | } |
286 | public override void VehicleFloatParam(int param, float value) { } | 297 | public override void VehicleFloatParam(int param, float value) { } |
287 | public override void VehicleVectorParam(int param, Vector3 value) {} | 298 | public override void VehicleVectorParam(int param, OMV.Vector3 value) {} |
288 | public override void VehicleRotationParam(int param, Quaternion rotation) { } | 299 | public override void VehicleRotationParam(int param, OMV.Quaternion rotation) { } |
289 | public override void VehicleFlags(int param, bool remove) { } | 300 | public override void VehicleFlags(int param, bool remove) { } |
290 | 301 | ||
291 | // Allows the detection of collisions with inherently non-physical prims. see llVolumeDetect for more | 302 | // Allows the detection of collisions with inherently non-physical prims. see llVolumeDetect for more |
292 | public override void SetVolumeDetect(int param) { return; } | 303 | public override void SetVolumeDetect(int param) { return; } |
293 | 304 | ||
294 | public override Vector3 GeometricCenter { get { return Vector3.Zero; } } | 305 | public override OMV.Vector3 GeometricCenter { get { return OMV.Vector3.Zero; } } |
295 | public override Vector3 CenterOfMass { get { return Vector3.Zero; } } | 306 | public override OMV.Vector3 CenterOfMass { get { return OMV.Vector3.Zero; } } |
296 | public override Vector3 Velocity { | 307 | public override OMV.Vector3 Velocity { |
297 | get { return _velocity; } | 308 | get { return _velocity; } |
298 | set { | 309 | set { |
299 | _velocity = value; | 310 | _velocity = value; |
300 | // m_log.DebugFormat("{0}: set velocity = {1}", LogHeader, _velocity); | 311 | // m_log.DebugFormat("{0}: set velocity = {1}", LogHeader, _velocity); |
301 | Scene.TaintedObject("BSCharacter.setVelocity", delegate() | 312 | PhysicsScene.TaintedObject("BSCharacter.setVelocity", delegate() |
302 | { | 313 | { |
303 | DetailLog("{0},BSCharacter.setVelocity,taint,vel={1}", LocalID, _velocity); | 314 | DetailLog("{0},BSCharacter.setVelocity,taint,vel={1}", LocalID, _velocity); |
304 | BulletSimAPI.SetObjectVelocity(Scene.WorldID, _localID, _velocity); | 315 | BulletSimAPI.SetObjectVelocity(PhysicsScene.WorldID, _localID, _velocity); |
305 | }); | 316 | }); |
306 | } | 317 | } |
307 | } | 318 | } |
308 | public override Vector3 Torque { | 319 | public override OMV.Vector3 Torque { |
309 | get { return _torque; } | 320 | get { return _torque; } |
310 | set { _torque = value; | 321 | set { _torque = value; |
311 | } | 322 | } |
@@ -315,19 +326,19 @@ public class BSCharacter : BSPhysObject | |||
315 | set { _collisionScore = value; | 326 | set { _collisionScore = value; |
316 | } | 327 | } |
317 | } | 328 | } |
318 | public override Vector3 Acceleration { | 329 | public override OMV.Vector3 Acceleration { |
319 | get { return _acceleration; } | 330 | get { return _acceleration; } |
320 | set { _acceleration = value; } | 331 | set { _acceleration = value; } |
321 | } | 332 | } |
322 | public override Quaternion Orientation { | 333 | public override OMV.Quaternion Orientation { |
323 | get { return _orientation; } | 334 | get { return _orientation; } |
324 | set { | 335 | set { |
325 | _orientation = value; | 336 | _orientation = value; |
326 | // m_log.DebugFormat("{0}: set orientation to {1}", LogHeader, _orientation); | 337 | // m_log.DebugFormat("{0}: set orientation to {1}", LogHeader, _orientation); |
327 | Scene.TaintedObject("BSCharacter.setOrientation", delegate() | 338 | PhysicsScene.TaintedObject("BSCharacter.setOrientation", delegate() |
328 | { | 339 | { |
329 | // _position = BulletSimAPI.GetObjectPosition(Scene.WorldID, _localID); | 340 | // _position = BulletSimAPI.GetObjectPosition(Scene.WorldID, _localID); |
330 | BulletSimAPI.SetObjectTranslation(Scene.WorldID, _localID, _position, _orientation); | 341 | BulletSimAPI.SetObjectTranslation(PhysicsScene.WorldID, _localID, _position, _orientation); |
331 | }); | 342 | }); |
332 | } | 343 | } |
333 | } | 344 | } |
@@ -364,11 +375,11 @@ public class BSCharacter : BSPhysObject | |||
364 | set { _throttleUpdates = value; } | 375 | set { _throttleUpdates = value; } |
365 | } | 376 | } |
366 | public override bool IsColliding { | 377 | public override bool IsColliding { |
367 | get { return (_collidingStep == Scene.SimulationStep); } | 378 | get { return (_collidingStep == PhysicsScene.SimulationStep); } |
368 | set { _isColliding = value; } | 379 | set { _isColliding = value; } |
369 | } | 380 | } |
370 | public override bool CollidingGround { | 381 | public override bool CollidingGround { |
371 | get { return (_collidingGroundStep == Scene.SimulationStep); } | 382 | get { return (_collidingGroundStep == PhysicsScene.SimulationStep); } |
372 | set { _collidingGround = value; } | 383 | set { _collidingGround = value; } |
373 | } | 384 | } |
374 | public override bool CollidingObj { | 385 | public override bool CollidingObj { |
@@ -378,7 +389,7 @@ public class BSCharacter : BSPhysObject | |||
378 | public override bool FloatOnWater { | 389 | public override bool FloatOnWater { |
379 | set { _floatOnWater = value; } | 390 | set { _floatOnWater = value; } |
380 | } | 391 | } |
381 | public override Vector3 RotationalVelocity { | 392 | public override OMV.Vector3 RotationalVelocity { |
382 | get { return _rotationalVelocity; } | 393 | get { return _rotationalVelocity; } |
383 | set { _rotationalVelocity = value; } | 394 | set { _rotationalVelocity = value; } |
384 | } | 395 | } |
@@ -390,16 +401,16 @@ public class BSCharacter : BSPhysObject | |||
390 | public override float Buoyancy { | 401 | public override float Buoyancy { |
391 | get { return _buoyancy; } | 402 | get { return _buoyancy; } |
392 | set { _buoyancy = value; | 403 | set { _buoyancy = value; |
393 | Scene.TaintedObject("BSCharacter.setBuoyancy", delegate() | 404 | PhysicsScene.TaintedObject("BSCharacter.setBuoyancy", delegate() |
394 | { | 405 | { |
395 | DetailLog("{0},BSCharacter.setBuoyancy,taint,buoy={1}", LocalID, _buoyancy); | 406 | DetailLog("{0},BSCharacter.setBuoyancy,taint,buoy={1}", LocalID, _buoyancy); |
396 | BulletSimAPI.SetObjectBuoyancy(Scene.WorldID, LocalID, _buoyancy); | 407 | BulletSimAPI.SetObjectBuoyancy(PhysicsScene.WorldID, LocalID, _buoyancy); |
397 | }); | 408 | }); |
398 | } | 409 | } |
399 | } | 410 | } |
400 | 411 | ||
401 | // Used for MoveTo | 412 | // Used for MoveTo |
402 | public override Vector3 PIDTarget { | 413 | public override OMV.Vector3 PIDTarget { |
403 | set { _PIDTarget = value; } | 414 | set { _PIDTarget = value; } |
404 | } | 415 | } |
405 | public override bool PIDActive { | 416 | public override bool PIDActive { |
@@ -425,19 +436,19 @@ public class BSCharacter : BSPhysObject | |||
425 | } | 436 | } |
426 | 437 | ||
427 | // For RotLookAt | 438 | // For RotLookAt |
428 | public override Quaternion APIDTarget { set { return; } } | 439 | public override OMV.Quaternion APIDTarget { set { return; } } |
429 | public override bool APIDActive { set { return; } } | 440 | public override bool APIDActive { set { return; } } |
430 | public override float APIDStrength { set { return; } } | 441 | public override float APIDStrength { set { return; } } |
431 | public override float APIDDamping { set { return; } } | 442 | public override float APIDDamping { set { return; } } |
432 | 443 | ||
433 | public override void AddForce(Vector3 force, bool pushforce) { | 444 | public override void AddForce(OMV.Vector3 force, bool pushforce) { |
434 | if (force.IsFinite()) | 445 | if (force.IsFinite()) |
435 | { | 446 | { |
436 | _force.X += force.X; | 447 | _force.X += force.X; |
437 | _force.Y += force.Y; | 448 | _force.Y += force.Y; |
438 | _force.Z += force.Z; | 449 | _force.Z += force.Z; |
439 | // m_log.DebugFormat("{0}: AddForce. adding={1}, newForce={2}", LogHeader, force, _force); | 450 | // m_log.DebugFormat("{0}: AddForce. adding={1}, newForce={2}", LogHeader, force, _force); |
440 | Scene.TaintedObject("BSCharacter.AddForce", delegate() | 451 | PhysicsScene.TaintedObject("BSCharacter.AddForce", delegate() |
441 | { | 452 | { |
442 | DetailLog("{0},BSCharacter.setAddForce,taint,addedForce={1}", LocalID, _force); | 453 | DetailLog("{0},BSCharacter.setAddForce,taint,addedForce={1}", LocalID, _force); |
443 | BulletSimAPI.SetObjectForce2(BSBody.Ptr, _force); | 454 | BulletSimAPI.SetObjectForce2(BSBody.Ptr, _force); |
@@ -450,42 +461,9 @@ public class BSCharacter : BSPhysObject | |||
450 | //m_lastUpdateSent = false; | 461 | //m_lastUpdateSent = false; |
451 | } | 462 | } |
452 | 463 | ||
453 | public override void AddAngularForce(Vector3 force, bool pushforce) { | 464 | public override void AddAngularForce(OMV.Vector3 force, bool pushforce) { |
454 | } | ||
455 | public override void SetMomentum(Vector3 momentum) { | ||
456 | } | ||
457 | |||
458 | // Turn on collision events at a rate no faster than one every the given milliseconds | ||
459 | public override void SubscribeEvents(int ms) { | ||
460 | _subscribedEventsMs = ms; | ||
461 | if (ms > 0) | ||
462 | { | ||
463 | // make sure first collision happens | ||
464 | _nextCollisionOkTime = Util.EnvironmentTickCount() - _subscribedEventsMs; | ||
465 | |||
466 | Scene.TaintedObject("BSCharacter.SubscribeEvents", delegate() | ||
467 | { | ||
468 | BulletSimAPI.AddToCollisionFlags2(BSBody.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); | ||
469 | }); | ||
470 | } | ||
471 | } | 465 | } |
472 | 466 | public override void SetMomentum(OMV.Vector3 momentum) { | |
473 | public override void ZeroMotion() | ||
474 | { | ||
475 | return; | ||
476 | } | ||
477 | |||
478 | // Stop collision events | ||
479 | public override void UnSubscribeEvents() { | ||
480 | _subscribedEventsMs = 0; | ||
481 | Scene.TaintedObject("BSCharacter.UnSubscribeEvents", delegate() | ||
482 | { | ||
483 | BulletSimAPI.RemoveFromCollisionFlags2(BSBody.Ptr, CollisionFlags.BS_SUBSCRIBE_COLLISION_EVENTS); | ||
484 | }); | ||
485 | } | ||
486 | // Return 'true' if someone has subscribed to events | ||
487 | public override bool SubscribedEvents() { | ||
488 | return (_subscribedEventsMs > 0); | ||
489 | } | 467 | } |
490 | 468 | ||
491 | // set _avatarVolume and _mass based on capsule size, _density and _scale | 469 | // set _avatarVolume and _mass based on capsule size, _density and _scale |
@@ -520,67 +498,15 @@ public class BSCharacter : BSPhysObject | |||
520 | // Do some sanity checking for the avatar. Make sure it's above ground and inbounds. | 498 | // Do some sanity checking for the avatar. Make sure it's above ground and inbounds. |
521 | PositionSanityCheck2(); | 499 | PositionSanityCheck2(); |
522 | 500 | ||
523 | float heightHere = Scene.TerrainManager.GetTerrainHeightAtXYZ(_position); // only for debug | 501 | float heightHere = PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(_position); // only for debug |
524 | DetailLog("{0},BSCharacter.UpdateProperties,call,pos={1},orient={2},vel={3},accel={4},rotVel={5},terrain={6}", | 502 | DetailLog("{0},BSCharacter.UpdateProperties,call,pos={1},orient={2},vel={3},accel={4},rotVel={5},terrain={6}", |
525 | LocalID, _position, _orientation, _velocity, _acceleration, _rotationalVelocity, heightHere); | 503 | LocalID, _position, _orientation, _velocity, _acceleration, _rotationalVelocity, heightHere); |
526 | } | 504 | } |
527 | 505 | ||
528 | // Called by the scene when a collision with this object is reported | ||
529 | // The collision, if it should be reported to the character, is placed in a collection | ||
530 | // that will later be sent to the simulator when SendCollisions() is called. | ||
531 | CollisionEventUpdate collisionCollection = null; | ||
532 | public override bool Collide(uint collidingWith, BSPhysObject collidee, Vector3 contactPoint, Vector3 contactNormal, float pentrationDepth) | ||
533 | { | ||
534 | bool ret = false; | ||
535 | |||
536 | // The following makes IsColliding() and IsCollidingGround() work | ||
537 | _collidingStep = Scene.SimulationStep; | ||
538 | if (collidingWith <= Scene.TerrainManager.HighestTerrainID) | ||
539 | { | ||
540 | _collidingGroundStep = Scene.SimulationStep; | ||
541 | } | ||
542 | // DetailLog("{0},BSCharacter.Collison,call,with={1}", LocalID, collidingWith); | ||
543 | |||
544 | // throttle collisions to the rate specified in the subscription | ||
545 | if (SubscribedEvents()) { | ||
546 | int nowTime = Scene.SimulationNowTime; | ||
547 | if (nowTime >= _nextCollisionOkTime) { | ||
548 | _nextCollisionOkTime = nowTime + _subscribedEventsMs; | ||
549 | |||
550 | if (collisionCollection == null) | ||
551 | collisionCollection = new CollisionEventUpdate(); | ||
552 | collisionCollection.AddCollider(collidingWith, new ContactPoint(contactPoint, contactNormal, pentrationDepth)); | ||
553 | ret = true; | ||
554 | } | ||
555 | } | ||
556 | return ret; | ||
557 | } | ||
558 | |||
559 | public override void SendCollisions() | ||
560 | { | ||
561 | /* | ||
562 | if (collisionCollection != null && collisionCollection.Count > 0) | ||
563 | { | ||
564 | base.SendCollisionUpdate(collisionCollection); | ||
565 | collisionCollection = null; | ||
566 | } | ||
567 | */ | ||
568 | // Kludge to make a collision call even if there are no collisions. | ||
569 | // This causes the avatar animation to get updated. | ||
570 | if (collisionCollection == null) | ||
571 | collisionCollection = new CollisionEventUpdate(); | ||
572 | base.SendCollisionUpdate(collisionCollection); | ||
573 | // If there were any collisions in the collection, make sure we don't use the | ||
574 | // same instance next time. | ||
575 | if (collisionCollection.Count > 0) | ||
576 | collisionCollection = null; | ||
577 | // End kludge | ||
578 | } | ||
579 | |||
580 | // Invoke the detailed logger and output something if it's enabled. | 506 | // Invoke the detailed logger and output something if it's enabled. |
581 | private void DetailLog(string msg, params Object[] args) | 507 | private void DetailLog(string msg, params Object[] args) |
582 | { | 508 | { |
583 | Scene.PhysicsLogging.Write(msg, args); | 509 | PhysicsScene.PhysicsLogging.Write(msg, args); |
584 | } | 510 | } |
585 | } | 511 | } |
586 | } | 512 | } |