aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/OdePlugin/ODEPrim.cs')
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODEPrim.cs489
1 files changed, 412 insertions, 77 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
index 79a7519..0a461e9 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
@@ -24,7 +24,6 @@
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27
28using System; 27using System;
29using System.Collections.Generic; 28using System.Collections.Generic;
30using System.Reflection; 29using System.Reflection;
@@ -118,6 +117,8 @@ namespace OpenSim.Region.Physics.OdePlugin
118 private PhysicsActor _parent = null; 117 private PhysicsActor _parent = null;
119 private PhysicsActor m_taintparent = null; 118 private PhysicsActor m_taintparent = null;
120 119
120 private List<OdePrim> childrenPrim = new List<OdePrim>();
121
121 private bool iscolliding = false; 122 private bool iscolliding = false;
122 private bool m_isphysical = false; 123 private bool m_isphysical = false;
123 private bool m_isSelected = false; 124 private bool m_isSelected = false;
@@ -147,6 +148,8 @@ namespace OpenSim.Region.Physics.OdePlugin
147 148
148 private IntPtr m_linkJoint = (IntPtr)0; 149 private IntPtr m_linkJoint = (IntPtr)0;
149 150
151 public volatile bool childPrim = false;
152
150 public OdePrim(String primName, OdeScene parent_scene, PhysicsVector pos, PhysicsVector size, 153 public OdePrim(String primName, OdeScene parent_scene, PhysicsVector pos, PhysicsVector size,
151 Quaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, bool pisPhysical, CollisionLocker dode) 154 Quaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, bool pisPhysical, CollisionLocker dode)
152 { 155 {
@@ -161,10 +164,10 @@ namespace OpenSim.Region.Physics.OdePlugin
161 m_density = parent_scene.geomDefaultDensity; 164 m_density = parent_scene.geomDefaultDensity;
162 m_tensor = parent_scene.bodyMotorJointMaxforceTensor; 165 m_tensor = parent_scene.bodyMotorJointMaxforceTensor;
163 body_autodisable_frames = parent_scene.bodyFramesAutoDisable; 166 body_autodisable_frames = parent_scene.bodyFramesAutoDisable;
164
165 167
166 prim_geom = (IntPtr)0; 168
167 prev_geom = (IntPtr)0; 169 prim_geom = IntPtr.Zero;
170 prev_geom = IntPtr.Zero;
168 171
169 if (size.X <= 0) size.X = 0.01f; 172 if (size.X <= 0) size.X = 0.01f;
170 if (size.Y <= 0) size.Y = 0.01f; 173 if (size.Y <= 0) size.Y = 0.01f;
@@ -247,64 +250,83 @@ namespace OpenSim.Region.Physics.OdePlugin
247 { 250 {
248 prev_geom = prim_geom; 251 prev_geom = prim_geom;
249 prim_geom = geom; 252 prim_geom = geom;
250 if (prim_geom != (IntPtr)0) 253 if (prim_geom != IntPtr.Zero)
251 { 254 {
252 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories); 255 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
253 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); 256 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
254 } 257 }
258
259 if (childPrim)
260 {
261 if (_parent != null && _parent is OdePrim)
262 {
263 OdePrim parent = (OdePrim)_parent;
264 parent.ChildSetGeom(this);
265 }
266 }
255 //m_log.Warn("Setting Geom to: " + prim_geom); 267 //m_log.Warn("Setting Geom to: " + prim_geom);
256 } 268 }
257 269
270
271
258 public void enableBodySoft() 272 public void enableBodySoft()
259 { 273 {
260 if (m_isphysical && Body != (IntPtr)0) 274 if (!childPrim)
261 d.BodyEnable(Body); 275 {
276 if (m_isphysical && Body != IntPtr.Zero)
277 d.BodyEnable(Body);
262 278
263 m_disabled = false; 279 m_disabled = false;
280 }
264 } 281 }
265 282
266 public void disableBodySoft() 283 public void disableBodySoft()
267 { 284 {
268 m_disabled = true; 285 m_disabled = true;
269 286
270 if (m_isphysical && Body != (IntPtr)0) 287 if (m_isphysical && Body != IntPtr.Zero)
271 d.BodyDisable(Body); 288 d.BodyDisable(Body);
272 } 289 }
273 290
274 public void enableBody() 291 public void enableBody()
275 { 292 {
276 // Sets the geom to a body 293 // Don't enable this body if we're a child prim
277 Body = d.BodyCreate(_parent_scene.world); 294 // this should be taken care of in the parent function not here
295 if (!childPrim)
296 {
297 // Sets the geom to a body
298 Body = d.BodyCreate(_parent_scene.world);
278 299
279 setMass(); 300 setMass();
280 d.BodySetPosition(Body, _position.X, _position.Y, _position.Z); 301 d.BodySetPosition(Body, _position.X, _position.Y, _position.Z);
281 d.Quaternion myrot = new d.Quaternion(); 302 d.Quaternion myrot = new d.Quaternion();
282 myrot.X = _orientation.X; 303 myrot.X = _orientation.X;
283 myrot.Y = _orientation.Y; 304 myrot.Y = _orientation.Y;
284 myrot.Z = _orientation.Z; 305 myrot.Z = _orientation.Z;
285 myrot.W = _orientation.W; 306 myrot.W = _orientation.W;
286 d.BodySetQuaternion(Body, ref myrot); 307 d.BodySetQuaternion(Body, ref myrot);
287 d.GeomSetBody(prim_geom, Body); 308 d.GeomSetBody(prim_geom, Body);
288 m_collisionCategories |= CollisionCategories.Body; 309 m_collisionCategories |= CollisionCategories.Body;
289 m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind); 310 m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind);
290 311
291 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories); 312 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
292 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); 313 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
293 314
294 d.BodySetAutoDisableFlag(Body, true); 315 d.BodySetAutoDisableFlag(Body, true);
295 d.BodySetAutoDisableSteps(Body, body_autodisable_frames); 316 d.BodySetAutoDisableSteps(Body, body_autodisable_frames);
296 317
297 m_interpenetrationcount = 0; 318 m_interpenetrationcount = 0;
298 m_collisionscore = 0; 319 m_collisionscore = 0;
299 m_disabled = false; 320 m_disabled = false;
300 321
301 // The body doesn't already have a finite rotation mode set here 322 // The body doesn't already have a finite rotation mode set here
302 if ((!m_angularlock.IsIdentical(PhysicsVector.Zero, 0)) && _parent == null) 323 if ((!m_angularlock.IsIdentical(PhysicsVector.Zero, 0)) && _parent == null)
303 { 324 {
304 createAMotor(m_angularlock); 325 createAMotor(m_angularlock);
305 } 326 }
306 327
307 _parent_scene.addActivePrim(this); 328 _parent_scene.addActivePrim(this);
329 }
308 } 330 }
309 331
310 #region Mass Calculation 332 #region Mass Calculation
@@ -627,20 +649,41 @@ namespace OpenSim.Region.Physics.OdePlugin
627 //this kills the body so things like 'mesh' can re-create it. 649 //this kills the body so things like 'mesh' can re-create it.
628 lock (this) 650 lock (this)
629 { 651 {
630 if (Body != (IntPtr)0) 652 if (!childPrim)
653 {
654 if (Body != IntPtr.Zero)
655 {
656 _parent_scene.remActivePrim(this);
657
658 m_collisionCategories &= ~CollisionCategories.Body;
659 m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land);
660
661 if (prim_geom != IntPtr.Zero)
662 {
663 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
664 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
665 }
666
667
668 d.BodyDestroy(Body);
669 Body = IntPtr.Zero;
670 }
671 }
672 else
631 { 673 {
674 _parent_scene.remActivePrim(this);
675
632 m_collisionCategories &= ~CollisionCategories.Body; 676 m_collisionCategories &= ~CollisionCategories.Body;
633 m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land); 677 m_collisionFlags &= ~(CollisionCategories.Wind | CollisionCategories.Land);
634 678
635 if (prim_geom != (IntPtr)0) 679 if (prim_geom != IntPtr.Zero)
636 { 680 {
637 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories); 681 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
638 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); 682 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
639 } 683 }
640 684
641 _parent_scene.remActivePrim(this); 685
642 d.BodyDestroy(Body); 686 Body = IntPtr.Zero;
643 Body = (IntPtr)0;
644 } 687 }
645 } 688 }
646 m_disabled = true; 689 m_disabled = true;
@@ -655,9 +698,20 @@ namespace OpenSim.Region.Physics.OdePlugin
655 Thread.Sleep(10); 698 Thread.Sleep(10);
656 699
657 //Kill Body so that mesh can re-make the geom 700 //Kill Body so that mesh can re-make the geom
658 if (IsPhysical && Body != (IntPtr) 0) 701 if (IsPhysical && Body != IntPtr.Zero)
659 { 702 {
660 disableBody(); 703 if (childPrim)
704 {
705 if (_parent != null)
706 {
707 OdePrim parent = (OdePrim)_parent;
708 parent.ChildDelink(this);
709 }
710 }
711 else
712 {
713 disableBody();
714 }
661 } 715 }
662 716
663 IMesh oldMesh = primMesh; 717 IMesh oldMesh = primMesh;
@@ -682,7 +736,7 @@ namespace OpenSim.Region.Physics.OdePlugin
682 736
683 try 737 try
684 { 738 {
685 if (prim_geom == (IntPtr)0) 739 if (prim_geom == IntPtr.Zero)
686 { 740 {
687 SetGeom(d.CreateTriMesh(m_targetSpace, _triMeshData, parent_scene.triCallback, null, null)); 741 SetGeom(d.CreateTriMesh(m_targetSpace, _triMeshData, parent_scene.triCallback, null, null));
688 } 742 }
@@ -715,7 +769,7 @@ namespace OpenSim.Region.Physics.OdePlugin
715 { 769 {
716 changeadd(timestep); 770 changeadd(timestep);
717 } 771 }
718 if (prim_geom != (IntPtr)0) 772 if (prim_geom != IntPtr.Zero)
719 { 773 {
720 if (!_position.IsIdentical(m_taintposition,0f)) 774 if (!_position.IsIdentical(m_taintposition,0f))
721 changemove(timestep); 775 changemove(timestep);
@@ -724,7 +778,7 @@ namespace OpenSim.Region.Physics.OdePlugin
724 rotate(timestep); 778 rotate(timestep);
725 // 779 //
726 780
727 if (m_taintPhysics != m_isphysical) 781 if (m_taintPhysics != m_isphysical && !(m_taintparent != _parent))
728 changePhysicsStatus(timestep); 782 changePhysicsStatus(timestep);
729 // 783 //
730 784
@@ -783,7 +837,7 @@ namespace OpenSim.Region.Physics.OdePlugin
783 if (Amotor != IntPtr.Zero) 837 if (Amotor != IntPtr.Zero)
784 { 838 {
785 d.JointDestroy(Amotor); 839 d.JointDestroy(Amotor);
786 Amotor = (IntPtr)0; 840 Amotor = IntPtr.Zero;
787 } 841 }
788 } 842 }
789 } 843 }
@@ -794,11 +848,18 @@ namespace OpenSim.Region.Physics.OdePlugin
794 848
795 private void changelink(float timestep) 849 private void changelink(float timestep)
796 { 850 {
851 // If the newly set parent is not null
852 // create link
797 if (_parent == null && m_taintparent != null) 853 if (_parent == null && m_taintparent != null)
798 { 854 {
799 if (m_taintparent.PhysicsActorType == (int)ActorTypes.Prim) 855 if (m_taintparent.PhysicsActorType == (int)ActorTypes.Prim)
800 { 856 {
801 OdePrim obj = (OdePrim)m_taintparent; 857 OdePrim obj = (OdePrim)m_taintparent;
858 //obj.disableBody();
859
860 obj.ParentPrim(this);
861
862 /*
802 if (obj.Body != (IntPtr)0 && Body != (IntPtr)0 && obj.Body != Body) 863 if (obj.Body != (IntPtr)0 && Body != (IntPtr)0 && obj.Body != Body)
803 { 864 {
804 _linkJointGroup = d.JointGroupCreate(0); 865 _linkJointGroup = d.JointGroupCreate(0);
@@ -806,18 +867,245 @@ namespace OpenSim.Region.Physics.OdePlugin
806 d.JointAttach(m_linkJoint, obj.Body, Body); 867 d.JointAttach(m_linkJoint, obj.Body, Body);
807 d.JointSetFixed(m_linkJoint); 868 d.JointSetFixed(m_linkJoint);
808 } 869 }
870 */
809 } 871 }
810 } 872 }
873 // If the newly set parent is null
874 // destroy link
811 else if (_parent != null && m_taintparent == null) 875 else if (_parent != null && m_taintparent == null)
812 { 876 {
813 if (Body != (IntPtr)0 && _linkJointGroup != (IntPtr)0) 877 if (_parent is OdePrim)
878 {
879 OdePrim obj = (OdePrim)_parent;
880 obj.ChildDelink(this);
881 childPrim = false;
882 //_parent = null;
883 }
884
885 /*
886 if (Body != (IntPtr)0 && _linkJointGroup != (IntPtr)0)
814 d.JointGroupDestroy(_linkJointGroup); 887 d.JointGroupDestroy(_linkJointGroup);
815 888
816 _linkJointGroup = (IntPtr)0; 889 _linkJointGroup = (IntPtr)0;
817 m_linkJoint = (IntPtr)0; 890 m_linkJoint = (IntPtr)0;
891 */
818 } 892 }
819 893
820 _parent = m_taintparent; 894 _parent = m_taintparent;
895 m_taintPhysics = m_isphysical;
896 }
897
898 // I'm the parent
899 // prim is the child
900 public void ParentPrim(OdePrim prim)
901 {
902 if (this.m_localID != prim.m_localID)
903 {
904 if (Body == IntPtr.Zero)
905 {
906 Body = d.BodyCreate(_parent_scene.world);
907 }
908 if (Body != IntPtr.Zero)
909 {
910 lock (childrenPrim)
911 {
912 if (!childrenPrim.Contains(prim))
913 {
914 childrenPrim.Add(prim);
915
916 foreach (OdePrim prm in childrenPrim)
917 {
918 d.Mass m2;
919 d.MassSetZero(out m2);
920 d.MassSetBoxTotal(out m2, prim.CalculateMass(), prm._size.X, prm._size.Y, prm._size.Z);
921
922
923 d.Quaternion quat = new d.Quaternion();
924 quat.W = prm._orientation.W;
925 quat.X = prm._orientation.X;
926 quat.Y = prm._orientation.Y;
927 quat.Z = prm._orientation.Z;
928
929 d.Matrix3 mat = new d.Matrix3();
930 d.RfromQ(out mat, ref quat);
931 d.MassRotate(out m2, ref mat);
932 d.MassTranslate(out m2, Position.X - prm.Position.X, Position.Y - prm.Position.Y, Position.Z - prm.Position.Z);
933 d.MassAdd(ref pMass, ref m2);
934 }
935 foreach (OdePrim prm in childrenPrim)
936 {
937 prm.m_collisionCategories |= CollisionCategories.Body;
938 prm.m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind);
939
940 d.GeomSetCategoryBits(prm.prim_geom, (int)prm.m_collisionCategories);
941 d.GeomSetCollideBits(prm.prim_geom, (int)prm.m_collisionFlags);
942
943
944 d.Quaternion quat = new d.Quaternion();
945 quat.W = prm._orientation.W;
946 quat.X = prm._orientation.X;
947 quat.Y = prm._orientation.Y;
948 quat.Z = prm._orientation.Z;
949
950 d.Matrix3 mat = new d.Matrix3();
951 d.RfromQ(out mat, ref quat);
952 if (Body != IntPtr.Zero)
953 {
954 d.GeomSetBody(prm.prim_geom, Body);
955 prm.childPrim = true;
956 d.GeomSetOffsetWorldPosition(prm.prim_geom, prm.Position.X , prm.Position.Y, prm.Position.Z);
957 //d.GeomSetOffsetPosition(prim.prim_geom,
958 // (Position.X - prm.Position.X) - pMass.c.X,
959 // (Position.Y - prm.Position.Y) - pMass.c.Y,
960 // (Position.Z - prm.Position.Z) - pMass.c.Z);
961 d.GeomSetOffsetWorldRotation(prm.prim_geom, ref mat);
962 //d.GeomSetOffsetRotation(prm.prim_geom, ref mat);
963 d.MassTranslate(out pMass, -pMass.c.X, -pMass.c.Y, -pMass.c.Z);
964 d.BodySetMass(Body, ref pMass);
965 }
966 else
967 {
968 m_log.Debug("[PHYSICS]:I ain't got no boooooooooddy, no body");
969 }
970
971
972 prm.m_interpenetrationcount = 0;
973 prm.m_collisionscore = 0;
974 prm.m_disabled = false;
975
976 // The body doesn't already have a finite rotation mode set here
977 if ((!m_angularlock.IsIdentical(PhysicsVector.Zero, 0)) && _parent == null)
978 {
979 prm.createAMotor(m_angularlock);
980 }
981 prm.Body = Body;
982 _parent_scene.addActivePrim(prm);
983 }
984
985 m_collisionCategories |= CollisionCategories.Body;
986 m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind);
987
988 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
989 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
990
991
992 d.Quaternion quat2 = new d.Quaternion();
993 quat2.W = _orientation.W;
994 quat2.X = _orientation.X;
995 quat2.Y = _orientation.Y;
996 quat2.Z = _orientation.Z;
997
998 d.Matrix3 mat2 = new d.Matrix3();
999 d.RfromQ(out mat2, ref quat2);
1000 d.GeomSetBody(prim_geom, Body);
1001 d.GeomSetOffsetWorldPosition(prim_geom, Position.X - pMass.c.X, Position.Y - pMass.c.Y, Position.Z - pMass.c.Z);
1002 //d.GeomSetOffsetPosition(prim.prim_geom,
1003 // (Position.X - prm.Position.X) - pMass.c.X,
1004 // (Position.Y - prm.Position.Y) - pMass.c.Y,
1005 // (Position.Z - prm.Position.Z) - pMass.c.Z);
1006 //d.GeomSetOffsetRotation(prim_geom, ref mat2);
1007 d.MassTranslate(out pMass, -pMass.c.X, -pMass.c.Y, -pMass.c.Z);
1008 d.BodySetMass(Body, ref pMass);
1009
1010 d.BodySetAutoDisableFlag(Body, true);
1011 d.BodySetAutoDisableSteps(Body, body_autodisable_frames);
1012
1013
1014 m_interpenetrationcount = 0;
1015 m_collisionscore = 0;
1016 m_disabled = false;
1017
1018 // The body doesn't already have a finite rotation mode set here
1019 if ((!m_angularlock.IsIdentical(PhysicsVector.Zero, 0)) && _parent == null)
1020 {
1021 createAMotor(m_angularlock);
1022 }
1023 d.BodySetPosition(Body, Position.X, Position.Y, Position.Z);
1024
1025 _parent_scene.addActivePrim(this);
1026 }
1027 }
1028 }
1029 }
1030
1031 }
1032
1033 private void ChildSetGeom(OdePrim odePrim)
1034 {
1035 //if (m_isphysical && Body != IntPtr.Zero)
1036 lock (childrenPrim)
1037 {
1038 foreach (OdePrim prm in childrenPrim)
1039 {
1040 //prm.childPrim = true;
1041 prm.disableBody();
1042 //prm.m_taintparent = null;
1043 //prm._parent = null;
1044 //prm.m_taintPhysics = false;
1045 //prm.m_disabled = true;
1046 //prm.childPrim = false;
1047 }
1048 }
1049 disableBody();
1050
1051
1052 if (Body != IntPtr.Zero)
1053 {
1054 _parent_scene.remActivePrim(this);
1055 }
1056
1057 lock (childrenPrim)
1058 {
1059 foreach (OdePrim prm in childrenPrim)
1060 {
1061 ParentPrim(prm);
1062 }
1063 }
1064
1065 }
1066
1067 private void ChildDelink(OdePrim odePrim)
1068 {
1069 // Okay, we have a delinked child.. need to rebuild the body.
1070 lock (childrenPrim)
1071 {
1072 foreach (OdePrim prm in childrenPrim)
1073 {
1074 prm.childPrim = true;
1075 prm.disableBody();
1076 //prm.m_taintparent = null;
1077 //prm._parent = null;
1078 //prm.m_taintPhysics = false;
1079 //prm.m_disabled = true;
1080 //prm.childPrim = false;
1081 }
1082 }
1083 disableBody();
1084
1085 lock (childrenPrim)
1086 {
1087 childrenPrim.Remove(odePrim);
1088 }
1089
1090
1091
1092
1093 if (Body != IntPtr.Zero)
1094 {
1095 _parent_scene.remActivePrim(this);
1096 }
1097
1098
1099
1100 lock (childrenPrim)
1101 {
1102 foreach (OdePrim prm in childrenPrim)
1103 {
1104 ParentPrim(prm);
1105 }
1106 }
1107
1108
821 } 1109 }
822 1110
823 private void changeSelectedStatus(float timestep) 1111 private void changeSelectedStatus(float timestep)
@@ -837,7 +1125,7 @@ namespace OpenSim.Region.Physics.OdePlugin
837 disableBodySoft(); 1125 disableBodySoft();
838 } 1126 }
839 1127
840 if (prim_geom != (IntPtr)0) 1128 if (prim_geom != IntPtr.Zero)
841 { 1129 {
842 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories); 1130 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
843 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); 1131 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
@@ -862,7 +1150,7 @@ namespace OpenSim.Region.Physics.OdePlugin
862 if (m_collidesWater) 1150 if (m_collidesWater)
863 m_collisionFlags |= CollisionCategories.Water; 1151 m_collisionFlags |= CollisionCategories.Water;
864 1152
865 if (prim_geom != (IntPtr)0) 1153 if (prim_geom != IntPtr.Zero)
866 { 1154 {
867 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories); 1155 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
868 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); 1156 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
@@ -993,7 +1281,7 @@ namespace OpenSim.Region.Physics.OdePlugin
993 { 1281 {
994 CreateGeom(m_targetSpace, _mesh); 1282 CreateGeom(m_targetSpace, _mesh);
995 1283
996 if (prim_geom != (IntPtr) 0) 1284 if (prim_geom != IntPtr.Zero)
997 { 1285 {
998 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); 1286 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
999 d.Quaternion myrot = new d.Quaternion(); 1287 d.Quaternion myrot = new d.Quaternion();
@@ -1004,7 +1292,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1004 d.GeomSetQuaternion(prim_geom, ref myrot); 1292 d.GeomSetQuaternion(prim_geom, ref myrot);
1005 } 1293 }
1006 1294
1007 if (m_isphysical && Body == (IntPtr)0) 1295 if (m_isphysical && Body == IntPtr.Zero)
1008 { 1296 {
1009 enableBody(); 1297 enableBody();
1010 } 1298 }
@@ -1023,16 +1311,16 @@ namespace OpenSim.Region.Physics.OdePlugin
1023 if (m_isphysical) 1311 if (m_isphysical)
1024 { 1312 {
1025 // This is a fallback.. May no longer be necessary. 1313 // This is a fallback.. May no longer be necessary.
1026 if (Body == (IntPtr) 0) 1314 if (Body == IntPtr.Zero)
1027 enableBody(); 1315 enableBody();
1028 //Prim auto disable after 20 frames, 1316 //Prim auto disable after 20 frames,
1029 //if you move it, re-enable the prim manually. 1317 //if you move it, re-enable the prim manually.
1030 if (_parent != null) 1318 if (_parent != null)
1031 { 1319 {
1032 if (m_linkJoint != (IntPtr)0) 1320 if (m_linkJoint != IntPtr.Zero)
1033 { 1321 {
1034 d.JointDestroy(m_linkJoint); 1322 d.JointDestroy(m_linkJoint);
1035 m_linkJoint = (IntPtr)0; 1323 m_linkJoint = IntPtr.Zero;
1036 } 1324 }
1037 } 1325 }
1038 d.BodySetPosition(Body, _position.X, _position.Y, _position.Z); 1326 d.BodySetPosition(Body, _position.X, _position.Y, _position.Z);
@@ -1058,7 +1346,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1058 m_targetSpace = tempspace; 1346 m_targetSpace = tempspace;
1059 1347
1060 _parent_scene.waitForSpaceUnlock(m_targetSpace); 1348 _parent_scene.waitForSpaceUnlock(m_targetSpace);
1061 if (prim_geom != (IntPtr) 0) 1349 if (prim_geom != IntPtr.Zero)
1062 { 1350 {
1063 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z); 1351 d.GeomSetPosition(prim_geom, _position.X, _position.Y, _position.Z);
1064 1352
@@ -1079,7 +1367,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1079 float fy = 0; 1367 float fy = 0;
1080 float fz = 0; 1368 float fz = 0;
1081 1369
1082 if (IsPhysical && Body != (IntPtr)0 && !m_isSelected) 1370 if (IsPhysical && Body != IntPtr.Zero && !m_isSelected)
1083 { 1371 {
1084 //float PID_P = 900.0f; 1372 //float PID_P = 900.0f;
1085 1373
@@ -1201,7 +1489,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1201 myrot.Z = _orientation.Z; 1489 myrot.Z = _orientation.Z;
1202 myrot.W = _orientation.W; 1490 myrot.W = _orientation.W;
1203 d.GeomSetQuaternion(prim_geom, ref myrot); 1491 d.GeomSetQuaternion(prim_geom, ref myrot);
1204 if (m_isphysical && Body != (IntPtr) 0) 1492 if (m_isphysical && Body != IntPtr.Zero)
1205 { 1493 {
1206 d.BodySetQuaternion(Body, ref myrot); 1494 d.BodySetQuaternion(Body, ref myrot);
1207 if (!m_angularlock.IsIdentical(new PhysicsVector(1, 1, 1), 0)) 1495 if (!m_angularlock.IsIdentical(new PhysicsVector(1, 1, 1), 0))
@@ -1222,10 +1510,10 @@ namespace OpenSim.Region.Physics.OdePlugin
1222 public void changedisable(float timestep) 1510 public void changedisable(float timestep)
1223 { 1511 {
1224 m_disabled = true; 1512 m_disabled = true;
1225 if (Body != (IntPtr)0) 1513 if (Body != IntPtr.Zero)
1226 { 1514 {
1227 d.BodyDisable(Body); 1515 d.BodyDisable(Body);
1228 Body = (IntPtr)0; 1516 Body = IntPtr.Zero;
1229 } 1517 }
1230 1518
1231 m_taintdisable = false; 1519 m_taintdisable = false;
@@ -1235,7 +1523,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1235 { 1523 {
1236 if (m_isphysical == true) 1524 if (m_isphysical == true)
1237 { 1525 {
1238 if (Body == (IntPtr)0) 1526 if (Body == IntPtr.Zero)
1239 { 1527 {
1240 if (_pbs.SculptEntry && _parent_scene.meshSculptedPrim) 1528 if (_pbs.SculptEntry && _parent_scene.meshSculptedPrim)
1241 { 1529 {
@@ -1249,7 +1537,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1249 } 1537 }
1250 else 1538 else
1251 { 1539 {
1252 if (Body != (IntPtr)0) 1540 if (Body != IntPtr.Zero)
1253 { 1541 {
1254 if (_pbs.SculptEntry && _parent_scene.meshSculptedPrim) 1542 if (_pbs.SculptEntry && _parent_scene.meshSculptedPrim)
1255 { 1543 {
@@ -1272,7 +1560,18 @@ namespace OpenSim.Region.Physics.OdePlugin
1272 1560
1273 changeadd(2f); 1561 changeadd(2f);
1274 } 1562 }
1275 disableBody(); 1563 if (childPrim)
1564 {
1565 if (_parent != null)
1566 {
1567 OdePrim parent = (OdePrim)_parent;
1568 parent.ChildDelink(this);
1569 }
1570 }
1571 else
1572 {
1573 disableBody();
1574 }
1276 } 1575 }
1277 } 1576 }
1278 1577
@@ -1301,9 +1600,20 @@ namespace OpenSim.Region.Physics.OdePlugin
1301 // Cleanup meshing here 1600 // Cleanup meshing here
1302 } 1601 }
1303 //kill body to rebuild 1602 //kill body to rebuild
1304 if (IsPhysical && Body != (IntPtr)0) 1603 if (IsPhysical && Body != IntPtr.Zero)
1305 { 1604 {
1306 disableBody(); 1605 if (childPrim)
1606 {
1607 if (_parent != null)
1608 {
1609 OdePrim parent = (OdePrim)_parent;
1610 parent.ChildDelink(this);
1611 }
1612 }
1613 else
1614 {
1615 disableBody();
1616 }
1307 } 1617 }
1308 if (d.SpaceQuery(m_targetSpace, prim_geom)) 1618 if (d.SpaceQuery(m_targetSpace, prim_geom))
1309 { 1619 {
@@ -1311,7 +1621,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1311 d.SpaceRemove(m_targetSpace, prim_geom); 1621 d.SpaceRemove(m_targetSpace, prim_geom);
1312 } 1622 }
1313 d.GeomDestroy(prim_geom); 1623 d.GeomDestroy(prim_geom);
1314 prim_geom = (IntPtr)0; 1624 prim_geom = IntPtr.Zero;
1315 // we don't need to do space calculation because the client sends a position update also. 1625 // we don't need to do space calculation because the client sends a position update also.
1316 1626
1317 // Construction of new prim 1627 // Construction of new prim
@@ -1349,7 +1659,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1349 d.GeomSetQuaternion(prim_geom, ref myrot); 1659 d.GeomSetQuaternion(prim_geom, ref myrot);
1350 1660
1351 //d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z); 1661 //d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z);
1352 if (IsPhysical && Body == (IntPtr)0) 1662 if (IsPhysical && Body == IntPtr.Zero && !childPrim)
1353 { 1663 {
1354 // Re creates body on size. 1664 // Re creates body on size.
1355 // EnableBody also does setMass() 1665 // EnableBody also does setMass()
@@ -1360,7 +1670,14 @@ namespace OpenSim.Region.Physics.OdePlugin
1360 _parent_scene.geom_name_map[prim_geom] = oldname; 1670 _parent_scene.geom_name_map[prim_geom] = oldname;
1361 1671
1362 changeSelectedStatus(timestamp); 1672 changeSelectedStatus(timestamp);
1363 1673 if (childPrim)
1674 {
1675 if (_parent is OdePrim)
1676 {
1677 OdePrim parent = (OdePrim)_parent;
1678 parent.ChildSetGeom(this);
1679 }
1680 }
1364 resetCollisionAccounting(); 1681 resetCollisionAccounting();
1365 m_taintsize = _size; 1682 m_taintsize = _size;
1366 } 1683 }
@@ -1541,7 +1858,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1541 { 1858 {
1542 m_collidesWater = m_taintCollidesWater; 1859 m_collidesWater = m_taintCollidesWater;
1543 1860
1544 if (prim_geom != (IntPtr)0) 1861 if (prim_geom != IntPtr.Zero)
1545 { 1862 {
1546 if (m_collidesWater) 1863 if (m_collidesWater)
1547 { 1864 {
@@ -1560,9 +1877,20 @@ namespace OpenSim.Region.Physics.OdePlugin
1560 string oldname = _parent_scene.geom_name_map[prim_geom]; 1877 string oldname = _parent_scene.geom_name_map[prim_geom];
1561 1878
1562 // Cleanup of old prim geometry and Bodies 1879 // Cleanup of old prim geometry and Bodies
1563 if (IsPhysical && Body != (IntPtr) 0) 1880 if (IsPhysical && Body != IntPtr.Zero)
1564 { 1881 {
1565 disableBody(); 1882 if (childPrim)
1883 {
1884 if (_parent != null)
1885 {
1886 OdePrim parent = (OdePrim)_parent;
1887 parent.ChildDelink(this);
1888 }
1889 }
1890 else
1891 {
1892 disableBody();
1893 }
1566 } 1894 }
1567 try 1895 try
1568 { 1896 {
@@ -1573,7 +1901,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1573 prim_geom = IntPtr.Zero; 1901 prim_geom = IntPtr.Zero;
1574 m_log.Error("[PHYSICS]: PrimGeom dead"); 1902 m_log.Error("[PHYSICS]: PrimGeom dead");
1575 } 1903 }
1576 prim_geom = (IntPtr) 0; 1904 prim_geom = IntPtr.Zero;
1577 // we don't need to do space calculation because the client sends a position update also. 1905 // we don't need to do space calculation because the client sends a position update also.
1578 if (_size.X <= 0) _size.X = 0.01f; 1906 if (_size.X <= 0) _size.X = 0.01f;
1579 if (_size.Y <= 0) _size.Y = 0.01f; 1907 if (_size.Y <= 0) _size.Y = 0.01f;
@@ -1608,7 +1936,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1608 d.GeomSetQuaternion(prim_geom, ref myrot); 1936 d.GeomSetQuaternion(prim_geom, ref myrot);
1609 1937
1610 //d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z); 1938 //d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z);
1611 if (IsPhysical && Body == (IntPtr)0) 1939 if (IsPhysical && Body == IntPtr.Zero)
1612 { 1940 {
1613 // Re creates body on size. 1941 // Re creates body on size.
1614 // EnableBody also does setMass() 1942 // EnableBody also does setMass()
@@ -1618,7 +1946,14 @@ namespace OpenSim.Region.Physics.OdePlugin
1618 _parent_scene.geom_name_map[prim_geom] = oldname; 1946 _parent_scene.geom_name_map[prim_geom] = oldname;
1619 1947
1620 changeSelectedStatus(timestamp); 1948 changeSelectedStatus(timestamp);
1621 1949 if (childPrim)
1950 {
1951 if (_parent is OdePrim)
1952 {
1953 OdePrim parent = (OdePrim)_parent;
1954 parent.ChildSetGeom(this);
1955 }
1956 }
1622 resetCollisionAccounting(); 1957 resetCollisionAccounting();
1623 m_taintshape = false; 1958 m_taintshape = false;
1624 } 1959 }
@@ -1658,7 +1993,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1658 Thread.Sleep(20); 1993 Thread.Sleep(20);
1659 if (IsPhysical) 1994 if (IsPhysical)
1660 { 1995 {
1661 if (Body != (IntPtr)0) 1996 if (Body != IntPtr.Zero)
1662 { 1997 {
1663 d.BodySetLinearVel(Body, m_taintVelocity.X, m_taintVelocity.Y, m_taintVelocity.Z); 1998 d.BodySetLinearVel(Body, m_taintVelocity.X, m_taintVelocity.Y, m_taintVelocity.Z);
1664 } 1999 }