aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2012-04-21 03:23:51 +0100
committerJustin Clark-Casey (justincc)2012-04-21 03:23:51 +0100
commitf60959459574b1473dbe35d780aa0fbe4d688580 (patch)
tree859f36e7b957565bc880650befdd4c3fc032e8fa /OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
parentAdd test for setting physics in a linkset (diff)
downloadopensim-SC-f60959459574b1473dbe35d780aa0fbe4d688580.zip
opensim-SC-f60959459574b1473dbe35d780aa0fbe4d688580.tar.gz
opensim-SC-f60959459574b1473dbe35d780aa0fbe4d688580.tar.bz2
opensim-SC-f60959459574b1473dbe35d780aa0fbe4d688580.tar.xz
refactor: Simplify ODEPrim.AddChildPrim() by returning early where appropriate.
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODEPrim.cs232
1 files changed, 117 insertions, 115 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
index 0a8cf75..cbb49ac 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
@@ -1042,142 +1042,144 @@ Console.WriteLine("ZProcessTaints for " + Name);
1042 /// <param name="prim">Child prim</param> 1042 /// <param name="prim">Child prim</param>
1043 private void AddChildPrim(OdePrim prim) 1043 private void AddChildPrim(OdePrim prim)
1044 { 1044 {
1045//Console.WriteLine("AddChildPrim " + Name); 1045 if (LocalID == prim.LocalID)
1046 if (LocalID != prim.LocalID) 1046 return;
1047
1048 if (Body == IntPtr.Zero)
1047 { 1049 {
1048 if (Body == IntPtr.Zero) 1050 Body = d.BodyCreate(_parent_scene.world);
1051 setMass();
1052 }
1053
1054 lock (childrenPrim)
1055 {
1056 if (childrenPrim.Contains(prim))
1057 return;
1058
1059//Console.WriteLine("childrenPrim.Add " + prim);
1060 childrenPrim.Add(prim);
1061
1062 foreach (OdePrim prm in childrenPrim)
1049 { 1063 {
1050 Body = d.BodyCreate(_parent_scene.world); 1064 d.Mass m2;
1051 setMass(); 1065 d.MassSetZero(out m2);
1066 d.MassSetBoxTotal(out m2, prim.CalculateMass(), prm._size.X, prm._size.Y, prm._size.Z);
1067
1068 d.Quaternion quat = new d.Quaternion();
1069 quat.W = prm._orientation.W;
1070 quat.X = prm._orientation.X;
1071 quat.Y = prm._orientation.Y;
1072 quat.Z = prm._orientation.Z;
1073
1074 d.Matrix3 mat = new d.Matrix3();
1075 d.RfromQ(out mat, ref quat);
1076 d.MassRotate(ref m2, ref mat);
1077 d.MassTranslate(ref m2, Position.X - prm.Position.X, Position.Y - prm.Position.Y, Position.Z - prm.Position.Z);
1078 d.MassAdd(ref pMass, ref m2);
1052 } 1079 }
1053 if (Body != IntPtr.Zero) 1080
1081 foreach (OdePrim prm in childrenPrim)
1054 { 1082 {
1055 lock (childrenPrim) 1083 prm.m_collisionCategories |= CollisionCategories.Body;
1056 { 1084 prm.m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind);
1057 if (!childrenPrim.Contains(prim))
1058 {
1059//Console.WriteLine("childrenPrim.Add " + prim);
1060 childrenPrim.Add(prim);
1061
1062 foreach (OdePrim prm in childrenPrim)
1063 {
1064 d.Mass m2;
1065 d.MassSetZero(out m2);
1066 d.MassSetBoxTotal(out m2, prim.CalculateMass(), prm._size.X, prm._size.Y, prm._size.Z);
1067
1068 d.Quaternion quat = new d.Quaternion();
1069 quat.W = prm._orientation.W;
1070 quat.X = prm._orientation.X;
1071 quat.Y = prm._orientation.Y;
1072 quat.Z = prm._orientation.Z;
1073
1074 d.Matrix3 mat = new d.Matrix3();
1075 d.RfromQ(out mat, ref quat);
1076 d.MassRotate(ref m2, ref mat);
1077 d.MassTranslate(ref m2, Position.X - prm.Position.X, Position.Y - prm.Position.Y, Position.Z - prm.Position.Z);
1078 d.MassAdd(ref pMass, ref m2);
1079 }
1080
1081 foreach (OdePrim prm in childrenPrim)
1082 {
1083 prm.m_collisionCategories |= CollisionCategories.Body;
1084 prm.m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind);
1085 1085
1086//Console.WriteLine(" GeomSetCategoryBits 1: " + prm.prim_geom + " - " + (int)prm.m_collisionCategories + " for " + Name); 1086//Console.WriteLine(" GeomSetCategoryBits 1: " + prm.prim_geom + " - " + (int)prm.m_collisionCategories + " for " + Name);
1087 d.GeomSetCategoryBits(prm.prim_geom, (int)prm.m_collisionCategories); 1087 d.GeomSetCategoryBits(prm.prim_geom, (int)prm.m_collisionCategories);
1088 d.GeomSetCollideBits(prm.prim_geom, (int)prm.m_collisionFlags); 1088 d.GeomSetCollideBits(prm.prim_geom, (int)prm.m_collisionFlags);
1089
1090 d.Quaternion quat = new d.Quaternion();
1091 quat.W = prm._orientation.W;
1092 quat.X = prm._orientation.X;
1093 quat.Y = prm._orientation.Y;
1094 quat.Z = prm._orientation.Z;
1095
1096 d.Matrix3 mat = new d.Matrix3();
1097 d.RfromQ(out mat, ref quat);
1098 if (Body != IntPtr.Zero)
1099 {
1100 d.GeomSetBody(prm.prim_geom, Body);
1101 prm.childPrim = true;
1102 d.GeomSetOffsetWorldPosition(prm.prim_geom, prm.Position.X , prm.Position.Y, prm.Position.Z);
1103 //d.GeomSetOffsetPosition(prim.prim_geom,
1104 // (Position.X - prm.Position.X) - pMass.c.X,
1105 // (Position.Y - prm.Position.Y) - pMass.c.Y,
1106 // (Position.Z - prm.Position.Z) - pMass.c.Z);
1107 d.GeomSetOffsetWorldRotation(prm.prim_geom, ref mat);
1108 //d.GeomSetOffsetRotation(prm.prim_geom, ref mat);
1109 d.MassTranslate(ref pMass, -pMass.c.X, -pMass.c.Y, -pMass.c.Z);
1110 d.BodySetMass(Body, ref pMass);
1111 }
1112 else
1113 {
1114 m_log.DebugFormat("[PHYSICS]: {0} ain't got no boooooooooddy, no body", Name);
1115 }
1116 1089
1117 prm.m_interpenetrationcount = 0; 1090 d.Quaternion quat = new d.Quaternion();
1118 prm.m_collisionscore = 0; 1091 quat.W = prm._orientation.W;
1119 prm.m_disabled = false; 1092 quat.X = prm._orientation.X;
1093 quat.Y = prm._orientation.Y;
1094 quat.Z = prm._orientation.Z;
1120 1095
1121 // The body doesn't already have a finite rotation mode set here 1096 d.Matrix3 mat = new d.Matrix3();
1122 if ((!m_angularlock.ApproxEquals(Vector3.Zero, 0f)) && _parent == null) 1097 d.RfromQ(out mat, ref quat);
1123 { 1098 if (Body != IntPtr.Zero)
1124 prm.createAMotor(m_angularlock); 1099 {
1125 } 1100 d.GeomSetBody(prm.prim_geom, Body);
1126 prm.Body = Body; 1101 prm.childPrim = true;
1127 _parent_scene.ActivatePrim(prm); 1102 d.GeomSetOffsetWorldPosition(prm.prim_geom, prm.Position.X , prm.Position.Y, prm.Position.Z);
1128 } 1103 //d.GeomSetOffsetPosition(prim.prim_geom,
1104 // (Position.X - prm.Position.X) - pMass.c.X,
1105 // (Position.Y - prm.Position.Y) - pMass.c.Y,
1106 // (Position.Z - prm.Position.Z) - pMass.c.Z);
1107 d.GeomSetOffsetWorldRotation(prm.prim_geom, ref mat);
1108 //d.GeomSetOffsetRotation(prm.prim_geom, ref mat);
1109 d.MassTranslate(ref pMass, -pMass.c.X, -pMass.c.Y, -pMass.c.Z);
1110 d.BodySetMass(Body, ref pMass);
1111 }
1112 else
1113 {
1114 m_log.DebugFormat("[PHYSICS]: {0} ain't got no boooooooooddy, no body", Name);
1115 }
1116
1117 prm.m_interpenetrationcount = 0;
1118 prm.m_collisionscore = 0;
1119 prm.m_disabled = false;
1120
1121 // The body doesn't already have a finite rotation mode set here
1122 if ((!m_angularlock.ApproxEquals(Vector3.Zero, 0f)) && _parent == null)
1123 {
1124 prm.createAMotor(m_angularlock);
1125 }
1126 prm.Body = Body;
1127 _parent_scene.ActivatePrim(prm);
1128 }
1129 1129
1130 m_collisionCategories |= CollisionCategories.Body; 1130 m_collisionCategories |= CollisionCategories.Body;
1131 m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind); 1131 m_collisionFlags |= (CollisionCategories.Land | CollisionCategories.Wind);
1132 1132
1133//Console.WriteLine("GeomSetCategoryBits 2: " + prim_geom + " - " + (int)m_collisionCategories + " for " + Name); 1133//Console.WriteLine("GeomSetCategoryBits 2: " + prim_geom + " - " + (int)m_collisionCategories + " for " + Name);
1134 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories); 1134 d.GeomSetCategoryBits(prim_geom, (int)m_collisionCategories);
1135//Console.WriteLine(" Post GeomSetCategoryBits 2"); 1135//Console.WriteLine(" Post GeomSetCategoryBits 2");
1136 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags); 1136 d.GeomSetCollideBits(prim_geom, (int)m_collisionFlags);
1137
1138 d.Quaternion quat2 = new d.Quaternion();
1139 quat2.W = _orientation.W;
1140 quat2.X = _orientation.X;
1141 quat2.Y = _orientation.Y;
1142 quat2.Z = _orientation.Z;
1143
1144 d.Matrix3 mat2 = new d.Matrix3();
1145 d.RfromQ(out mat2, ref quat2);
1146 d.GeomSetBody(prim_geom, Body);
1147 d.GeomSetOffsetWorldPosition(prim_geom, Position.X - pMass.c.X, Position.Y - pMass.c.Y, Position.Z - pMass.c.Z);
1148 //d.GeomSetOffsetPosition(prim.prim_geom,
1149 // (Position.X - prm.Position.X) - pMass.c.X,
1150 // (Position.Y - prm.Position.Y) - pMass.c.Y,
1151 // (Position.Z - prm.Position.Z) - pMass.c.Z);
1152 //d.GeomSetOffsetRotation(prim_geom, ref mat2);
1153 d.MassTranslate(ref pMass, -pMass.c.X, -pMass.c.Y, -pMass.c.Z);
1154 d.BodySetMass(Body, ref pMass);
1155
1156 d.BodySetAutoDisableFlag(Body, true);
1157 d.BodySetAutoDisableSteps(Body, body_autodisable_frames);
1158 1137
1159 m_interpenetrationcount = 0; 1138 d.Quaternion quat2 = new d.Quaternion();
1160 m_collisionscore = 0; 1139 quat2.W = _orientation.W;
1161 m_disabled = false; 1140 quat2.X = _orientation.X;
1141 quat2.Y = _orientation.Y;
1142 quat2.Z = _orientation.Z;
1162 1143
1163 // The body doesn't already have a finite rotation mode set here 1144 d.Matrix3 mat2 = new d.Matrix3();
1164 if ((!m_angularlock.ApproxEquals(Vector3.Zero, 0f)) && _parent == null) 1145 d.RfromQ(out mat2, ref quat2);
1165 { 1146 d.GeomSetBody(prim_geom, Body);
1166 createAMotor(m_angularlock); 1147 d.GeomSetOffsetWorldPosition(prim_geom, Position.X - pMass.c.X, Position.Y - pMass.c.Y, Position.Z - pMass.c.Z);
1167 } 1148 //d.GeomSetOffsetPosition(prim.prim_geom,
1168 d.BodySetPosition(Body, Position.X, Position.Y, Position.Z); 1149 // (Position.X - prm.Position.X) - pMass.c.X,
1169 if (m_vehicle.Type != Vehicle.TYPE_NONE) 1150 // (Position.Y - prm.Position.Y) - pMass.c.Y,
1170 m_vehicle.Enable(Body, _parent_scene); 1151 // (Position.Z - prm.Position.Z) - pMass.c.Z);
1152 //d.GeomSetOffsetRotation(prim_geom, ref mat2);
1153 d.MassTranslate(ref pMass, -pMass.c.X, -pMass.c.Y, -pMass.c.Z);
1154 d.BodySetMass(Body, ref pMass);
1171 1155
1172 _parent_scene.ActivatePrim(this); 1156 d.BodySetAutoDisableFlag(Body, true);
1173 } 1157 d.BodySetAutoDisableSteps(Body, body_autodisable_frames);
1174 } 1158
1159 m_interpenetrationcount = 0;
1160 m_collisionscore = 0;
1161 m_disabled = false;
1162
1163 // The body doesn't already have a finite rotation mode set here
1164 if ((!m_angularlock.ApproxEquals(Vector3.Zero, 0f)) && _parent == null)
1165 {
1166 createAMotor(m_angularlock);
1175 } 1167 }
1168
1169 d.BodySetPosition(Body, Position.X, Position.Y, Position.Z);
1170
1171 if (m_vehicle.Type != Vehicle.TYPE_NONE)
1172 m_vehicle.Enable(Body, _parent_scene);
1173
1174 _parent_scene.ActivatePrim(this);
1176 } 1175 }
1177 } 1176 }
1178 1177
1179 private void ChildSetGeom(OdePrim odePrim) 1178 private void ChildSetGeom(OdePrim odePrim)
1180 { 1179 {
1180// m_log.DebugFormat(
1181// "[ODE PRIM]: ChildSetGeom {0} {1} for {2} {3}", odePrim.Name, odePrim.LocalID, Name, LocalID);
1182
1181 //if (IsPhysical && Body != IntPtr.Zero) 1183 //if (IsPhysical && Body != IntPtr.Zero)
1182 lock (childrenPrim) 1184 lock (childrenPrim)
1183 { 1185 {