diff options
Diffstat (limited to 'OpenSim/Region/Physics/BulletSPlugin')
-rw-r--r-- | OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | 96 |
1 files changed, 57 insertions, 39 deletions
diff --git a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs index cbfd7e3..4ba2f62 100644 --- a/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs +++ b/OpenSim/Region/Physics/BulletSPlugin/BSDynamics.cs | |||
@@ -92,7 +92,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
92 | private float m_angularMotorDecayTimescale = 0; // motor angular velocity decay rate | 92 | private float m_angularMotorDecayTimescale = 0; // motor angular velocity decay rate |
93 | private Vector3 m_angularFrictionTimescale = Vector3.Zero; // body angular velocity decay rate | 93 | private Vector3 m_angularFrictionTimescale = Vector3.Zero; // body angular velocity decay rate |
94 | private Vector3 m_lastAngularVelocity = Vector3.Zero; // what was last applied to body | 94 | private Vector3 m_lastAngularVelocity = Vector3.Zero; // what was last applied to body |
95 | // private Vector3 m_lastVertAttractor = Vector3.Zero; // what VA was last applied to body | 95 | private Vector3 m_lastVertAttractor = Vector3.Zero; // what VA was last applied to body |
96 | 96 | ||
97 | //Deflection properties | 97 | //Deflection properties |
98 | // private float m_angularDeflectionEfficiency = 0; | 98 | // private float m_angularDeflectionEfficiency = 0; |
@@ -352,8 +352,9 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
352 | // m_bankingMix = 1; | 352 | // m_bankingMix = 1; |
353 | // m_bankingTimescale = 1; | 353 | // m_bankingTimescale = 1; |
354 | // m_referenceFrame = Quaternion.Identity; | 354 | // m_referenceFrame = Quaternion.Identity; |
355 | m_flags |= (VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.LIMIT_ROLL_ONLY | | 355 | m_flags |= (VehicleFlag.NO_DEFLECTION_UP |
356 | VehicleFlag.LIMIT_MOTOR_UP); | 356 | | VehicleFlag.LIMIT_ROLL_ONLY |
357 | | VehicleFlag.LIMIT_MOTOR_UP); | ||
357 | m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY | VehicleFlag.HOVER_GLOBAL_HEIGHT); | 358 | m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY | VehicleFlag.HOVER_GLOBAL_HEIGHT); |
358 | m_flags |= (VehicleFlag.HOVER_UP_ONLY); | 359 | m_flags |= (VehicleFlag.HOVER_UP_ONLY); |
359 | break; | 360 | break; |
@@ -380,12 +381,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
380 | // m_bankingMix = 0.8f; | 381 | // m_bankingMix = 0.8f; |
381 | // m_bankingTimescale = 1; | 382 | // m_bankingTimescale = 1; |
382 | // m_referenceFrame = Quaternion.Identity; | 383 | // m_referenceFrame = Quaternion.Identity; |
383 | m_flags &= ~(VehicleFlag.HOVER_TERRAIN_ONLY | | 384 | m_flags &= ~(VehicleFlag.HOVER_TERRAIN_ONLY |
384 | VehicleFlag.HOVER_GLOBAL_HEIGHT | VehicleFlag.HOVER_UP_ONLY); | 385 | | VehicleFlag.HOVER_GLOBAL_HEIGHT |
385 | m_flags &= ~(VehicleFlag.LIMIT_ROLL_ONLY); | 386 | | VehicleFlag.LIMIT_ROLL_ONLY |
386 | m_flags |= (VehicleFlag.NO_DEFLECTION_UP | | 387 | | VehicleFlag.HOVER_UP_ONLY); |
387 | VehicleFlag.LIMIT_MOTOR_UP); | 388 | m_flags |= (VehicleFlag.NO_DEFLECTION_UP |
388 | m_flags |= (VehicleFlag.HOVER_WATER_ONLY); | 389 | | VehicleFlag.LIMIT_MOTOR_UP |
390 | | VehicleFlag.HOVER_WATER_ONLY); | ||
389 | break; | 391 | break; |
390 | case Vehicle.TYPE_AIRPLANE: | 392 | case Vehicle.TYPE_AIRPLANE: |
391 | m_linearFrictionTimescale = new Vector3(200, 10, 5); | 393 | m_linearFrictionTimescale = new Vector3(200, 10, 5); |
@@ -410,9 +412,12 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
410 | // m_bankingMix = 0.7f; | 412 | // m_bankingMix = 0.7f; |
411 | // m_bankingTimescale = 2; | 413 | // m_bankingTimescale = 2; |
412 | // m_referenceFrame = Quaternion.Identity; | 414 | // m_referenceFrame = Quaternion.Identity; |
413 | m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY | | 415 | m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY |
414 | VehicleFlag.HOVER_GLOBAL_HEIGHT | VehicleFlag.HOVER_UP_ONLY); | 416 | | VehicleFlag.HOVER_TERRAIN_ONLY |
415 | m_flags &= ~(VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.LIMIT_MOTOR_UP); | 417 | | VehicleFlag.HOVER_GLOBAL_HEIGHT |
418 | | VehicleFlag.HOVER_UP_ONLY | ||
419 | | VehicleFlag.NO_DEFLECTION_UP | ||
420 | | VehicleFlag.LIMIT_MOTOR_UP); | ||
416 | m_flags |= (VehicleFlag.LIMIT_ROLL_ONLY); | 421 | m_flags |= (VehicleFlag.LIMIT_ROLL_ONLY); |
417 | break; | 422 | break; |
418 | case Vehicle.TYPE_BALLOON: | 423 | case Vehicle.TYPE_BALLOON: |
@@ -438,11 +443,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
438 | // m_bankingMix = 0.7f; | 443 | // m_bankingMix = 0.7f; |
439 | // m_bankingTimescale = 5; | 444 | // m_bankingTimescale = 5; |
440 | // m_referenceFrame = Quaternion.Identity; | 445 | // m_referenceFrame = Quaternion.Identity; |
441 | m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY | VehicleFlag.HOVER_TERRAIN_ONLY | | 446 | m_flags &= ~(VehicleFlag.HOVER_WATER_ONLY |
442 | VehicleFlag.HOVER_UP_ONLY); | 447 | | VehicleFlag.HOVER_TERRAIN_ONLY |
443 | m_flags &= ~(VehicleFlag.NO_DEFLECTION_UP | VehicleFlag.LIMIT_MOTOR_UP); | 448 | | VehicleFlag.HOVER_UP_ONLY |
444 | m_flags |= (VehicleFlag.LIMIT_ROLL_ONLY); | 449 | | VehicleFlag.NO_DEFLECTION_UP |
445 | m_flags |= (VehicleFlag.HOVER_GLOBAL_HEIGHT); | 450 | | VehicleFlag.LIMIT_MOTOR_UP); |
451 | m_flags |= (VehicleFlag.LIMIT_ROLL_ONLY | ||
452 | | VehicleFlag.HOVER_GLOBAL_HEIGHT); | ||
446 | break; | 453 | break; |
447 | } | 454 | } |
448 | }//end SetDefaultsForType | 455 | }//end SetDefaultsForType |
@@ -451,7 +458,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
451 | // Do any updating needed for a vehicle | 458 | // Do any updating needed for a vehicle |
452 | public void Refresh() | 459 | public void Refresh() |
453 | { | 460 | { |
454 | if (Type == Vehicle.TYPE_NONE) return; | 461 | if (!IsActive) |
462 | return; | ||
455 | 463 | ||
456 | // Set the prim's inertia to zero. The vehicle code handles that and this | 464 | // Set the prim's inertia to zero. The vehicle code handles that and this |
457 | // removes the torque action introduced by Bullet. | 465 | // removes the torque action introduced by Bullet. |
@@ -470,7 +478,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
470 | LimitRotation(pTimestep); | 478 | LimitRotation(pTimestep); |
471 | 479 | ||
472 | // remember the position so next step we can limit absolute movement effects | 480 | // remember the position so next step we can limit absolute movement effects |
473 | m_lastPositionVector = Prim.Position; | 481 | m_lastPositionVector = Prim.ForcePosition; |
474 | 482 | ||
475 | VDetailLog("{0},BSDynamics.Step,done,pos={1},force={2},velocity={3},angvel={4}", | 483 | VDetailLog("{0},BSDynamics.Step,done,pos={1},force={2},velocity={3},angvel={4}", |
476 | Prim.LocalID, Prim.Position, Prim.Force, Prim.Velocity, Prim.RotationalVelocity); | 484 | Prim.LocalID, Prim.Position, Prim.Force, Prim.Velocity, Prim.RotationalVelocity); |
@@ -524,7 +532,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
524 | } | 532 | } |
525 | 533 | ||
526 | // convert requested object velocity to object relative vector | 534 | // convert requested object velocity to object relative vector |
527 | Quaternion rotq = Prim.Orientation; | 535 | Quaternion rotq = Prim.ForceOrientation; |
528 | m_newVelocity = m_lastLinearVelocityVector * rotq; | 536 | m_newVelocity = m_lastLinearVelocityVector * rotq; |
529 | 537 | ||
530 | // Add the various forces into m_dir which will be our new direction vector (velocity) | 538 | // Add the various forces into m_dir which will be our new direction vector (velocity) |
@@ -541,19 +549,19 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
541 | m_dir.Z = vel_now.Z; // Preserve the accumulated falling velocity | 549 | m_dir.Z = vel_now.Z; // Preserve the accumulated falling velocity |
542 | */ | 550 | */ |
543 | 551 | ||
544 | Vector3 pos = Prim.Position; | 552 | Vector3 pos = Prim.ForcePosition; |
545 | // Vector3 accel = new Vector3(-(m_dir.X - m_lastLinearVelocityVector.X / 0.1f), -(m_dir.Y - m_lastLinearVelocityVector.Y / 0.1f), m_dir.Z - m_lastLinearVelocityVector.Z / 0.1f); | 553 | // Vector3 accel = new Vector3(-(m_dir.X - m_lastLinearVelocityVector.X / 0.1f), -(m_dir.Y - m_lastLinearVelocityVector.Y / 0.1f), m_dir.Z - m_lastLinearVelocityVector.Z / 0.1f); |
546 | 554 | ||
547 | // If below the terrain, move us above the ground a little. | 555 | // If below the terrain, move us above the ground a little. |
548 | float terrainHeight = Prim.PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(pos); | 556 | float terrainHeight = Prim.PhysicsScene.TerrainManager.GetTerrainHeightAtXYZ(pos); |
549 | // Taking the rotated size doesn't work here because m_prim.Size is the size of the root prim and not the linkset. | 557 | // Taking the rotated size doesn't work here because m_prim.Size is the size of the root prim and not the linkset. |
550 | // Need to add a m_prim.LinkSet.Size similar to m_prim.LinkSet.Mass. | 558 | // Need to add a m_prim.LinkSet.Size similar to m_prim.LinkSet.Mass. |
551 | // Vector3 rotatedSize = m_prim.Size * m_prim.Orientation; | 559 | // Vector3 rotatedSize = m_prim.Size * m_prim.ForceOrientation; |
552 | // if (rotatedSize.Z < terrainHeight) | 560 | // if (rotatedSize.Z < terrainHeight) |
553 | if (pos.Z < terrainHeight) | 561 | if (pos.Z < terrainHeight) |
554 | { | 562 | { |
555 | pos.Z = terrainHeight + 2; | 563 | pos.Z = terrainHeight + 2; |
556 | Prim.Position = pos; | 564 | Prim.ForcePosition = pos; |
557 | VDetailLog("{0},MoveLinear,terrainHeight,terrainHeight={1},pos={2}", Prim.LocalID, terrainHeight, pos); | 565 | VDetailLog("{0},MoveLinear,terrainHeight,terrainHeight={1},pos={2}", Prim.LocalID, terrainHeight, pos); |
558 | } | 566 | } |
559 | 567 | ||
@@ -583,7 +591,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
583 | { | 591 | { |
584 | if ((pos.Z - m_VhoverTargetHeight) > .2 || (pos.Z - m_VhoverTargetHeight) < -.2) | 592 | if ((pos.Z - m_VhoverTargetHeight) > .2 || (pos.Z - m_VhoverTargetHeight) < -.2) |
585 | { | 593 | { |
586 | Prim.Position = pos; | 594 | Prim.ForcePosition = pos; |
587 | } | 595 | } |
588 | } | 596 | } |
589 | else | 597 | else |
@@ -635,12 +643,13 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
635 | } | 643 | } |
636 | if (changed) | 644 | if (changed) |
637 | { | 645 | { |
638 | Prim.Position = pos; | 646 | Prim.ForcePosition = pos; |
639 | VDetailLog("{0},MoveLinear,blockingEndPoint,block={1},origPos={2},pos={3}", | 647 | VDetailLog("{0},MoveLinear,blockingEndPoint,block={1},origPos={2},pos={3}", |
640 | Prim.LocalID, m_BlockingEndPoint, posChange, pos); | 648 | Prim.LocalID, m_BlockingEndPoint, posChange, pos); |
641 | } | 649 | } |
642 | } | 650 | } |
643 | 651 | ||
652 | // Limit absolute vertical change | ||
644 | float Zchange = Math.Abs(posChange.Z); | 653 | float Zchange = Math.Abs(posChange.Z); |
645 | if ((m_flags & (VehicleFlag.LIMIT_MOTOR_UP)) != 0) | 654 | if ((m_flags & (VehicleFlag.LIMIT_MOTOR_UP)) != 0) |
646 | { | 655 | { |
@@ -659,6 +668,8 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
659 | grav.Z = (float)(grav.Z * 1.037125); | 668 | grav.Z = (float)(grav.Z * 1.037125); |
660 | VDetailLog("{0},MoveLinear,limitMotorUp,grav={1}", Prim.LocalID, grav); | 669 | VDetailLog("{0},MoveLinear,limitMotorUp,grav={1}", Prim.LocalID, grav); |
661 | } | 670 | } |
671 | |||
672 | // If not changing some axis, reduce out velocity | ||
662 | if ((m_flags & (VehicleFlag.NO_X)) != 0) | 673 | if ((m_flags & (VehicleFlag.NO_X)) != 0) |
663 | m_newVelocity.X = 0; | 674 | m_newVelocity.X = 0; |
664 | if ((m_flags & (VehicleFlag.NO_Y)) != 0) | 675 | if ((m_flags & (VehicleFlag.NO_Y)) != 0) |
@@ -701,19 +712,19 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
701 | // a newly set velocity, this routine steps the value from the previous | 712 | // a newly set velocity, this routine steps the value from the previous |
702 | // value (m_angularMotorVelocity) to the requested value (m_angularMotorDirection). | 713 | // value (m_angularMotorVelocity) to the requested value (m_angularMotorDirection). |
703 | // There are m_angularMotorApply steps. | 714 | // There are m_angularMotorApply steps. |
704 | Vector3 origAngularVelocity = m_angularMotorVelocity; | 715 | Vector3 origVel = m_angularMotorVelocity; |
716 | Vector3 origDir = m_angularMotorDirection; | ||
717 | |||
705 | // ramp up to new value | 718 | // ramp up to new value |
706 | // current velocity += error / ( time to get there / step interval) | 719 | // new velocity += error / ( time to get there / step interval) |
707 | // requested speed - last motor speed | 720 | // requested speed - last motor speed |
708 | m_angularMotorVelocity.X += (m_angularMotorDirection.X - m_angularMotorVelocity.X) / (m_angularMotorTimescale / pTimestep); | 721 | m_angularMotorVelocity.X += (m_angularMotorDirection.X - m_angularMotorVelocity.X) / (m_angularMotorTimescale / pTimestep); |
709 | m_angularMotorVelocity.Y += (m_angularMotorDirection.Y - m_angularMotorVelocity.Y) / (m_angularMotorTimescale / pTimestep); | 722 | m_angularMotorVelocity.Y += (m_angularMotorDirection.Y - m_angularMotorVelocity.Y) / (m_angularMotorTimescale / pTimestep); |
710 | m_angularMotorVelocity.Z += (m_angularMotorDirection.Z - m_angularMotorVelocity.Z) / (m_angularMotorTimescale / pTimestep); | 723 | m_angularMotorVelocity.Z += (m_angularMotorDirection.Z - m_angularMotorVelocity.Z) / (m_angularMotorTimescale / pTimestep); |
711 | 724 | ||
712 | VDetailLog("{0},MoveAngular,angularMotorApply,apply={1},angTScale={2},timeStep={3},origvel={4},dir={5},vel={6}", | 725 | VDetailLog("{0},MoveAngular,angularMotorApply,apply={1},angTScale={2},timeStep={3},origvel={4},origDir={5},vel={6}", |
713 | Prim.LocalID, m_angularMotorApply, m_angularMotorTimescale, pTimestep, origAngularVelocity, m_angularMotorDirection, m_angularMotorVelocity); | 726 | Prim.LocalID, m_angularMotorApply, m_angularMotorTimescale, pTimestep, origVel, origDir, m_angularMotorVelocity); |
714 | 727 | ||
715 | // This is done so that if script request rate is less than phys frame rate the expected | ||
716 | // velocity may still be acheived. | ||
717 | m_angularMotorApply--; | 728 | m_angularMotorApply--; |
718 | } | 729 | } |
719 | else | 730 | else |
@@ -727,25 +738,32 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
727 | 738 | ||
728 | // Vertical attractor section | 739 | // Vertical attractor section |
729 | Vector3 vertattr = Vector3.Zero; | 740 | Vector3 vertattr = Vector3.Zero; |
730 | if (m_verticalAttractionTimescale < 300) | 741 | Vector3 deflection = Vector3.Zero; |
742 | Vector3 banking = Vector3.Zero; | ||
743 | |||
744 | if (m_verticalAttractionTimescale < 300 && m_lastAngularVelocity != Vector3.Zero) | ||
731 | { | 745 | { |
732 | float VAservo = 0.2f / (m_verticalAttractionTimescale / pTimestep); | 746 | float VAservo = 0.2f / (m_verticalAttractionTimescale / pTimestep); |
747 | VAservo *= (m_verticalAttractionEfficiency * m_verticalAttractionEfficiency); | ||
748 | |||
733 | // get present body rotation | 749 | // get present body rotation |
734 | Quaternion rotq = Prim.Orientation; | 750 | Quaternion rotq = Prim.ForceOrientation; |
735 | // make a vector pointing up | 751 | // vector pointing up |
736 | Vector3 verterr = Vector3.Zero; | 752 | Vector3 verterr = Vector3.Zero; |
737 | verterr.Z = 1.0f; | 753 | verterr.Z = 1.0f; |
754 | |||
738 | // rotate it to Body Angle | 755 | // rotate it to Body Angle |
739 | verterr = verterr * rotq; | 756 | verterr = verterr * rotq; |
740 | // verterr.X and .Y are the World error ammounts. They are 0 when there is no error (Vehicle Body is 'vertical'), and .Z will be 1. | 757 | // verterr.X and .Y are the World error amounts. They are 0 when there is no error (Vehicle Body is 'vertical'), and .Z will be 1. |
741 | // As the body leans to its side |.X| will increase to 1 and .Z fall to 0. As body inverts |.X| will fall and .Z will go | 758 | // As the body leans to its side |.X| will increase to 1 and .Z fall to 0. As body inverts |.X| will fall and .Z will go |
742 | // negative. Similar for tilt and |.Y|. .X and .Y must be modulated to prevent a stable inverted body. | 759 | // negative. Similar for tilt and |.Y|. .X and .Y must be modulated to prevent a stable inverted body. |
760 | |||
761 | // Error is 0 (no error) to +/- 2 (max error) | ||
743 | if (verterr.Z < 0.0f) | 762 | if (verterr.Z < 0.0f) |
744 | { | 763 | { |
745 | verterr.X = 2.0f - verterr.X; | 764 | verterr.X = 2.0f - verterr.X; |
746 | verterr.Y = 2.0f - verterr.Y; | 765 | verterr.Y = 2.0f - verterr.Y; |
747 | } | 766 | } |
748 | // Error is 0 (no error) to +/- 2 (max error) | ||
749 | // scale it by VAservo | 767 | // scale it by VAservo |
750 | verterr = verterr * VAservo; | 768 | verterr = verterr * VAservo; |
751 | 769 | ||
@@ -765,7 +783,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
765 | 783 | ||
766 | } // else vertical attractor is off | 784 | } // else vertical attractor is off |
767 | 785 | ||
768 | // m_lastVertAttractor = vertattr; | 786 | m_lastVertAttractor = vertattr; |
769 | 787 | ||
770 | // Bank section tba | 788 | // Bank section tba |
771 | 789 | ||
@@ -799,7 +817,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
799 | 817 | ||
800 | internal void LimitRotation(float timestep) | 818 | internal void LimitRotation(float timestep) |
801 | { | 819 | { |
802 | Quaternion rotq = Prim.Orientation; | 820 | Quaternion rotq = Prim.ForceOrientation; |
803 | Quaternion m_rot = rotq; | 821 | Quaternion m_rot = rotq; |
804 | bool changed = false; | 822 | bool changed = false; |
805 | if (m_RollreferenceFrame != Quaternion.Identity) | 823 | if (m_RollreferenceFrame != Quaternion.Identity) |
@@ -834,7 +852,7 @@ namespace OpenSim.Region.Physics.BulletSPlugin | |||
834 | } | 852 | } |
835 | if (changed) | 853 | if (changed) |
836 | { | 854 | { |
837 | Prim.Orientation = m_rot; | 855 | Prim.ForceOrientation = m_rot; |
838 | VDetailLog("{0},LimitRotation,done,orig={1},new={2}", Prim.LocalID, rotq, m_rot); | 856 | VDetailLog("{0},LimitRotation,done,orig={1},new={2}", Prim.LocalID, rotq, m_rot); |
839 | } | 857 | } |
840 | 858 | ||