aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/PhysicsModules/ubOde/ODECharacter.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/PhysicsModules/ubOde/ODECharacter.cs')
-rw-r--r--OpenSim/Region/PhysicsModules/ubOde/ODECharacter.cs889
1 files changed, 524 insertions, 365 deletions
diff --git a/OpenSim/Region/PhysicsModules/ubOde/ODECharacter.cs b/OpenSim/Region/PhysicsModules/ubOde/ODECharacter.cs
index 0e46471..60cc549 100644
--- a/OpenSim/Region/PhysicsModules/ubOde/ODECharacter.cs
+++ b/OpenSim/Region/PhysicsModules/ubOde/ODECharacter.cs
@@ -32,7 +32,6 @@ using System;
32using System.Collections.Generic; 32using System.Collections.Generic;
33using System.Reflection; 33using System.Reflection;
34using OpenMetaverse; 34using OpenMetaverse;
35using OdeAPI;
36using OpenSim.Framework; 35using OpenSim.Framework;
37using OpenSim.Region.PhysicsModules.SharedBase; 36using OpenSim.Region.PhysicsModules.SharedBase;
38using log4net; 37using log4net;
@@ -43,7 +42,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
43 /// Various properties that ODE uses for AMotors but isn't exposed in ODE.NET so we must define them ourselves. 42 /// Various properties that ODE uses for AMotors but isn't exposed in ODE.NET so we must define them ourselves.
44 /// </summary> 43 /// </summary>
45 44
46 public enum dParam : int 45 public enum dParam:int
47 { 46 {
48 LowStop = 0, 47 LowStop = 0,
49 HiStop = 1, 48 HiStop = 1,
@@ -68,7 +67,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
68 StopCFM3 = 8 + 512 67 StopCFM3 = 8 + 512
69 } 68 }
70 69
71 public class OdeCharacter : PhysicsActor 70 public class OdeCharacter:PhysicsActor
72 { 71 {
73 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 72 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
74 73
@@ -122,7 +121,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
122 121
123 private bool m_freemove = false; 122 private bool m_freemove = false;
124 123
125// private string m_name = String.Empty; 124 // private string m_name = String.Empty;
126 // other filter control 125 // other filter control
127 int m_colliderfilter = 0; 126 int m_colliderfilter = 0;
128 int m_colliderGroundfilter = 0; 127 int m_colliderGroundfilter = 0;
@@ -144,7 +143,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
144 143
145 public IntPtr Amotor = IntPtr.Zero; 144 public IntPtr Amotor = IntPtr.Zero;
146 145
147 public d.Mass ShellMass; 146 internal SafeNativeMethods.Mass ShellMass;
148 147
149 public int m_eventsubscription = 0; 148 public int m_eventsubscription = 0;
150 private int m_cureventsubscription = 0; 149 private int m_cureventsubscription = 0;
@@ -165,7 +164,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
165 private float m_targetHoverHeight; 164 private float m_targetHoverHeight;
166 165
167 166
168 public OdeCharacter(uint localID, String avName, ODEScene parent_scene, Vector3 pos, Vector3 pSize, float pfeetOffset, float density, float walk_divisor, float rundivisor) 167 public OdeCharacter(uint localID,String avName,ODEScene parent_scene,Vector3 pos,Vector3 pSize,float pfeetOffset,float density,float walk_divisor,float rundivisor)
169 { 168 {
170 m_uuid = UUID.Random(); 169 m_uuid = UUID.Random();
171 m_localID = localID; 170 m_localID = localID;
@@ -174,21 +173,21 @@ namespace OpenSim.Region.PhysicsModule.ubOde
174 timeStep = parent_scene.ODE_STEPSIZE; 173 timeStep = parent_scene.ODE_STEPSIZE;
175 invtimeStep = 1 / timeStep; 174 invtimeStep = 1 / timeStep;
176 175
177 if (pos.IsFinite()) 176 if(pos.IsFinite())
178 { 177 {
179 if (pos.Z > 99999f) 178 if(pos.Z > 99999f)
180 { 179 {
181 pos.Z = parent_scene.GetTerrainHeightAtXY(127, 127) + 5; 180 pos.Z = parent_scene.GetTerrainHeightAtXY(127,127) + 5;
182 } 181 }
183 if (pos.Z < -100f) // shouldn't this be 0 ? 182 if(pos.Z < -100f) // shouldn't this be 0 ?
184 { 183 {
185 pos.Z = parent_scene.GetTerrainHeightAtXY(127, 127) + 5; 184 pos.Z = parent_scene.GetTerrainHeightAtXY(127,127) + 5;
186 } 185 }
187 _position = pos; 186 _position = pos;
188 } 187 }
189 else 188 else
190 { 189 {
191 _position = new Vector3(((float)m_parent_scene.WorldExtents.X * 0.5f), ((float)m_parent_scene.WorldExtents.Y * 0.5f), parent_scene.GetTerrainHeightAtXY(128f, 128f) + 10f); 190 _position = new Vector3(((float)m_parent_scene.WorldExtents.X * 0.5f),((float)m_parent_scene.WorldExtents.Y * 0.5f),parent_scene.GetTerrainHeightAtXY(128f,128f) + 10f);
192 m_log.Warn("[PHYSICS]: Got NaN Position on Character Create"); 191 m_log.Warn("[PHYSICS]: Got NaN Position on Character Create");
193 } 192 }
194 193
@@ -216,7 +215,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
216 walkDivisor = walk_divisor; 215 walkDivisor = walk_divisor;
217 runDivisor = rundivisor; 216 runDivisor = rundivisor;
218 217
219 m_mass = m_density * m_size.X * m_size.Y * m_size.Z; ; // sure we have a default 218 m_mass = m_density * m_size.X * m_size.Y * m_size.Z;
219 ; // sure we have a default
220 220
221 PID_D = basePID_D * m_mass * invtimeStep; 221 PID_D = basePID_D * m_mass * invtimeStep;
222 PID_P = basePID_P * m_mass * invtimeStep; 222 PID_P = basePID_P * m_mass * invtimeStep;
@@ -225,13 +225,19 @@ namespace OpenSim.Region.PhysicsModule.ubOde
225 225
226 Name = avName; 226 Name = avName;
227 227
228 AddChange(changes.Add, null); 228 AddChange(changes.Add,null);
229 } 229 }
230 230
231 public override int PhysicsActorType 231 public override int PhysicsActorType
232 { 232 {
233 get { return (int)ActorTypes.Agent; } 233 get
234 set { return; } 234 {
235 return (int)ActorTypes.Agent;
236 }
237 set
238 {
239 return;
240 }
235 } 241 }
236 242
237 public override void getContactData(ref ContactData cdata) 243 public override void getContactData(ref ContactData cdata)
@@ -241,68 +247,116 @@ namespace OpenSim.Region.PhysicsModule.ubOde
241 cdata.softcolide = false; 247 cdata.softcolide = false;
242 } 248 }
243 249
244 public override bool Building { get; set; } 250 public override bool Building
251 {
252 get; set;
253 }
245 254
246 /// <summary> 255 /// <summary>
247 /// If this is set, the avatar will move faster 256 /// If this is set, the avatar will move faster
248 /// </summary> 257 /// </summary>
249 public override bool SetAlwaysRun 258 public override bool SetAlwaysRun
250 { 259 {
251 get { return m_alwaysRun; } 260 get
252 set { m_alwaysRun = value; } 261 {
262 return m_alwaysRun;
263 }
264 set
265 {
266 m_alwaysRun = value;
267 }
253 } 268 }
254 269
255 public override uint LocalID 270 public override uint LocalID
256 { 271 {
257 get { return m_localID; } 272 get
258 set { m_localID = value; } 273 {
274 return m_localID;
275 }
276 set
277 {
278 m_localID = value;
279 }
259 } 280 }
260 281
261 public override PhysicsActor ParentActor 282 public override PhysicsActor ParentActor
262 { 283 {
263 get { return (PhysicsActor)this; } 284 get
285 {
286 return (PhysicsActor)this;
287 }
264 } 288 }
265 289
266 public override bool Grabbed 290 public override bool Grabbed
267 { 291 {
268 set { return; } 292 set
293 {
294 return;
295 }
269 } 296 }
270 297
271 public override bool Selected 298 public override bool Selected
272 { 299 {
273 set { return; } 300 set
301 {
302 return;
303 }
274 } 304 }
275 305
276 public override float Buoyancy 306 public override float Buoyancy
277 { 307 {
278 get { return m_buoyancy; } 308 get
279 set { m_buoyancy = value; } 309 {
310 return m_buoyancy;
311 }
312 set
313 {
314 m_buoyancy = value;
315 }
280 } 316 }
281 317
282 public override bool FloatOnWater 318 public override bool FloatOnWater
283 { 319 {
284 set { return; } 320 set
321 {
322 return;
323 }
285 } 324 }
286 325
287 public override bool IsPhysical 326 public override bool IsPhysical
288 { 327 {
289 get { return m_isPhysical; } 328 get
290 set { return; } 329 {
330 return m_isPhysical;
331 }
332 set
333 {
334 return;
335 }
291 } 336 }
292 337
293 public override bool ThrottleUpdates 338 public override bool ThrottleUpdates
294 { 339 {
295 get { return false; } 340 get
296 set { return; } 341 {
342 return false;
343 }
344 set
345 {
346 return;
347 }
297 } 348 }
298 349
299 public override bool Flying 350 public override bool Flying
300 { 351 {
301 get { return m_flying; } 352 get
353 {
354 return m_flying;
355 }
302 set 356 set
303 { 357 {
304 m_flying = value; 358 m_flying = value;
305// m_log.DebugFormat("[PHYSICS]: Set OdeCharacter Flying to {0}", flying); 359 // m_log.DebugFormat("[PHYSICS]: Set OdeCharacter Flying to {0}", flying);
306 } 360 }
307 } 361 }
308 362
@@ -312,23 +366,26 @@ namespace OpenSim.Region.PhysicsModule.ubOde
312 /// </summary> 366 /// </summary>
313 public override bool IsColliding 367 public override bool IsColliding
314 { 368 {
315 get { return (m_iscolliding || m_iscollidingGround); } 369 get
370 {
371 return (m_iscolliding || m_iscollidingGround);
372 }
316 set 373 set
317 { 374 {
318 if (value) 375 if(value)
319 { 376 {
320 m_colliderfilter += 3; 377 m_colliderfilter += 3;
321 if (m_colliderfilter > 3) 378 if(m_colliderfilter > 3)
322 m_colliderfilter = 3; 379 m_colliderfilter = 3;
323 } 380 }
324 else 381 else
325 { 382 {
326 m_colliderfilter--; 383 m_colliderfilter--;
327 if (m_colliderfilter < 0) 384 if(m_colliderfilter < 0)
328 m_colliderfilter = 0; 385 m_colliderfilter = 0;
329 } 386 }
330 387
331 if (m_colliderfilter == 0) 388 if(m_colliderfilter == 0)
332 m_iscolliding = false; 389 m_iscolliding = false;
333 else 390 else
334 { 391 {
@@ -344,28 +401,31 @@ namespace OpenSim.Region.PhysicsModule.ubOde
344 /// </summary> 401 /// </summary>
345 public override bool CollidingGround 402 public override bool CollidingGround
346 { 403 {
347 get { return m_iscollidingGround; } 404 get
405 {
406 return m_iscollidingGround;
407 }
348 set 408 set
349 { 409 {
350/* we now control this 410 /* we now control this
351 if (value) 411 if (value)
352 { 412 {
353 m_colliderGroundfilter += 2; 413 m_colliderGroundfilter += 2;
354 if (m_colliderGroundfilter > 2) 414 if (m_colliderGroundfilter > 2)
355 m_colliderGroundfilter = 2; 415 m_colliderGroundfilter = 2;
356 } 416 }
357 else 417 else
358 { 418 {
359 m_colliderGroundfilter--; 419 m_colliderGroundfilter--;
360 if (m_colliderGroundfilter < 0) 420 if (m_colliderGroundfilter < 0)
361 m_colliderGroundfilter = 0; 421 m_colliderGroundfilter = 0;
362 } 422 }
363 423
364 if (m_colliderGroundfilter == 0) 424 if (m_colliderGroundfilter == 0)
365 m_iscollidingGround = false; 425 m_iscollidingGround = false;
366 else 426 else
367 m_iscollidingGround = true; 427 m_iscollidingGround = true;
368 */ 428 */
369 } 429 }
370 430
371 } 431 }
@@ -375,31 +435,34 @@ namespace OpenSim.Region.PhysicsModule.ubOde
375 /// </summary> 435 /// </summary>
376 public override bool CollidingObj 436 public override bool CollidingObj
377 { 437 {
378 get { return m_iscollidingObj; } 438 get
439 {
440 return m_iscollidingObj;
441 }
379 set 442 set
380 { 443 {
381 // Ubit filter this also 444 // Ubit filter this also
382 if (value) 445 if(value)
383 { 446 {
384 m_colliderObjectfilter += 2; 447 m_colliderObjectfilter += 2;
385 if (m_colliderObjectfilter > 2) 448 if(m_colliderObjectfilter > 2)
386 m_colliderObjectfilter = 2; 449 m_colliderObjectfilter = 2;
387 } 450 }
388 else 451 else
389 { 452 {
390 m_colliderObjectfilter--; 453 m_colliderObjectfilter--;
391 if (m_colliderObjectfilter < 0) 454 if(m_colliderObjectfilter < 0)
392 m_colliderObjectfilter = 0; 455 m_colliderObjectfilter = 0;
393 } 456 }
394 457
395 if (m_colliderObjectfilter == 0) 458 if(m_colliderObjectfilter == 0)
396 m_iscollidingObj = false; 459 m_iscollidingObj = false;
397 else 460 else
398 m_iscollidingObj = true; 461 m_iscollidingObj = true;
399 462
400// m_iscollidingObj = value; 463 // m_iscollidingObj = value;
401 464
402 if (m_iscollidingObj) 465 if(m_iscollidingObj)
403 m_pidControllerActive = false; 466 m_pidControllerActive = false;
404 else 467 else
405 m_pidControllerActive = true; 468 m_pidControllerActive = true;
@@ -418,7 +481,10 @@ namespace OpenSim.Region.PhysicsModule.ubOde
418 481
419 public override bool Stopped 482 public override bool Stopped
420 { 483 {
421 get { return _zeroFlag; } 484 get
485 {
486 return _zeroFlag;
487 }
422 } 488 }
423 489
424 /// <summary> 490 /// <summary>
@@ -428,20 +494,23 @@ namespace OpenSim.Region.PhysicsModule.ubOde
428 /// </summary> 494 /// </summary>
429 public override Vector3 Position 495 public override Vector3 Position
430 { 496 {
431 get { return _position; } 497 get
498 {
499 return _position;
500 }
432 set 501 set
433 { 502 {
434 if (value.IsFinite()) 503 if(value.IsFinite())
435 { 504 {
436 if (value.Z > 9999999f) 505 if(value.Z > 9999999f)
437 { 506 {
438 value.Z = m_parent_scene.GetTerrainHeightAtXY(127, 127) + 5; 507 value.Z = m_parent_scene.GetTerrainHeightAtXY(127,127) + 5;
439 } 508 }
440 if (value.Z < -100f) 509 if(value.Z < -100f)
441 { 510 {
442 value.Z = m_parent_scene.GetTerrainHeightAtXY(127, 127) + 5; 511 value.Z = m_parent_scene.GetTerrainHeightAtXY(127,127) + 5;
443 } 512 }
444 AddChange(changes.Position, value); 513 AddChange(changes.Position,value);
445 } 514 }
446 else 515 else
447 { 516 {
@@ -452,8 +521,14 @@ namespace OpenSim.Region.PhysicsModule.ubOde
452 521
453 public override Vector3 RotationalVelocity 522 public override Vector3 RotationalVelocity
454 { 523 {
455 get { return m_rotationalVelocity; } 524 get
456 set { m_rotationalVelocity = value; } 525 {
526 return m_rotationalVelocity;
527 }
528 set
529 {
530 m_rotationalVelocity = value;
531 }
457 } 532 }
458 533
459 /// <summary> 534 /// <summary>
@@ -468,7 +543,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
468 } 543 }
469 set 544 set
470 { 545 {
471 if (value.IsFinite()) 546 if(value.IsFinite())
472 { 547 {
473 if(value.X <0.01f) 548 if(value.X <0.01f)
474 value.X = 0.01f; 549 value.X = 0.01f;
@@ -477,7 +552,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
477 if(value.Z <0.01f) 552 if(value.Z <0.01f)
478 value.Z = 0.01f; 553 value.Z = 0.01f;
479 554
480 AddChange(changes.Size, value); 555 AddChange(changes.Size,value);
481 } 556 }
482 else 557 else
483 { 558 {
@@ -486,21 +561,21 @@ namespace OpenSim.Region.PhysicsModule.ubOde
486 } 561 }
487 } 562 }
488 563
489 public override void setAvatarSize(Vector3 size, float feetOffset) 564 public override void setAvatarSize(Vector3 size,float feetOffset)
490 { 565 {
491 if (size.IsFinite()) 566 if(size.IsFinite())
492 { 567 {
493 if (size.X < 0.01f) 568 if(size.X < 0.01f)
494 size.X = 0.01f; 569 size.X = 0.01f;
495 if (size.Y < 0.01f) 570 if(size.Y < 0.01f)
496 size.Y = 0.01f; 571 size.Y = 0.01f;
497 if (size.Z < 0.01f) 572 if(size.Z < 0.01f)
498 size.Z = 0.01f; 573 size.Z = 0.01f;
499 574
500 strAvatarSize st = new strAvatarSize(); 575 strAvatarSize st = new strAvatarSize();
501 st.size = size; 576 st.size = size;
502 st.offset = feetOffset; 577 st.offset = feetOffset;
503 AddChange(changes.AvatarSize, st); 578 AddChange(changes.AvatarSize,st);
504 } 579 }
505 else 580 else
506 { 581 {
@@ -545,32 +620,44 @@ namespace OpenSim.Region.PhysicsModule.ubOde
545 620
546 public override Vector3 Force 621 public override Vector3 Force
547 { 622 {
548 get { return _target_velocity; } 623 get
549 set { return; } 624 {
625 return _target_velocity;
626 }
627 set
628 {
629 return;
630 }
550 } 631 }
551 632
552 public override int VehicleType 633 public override int VehicleType
553 { 634 {
554 get { return 0; } 635 get
555 set { return; } 636 {
637 return 0;
638 }
639 set
640 {
641 return;
642 }
556 } 643 }
557 644
558 public override void VehicleFloatParam(int param, float value) 645 public override void VehicleFloatParam(int param,float value)
559 { 646 {
560 647
561 } 648 }
562 649
563 public override void VehicleVectorParam(int param, Vector3 value) 650 public override void VehicleVectorParam(int param,Vector3 value)
564 { 651 {
565 652
566 } 653 }
567 654
568 public override void VehicleRotationParam(int param, Quaternion rotation) 655 public override void VehicleRotationParam(int param,Quaternion rotation)
569 { 656 {
570 657
571 } 658 }
572 659
573 public override void VehicleFlags(int param, bool remove) 660 public override void VehicleFlags(int param,bool remove)
574 { 661 {
575 662
576 } 663 }
@@ -600,7 +687,10 @@ namespace OpenSim.Region.PhysicsModule.ubOde
600 687
601 public override PrimitiveBaseShape Shape 688 public override PrimitiveBaseShape Shape
602 { 689 {
603 set { return; } 690 set
691 {
692 return;
693 }
604 } 694 }
605 695
606 public override Vector3 rootVelocity 696 public override Vector3 rootVelocity
@@ -619,9 +709,9 @@ namespace OpenSim.Region.PhysicsModule.ubOde
619 } 709 }
620 set 710 set
621 { 711 {
622 if (value.IsFinite()) 712 if(value.IsFinite())
623 { 713 {
624 AddChange(changes.Velocity, value); 714 AddChange(changes.Velocity,value);
625 } 715 }
626 else 716 else
627 { 717 {
@@ -638,9 +728,9 @@ namespace OpenSim.Region.PhysicsModule.ubOde
638 } 728 }
639 set 729 set
640 { 730 {
641 if (value.IsFinite()) 731 if(value.IsFinite())
642 { 732 {
643 AddChange(changes.TargetVelocity, value); 733 AddChange(changes.TargetVelocity,value);
644 } 734 }
645 else 735 else
646 { 736 {
@@ -651,38 +741,62 @@ namespace OpenSim.Region.PhysicsModule.ubOde
651 741
652 public override Vector3 Torque 742 public override Vector3 Torque
653 { 743 {
654 get { return Vector3.Zero; } 744 get
655 set { return; } 745 {
746 return Vector3.Zero;
747 }
748 set
749 {
750 return;
751 }
656 } 752 }
657 753
658 public override float CollisionScore 754 public override float CollisionScore
659 { 755 {
660 get { return 0f; } 756 get
661 set { } 757 {
758 return 0f;
759 }
760 set
761 {
762 }
662 } 763 }
663 764
664 public override bool Kinematic 765 public override bool Kinematic
665 { 766 {
666 get { return false; } 767 get
667 set { } 768 {
769 return false;
770 }
771 set
772 {
773 }
668 } 774 }
669 775
670 public override Quaternion Orientation 776 public override Quaternion Orientation
671 { 777 {
672 get { return m_orientation; } 778 get
779 {
780 return m_orientation;
781 }
673 set 782 set
674 { 783 {
675// fakeori = value; 784 // fakeori = value;
676// givefakeori++; 785 // givefakeori++;
677 value.Normalize(); 786 value.Normalize();
678 AddChange(changes.Orientation, value); 787 AddChange(changes.Orientation,value);
679 } 788 }
680 } 789 }
681 790
682 public override Vector3 Acceleration 791 public override Vector3 Acceleration
683 { 792 {
684 get { return _acceleration; } 793 get
685 set { } 794 {
795 return _acceleration;
796 }
797 set
798 {
799 }
686 } 800 }
687 801
688 public void SetAcceleration(Vector3 accel) 802 public void SetAcceleration(Vector3 accel)
@@ -696,17 +810,17 @@ namespace OpenSim.Region.PhysicsModule.ubOde
696 /// The PID controller takes this target velocity and tries to make it a reality 810 /// The PID controller takes this target velocity and tries to make it a reality
697 /// </summary> 811 /// </summary>
698 /// <param name="force"></param> 812 /// <param name="force"></param>
699 public override void AddForce(Vector3 force, bool pushforce) 813 public override void AddForce(Vector3 force,bool pushforce)
700 { 814 {
701 if (force.IsFinite()) 815 if(force.IsFinite())
702 { 816 {
703 if (pushforce) 817 if(pushforce)
704 { 818 {
705 AddChange(changes.Force, force * m_density / (m_parent_scene.ODE_STEPSIZE * 28f)); 819 AddChange(changes.Force,force * m_density / (m_parent_scene.ODE_STEPSIZE * 28f));
706 } 820 }
707 else 821 else
708 { 822 {
709 AddChange(changes.TargetVelocity, force); 823 AddChange(changes.TargetVelocity,force);
710 } 824 }
711 } 825 }
712 else 826 else
@@ -716,19 +830,19 @@ namespace OpenSim.Region.PhysicsModule.ubOde
716 //m_lastUpdateSent = false; 830 //m_lastUpdateSent = false;
717 } 831 }
718 832
719 public override void AddAngularForce(Vector3 force, bool pushforce) 833 public override void AddAngularForce(Vector3 force,bool pushforce)
720 { 834 {
721 835
722 } 836 }
723 837
724 public override void SetMomentum(Vector3 momentum) 838 public override void SetMomentum(Vector3 momentum)
725 { 839 {
726 if (momentum.IsFinite()) 840 if(momentum.IsFinite())
727 AddChange(changes.Momentum, momentum); 841 AddChange(changes.Momentum,momentum);
728 } 842 }
729 843
730 844
731 private void AvatarGeomAndBodyCreation(float npositionX, float npositionY, float npositionZ) 845 private void AvatarGeomAndBodyCreation(float npositionX,float npositionY,float npositionZ)
732 { 846 {
733 // sizes one day should came from visual parameters 847 // sizes one day should came from visual parameters
734 float sx = m_size.X; 848 float sx = m_size.X;
@@ -739,7 +853,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
739 boneOff = bot + 0.3f; 853 boneOff = bot + 0.3f;
740 854
741 float feetsz = sz * 0.45f; 855 float feetsz = sz * 0.45f;
742 if (feetsz > 0.6f) 856 if(feetsz > 0.6f)
743 feetsz = 0.6f; 857 feetsz = 0.6f;
744 858
745 feetOff = bot + feetsz; 859 feetOff = bot + feetsz;
@@ -751,29 +865,28 @@ namespace OpenSim.Region.PhysicsModule.ubOde
751 865
752 m_parent_scene.waitForSpaceUnlock(m_parent_scene.CharsSpace); 866 m_parent_scene.waitForSpaceUnlock(m_parent_scene.CharsSpace);
753 867
754 collider = d.HashSpaceCreate(m_parent_scene.CharsSpace); 868 collider = SafeNativeMethods.SimpleSpaceCreate(m_parent_scene.CharsSpace);
755 d.HashSpaceSetLevels(collider, -4, 3); 869 SafeNativeMethods.SpaceSetSublevel(collider,3);
756 d.SpaceSetSublevel(collider, 3); 870 SafeNativeMethods.SpaceSetCleanup(collider,false);
757 d.SpaceSetCleanup(collider, false); 871 SafeNativeMethods.GeomSetCategoryBits(collider,(uint)m_collisionCategories);
758 d.GeomSetCategoryBits(collider, (uint)m_collisionCategories); 872 SafeNativeMethods.GeomSetCollideBits(collider,(uint)m_collisionFlags);
759 d.GeomSetCollideBits(collider, (uint)m_collisionFlags);
760 873
761 float r = m_size.X; 874 float r = m_size.X;
762 if (m_size.Y > r) 875 if(m_size.Y > r)
763 r = m_size.Y; 876 r = m_size.Y;
764 float l = m_size.Z - r; 877 float l = m_size.Z - r;
765 r *= 0.5f; 878 r *= 0.5f;
766 879
767 capsule = d.CreateCapsule(collider, r, l); 880 capsule = SafeNativeMethods.CreateCapsule(collider,r,l);
768 881
769 m_mass = m_density * m_size.X * m_size.Y * m_size.Z; // update mass 882 m_mass = m_density * m_size.X * m_size.Y * m_size.Z; // update mass
770 883
771 d.MassSetBoxTotal(out ShellMass, m_mass, m_size.X, m_size.Y, m_size.Z); 884 SafeNativeMethods.MassSetBoxTotal(out ShellMass,m_mass,m_size.X,m_size.Y,m_size.Z);
772 885
773 PID_D = basePID_D * m_mass / m_parent_scene.ODE_STEPSIZE; 886 PID_D = basePID_D * m_mass / m_parent_scene.ODE_STEPSIZE;
774 PID_P = basePID_P * m_mass / m_parent_scene.ODE_STEPSIZE; 887 PID_P = basePID_P * m_mass / m_parent_scene.ODE_STEPSIZE;
775 888
776 Body = d.BodyCreate(m_parent_scene.world); 889 Body = SafeNativeMethods.BodyCreate(m_parent_scene.world);
777 890
778 _zeroFlag = false; 891 _zeroFlag = false;
779 m_pidControllerActive = true; 892 m_pidControllerActive = true;
@@ -781,53 +894,53 @@ namespace OpenSim.Region.PhysicsModule.ubOde
781 894
782 _velocity = Vector3.Zero; 895 _velocity = Vector3.Zero;
783 896
784 d.BodySetAutoDisableFlag(Body, false); 897 SafeNativeMethods.BodySetAutoDisableFlag(Body,false);
785 d.BodySetPosition(Body, npositionX, npositionY, npositionZ); 898 SafeNativeMethods.BodySetPosition(Body,npositionX,npositionY,npositionZ);
786 899
787 _position.X = npositionX; 900 _position.X = npositionX;
788 _position.Y = npositionY; 901 _position.Y = npositionY;
789 _position.Z = npositionZ; 902 _position.Z = npositionZ;
790 903
791 d.BodySetMass(Body, ref ShellMass); 904 SafeNativeMethods.BodySetMass(Body,ref ShellMass);
792 d.GeomSetBody(capsule, Body); 905 SafeNativeMethods.GeomSetBody(capsule,Body);
793 906
794 // The purpose of the AMotor here is to keep the avatar's physical 907 // The purpose of the AMotor here is to keep the avatar's physical
795 // surrogate from rotating while moving 908 // surrogate from rotating while moving
796 Amotor = d.JointCreateAMotor(m_parent_scene.world, IntPtr.Zero); 909 Amotor = SafeNativeMethods.JointCreateAMotor(m_parent_scene.world,IntPtr.Zero);
797 d.JointAttach(Amotor, Body, IntPtr.Zero); 910 SafeNativeMethods.JointAttach(Amotor,Body,IntPtr.Zero);
798 911
799 d.JointSetAMotorMode(Amotor, 0); 912 SafeNativeMethods.JointSetAMotorMode(Amotor,0);
800 d.JointSetAMotorNumAxes(Amotor, 3); 913 SafeNativeMethods.JointSetAMotorNumAxes(Amotor,3);
801 d.JointSetAMotorAxis(Amotor, 0, 0, 1, 0, 0); 914 SafeNativeMethods.JointSetAMotorAxis(Amotor,0,0,1,0,0);
802 d.JointSetAMotorAxis(Amotor, 1, 0, 0, 1, 0); 915 SafeNativeMethods.JointSetAMotorAxis(Amotor,1,0,0,1,0);
803 d.JointSetAMotorAxis(Amotor, 2, 0, 0, 0, 1); 916 SafeNativeMethods.JointSetAMotorAxis(Amotor,2,0,0,0,1);
804 917
805 d.JointSetAMotorAngle(Amotor, 0, 0); 918 SafeNativeMethods.JointSetAMotorAngle(Amotor,0,0);
806 d.JointSetAMotorAngle(Amotor, 1, 0); 919 SafeNativeMethods.JointSetAMotorAngle(Amotor,1,0);
807 d.JointSetAMotorAngle(Amotor, 2, 0); 920 SafeNativeMethods.JointSetAMotorAngle(Amotor,2,0);
808 921
809 d.JointSetAMotorParam(Amotor, (int)dParam.StopCFM, 0f); // make it HARD 922 SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.StopCFM,0f); // make it HARD
810 d.JointSetAMotorParam(Amotor, (int)dParam.StopCFM2, 0f); 923 SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.StopCFM2,0f);
811 d.JointSetAMotorParam(Amotor, (int)dParam.StopCFM3, 0f); 924 SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.StopCFM3,0f);
812 d.JointSetAMotorParam(Amotor, (int)dParam.StopERP, 0.8f); 925 SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.StopERP,0.8f);
813 d.JointSetAMotorParam(Amotor, (int)dParam.StopERP2, 0.8f); 926 SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.StopERP2,0.8f);
814 d.JointSetAMotorParam(Amotor, (int)dParam.StopERP3, 0.8f); 927 SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.StopERP3,0.8f);
815 928
816 // These lowstops and high stops are effectively (no wiggle room) 929 // These lowstops and high stops are effectively (no wiggle room)
817 d.JointSetAMotorParam(Amotor, (int)dParam.LowStop, -1e-5f); 930 SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.LowStop,-1e-5f);
818 d.JointSetAMotorParam(Amotor, (int)dParam.HiStop, 1e-5f); 931 SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.HiStop,1e-5f);
819 d.JointSetAMotorParam(Amotor, (int)dParam.LoStop2, -1e-5f); 932 SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.LoStop2,-1e-5f);
820 d.JointSetAMotorParam(Amotor, (int)dParam.HiStop2, 1e-5f); 933 SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.HiStop2,1e-5f);
821 d.JointSetAMotorParam(Amotor, (int)dParam.LoStop3, -1e-5f); 934 SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.LoStop3,-1e-5f);
822 d.JointSetAMotorParam(Amotor, (int)dParam.HiStop3, 1e-5f); 935 SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.HiStop3,1e-5f);
823 936
824 d.JointSetAMotorParam(Amotor, (int)d.JointParam.Vel, 0); 937 SafeNativeMethods.JointSetAMotorParam(Amotor,(int)SafeNativeMethods.JointParam.Vel,0);
825 d.JointSetAMotorParam(Amotor, (int)d.JointParam.Vel2, 0); 938 SafeNativeMethods.JointSetAMotorParam(Amotor,(int)SafeNativeMethods.JointParam.Vel2,0);
826 d.JointSetAMotorParam(Amotor, (int)d.JointParam.Vel3, 0); 939 SafeNativeMethods.JointSetAMotorParam(Amotor,(int)SafeNativeMethods.JointParam.Vel3,0);
827 940
828 d.JointSetAMotorParam(Amotor, (int)dParam.FMax, 5e8f); 941 SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.FMax,5e8f);
829 d.JointSetAMotorParam(Amotor, (int)dParam.FMax2, 5e8f); 942 SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.FMax2,5e8f);
830 d.JointSetAMotorParam(Amotor, (int)dParam.FMax3, 5e8f); 943 SafeNativeMethods.JointSetAMotorParam(Amotor,(int)dParam.FMax3,5e8f);
831 } 944 }
832 945
833 /// <summary> 946 /// <summary>
@@ -836,38 +949,38 @@ namespace OpenSim.Region.PhysicsModule.ubOde
836 private void AvatarGeomAndBodyDestroy() 949 private void AvatarGeomAndBodyDestroy()
837 { 950 {
838 // Kill the Amotor 951 // Kill the Amotor
839 if (Amotor != IntPtr.Zero) 952 if(Amotor != IntPtr.Zero)
840 { 953 {
841 d.JointDestroy(Amotor); 954 SafeNativeMethods.JointDestroy(Amotor);
842 Amotor = IntPtr.Zero; 955 Amotor = IntPtr.Zero;
843 } 956 }
844 957
845 if (Body != IntPtr.Zero) 958 if(Body != IntPtr.Zero)
846 { 959 {
847 //kill the body 960 //kill the body
848 d.BodyDestroy(Body); 961 SafeNativeMethods.BodyDestroy(Body);
849 Body = IntPtr.Zero; 962 Body = IntPtr.Zero;
850 } 963 }
851 964
852 //kill the Geoms 965 //kill the Geoms
853 if (capsule != IntPtr.Zero) 966 if(capsule != IntPtr.Zero)
854 { 967 {
855 m_parent_scene.actor_name_map.Remove(capsule); 968 m_parent_scene.actor_name_map.Remove(capsule);
856 m_parent_scene.waitForSpaceUnlock(collider); 969 m_parent_scene.waitForSpaceUnlock(collider);
857 d.GeomDestroy(capsule); 970 SafeNativeMethods.GeomDestroy(capsule);
858 capsule = IntPtr.Zero; 971 capsule = IntPtr.Zero;
859 } 972 }
860 973
861 if (collider != IntPtr.Zero) 974 if(collider != IntPtr.Zero)
862 { 975 {
863 d.SpaceDestroy(collider); 976 SafeNativeMethods.SpaceDestroy(collider);
864 collider = IntPtr.Zero; 977 collider = IntPtr.Zero;
865 } 978 }
866 979
867 } 980 }
868 981
869 //in place 2D rotation around Z assuming rot is normalised and is a rotation around Z 982 //in place 2D rotation around Z assuming rot is normalised and is a rotation around Z
870 public void RotateXYonZ(ref float x, ref float y, ref Quaternion rot) 983 public void RotateXYonZ(ref float x,ref float y,ref Quaternion rot)
871 { 984 {
872 float sin = 2.0f * rot.Z * rot.W; 985 float sin = 2.0f * rot.Z * rot.W;
873 float cos = rot.W * rot.W - rot.Z * rot.Z; 986 float cos = rot.W * rot.W - rot.Z * rot.Z;
@@ -876,22 +989,22 @@ namespace OpenSim.Region.PhysicsModule.ubOde
876 x = tx * cos - y * sin; 989 x = tx * cos - y * sin;
877 y = tx * sin + y * cos; 990 y = tx * sin + y * cos;
878 } 991 }
879 public void RotateXYonZ(ref float x, ref float y, ref float sin, ref float cos) 992 public void RotateXYonZ(ref float x,ref float y,ref float sin,ref float cos)
880 { 993 {
881 float tx = x; 994 float tx = x;
882 x = tx * cos - y * sin; 995 x = tx * cos - y * sin;
883 y = tx * sin + y * cos; 996 y = tx * sin + y * cos;
884 } 997 }
885 public void invRotateXYonZ(ref float x, ref float y, ref float sin, ref float cos) 998 public void invRotateXYonZ(ref float x,ref float y,ref float sin,ref float cos)
886 { 999 {
887 float tx = x; 1000 float tx = x;
888 x = tx * cos + y * sin; 1001 x = tx * cos + y * sin;
889 y = -tx * sin + y * cos; 1002 y = -tx * sin + y * cos;
890 } 1003 }
891 1004
892 public void invRotateXYonZ(ref float x, ref float y, ref Quaternion rot) 1005 public void invRotateXYonZ(ref float x,ref float y,ref Quaternion rot)
893 { 1006 {
894 float sin = - 2.0f * rot.Z * rot.W; 1007 float sin = -2.0f * rot.Z * rot.W;
895 float cos = rot.W * rot.W - rot.Z * rot.Z; 1008 float cos = rot.W * rot.W - rot.Z * rot.Z;
896 float tx = x; 1009 float tx = x;
897 1010
@@ -899,13 +1012,13 @@ namespace OpenSim.Region.PhysicsModule.ubOde
899 y = tx * sin + y * cos; 1012 y = tx * sin + y * cos;
900 } 1013 }
901 1014
902 public bool Collide(IntPtr me, IntPtr other, bool reverse, ref d.ContactGeom contact, 1015 internal bool Collide(IntPtr me,IntPtr other,bool reverse,ref SafeNativeMethods.ContactGeom contact,
903 ref d.ContactGeom altContact , ref bool useAltcontact, ref bool feetcollision) 1016 ref SafeNativeMethods.ContactGeom altContact,ref bool useAltcontact,ref bool feetcollision)
904 { 1017 {
905 feetcollision = false; 1018 feetcollision = false;
906 useAltcontact = false; 1019 useAltcontact = false;
907 1020
908 if (me == capsule) 1021 if(me == capsule)
909 { 1022 {
910 Vector3 offset; 1023 Vector3 offset;
911 1024
@@ -915,25 +1028,25 @@ namespace OpenSim.Region.PhysicsModule.ubOde
915 offset.X = contact.pos.X - _position.X; 1028 offset.X = contact.pos.X - _position.X;
916 offset.Y = contact.pos.Y - _position.Y; 1029 offset.Y = contact.pos.Y - _position.Y;
917 1030
918 d.GeomClassID gtype = d.GeomGetClass(other); 1031 SafeNativeMethods.GeomClassID gtype = SafeNativeMethods.GeomGetClass(other);
919 if (gtype == d.GeomClassID.CapsuleClass) 1032 if(gtype == SafeNativeMethods.GeomClassID.CapsuleClass)
920 { 1033 {
921 Vector3 roff = offset * Quaternion.Inverse(m_orientation2D); 1034 Vector3 roff = offset * Quaternion.Inverse(m_orientation2D);
922 float r = roff.X *roff.X / AvaAvaSizeXsq; 1035 float r = roff.X *roff.X / AvaAvaSizeXsq;
923 r += (roff.Y * roff.Y) / AvaAvaSizeYsq; 1036 r += (roff.Y * roff.Y) / AvaAvaSizeYsq;
924 if (r > 1.0f) 1037 if(r > 1.0f)
925 return false; 1038 return false;
926 1039
927 float dp = 1.0f -(float)Math.Sqrt((double)r); 1040 float dp = 1.0f -(float)Math.Sqrt((double)r);
928 if (dp > 0.05f) 1041 if(dp > 0.05f)
929 dp = 0.05f; 1042 dp = 0.05f;
930 1043
931 contact.depth = dp; 1044 contact.depth = dp;
932 1045
933 if (offset.Z < 0) 1046 if(offset.Z < 0)
934 { 1047 {
935 feetcollision = true; 1048 feetcollision = true;
936 if (h < boneOff) 1049 if(h < boneOff)
937 { 1050 {
938 m_collideNormal.X = contact.normal.X; 1051 m_collideNormal.X = contact.normal.X;
939 m_collideNormal.Y = contact.normal.Y; 1052 m_collideNormal.Y = contact.normal.Y;
@@ -944,18 +1057,18 @@ namespace OpenSim.Region.PhysicsModule.ubOde
944 return true; 1057 return true;
945 } 1058 }
946 1059
947 if (gtype == d.GeomClassID.SphereClass && d.GeomGetBody(other) != IntPtr.Zero) 1060 if(gtype == SafeNativeMethods.GeomClassID.SphereClass && SafeNativeMethods.GeomGetBody(other) != IntPtr.Zero)
948 { 1061 {
949 if(d.GeomSphereGetRadius(other) < 0.5) 1062 if(SafeNativeMethods.GeomSphereGetRadius(other) < 0.5)
950 return true; 1063 return true;
951 } 1064 }
952 1065
953 if (offset.Z > 0 || contact.normal.Z > 0.35f) 1066 if(offset.Z > 0 || contact.normal.Z > 0.35f)
954 { 1067 {
955 if (offset.Z <= 0) 1068 if(offset.Z <= 0)
956 { 1069 {
957 feetcollision = true; 1070 feetcollision = true;
958 if (h < boneOff) 1071 if(h < boneOff)
959 { 1072 {
960 m_collideNormal.X = contact.normal.X; 1073 m_collideNormal.X = contact.normal.X;
961 m_collideNormal.Y = contact.normal.Y; 1074 m_collideNormal.Y = contact.normal.Y;
@@ -970,7 +1083,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
970 return true; 1083 return true;
971 1084
972 feetcollision = true; 1085 feetcollision = true;
973 if (h < boneOff) 1086 if(h < boneOff)
974 { 1087 {
975 m_collideNormal.X = contact.normal.X; 1088 m_collideNormal.X = contact.normal.X;
976 m_collideNormal.Y = contact.normal.Y; 1089 m_collideNormal.Y = contact.normal.Y;
@@ -990,18 +1103,18 @@ namespace OpenSim.Region.PhysicsModule.ubOde
990 t = Math.Abs(t); 1103 t = Math.Abs(t);
991 if(t > 1e-6) 1104 if(t > 1e-6)
992 { 1105 {
993 tdp /= t; 1106 tdp /= t;
994 tdp *= contact.normal.X; 1107 tdp *= contact.normal.X;
995 } 1108 }
996 else 1109 else
997 tdp *= 10; 1110 tdp *= 10;
998 1111
999 if (tdp > 0.25f) 1112 if(tdp > 0.25f)
1000 tdp = 0.25f; 1113 tdp = 0.25f;
1001 1114
1002 altContact.depth = tdp; 1115 altContact.depth = tdp;
1003 1116
1004 if (reverse) 1117 if(reverse)
1005 { 1118 {
1006 altContact.normal.X = offset.X; 1119 altContact.normal.X = offset.X;
1007 altContact.normal.Y = offset.Y; 1120 altContact.normal.Y = offset.Y;
@@ -1025,28 +1138,28 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1025 /// <param name="timeStep"></param> 1138 /// <param name="timeStep"></param>
1026 public void Move(List<OdeCharacter> defects) 1139 public void Move(List<OdeCharacter> defects)
1027 { 1140 {
1028 if (Body == IntPtr.Zero) 1141 if(Body == IntPtr.Zero)
1029 return; 1142 return;
1030 1143
1031 d.Vector3 dtmp = d.BodyGetPosition(Body); 1144 SafeNativeMethods.Vector3 dtmp = SafeNativeMethods.BodyGetPosition(Body);
1032 Vector3 localpos = new Vector3(dtmp.X, dtmp.Y, dtmp.Z); 1145 Vector3 localpos = new Vector3(dtmp.X,dtmp.Y,dtmp.Z);
1033 1146
1034 // the Amotor still lets avatar rotation to drift during colisions 1147 // the Amotor still lets avatar rotation to drift during colisions
1035 // so force it back to identity 1148 // so force it back to identity
1036 1149
1037 d.Quaternion qtmp; 1150 SafeNativeMethods.Quaternion qtmp;
1038 qtmp.W = m_orientation2D.W; 1151 qtmp.W = m_orientation2D.W;
1039 qtmp.X = m_orientation2D.X; 1152 qtmp.X = m_orientation2D.X;
1040 qtmp.Y = m_orientation2D.Y; 1153 qtmp.Y = m_orientation2D.Y;
1041 qtmp.Z = m_orientation2D.Z; 1154 qtmp.Z = m_orientation2D.Z;
1042 d.BodySetQuaternion(Body, ref qtmp); 1155 SafeNativeMethods.BodySetQuaternion(Body,ref qtmp);
1043 1156
1044 if (m_pidControllerActive == false) 1157 if(m_pidControllerActive == false)
1045 { 1158 {
1046 _zeroPosition = localpos; 1159 _zeroPosition = localpos;
1047 } 1160 }
1048 1161
1049 if (!localpos.IsFinite()) 1162 if(!localpos.IsFinite())
1050 { 1163 {
1051 m_log.Warn("[PHYSICS]: Avatar Position is non-finite!"); 1164 m_log.Warn("[PHYSICS]: Avatar Position is non-finite!");
1052 defects.Add(this); 1165 defects.Add(this);
@@ -1059,44 +1172,44 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1059 1172
1060 // check outbounds forcing to be in world 1173 // check outbounds forcing to be in world
1061 bool fixbody = false; 1174 bool fixbody = false;
1062 if (localpos.X < 0.0f) 1175 if(localpos.X < 0.0f)
1063 { 1176 {
1064 fixbody = true; 1177 fixbody = true;
1065 localpos.X = 0.1f; 1178 localpos.X = 0.1f;
1066 } 1179 }
1067 else if (localpos.X > m_parent_scene.WorldExtents.X - 0.1f) 1180 else if(localpos.X > m_parent_scene.WorldExtents.X - 0.1f)
1068 { 1181 {
1069 fixbody = true; 1182 fixbody = true;
1070 localpos.X = m_parent_scene.WorldExtents.X - 0.1f; 1183 localpos.X = m_parent_scene.WorldExtents.X - 0.1f;
1071 } 1184 }
1072 if (localpos.Y < 0.0f) 1185 if(localpos.Y < 0.0f)
1073 { 1186 {
1074 fixbody = true; 1187 fixbody = true;
1075 localpos.Y = 0.1f; 1188 localpos.Y = 0.1f;
1076 } 1189 }
1077 else if (localpos.Y > m_parent_scene.WorldExtents.Y - 0.1) 1190 else if(localpos.Y > m_parent_scene.WorldExtents.Y - 0.1)
1078 { 1191 {
1079 fixbody = true; 1192 fixbody = true;
1080 localpos.Y = m_parent_scene.WorldExtents.Y - 0.1f; 1193 localpos.Y = m_parent_scene.WorldExtents.Y - 0.1f;
1081 } 1194 }
1082 if (fixbody) 1195 if(fixbody)
1083 { 1196 {
1084 m_freemove = false; 1197 m_freemove = false;
1085 d.BodySetPosition(Body, localpos.X, localpos.Y, localpos.Z); 1198 SafeNativeMethods.BodySetPosition(Body,localpos.X,localpos.Y,localpos.Z);
1086 } 1199 }
1087 1200
1088 float breakfactor; 1201 float breakfactor;
1089 1202
1090 Vector3 vec = Vector3.Zero; 1203 Vector3 vec = Vector3.Zero;
1091 dtmp = d.BodyGetLinearVel(Body); 1204 dtmp = SafeNativeMethods.BodyGetLinearVel(Body);
1092 Vector3 vel = new Vector3(dtmp.X, dtmp.Y, dtmp.Z); 1205 Vector3 vel = new Vector3(dtmp.X,dtmp.Y,dtmp.Z);
1093 float velLengthSquared = vel.LengthSquared(); 1206 float velLengthSquared = vel.LengthSquared();
1094 1207
1095 Vector3 ctz = _target_velocity; 1208 Vector3 ctz = _target_velocity;
1096 1209
1097 float movementdivisor = 1f; 1210 float movementdivisor = 1f;
1098 //Ubit change divisions into multiplications below 1211 //Ubit change divisions into multiplications below
1099 if (!m_alwaysRun) 1212 if(!m_alwaysRun)
1100 movementdivisor = 1 / walkDivisor; 1213 movementdivisor = 1 / walkDivisor;
1101 else 1214 else
1102 movementdivisor = 1 / runDivisor; 1215 movementdivisor = 1 / runDivisor;
@@ -1107,25 +1220,25 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1107 //****************************************** 1220 //******************************************
1108 // colide with land 1221 // colide with land
1109 1222
1110 d.AABB aabb; 1223 SafeNativeMethods.AABB aabb;
1111// d.GeomGetAABB(feetbox, out aabb); 1224 // d.GeomGetAABB(feetbox, out aabb);
1112 d.GeomGetAABB(capsule, out aabb); 1225 SafeNativeMethods.GeomGetAABB(capsule,out aabb);
1113 float chrminZ = aabb.MinZ; // move up a bit 1226 float chrminZ = aabb.MinZ; // move up a bit
1114 Vector3 posch = localpos; 1227 Vector3 posch = localpos;
1115 1228
1116 float ftmp; 1229 float ftmp;
1117 1230
1118 if (m_flying) 1231 if(m_flying)
1119 { 1232 {
1120 ftmp = timeStep; 1233 ftmp = timeStep;
1121 posch.X += vel.X * ftmp; 1234 posch.X += vel.X * ftmp;
1122 posch.Y += vel.Y * ftmp; 1235 posch.Y += vel.Y * ftmp;
1123 } 1236 }
1124 1237
1125 float terrainheight = m_parent_scene.GetTerrainHeightAtXY(posch.X, posch.Y); 1238 float terrainheight = m_parent_scene.GetTerrainHeightAtXY(posch.X,posch.Y);
1126 if (chrminZ < terrainheight) 1239 if(chrminZ < terrainheight)
1127 { 1240 {
1128 if (ctz.Z < 0) 1241 if(ctz.Z < 0)
1129 ctz.Z = 0; 1242 ctz.Z = 0;
1130 1243
1131 if(!m_haveLastFallVel) 1244 if(!m_haveLastFallVel)
@@ -1134,12 +1247,12 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1134 m_haveLastFallVel = true; 1247 m_haveLastFallVel = true;
1135 } 1248 }
1136 1249
1137 Vector3 n = m_parent_scene.GetTerrainNormalAtXY(posch.X, posch.Y); 1250 Vector3 n = m_parent_scene.GetTerrainNormalAtXY(posch.X,posch.Y);
1138 float depth = terrainheight - chrminZ; 1251 float depth = terrainheight - chrminZ;
1139 1252
1140 vec.Z = depth * PID_P * 50; 1253 vec.Z = depth * PID_P * 50;
1141 1254
1142 if (!m_flying) 1255 if(!m_flying)
1143 { 1256 {
1144 vec.Z += -vel.Z * PID_D; 1257 vec.Z += -vel.Z * PID_D;
1145 if(n.Z < 0.4f) 1258 if(n.Z < 0.4f)
@@ -1155,19 +1268,19 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1155 n.X = 0f; 1268 n.X = 0f;
1156 n.Y = 0f; 1269 n.Y = 0f;
1157 n.Z = 1.0f; 1270 n.Z = 1.0f;
1158 } 1271 }
1159 } 1272 }
1160 } 1273 }
1161 1274
1162 if (depth < 0.2f) 1275 if(depth < 0.2f)
1163 { 1276 {
1164 m_colliderGroundfilter++; 1277 m_colliderGroundfilter++;
1165 if (m_colliderGroundfilter > 2) 1278 if(m_colliderGroundfilter > 2)
1166 { 1279 {
1167 m_iscolliding = true; 1280 m_iscolliding = true;
1168 m_colliderfilter = 2; 1281 m_colliderfilter = 2;
1169 1282
1170 if (m_colliderGroundfilter > 10) 1283 if(m_colliderGroundfilter > 10)
1171 { 1284 {
1172 m_colliderGroundfilter = 10; 1285 m_colliderGroundfilter = 10;
1173 m_freemove = false; 1286 m_freemove = false;
@@ -1187,19 +1300,19 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1187 contact.SurfaceNormal.X = -n.X; 1300 contact.SurfaceNormal.X = -n.X;
1188 contact.SurfaceNormal.Y = -n.Y; 1301 contact.SurfaceNormal.Y = -n.Y;
1189 contact.SurfaceNormal.Z = -n.Z; 1302 contact.SurfaceNormal.Z = -n.Z;
1190 contact.RelativeSpeed = Vector3.Dot(m_lastFallVel, n); 1303 contact.RelativeSpeed = Vector3.Dot(m_lastFallVel,n);
1191 contact.CharacterFeet = true; 1304 contact.CharacterFeet = true;
1192 AddCollisionEvent(0, contact); 1305 AddCollisionEvent(0,contact);
1193 m_lastFallVel = vel; 1306 m_lastFallVel = vel;
1194 1307
1195// vec.Z *= 0.5f; 1308 // vec.Z *= 0.5f;
1196 } 1309 }
1197 } 1310 }
1198 1311
1199 else 1312 else
1200 { 1313 {
1201 m_colliderGroundfilter -= 5; 1314 m_colliderGroundfilter -= 5;
1202 if (m_colliderGroundfilter <= 0) 1315 if(m_colliderGroundfilter <= 0)
1203 { 1316 {
1204 m_colliderGroundfilter = 0; 1317 m_colliderGroundfilter = 0;
1205 m_iscollidingGround = false; 1318 m_iscollidingGround = false;
@@ -1210,7 +1323,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1210 { 1323 {
1211 m_haveLastFallVel = false; 1324 m_haveLastFallVel = false;
1212 m_colliderGroundfilter -= 5; 1325 m_colliderGroundfilter -= 5;
1213 if (m_colliderGroundfilter <= 0) 1326 if(m_colliderGroundfilter <= 0)
1214 { 1327 {
1215 m_colliderGroundfilter = 0; 1328 m_colliderGroundfilter = 0;
1216 m_iscollidingGround = false; 1329 m_iscollidingGround = false;
@@ -1219,11 +1332,11 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1219 1332
1220 bool hoverPIDActive = false; 1333 bool hoverPIDActive = false;
1221 1334
1222 if (m_useHoverPID && m_PIDHoverTau != 0 && m_PIDHoverHeight != 0) 1335 if(m_useHoverPID && m_PIDHoverTau != 0 && m_PIDHoverHeight != 0)
1223 { 1336 {
1224 hoverPIDActive = true; 1337 hoverPIDActive = true;
1225 1338
1226 switch (m_PIDHoverType) 1339 switch(m_PIDHoverType)
1227 { 1340 {
1228 case PIDHoverType.Ground: 1341 case PIDHoverType.Ground:
1229 m_targetHoverHeight = terrainheight + m_PIDHoverHeight; 1342 m_targetHoverHeight = terrainheight + m_PIDHoverHeight;
@@ -1231,20 +1344,20 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1231 1344
1232 case PIDHoverType.GroundAndWater: 1345 case PIDHoverType.GroundAndWater:
1233 float waterHeight = m_parent_scene.GetWaterLevel(); 1346 float waterHeight = m_parent_scene.GetWaterLevel();
1234 if (terrainheight > waterHeight) 1347 if(terrainheight > waterHeight)
1235 m_targetHoverHeight = terrainheight + m_PIDHoverHeight; 1348 m_targetHoverHeight = terrainheight + m_PIDHoverHeight;
1236 else 1349 else
1237 m_targetHoverHeight = waterHeight + m_PIDHoverHeight; 1350 m_targetHoverHeight = waterHeight + m_PIDHoverHeight;
1238 break; 1351 break;
1239 } // end switch (m_PIDHoverType) 1352 } // end switch (m_PIDHoverType)
1240 1353
1241 // don't go underground 1354 // don't go underground
1242 if (m_targetHoverHeight > terrainheight + 0.5f * (aabb.MaxZ - aabb.MinZ)) 1355 if(m_targetHoverHeight > terrainheight + 0.5f * (aabb.MaxZ - aabb.MinZ))
1243 { 1356 {
1244 float fz = (m_targetHoverHeight - localpos.Z); 1357 float fz = (m_targetHoverHeight - localpos.Z);
1245 1358
1246 // if error is zero, use position control; otherwise, velocity control 1359 // if error is zero, use position control; otherwise, velocity control
1247 if (Math.Abs(fz) < 0.01f) 1360 if(Math.Abs(fz) < 0.01f)
1248 { 1361 {
1249 ctz.Z = 0; 1362 ctz.Z = 0;
1250 } 1363 }
@@ -1254,9 +1367,9 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1254 fz /= m_PIDHoverTau; 1367 fz /= m_PIDHoverTau;
1255 1368
1256 float tmp = Math.Abs(fz); 1369 float tmp = Math.Abs(fz);
1257 if (tmp > 50) 1370 if(tmp > 50)
1258 fz = 50 * Math.Sign(fz); 1371 fz = 50 * Math.Sign(fz);
1259 else if (tmp < 0.1) 1372 else if(tmp < 0.1)
1260 fz = 0.1f * Math.Sign(fz); 1373 fz = 0.1f * Math.Sign(fz);
1261 1374
1262 ctz.Z = fz; 1375 ctz.Z = fz;
@@ -1265,43 +1378,43 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1265 } 1378 }
1266 1379
1267 //****************************************** 1380 //******************************************
1268 if (!m_iscolliding) 1381 if(!m_iscolliding)
1269 m_collideNormal.Z = 0; 1382 m_collideNormal.Z = 0;
1270 1383
1271 bool tviszero = (ctz.X == 0.0f && ctz.Y == 0.0f && ctz.Z == 0.0f); 1384 bool tviszero = (ctz.X == 0.0f && ctz.Y == 0.0f && ctz.Z == 0.0f);
1272 1385
1273 if (!tviszero) 1386 if(!tviszero)
1274 { 1387 {
1275 m_freemove = false; 1388 m_freemove = false;
1276 1389
1277 // movement relative to surface if moving on it 1390 // movement relative to surface if moving on it
1278 // dont disturbe vertical movement, ie jumps 1391 // dont disturbe vertical movement, ie jumps
1279 if (m_iscolliding && !m_flying && ctz.Z == 0 && m_collideNormal.Z > 0.2f && m_collideNormal.Z < 0.94f) 1392 if(m_iscolliding && !m_flying && ctz.Z == 0 && m_collideNormal.Z > 0.2f && m_collideNormal.Z < 0.94f)
1280 { 1393 {
1281 float p = ctz.X * m_collideNormal.X + ctz.Y * m_collideNormal.Y; 1394 float p = ctz.X * m_collideNormal.X + ctz.Y * m_collideNormal.Y;
1282 ctz.X *= (float)Math.Sqrt(1 - m_collideNormal.X * m_collideNormal.X); 1395 ctz.X *= (float)Math.Sqrt(1 - m_collideNormal.X * m_collideNormal.X);
1283 ctz.Y *= (float)Math.Sqrt(1 - m_collideNormal.Y * m_collideNormal.Y); 1396 ctz.Y *= (float)Math.Sqrt(1 - m_collideNormal.Y * m_collideNormal.Y);
1284 ctz.Z -= p; 1397 ctz.Z -= p;
1285 if (ctz.Z < 0) 1398 if(ctz.Z < 0)
1286 ctz.Z *= 2; 1399 ctz.Z *= 2;
1287 1400
1288 } 1401 }
1289 1402
1290 } 1403 }
1291 1404
1292 if (!m_freemove) 1405 if(!m_freemove)
1293 { 1406 {
1294 1407
1295 // if velocity is zero, use position control; otherwise, velocity control 1408 // if velocity is zero, use position control; otherwise, velocity control
1296 if (tviszero && m_iscolliding && !m_flying) 1409 if(tviszero && m_iscolliding && !m_flying)
1297 { 1410 {
1298 // keep track of where we stopped. No more slippin' & slidin' 1411 // keep track of where we stopped. No more slippin' & slidin'
1299 if (!_zeroFlag) 1412 if(!_zeroFlag)
1300 { 1413 {
1301 _zeroFlag = true; 1414 _zeroFlag = true;
1302 _zeroPosition = localpos; 1415 _zeroPosition = localpos;
1303 } 1416 }
1304 if (m_pidControllerActive) 1417 if(m_pidControllerActive)
1305 { 1418 {
1306 // We only want to deactivate the PID Controller if we think we want to have our surrogate 1419 // We only want to deactivate the PID Controller if we think we want to have our surrogate
1307 // react to the physics scene by moving it's position. 1420 // react to the physics scene by moving it's position.
@@ -1314,12 +1427,12 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1314 vec.Z += -vel.Z * PID_D + (_zeroPosition.Z - localpos.Z) * PID_P; 1427 vec.Z += -vel.Z * PID_D + (_zeroPosition.Z - localpos.Z) * PID_P;
1315 else 1428 else
1316 vec.Z += (-vel.Z * PID_D + (_zeroPosition.Z - localpos.Z) * PID_P) * 0.2f; 1429 vec.Z += (-vel.Z * PID_D + (_zeroPosition.Z - localpos.Z) * PID_P) * 0.2f;
1317/* 1430 /*
1318 if (flying) 1431 if (flying)
1319 { 1432 {
1320 vec.Z += -vel.Z * PID_D + (_zeroPosition.Z - localpos.Z) * PID_P; 1433 vec.Z += -vel.Z * PID_D + (_zeroPosition.Z - localpos.Z) * PID_P;
1321 } 1434 }
1322*/ 1435 */
1323 } 1436 }
1324 //PidStatus = true; 1437 //PidStatus = true;
1325 } 1438 }
@@ -1328,12 +1441,12 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1328 m_pidControllerActive = true; 1441 m_pidControllerActive = true;
1329 _zeroFlag = false; 1442 _zeroFlag = false;
1330 1443
1331 if (m_iscolliding) 1444 if(m_iscolliding)
1332 { 1445 {
1333 if (!m_flying) 1446 if(!m_flying)
1334 { 1447 {
1335 // we are on a surface 1448 // we are on a surface
1336 if (ctz.Z > 0f) 1449 if(ctz.Z > 0f)
1337 { 1450 {
1338 // moving up or JUMPING 1451 // moving up or JUMPING
1339 vec.Z += (ctz.Z - vel.Z) * PID_D * 2f; 1452 vec.Z += (ctz.Z - vel.Z) * PID_D * 2f;
@@ -1343,9 +1456,9 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1343 else 1456 else
1344 { 1457 {
1345 // we are moving down on a surface 1458 // we are moving down on a surface
1346 if (ctz.Z == 0) 1459 if(ctz.Z == 0)
1347 { 1460 {
1348 if (vel.Z > 0) 1461 if(vel.Z > 0)
1349 vec.Z -= vel.Z * PID_D * 2f; 1462 vec.Z -= vel.Z * PID_D * 2f;
1350 vec.X += (ctz.X - vel.X) * (PID_D); 1463 vec.X += (ctz.X - vel.X) * (PID_D);
1351 vec.Y += (ctz.Y - vel.Y) * (PID_D); 1464 vec.Y += (ctz.Y - vel.Y) * (PID_D);
@@ -1353,15 +1466,15 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1353 // intencionally going down 1466 // intencionally going down
1354 else 1467 else
1355 { 1468 {
1356 if (ctz.Z < vel.Z) 1469 if(ctz.Z < vel.Z)
1357 vec.Z += (ctz.Z - vel.Z) * PID_D; 1470 vec.Z += (ctz.Z - vel.Z) * PID_D;
1358 else 1471 else
1359 { 1472 {
1360 } 1473 }
1361 1474
1362 if (Math.Abs(ctz.X) > Math.Abs(vel.X)) 1475 if(Math.Abs(ctz.X) > Math.Abs(vel.X))
1363 vec.X += (ctz.X - vel.X) * (PID_D); 1476 vec.X += (ctz.X - vel.X) * (PID_D);
1364 if (Math.Abs(ctz.Y) > Math.Abs(vel.Y)) 1477 if(Math.Abs(ctz.Y) > Math.Abs(vel.Y))
1365 vec.Y += (ctz.Y - vel.Y) * (PID_D); 1478 vec.Y += (ctz.Y - vel.Y) * (PID_D);
1366 } 1479 }
1367 } 1480 }
@@ -1378,7 +1491,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1378 } 1491 }
1379 else // ie not colliding 1492 else // ie not colliding
1380 { 1493 {
1381 if (m_flying || hoverPIDActive) //(!m_iscolliding && flying) 1494 if(m_flying || hoverPIDActive) //(!m_iscolliding && flying)
1382 { 1495 {
1383 // we're in mid air suspended 1496 // we're in mid air suspended
1384 vec.X += (ctz.X - vel.X) * (PID_D); 1497 vec.X += (ctz.X - vel.X) * (PID_D);
@@ -1395,13 +1508,13 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1395 vec.X += (ctz.X - vel.X) * PID_D * 0.833f; 1508 vec.X += (ctz.X - vel.X) * PID_D * 0.833f;
1396 vec.Y += (ctz.Y - vel.Y) * PID_D * 0.833f; 1509 vec.Y += (ctz.Y - vel.Y) * PID_D * 0.833f;
1397 // hack for breaking on fall 1510 // hack for breaking on fall
1398 if (ctz.Z == -9999f) 1511 if(ctz.Z == -9999f)
1399 vec.Z += -vel.Z * PID_D - m_parent_scene.gravityz * m_mass; 1512 vec.Z += -vel.Z * PID_D - m_parent_scene.gravityz * m_mass;
1400 } 1513 }
1401 } 1514 }
1402 } 1515 }
1403 1516
1404 if (velLengthSquared > 2500.0f) // 50m/s apply breaks 1517 if(velLengthSquared > 2500.0f) // 50m/s apply breaks
1405 { 1518 {
1406 breakfactor = 0.16f * m_mass; 1519 breakfactor = 0.16f * m_mass;
1407 vec.X -= breakfactor * vel.X; 1520 vec.X -= breakfactor * vel.X;
@@ -1414,13 +1527,13 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1414 breakfactor = m_mass; 1527 breakfactor = m_mass;
1415 vec.X -= breakfactor * vel.X; 1528 vec.X -= breakfactor * vel.X;
1416 vec.Y -= breakfactor * vel.Y; 1529 vec.Y -= breakfactor * vel.Y;
1417 if (m_flying) 1530 if(m_flying)
1418 vec.Z -= 0.5f * breakfactor * vel.Z; 1531 vec.Z -= 0.5f * breakfactor * vel.Z;
1419 else 1532 else
1420 vec.Z -= .16f* m_mass * vel.Z; 1533 vec.Z -= .16f* m_mass * vel.Z;
1421 } 1534 }
1422 1535
1423 if (m_flying || hoverPIDActive) 1536 if(m_flying || hoverPIDActive)
1424 { 1537 {
1425 vec.Z -= m_parent_scene.gravityz * m_mass; 1538 vec.Z -= m_parent_scene.gravityz * m_mass;
1426 1539
@@ -1429,18 +1542,18 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1429 //Added for auto fly height. Kitto Flora 1542 //Added for auto fly height. Kitto Flora
1430 float target_altitude = terrainheight + MinimumGroundFlightOffset; 1543 float target_altitude = terrainheight + MinimumGroundFlightOffset;
1431 1544
1432 if (localpos.Z < target_altitude) 1545 if(localpos.Z < target_altitude)
1433 { 1546 {
1434 vec.Z += (target_altitude - localpos.Z) * PID_P * 5.0f; 1547 vec.Z += (target_altitude - localpos.Z) * PID_P * 5.0f;
1435 } 1548 }
1436 // end add Kitto Flora 1549 // end add Kitto Flora
1437 } 1550 }
1438 } 1551 }
1439 1552
1440 if (vec.IsFinite()) 1553 if(vec.IsFinite())
1441 { 1554 {
1442 if (vec.X != 0 || vec.Y !=0 || vec.Z !=0) 1555 if(vec.X != 0 || vec.Y !=0 || vec.Z !=0)
1443 d.BodyAddForce(Body, vec.X, vec.Y, vec.Z); 1556 SafeNativeMethods.BodyAddForce(Body,vec.X,vec.Y,vec.Z);
1444 } 1557 }
1445 else 1558 else
1446 { 1559 {
@@ -1457,7 +1570,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1457 // _position = localpos; 1570 // _position = localpos;
1458 _position = localpos; 1571 _position = localpos;
1459 1572
1460 if (_zeroFlag) 1573 if(_zeroFlag)
1461 { 1574 {
1462 _velocity = Vector3.Zero; 1575 _velocity = Vector3.Zero;
1463 _acceleration = Vector3.Zero; 1576 _acceleration = Vector3.Zero;
@@ -1465,12 +1578,12 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1465 } 1578 }
1466 else 1579 else
1467 { 1580 {
1468 Vector3 a =_velocity; // previus velocity 1581 Vector3 a = _velocity; // previus velocity
1469 SetSmooth(ref _velocity, ref vel, 2); 1582 SetSmooth(ref _velocity,ref vel,2);
1470 a = (_velocity - a) * invtimeStep; 1583 a = (_velocity - a) * invtimeStep;
1471 SetSmooth(ref _acceleration, ref a, 2); 1584 SetSmooth(ref _acceleration,ref a,2);
1472 1585
1473 dtmp = d.BodyGetAngularVel(Body); 1586 dtmp = SafeNativeMethods.BodyGetAngularVel(Body);
1474 m_rotationalVelocity.X = 0f; 1587 m_rotationalVelocity.X = 0f;
1475 m_rotationalVelocity.Y = 0f; 1588 m_rotationalVelocity.Y = 0f;
1476 m_rotationalVelocity.Z = dtmp.Z; 1589 m_rotationalVelocity.Z = dtmp.Z;
@@ -1478,30 +1591,30 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1478 } 1591 }
1479 } 1592 }
1480 1593
1481 public void round(ref Vector3 v, int digits) 1594 public void round(ref Vector3 v,int digits)
1482 { 1595 {
1483 v.X = (float)Math.Round(v.X, digits); 1596 v.X = (float)Math.Round(v.X,digits);
1484 v.Y = (float)Math.Round(v.Y, digits); 1597 v.Y = (float)Math.Round(v.Y,digits);
1485 v.Z = (float)Math.Round(v.Z, digits); 1598 v.Z = (float)Math.Round(v.Z,digits);
1486 } 1599 }
1487 1600
1488 public void SetSmooth(ref Vector3 dst, ref Vector3 value) 1601 public void SetSmooth(ref Vector3 dst,ref Vector3 value)
1489 { 1602 {
1490 dst.X = 0.1f * dst.X + 0.9f * value.X; 1603 dst.X = 0.1f * dst.X + 0.9f * value.X;
1491 dst.Y = 0.1f * dst.Y + 0.9f * value.Y; 1604 dst.Y = 0.1f * dst.Y + 0.9f * value.Y;
1492 dst.Z = 0.1f * dst.Z + 0.9f * value.Z; 1605 dst.Z = 0.1f * dst.Z + 0.9f * value.Z;
1493 } 1606 }
1494 1607
1495 public void SetSmooth(ref Vector3 dst, ref Vector3 value, int rounddigits) 1608 public void SetSmooth(ref Vector3 dst,ref Vector3 value,int rounddigits)
1496 { 1609 {
1497 dst.X = 0.4f * dst.X + 0.6f * value.X; 1610 dst.X = 0.4f * dst.X + 0.6f * value.X;
1498 dst.X = (float)Math.Round(dst.X, rounddigits); 1611 dst.X = (float)Math.Round(dst.X,rounddigits);
1499 1612
1500 dst.Y = 0.4f * dst.Y + 0.6f * value.Y; 1613 dst.Y = 0.4f * dst.Y + 0.6f * value.Y;
1501 dst.Y = (float)Math.Round(dst.Y, rounddigits); 1614 dst.Y = (float)Math.Round(dst.Y,rounddigits);
1502 1615
1503 dst.Z = 0.4f * dst.Z + 0.6f * value.Z; 1616 dst.Z = 0.4f * dst.Z + 0.6f * value.Z;
1504 dst.Z = (float)Math.Round(dst.Z, rounddigits); 1617 dst.Z = (float)Math.Round(dst.Z,rounddigits);
1505 } 1618 }
1506 1619
1507 1620
@@ -1516,8 +1629,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1516 { 1629 {
1517 return; 1630 return;
1518 1631
1519// if (Body == IntPtr.Zero) 1632 // if (Body == IntPtr.Zero)
1520// return; 1633 // return;
1521 1634
1522 } 1635 }
1523 1636
@@ -1526,16 +1639,38 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1526 /// </summary> 1639 /// </summary>
1527 public void Destroy() 1640 public void Destroy()
1528 { 1641 {
1529 AddChange(changes.Remove, null); 1642 AddChange(changes.Remove,null);
1530 } 1643 }
1531 1644
1532 public override void CrossingFailure() 1645 public override void CrossingFailure()
1533 { 1646 {
1534 } 1647 }
1535 1648
1536 public override Vector3 PIDTarget { set { return; } } 1649 public override Vector3 PIDTarget
1537 public override bool PIDActive {get {return m_pidControllerActive;} set { return; } } 1650 {
1538 public override float PIDTau { set { return; } } 1651 set
1652 {
1653 return;
1654 }
1655 }
1656 public override bool PIDActive
1657 {
1658 get
1659 {
1660 return m_pidControllerActive;
1661 }
1662 set
1663 {
1664 return;
1665 }
1666 }
1667 public override float PIDTau
1668 {
1669 set
1670 {
1671 return;
1672 }
1673 }
1539 1674
1540 public override float PIDHoverHeight 1675 public override float PIDHoverHeight
1541 { 1676 {
@@ -1548,11 +1683,11 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1548 { 1683 {
1549 get 1684 get
1550 { 1685 {
1551 return m_useHoverPID; 1686 return m_useHoverPID;
1552 } 1687 }
1553 set 1688 set
1554 { 1689 {
1555 AddChange(changes.PIDHoverActive, value); 1690 AddChange(changes.PIDHoverActive,value);
1556 } 1691 }
1557 } 1692 }
1558 1693
@@ -1568,26 +1703,50 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1568 { 1703 {
1569 set 1704 set
1570 { 1705 {
1571 float tmp =0; 1706 float tmp = 0;
1572 if (value > 0) 1707 if(value > 0)
1573 { 1708 {
1574 float mint = (0.05f > timeStep ? 0.05f : timeStep); 1709 float mint = (0.05f > timeStep ? 0.05f : timeStep);
1575 if (value < mint) 1710 if(value < mint)
1576 tmp = mint; 1711 tmp = mint;
1577 else 1712 else
1578 tmp = value; 1713 tmp = value;
1579 } 1714 }
1580 AddChange(changes.PIDHoverTau, tmp); 1715 AddChange(changes.PIDHoverTau,tmp);
1581 } 1716 }
1582 } 1717 }
1583 1718
1584 public override Quaternion APIDTarget { set { return; } } 1719 public override Quaternion APIDTarget
1720 {
1721 set
1722 {
1723 return;
1724 }
1725 }
1585 1726
1586 public override bool APIDActive { set { return; } } 1727 public override bool APIDActive
1728 {
1729 set
1730 {
1731 return;
1732 }
1733 }
1587 1734
1588 public override float APIDStrength { set { return; } } 1735 public override float APIDStrength
1736 {
1737 set
1738 {
1739 return;
1740 }
1741 }
1589 1742
1590 public override float APIDDamping { set { return; } } 1743 public override float APIDDamping
1744 {
1745 set
1746 {
1747 return;
1748 }
1749 }
1591 1750
1592 public override void SubscribeEvents(int ms) 1751 public override void SubscribeEvents(int ms)
1593 { 1752 {
@@ -1605,34 +1764,34 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1605 CollisionEventsThisFrame.Clear(); 1764 CollisionEventsThisFrame.Clear();
1606 } 1765 }
1607 1766
1608 public override void AddCollisionEvent(uint CollidedWith, ContactPoint contact) 1767 public override void AddCollisionEvent(uint CollidedWith,ContactPoint contact)
1609 { 1768 {
1610 lock(CollisionEventsThisFrame) 1769 lock(CollisionEventsThisFrame)
1611 CollisionEventsThisFrame.AddCollider(CollidedWith, contact); 1770 CollisionEventsThisFrame.AddCollider(CollidedWith,contact);
1612 m_parent_scene.AddCollisionEventReporting(this); 1771 m_parent_scene.AddCollisionEventReporting(this);
1613 } 1772 }
1614 1773
1615 public void SendCollisions(int timestep) 1774 public void SendCollisions(int timestep)
1616 { 1775 {
1617 if (m_cureventsubscription < 50000) 1776 if(m_cureventsubscription < 50000)
1618 m_cureventsubscription += timestep; 1777 m_cureventsubscription += timestep;
1619 1778
1620 if (m_cureventsubscription < m_eventsubscription) 1779 if(m_cureventsubscription < m_eventsubscription)
1621 return; 1780 return;
1622 1781
1623 lock(CollisionEventsThisFrame) 1782 lock(CollisionEventsThisFrame)
1624 { 1783 {
1625 int ncolisions = CollisionEventsThisFrame.m_objCollisionList.Count; 1784 int ncolisions = CollisionEventsThisFrame.m_objCollisionList.Count;
1626 1785
1627 if (!SentEmptyCollisionsEvent || ncolisions > 0) 1786 if(!SentEmptyCollisionsEvent || ncolisions > 0)
1628 { 1787 {
1629 base.SendCollisionUpdate(CollisionEventsThisFrame); 1788 base.SendCollisionUpdate(CollisionEventsThisFrame);
1630 m_cureventsubscription = 0; 1789 m_cureventsubscription = 0;
1631 1790
1632 if (ncolisions == 0) 1791 if(ncolisions == 0)
1633 { 1792 {
1634 SentEmptyCollisionsEvent = true; 1793 SentEmptyCollisionsEvent = true;
1635 // _parent_scene.RemoveCollisionEventReporting(this); 1794 // _parent_scene.RemoveCollisionEventReporting(this);
1636 } 1795 }
1637 else 1796 else
1638 { 1797 {
@@ -1645,20 +1804,20 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1645 1804
1646 public override bool SubscribedEvents() 1805 public override bool SubscribedEvents()
1647 { 1806 {
1648 if (m_eventsubscription > 0) 1807 if(m_eventsubscription > 0)
1649 return true; 1808 return true;
1650 return false; 1809 return false;
1651 } 1810 }
1652 1811
1653 private void changePhysicsStatus(bool NewStatus) 1812 private void changePhysicsStatus(bool NewStatus)
1654 { 1813 {
1655 if (NewStatus != m_isPhysical) 1814 if(NewStatus != m_isPhysical)
1656 { 1815 {
1657 if (NewStatus) 1816 if(NewStatus)
1658 { 1817 {
1659 AvatarGeomAndBodyDestroy(); 1818 AvatarGeomAndBodyDestroy();
1660 1819
1661 AvatarGeomAndBodyCreation(_position.X, _position.Y, _position.Z); 1820 AvatarGeomAndBodyCreation(_position.X,_position.Y,_position.Z);
1662 1821
1663 m_parent_scene.actor_name_map[collider] = (PhysicsActor)this; 1822 m_parent_scene.actor_name_map[collider] = (PhysicsActor)this;
1664 m_parent_scene.actor_name_map[capsule] = (PhysicsActor)this; 1823 m_parent_scene.actor_name_map[capsule] = (PhysicsActor)this;
@@ -1698,20 +1857,20 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1698 1857
1699 private void changeSize(Vector3 pSize) 1858 private void changeSize(Vector3 pSize)
1700 { 1859 {
1701 if (pSize.IsFinite()) 1860 if(pSize.IsFinite())
1702 { 1861 {
1703 // for now only look to Z changes since viewers also don't change X and Y 1862 // for now only look to Z changes since viewers also don't change X and Y
1704 if (pSize.Z != m_size.Z) 1863 if(pSize.Z != m_size.Z)
1705 { 1864 {
1706 AvatarGeomAndBodyDestroy(); 1865 AvatarGeomAndBodyDestroy();
1707 1866
1708 float oldsz = m_size.Z; 1867 float oldsz = m_size.Z;
1709 m_size = pSize; 1868 m_size = pSize;
1710 1869
1711 AvatarGeomAndBodyCreation(_position.X, _position.Y, 1870 AvatarGeomAndBodyCreation(_position.X,_position.Y,
1712 _position.Z + (m_size.Z - oldsz) * 0.5f); 1871 _position.Z + (m_size.Z - oldsz) * 0.5f);
1713 1872
1714// Velocity = Vector3.Zero; 1873 // Velocity = Vector3.Zero;
1715 m_targetVelocity = Vector3.Zero; 1874 m_targetVelocity = Vector3.Zero;
1716 1875
1717 m_parent_scene.actor_name_map[collider] = (PhysicsActor)this; 1876 m_parent_scene.actor_name_map[collider] = (PhysicsActor)this;
@@ -1726,18 +1885,18 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1726 } 1885 }
1727 } 1886 }
1728 1887
1729 private void changePosition( Vector3 newPos) 1888 private void changePosition(Vector3 newPos)
1730 { 1889 {
1731 if (Body != IntPtr.Zero) 1890 if(Body != IntPtr.Zero)
1732 d.BodySetPosition(Body, newPos.X, newPos.Y, newPos.Z); 1891 SafeNativeMethods.BodySetPosition(Body,newPos.X,newPos.Y,newPos.Z);
1733 _position = newPos; 1892 _position = newPos;
1734 m_freemove = false; 1893 m_freemove = false;
1735 m_pidControllerActive = true; 1894 m_pidControllerActive = true;
1736 } 1895 }
1737 1896
1738 private void changeOrientation(Quaternion newOri) 1897 private void changeOrientation(Quaternion newOri)
1739 { 1898 {
1740 if (m_orientation != newOri) 1899 if(m_orientation != newOri)
1741 { 1900 {
1742 m_orientation = newOri; // keep a copy for core use 1901 m_orientation = newOri; // keep a copy for core use
1743 // but only use rotations around Z 1902 // but only use rotations around Z
@@ -1746,7 +1905,7 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1746 m_orientation2D.Z = newOri.Z; 1905 m_orientation2D.Z = newOri.Z;
1747 1906
1748 float t = m_orientation2D.W * m_orientation2D.W + m_orientation2D.Z * m_orientation2D.Z; 1907 float t = m_orientation2D.W * m_orientation2D.W + m_orientation2D.Z * m_orientation2D.Z;
1749 if (t > 0) 1908 if(t > 0)
1750 { 1909 {
1751 t = 1.0f / (float)Math.Sqrt(t); 1910 t = 1.0f / (float)Math.Sqrt(t);
1752 m_orientation2D.W *= t; 1911 m_orientation2D.W *= t;
@@ -1760,12 +1919,12 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1760 m_orientation2D.Y = 0f; 1919 m_orientation2D.Y = 0f;
1761 m_orientation2D.X = 0f; 1920 m_orientation2D.X = 0f;
1762 1921
1763 d.Quaternion myrot = new d.Quaternion(); 1922 SafeNativeMethods.Quaternion myrot = new SafeNativeMethods.Quaternion();
1764 myrot.X = m_orientation2D.X; 1923 myrot.X = m_orientation2D.X;
1765 myrot.Y = m_orientation2D.Y; 1924 myrot.Y = m_orientation2D.Y;
1766 myrot.Z = m_orientation2D.Z; 1925 myrot.Z = m_orientation2D.Z;
1767 myrot.W = m_orientation2D.W; 1926 myrot.W = m_orientation2D.W;
1768 d.BodySetQuaternion(Body, ref myrot); 1927 SafeNativeMethods.BodySetQuaternion(Body,ref myrot);
1769 } 1928 }
1770 } 1929 }
1771 1930
@@ -1774,8 +1933,8 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1774 _velocity = newVel; 1933 _velocity = newVel;
1775 setFreeMove(); 1934 setFreeMove();
1776 1935
1777 if (Body != IntPtr.Zero) 1936 if(Body != IntPtr.Zero)
1778 d.BodySetLinearVel(Body, newVel.X, newVel.Y, newVel.Z); 1937 SafeNativeMethods.BodySetLinearVel(Body,newVel.X,newVel.Y,newVel.Z);
1779 } 1938 }
1780 1939
1781 private void changeTargetVelocity(Vector3 newVel) 1940 private void changeTargetVelocity(Vector3 newVel)
@@ -1842,10 +2001,10 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1842 { 2001 {
1843 setFreeMove(); 2002 setFreeMove();
1844 2003
1845 if (Body != IntPtr.Zero) 2004 if(Body != IntPtr.Zero)
1846 { 2005 {
1847 if (newForce.X != 0f || newForce.Y != 0f || newForce.Z != 0) 2006 if(newForce.X != 0f || newForce.Y != 0f || newForce.Z != 0)
1848 d.BodyAddForce(Body, newForce.X, newForce.Y, newForce.Z); 2007 SafeNativeMethods.BodyAddForce(Body,newForce.X,newForce.Y,newForce.Z);
1849 } 2008 }
1850 } 2009 }
1851 2010
@@ -1855,15 +2014,15 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1855 _velocity = newmomentum; 2014 _velocity = newmomentum;
1856 setFreeMove(); 2015 setFreeMove();
1857 2016
1858 if (Body != IntPtr.Zero) 2017 if(Body != IntPtr.Zero)
1859 d.BodySetLinearVel(Body, newmomentum.X, newmomentum.Y, newmomentum.Z); 2018 SafeNativeMethods.BodySetLinearVel(Body,newmomentum.X,newmomentum.Y,newmomentum.Z);
1860 } 2019 }
1861 2020
1862 private void changePIDHoverHeight(float val) 2021 private void changePIDHoverHeight(float val)
1863 { 2022 {
1864 m_PIDHoverHeight = val; 2023 m_PIDHoverHeight = val;
1865 if (val == 0) 2024 if(val == 0)
1866 m_useHoverPID = false; 2025 m_useHoverPID = false;
1867 } 2026 }
1868 2027
1869 private void changePIDHoverType(PIDHoverType type) 2028 private void changePIDHoverType(PIDHoverType type)
@@ -1885,15 +2044,15 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1885 { 2044 {
1886 } 2045 }
1887 2046
1888 public bool DoAChange(changes what, object arg) 2047 public bool DoAChange(changes what,object arg)
1889 { 2048 {
1890 if (collider == IntPtr.Zero && what != changes.Add && what != changes.Remove) 2049 if(collider == IntPtr.Zero && what != changes.Add && what != changes.Remove)
1891 { 2050 {
1892 return false; 2051 return false;
1893 } 2052 }
1894 2053
1895 // nasty switch 2054 // nasty switch
1896 switch (what) 2055 switch(what)
1897 { 2056 {
1898 case changes.Add: 2057 case changes.Add:
1899 changeAdd(); 2058 changeAdd();
@@ -1981,35 +2140,35 @@ namespace OpenSim.Region.PhysicsModule.ubOde
1981 changePIDHoverActive((bool)arg); 2140 changePIDHoverActive((bool)arg);
1982 break; 2141 break;
1983 2142
1984/* not in use for now 2143 /* not in use for now
1985 case changes.Shape: 2144 case changes.Shape:
1986 changeShape((PrimitiveBaseShape)arg); 2145 changeShape((PrimitiveBaseShape)arg);
1987 break; 2146 break;
1988 2147
1989 case changes.CollidesWater: 2148 case changes.CollidesWater:
1990 changeFloatOnWater((bool)arg); 2149 changeFloatOnWater((bool)arg);
1991 break; 2150 break;
1992 2151
1993 case changes.VolumeDtc: 2152 case changes.VolumeDtc:
1994 changeVolumedetetion((bool)arg); 2153 changeVolumedetetion((bool)arg);
1995 break; 2154 break;
1996 2155
1997 case changes.Physical: 2156 case changes.Physical:
1998 changePhysicsStatus((bool)arg); 2157 changePhysicsStatus((bool)arg);
1999 break; 2158 break;
2000 2159
2001 case changes.Selected: 2160 case changes.Selected:
2002 changeSelectedStatus((bool)arg); 2161 changeSelectedStatus((bool)arg);
2003 break; 2162 break;
2004 2163
2005 case changes.disabled: 2164 case changes.disabled:
2006 changeDisable((bool)arg); 2165 changeDisable((bool)arg);
2007 break; 2166 break;
2008 2167
2009 case changes.building: 2168 case changes.building:
2010 changeBuilding((bool)arg); 2169 changeBuilding((bool)arg);
2011 break; 2170 break;
2012*/ 2171 */
2013 case changes.Null: 2172 case changes.Null:
2014 donullchange(); 2173 donullchange();
2015 break; 2174 break;
@@ -2021,9 +2180,9 @@ namespace OpenSim.Region.PhysicsModule.ubOde
2021 return false; 2180 return false;
2022 } 2181 }
2023 2182
2024 public void AddChange(changes what, object arg) 2183 public void AddChange(changes what,object arg)
2025 { 2184 {
2026 m_parent_scene.AddChange((PhysicsActor)this, what, arg); 2185 m_parent_scene.AddChange((PhysicsActor)this,what,arg);
2027 } 2186 }
2028 2187
2029 private struct strAvatarSize 2188 private struct strAvatarSize