aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
diff options
context:
space:
mode:
authorTeravus Ovares2007-12-19 22:42:06 +0000
committerTeravus Ovares2007-12-19 22:42:06 +0000
commit27e028752600921deac57e281f1df6d8c7310c5d (patch)
treef94a99a6e7ad4d4325d336561f0e6365ec44f6d3 /OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
parentThank you very much, CharlieO for: (diff)
downloadopensim-SC-27e028752600921deac57e281f1df6d8c7310c5d.zip
opensim-SC-27e028752600921deac57e281f1df6d8c7310c5d.tar.gz
opensim-SC-27e028752600921deac57e281f1df6d8c7310c5d.tar.bz2
opensim-SC-27e028752600921deac57e281f1df6d8c7310c5d.tar.xz
* Re-did the mass calculations in ODE for Prim
* Exposed the mass as a PhysicsActor read only property (so scripts can get at it - hint hint -) * Hollow and Path Cuts affect the prim mass (all Hollow Types are supported in this calculation (sphere,square,triangle)) * Prim no longer sink into the ground.
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODEPrim.cs124
1 files changed, 118 insertions, 6 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
index 2ec8131..26cb24b 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
@@ -65,6 +65,9 @@ namespace OpenSim.Region.Physics.OdePlugin
65 private bool m_throttleUpdates = false; 65 private bool m_throttleUpdates = false;
66 private int throttleCounter = 0; 66 private int throttleCounter = 0;
67 public bool outofBounds = false; 67 public bool outofBounds = false;
68 private float m_density = 0f;
69
70
68 71
69 public bool _zeroFlag = false; 72 public bool _zeroFlag = false;
70 private bool m_lastUpdateSent = false; 73 private bool m_lastUpdateSent = false;
@@ -73,7 +76,7 @@ namespace OpenSim.Region.Physics.OdePlugin
73 private String m_primName; 76 private String m_primName;
74 private PhysicsVector _target_velocity; 77 private PhysicsVector _target_velocity;
75 public d.Mass pMass; 78 public d.Mass pMass;
76 private const float MassMultiplier = 150f; // Ref: Water: 1000kg.. this iset to 500 79 private const float MassMultiplier = 150f;
77 private int debugcounter = 0; 80 private int debugcounter = 0;
78 81
79 public OdePrim(String primName, OdeScene parent_scene, IntPtr targetSpace, PhysicsVector pos, PhysicsVector size, 82 public OdePrim(String primName, OdeScene parent_scene, IntPtr targetSpace, PhysicsVector pos, PhysicsVector size,
@@ -182,15 +185,104 @@ namespace OpenSim.Region.Physics.OdePlugin
182 185
183 _parent_scene.addActivePrim(this); 186 _parent_scene.addActivePrim(this);
184 } 187 }
185 public void setMass() 188 private float CalculateMass()
186 { 189 {
187 //Sets Mass based on member MassMultiplier. 190 float volume = 0;
191
192 // No material is passed to the physics engines yet.. soo..
193 float density = 2.7f; // Aluminum g/cm3;
194
195 float returnMass = 0;
196
197 switch (_pbs.ProfileShape)
198 {
199 case ProfileShape.Square:
200 // Profile Volume
201
202 volume = _size.X * _size.Y * _size.Z;
203
204 // If the user has 'hollowed out'
205 if (((float)_pbs.ProfileHollow / 50000f) > 0.0)
206 {
207 float hollowAmount = (float)_pbs.ProfileHollow / 50000f;
208 //break;
209 float hollowVolume = 0;
210 switch (_pbs.HollowShape)
211 {
212 case HollowShape.Square:
213 case HollowShape.Same:
214 // Cube Hollow
215 float hollowsizex = _size.X * hollowAmount;
216 float hollowsizey = _size.Y * hollowAmount;
217 float hollowsizez = _size.Z * hollowAmount;
218 hollowVolume = hollowsizex * hollowsizey * hollowsizez;
219 break;
220
221 case HollowShape.Circle:
222 // Hollow shape is a perfect cyllinder in respect to the cube's scale
223 float hRadius = _size.X / 2;
224 float hLength = _size.Z;
225
226 // pi * r2 * h
227 hollowVolume = ((float)(Math.PI * Math.Pow(hRadius, 2) * hLength) * hollowAmount);
228 break;
229
230 case HollowShape.Triangle:
231 float aLength = _size.Y; // Triangle is an Equilateral Triangular Prism with aLength = to _size.Y
232 // 1/2 abh
233 hollowVolume = (float)((0.5 * aLength * _size.X * _size.Z) * hollowAmount);
234 break;
235
236 default:
237 hollowVolume = 0;
238 break;
239 }
240 volume = volume - hollowVolume;
241
242 }
243
244 break;
245
246 default:
247 volume = _size.X * _size.Y * _size.Z;
248 break;
249 }
250
251 // Calculate Path cut effect on volume
252 // Not exact, in the triangle hollow example
253 // They should ever be less then zero..
254 // we'll ignore it if it's less then zero
255 float PathCutEndAmount = _pbs.ProfileEnd;
256 float PathCutStartAmount = _pbs.ProfileBegin;
257 if (((PathCutStartAmount + PathCutEndAmount)/50000f) > 0.0f)
258 {
259
260 float pathCutAmount = ((PathCutStartAmount + PathCutEndAmount) / 50000f);
261
262 if (pathCutAmount >= 0.99f)
263 pathCutAmount=0.99f;
264
265 volume = volume - (volume * pathCutAmount);
266 }
267
268 returnMass = density * volume;
269
270 return returnMass;
271 }
272
273 public void setMass()
274 {
188 if (Body != (IntPtr)0) 275 if (Body != (IntPtr)0)
189 { 276 {
190 d.MassSetBox(out pMass, (_size.X * _size.Y * _size.Z * MassMultiplier), _size.X, _size.Y, _size.Z); 277 //if (_pbs.ProfileShape = ProfileShape.Square) {
278
279 d.MassSetBoxTotal(out pMass, CalculateMass(), _size.X, _size.Y, _size.Z);
191 d.BodySetMass(Body, ref pMass); 280 d.BodySetMass(Body, ref pMass);
192 } 281 }
193 } 282 }
283
284
285
194 public void disableBody() 286 public void disableBody()
195 { 287 {
196 //this kills the body so things like 'mesh' can re-create it. 288 //this kills the body so things like 'mesh' can re-create it.
@@ -212,7 +304,7 @@ namespace OpenSim.Region.Physics.OdePlugin
212 int[] indexList = mesh.getIndexListAsIntLocked(); // Also pinned, needs release after usage 304 int[] indexList = mesh.getIndexListAsIntLocked(); // Also pinned, needs release after usage
213 int VertexCount = vertexList.GetLength(0) / 3; 305 int VertexCount = vertexList.GetLength(0) / 3;
214 int IndexCount = indexList.GetLength(0); 306 int IndexCount = indexList.GetLength(0);
215 307
216 _triMeshData = d.GeomTriMeshDataCreate(); 308 _triMeshData = d.GeomTriMeshDataCreate();
217 309
218 d.GeomTriMeshDataBuildSimple(_triMeshData, vertexList, 3 * sizeof(float), VertexCount, indexList, IndexCount, 310 d.GeomTriMeshDataBuildSimple(_triMeshData, vertexList, 3 * sizeof(float), VertexCount, indexList, IndexCount,
@@ -220,7 +312,7 @@ namespace OpenSim.Region.Physics.OdePlugin
220 d.GeomTriMeshDataPreprocess(_triMeshData); 312 d.GeomTriMeshDataPreprocess(_triMeshData);
221 313
222 prim_geom = d.CreateTriMesh(m_targetSpace, _triMeshData, parent_scene.triCallback, null, null); 314 prim_geom = d.CreateTriMesh(m_targetSpace, _triMeshData, parent_scene.triCallback, null, null);
223 315
224 if (IsPhysical && Body == (IntPtr)0) 316 if (IsPhysical && Body == (IntPtr)0)
225 { 317 {
226 // Recreate the body 318 // Recreate the body
@@ -502,6 +594,26 @@ namespace OpenSim.Region.Physics.OdePlugin
502 } 594 }
503 } 595 }
504 596
597 public override float Mass
598 {
599 get { return CalculateMass(); }
600 }
601
602 public override PhysicsVector Force
603 {
604 get { return PhysicsVector.Zero; }
605 }
606
607 public override PhysicsVector CenterOfMass
608 {
609 get { return PhysicsVector.Zero; }
610 }
611
612 public override PhysicsVector GeometricCenter
613 {
614 get { return PhysicsVector.Zero; }
615 }
616
505 public override PrimitiveBaseShape Shape 617 public override PrimitiveBaseShape Shape
506 { 618 {
507 set 619 set