diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETPrim.cs | 102 |
1 files changed, 75 insertions, 27 deletions
diff --git a/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETPrim.cs b/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETPrim.cs index 920ed96..dc3229a 100644 --- a/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETPrim.cs +++ b/OpenSim/Region/Physics/BulletDotNETPlugin/BulletDotNETPrim.cs | |||
@@ -154,7 +154,8 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin | |||
154 | private Vector3 _target_velocity; | 154 | private Vector3 _target_velocity; |
155 | 155 | ||
156 | public int m_eventsubscription; | 156 | public int m_eventsubscription; |
157 | // private CollisionEventUpdate CollisionEventsThisFrame = null; | 157 | private int m_requestedUpdateFrequency = 0; |
158 | private CollisionEventUpdate CollisionEventsThisFrame = null; | ||
158 | 159 | ||
159 | public volatile bool childPrim; | 160 | public volatile bool childPrim; |
160 | 161 | ||
@@ -595,6 +596,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin | |||
595 | public override void SubscribeEvents(int ms) | 596 | public override void SubscribeEvents(int ms) |
596 | { | 597 | { |
597 | m_eventsubscription = ms; | 598 | m_eventsubscription = ms; |
599 | m_requestedUpdateFrequency = ms; | ||
598 | _parent_scene.addCollisionEventReporting(this); | 600 | _parent_scene.addCollisionEventReporting(this); |
599 | } | 601 | } |
600 | 602 | ||
@@ -602,6 +604,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin | |||
602 | { | 604 | { |
603 | _parent_scene.remCollisionEventReporting(this); | 605 | _parent_scene.remCollisionEventReporting(this); |
604 | m_eventsubscription = 0; | 606 | m_eventsubscription = 0; |
607 | m_requestedUpdateFrequency = 0; | ||
605 | } | 608 | } |
606 | 609 | ||
607 | public override bool SubscribedEvents() | 610 | public override bool SubscribedEvents() |
@@ -611,7 +614,28 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin | |||
611 | 614 | ||
612 | #endregion | 615 | #endregion |
613 | 616 | ||
617 | public void AddCollision(uint collideWith, ContactPoint contact) | ||
618 | { | ||
619 | if (CollisionEventsThisFrame == null) | ||
620 | { | ||
621 | CollisionEventsThisFrame = new CollisionEventUpdate(); | ||
622 | } | ||
623 | CollisionEventsThisFrame.addCollider(collideWith, contact); | ||
624 | } | ||
614 | 625 | ||
626 | public void SendCollisions() | ||
627 | { | ||
628 | if (m_eventsubscription >= m_requestedUpdateFrequency) | ||
629 | { | ||
630 | if (CollisionEventsThisFrame != null) | ||
631 | { | ||
632 | base.SendCollisionUpdate(CollisionEventsThisFrame); | ||
633 | } | ||
634 | CollisionEventsThisFrame = null; | ||
635 | // m_eventsubscription = 0; | ||
636 | } | ||
637 | return; | ||
638 | } | ||
615 | 639 | ||
616 | internal void Dispose() | 640 | internal void Dispose() |
617 | { | 641 | { |
@@ -759,7 +783,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin | |||
759 | { | 783 | { |
760 | if (m_taintadd) | 784 | if (m_taintadd) |
761 | { | 785 | { |
762 | m_log.Debug("[PHYSICS]: TaintAdd"); | 786 | // m_log.Debug("[PHYSICS]: TaintAdd"); |
763 | changeadd(timestep); | 787 | changeadd(timestep); |
764 | } | 788 | } |
765 | 789 | ||
@@ -771,7 +795,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin | |||
771 | SetBody(Mass); | 795 | SetBody(Mass); |
772 | else | 796 | else |
773 | SetBody(0); | 797 | SetBody(0); |
774 | m_log.Debug("[PHYSICS]: GEOM_DOESNT_EXSIT"); | 798 | // m_log.Debug("[PHYSICS]: GEOM_DOESNT_EXSIT"); |
775 | } | 799 | } |
776 | 800 | ||
777 | if (prim_geom.Handle == IntPtr.Zero) | 801 | if (prim_geom.Handle == IntPtr.Zero) |
@@ -782,31 +806,31 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin | |||
782 | SetBody(Mass); | 806 | SetBody(Mass); |
783 | else | 807 | else |
784 | SetBody(0); | 808 | SetBody(0); |
785 | m_log.Debug("[PHYSICS]: GEOM_DOESNT_EXSIT"); | 809 | // m_log.Debug("[PHYSICS]: GEOM_DOESNT_EXSIT"); |
786 | 810 | ||
787 | } | 811 | } |
788 | 812 | ||
789 | if (!_position.ApproxEquals(m_taintposition, 0f)) | 813 | if (!_position.ApproxEquals(m_taintposition, 0f)) |
790 | { | 814 | { |
791 | m_log.Debug("[PHYSICS]: TaintMove"); | 815 | // m_log.Debug("[PHYSICS]: TaintMove"); |
792 | changemove(timestep); | 816 | changemove(timestep); |
793 | } | 817 | } |
794 | if (m_taintrot != _orientation) | 818 | if (m_taintrot != _orientation) |
795 | { | 819 | { |
796 | m_log.Debug("[PHYSICS]: TaintRotate"); | 820 | // m_log.Debug("[PHYSICS]: TaintRotate"); |
797 | rotate(timestep); | 821 | rotate(timestep); |
798 | } // | 822 | } // |
799 | 823 | ||
800 | if (m_taintPhysics != m_isphysical && !(m_taintparent != _parent)) | 824 | if (m_taintPhysics != m_isphysical && !(m_taintparent != _parent)) |
801 | { | 825 | { |
802 | m_log.Debug("[PHYSICS]: TaintPhysics"); | 826 | // m_log.Debug("[PHYSICS]: TaintPhysics"); |
803 | changePhysicsStatus(timestep); | 827 | changePhysicsStatus(timestep); |
804 | } | 828 | } |
805 | // | 829 | // |
806 | 830 | ||
807 | if (!_size.ApproxEquals(m_taintsize, 0f)) | 831 | if (!_size.ApproxEquals(m_taintsize, 0f)) |
808 | { | 832 | { |
809 | m_log.Debug("[PHYSICS]: TaintSize"); | 833 | // m_log.Debug("[PHYSICS]: TaintSize"); |
810 | changesize(timestep); | 834 | changesize(timestep); |
811 | } | 835 | } |
812 | 836 | ||
@@ -814,43 +838,43 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin | |||
814 | 838 | ||
815 | if (m_taintshape) | 839 | if (m_taintshape) |
816 | { | 840 | { |
817 | m_log.Debug("[PHYSICS]: TaintShape"); | 841 | // m_log.Debug("[PHYSICS]: TaintShape"); |
818 | changeshape(timestep); | 842 | changeshape(timestep); |
819 | } // | 843 | } // |
820 | 844 | ||
821 | if (m_taintforce) | 845 | if (m_taintforce) |
822 | { | 846 | { |
823 | m_log.Debug("[PHYSICS]: TaintForce"); | 847 | // m_log.Debug("[PHYSICS]: TaintForce"); |
824 | changeAddForce(timestep); | 848 | changeAddForce(timestep); |
825 | } | 849 | } |
826 | if (m_taintaddangularforce) | 850 | if (m_taintaddangularforce) |
827 | { | 851 | { |
828 | m_log.Debug("[PHYSICS]: TaintAngularForce"); | 852 | // m_log.Debug("[PHYSICS]: TaintAngularForce"); |
829 | changeAddAngularForce(timestep); | 853 | changeAddAngularForce(timestep); |
830 | } | 854 | } |
831 | if (!m_taintTorque.ApproxEquals(Vector3.Zero, 0.001f)) | 855 | if (!m_taintTorque.ApproxEquals(Vector3.Zero, 0.001f)) |
832 | { | 856 | { |
833 | m_log.Debug("[PHYSICS]: TaintTorque"); | 857 | // m_log.Debug("[PHYSICS]: TaintTorque"); |
834 | changeSetTorque(timestep); | 858 | changeSetTorque(timestep); |
835 | } | 859 | } |
836 | if (m_taintdisable) | 860 | if (m_taintdisable) |
837 | { | 861 | { |
838 | m_log.Debug("[PHYSICS]: TaintDisable"); | 862 | // m_log.Debug("[PHYSICS]: TaintDisable"); |
839 | changedisable(timestep); | 863 | changedisable(timestep); |
840 | } | 864 | } |
841 | if (m_taintselected != m_isSelected) | 865 | if (m_taintselected != m_isSelected) |
842 | { | 866 | { |
843 | m_log.Debug("[PHYSICS]: TaintSelected"); | 867 | // m_log.Debug("[PHYSICS]: TaintSelected"); |
844 | changeSelectedStatus(timestep); | 868 | changeSelectedStatus(timestep); |
845 | } | 869 | } |
846 | if (!m_taintVelocity.ApproxEquals(Vector3.Zero, 0.001f)) | 870 | if (!m_taintVelocity.ApproxEquals(Vector3.Zero, 0.001f)) |
847 | { | 871 | { |
848 | m_log.Debug("[PHYSICS]: TaintVelocity"); | 872 | // m_log.Debug("[PHYSICS]: TaintVelocity"); |
849 | changevelocity(timestep); | 873 | changevelocity(timestep); |
850 | } | 874 | } |
851 | if (m_taintparent != _parent) | 875 | if (m_taintparent != _parent) |
852 | { | 876 | { |
853 | m_log.Debug("[PHYSICS]: TaintLink"); | 877 | // m_log.Debug("[PHYSICS]: TaintLink"); |
854 | changelink(timestep); | 878 | changelink(timestep); |
855 | } | 879 | } |
856 | if (m_taintCollidesWater != m_collidesWater) | 880 | if (m_taintCollidesWater != m_collidesWater) |
@@ -859,7 +883,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin | |||
859 | } | 883 | } |
860 | if (!m_angularlock.ApproxEquals(m_taintAngularLock, 0)) | 884 | if (!m_angularlock.ApproxEquals(m_taintAngularLock, 0)) |
861 | { | 885 | { |
862 | m_log.Debug("[PHYSICS]: TaintAngularLock"); | 886 | // m_log.Debug("[PHYSICS]: TaintAngularLock"); |
863 | changeAngularLock(timestep); | 887 | changeAngularLock(timestep); |
864 | } | 888 | } |
865 | if (m_taintremove) | 889 | if (m_taintremove) |
@@ -917,7 +941,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin | |||
917 | private void changemove(float timestep) | 941 | private void changemove(float timestep) |
918 | { | 942 | { |
919 | 943 | ||
920 | m_log.Debug("[PHYSICS]: _________ChangeMove"); | 944 | // m_log.Debug("[PHYSICS]: _________ChangeMove"); |
921 | if (!m_isphysical) | 945 | if (!m_isphysical) |
922 | { | 946 | { |
923 | tempTransform2 = Body.getWorldTransform(); | 947 | tempTransform2 = Body.getWorldTransform(); |
@@ -977,7 +1001,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin | |||
977 | 1001 | ||
978 | private void rotate(float timestep) | 1002 | private void rotate(float timestep) |
979 | { | 1003 | { |
980 | m_log.Debug("[PHYSICS]: _________ChangeRotate"); | 1004 | // m_log.Debug("[PHYSICS]: _________ChangeRotate"); |
981 | tempTransform2 = Body.getWorldTransform(); | 1005 | tempTransform2 = Body.getWorldTransform(); |
982 | tempOrientation2 = new btQuaternion(_orientation.X, _orientation.Y, _orientation.Z, _orientation.W); | 1006 | tempOrientation2 = new btQuaternion(_orientation.X, _orientation.Y, _orientation.Z, _orientation.W); |
983 | tempTransform2.setRotation(tempOrientation2); | 1007 | tempTransform2.setRotation(tempOrientation2); |
@@ -1000,7 +1024,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin | |||
1000 | //Body = null; | 1024 | //Body = null; |
1001 | // TODO: dispose parts that make up body | 1025 | // TODO: dispose parts that make up body |
1002 | } | 1026 | } |
1003 | m_log.Debug("[PHYSICS]: _________ChangePhysics"); | 1027 | // m_log.Debug("[PHYSICS]: _________ChangePhysics"); |
1004 | 1028 | ||
1005 | ProcessGeomCreation(); | 1029 | ProcessGeomCreation(); |
1006 | 1030 | ||
@@ -1092,7 +1116,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin | |||
1092 | // TODO: dispose parts that make up body | 1116 | // TODO: dispose parts that make up body |
1093 | } | 1117 | } |
1094 | 1118 | ||
1095 | m_log.Debug("[PHYSICS]: _________ChangeSize"); | 1119 | // m_log.Debug("[PHYSICS]: _________ChangeSize"); |
1096 | SetCollisionShape(null); | 1120 | SetCollisionShape(null); |
1097 | // Construction of new prim | 1121 | // Construction of new prim |
1098 | ProcessGeomCreation(); | 1122 | ProcessGeomCreation(); |
@@ -1297,13 +1321,13 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin | |||
1297 | // TODO: throw new NotImplementedException(); | 1321 | // TODO: throw new NotImplementedException(); |
1298 | if (m_taintselected) | 1322 | if (m_taintselected) |
1299 | { | 1323 | { |
1300 | Body.setCollisionFlags((int)ContactFlags.CF_NO_CONTACT_RESPONSE); | 1324 | // Body.setCollisionFlags((int)ContactFlags.CF_NO_CONTACT_RESPONSE); |
1301 | disableBodySoft(); | 1325 | disableBodySoft(); |
1302 | 1326 | ||
1303 | } | 1327 | } |
1304 | else | 1328 | else |
1305 | { | 1329 | { |
1306 | Body.setCollisionFlags(0 | (int)ContactFlags.CF_CUSTOM_MATERIAL_CALLBACK); | 1330 | // Body.setCollisionFlags(0 | (int)ContactFlags.CF_CUSTOM_MATERIAL_CALLBACK); |
1307 | enableBodySoft(); | 1331 | enableBodySoft(); |
1308 | } | 1332 | } |
1309 | m_isSelected = m_taintselected; | 1333 | m_isSelected = m_taintselected; |
@@ -1605,6 +1629,11 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin | |||
1605 | enableBodySoft(); | 1629 | enableBodySoft(); |
1606 | } | 1630 | } |
1607 | */ | 1631 | */ |
1632 | if (!Body.isActive()) | ||
1633 | { | ||
1634 | Body.clearForces(); | ||
1635 | enableBodySoft(); | ||
1636 | } | ||
1608 | // 35x10 = 350n times the mass per second applied maximum. | 1637 | // 35x10 = 350n times the mass per second applied maximum. |
1609 | 1638 | ||
1610 | float nmax = 35f * m_mass; | 1639 | float nmax = 35f * m_mass; |
@@ -1632,6 +1661,12 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin | |||
1632 | Body.applyCentralImpulse(tempAddForce); | 1661 | Body.applyCentralImpulse(tempAddForce); |
1633 | } | 1662 | } |
1634 | } | 1663 | } |
1664 | else | ||
1665 | { | ||
1666 | // if no forces on the prim, make sure everything is zero | ||
1667 | Body.clearForces(); | ||
1668 | enableBodySoft(); | ||
1669 | } | ||
1635 | } | 1670 | } |
1636 | else | 1671 | else |
1637 | { | 1672 | { |
@@ -1985,7 +2020,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin | |||
1985 | 2020 | ||
1986 | public void CreateGeom(IntPtr m_targetSpace, IMesh p_mesh) | 2021 | public void CreateGeom(IntPtr m_targetSpace, IMesh p_mesh) |
1987 | { | 2022 | { |
1988 | m_log.Debug("[PHYSICS]: _________CreateGeom"); | 2023 | // m_log.Debug("[PHYSICS]: _________CreateGeom"); |
1989 | if (p_mesh != null) | 2024 | if (p_mesh != null) |
1990 | { | 2025 | { |
1991 | //_mesh = _parent_scene.mesher.CreateMesh(m_primName, _pbs, _size, _parent_scene.meshSculptLOD, IsPhysical); | 2026 | //_mesh = _parent_scene.mesher.CreateMesh(m_primName, _pbs, _size, _parent_scene.meshSculptLOD, IsPhysical); |
@@ -2042,7 +2077,7 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin | |||
2042 | // TODO: Set Collision Body Mesh | 2077 | // TODO: Set Collision Body Mesh |
2043 | // This sleeper is there to moderate how long it takes between | 2078 | // This sleeper is there to moderate how long it takes between |
2044 | // setting up the mesh and pre-processing it when we get rapid fire mesh requests on a single object | 2079 | // setting up the mesh and pre-processing it when we get rapid fire mesh requests on a single object |
2045 | m_log.Debug("_________SetMesh"); | 2080 | // m_log.Debug("_________SetMesh"); |
2046 | Thread.Sleep(10); | 2081 | Thread.Sleep(10); |
2047 | 2082 | ||
2048 | //Kill Body so that mesh can re-make the geom | 2083 | //Kill Body so that mesh can re-make the geom |
@@ -2159,7 +2194,14 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin | |||
2159 | 2194 | ||
2160 | // Body = new btRigidBody(mass, tempMotionState1, prim_geom); | 2195 | // Body = new btRigidBody(mass, tempMotionState1, prim_geom); |
2161 | //else | 2196 | //else |
2162 | Body = new btRigidBody(mass, tempMotionState1, prim_geom, tempInertia1); | 2197 | // Body = new btRigidBody(mass, tempMotionState1, prim_geom, tempInertia1); |
2198 | if (Body == null) | ||
2199 | { | ||
2200 | Body = new btRigidBody(mass, tempMotionState1, prim_geom, tempInertia1); | ||
2201 | // add localID so we can later map bullet object back to OpenSim object | ||
2202 | Body.setUserPointer(new IntPtr((int)m_localID)); | ||
2203 | } | ||
2204 | |||
2163 | 2205 | ||
2164 | if (prim_geom is btGImpactMeshShape) | 2206 | if (prim_geom is btGImpactMeshShape) |
2165 | { | 2207 | { |
@@ -2250,7 +2292,13 @@ namespace OpenSim.Region.Physics.BulletDotNETPlugin | |||
2250 | 2292 | ||
2251 | // Body = new btRigidBody(mass, tempMotionState1, prim_geom); | 2293 | // Body = new btRigidBody(mass, tempMotionState1, prim_geom); |
2252 | //else | 2294 | //else |
2253 | Body = new btRigidBody(mass, tempMotionState1, prim_geom, tempInertia1); | 2295 | // Body = new btRigidBody(mass, tempMotionState1, prim_geom, tempInertia1); |
2296 | if (Body == null) | ||
2297 | { | ||
2298 | Body = new btRigidBody(mass, tempMotionState1, prim_geom, tempInertia1); | ||
2299 | // each body has the localID stored into it so we can identify collision objects | ||
2300 | Body.setUserPointer(new IntPtr((int)m_localID)); | ||
2301 | } | ||
2254 | 2302 | ||
2255 | if (prim_geom is btGImpactMeshShape) | 2303 | if (prim_geom is btGImpactMeshShape) |
2256 | { | 2304 | { |