aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/OdePlugin
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/OdePlugin')
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODECharacter.cs28
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODEPrim.cs124
2 files changed, 144 insertions, 8 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
index 6f22ecf..04bf9a0 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
@@ -46,6 +46,7 @@ namespace OpenSim.Region.Physics.OdePlugin
46 private PhysicsVector _target_velocity; 46 private PhysicsVector _target_velocity;
47 private PhysicsVector _acceleration; 47 private PhysicsVector _acceleration;
48 private PhysicsVector m_rotationalVelocity; 48 private PhysicsVector m_rotationalVelocity;
49 private float m_density = 50f;
49 private bool m_pidControllerActive = true; 50 private bool m_pidControllerActive = true;
50 private static float PID_D = 3020.0f; 51 private static float PID_D = 3020.0f;
51 private static float PID_P = 7000.0f; 52 private static float PID_P = 7000.0f;
@@ -93,7 +94,7 @@ namespace OpenSim.Region.Physics.OdePlugin
93 { 94 {
94 95
95 Shell = d.CreateCapsule(parent_scene.space, CAPSULE_RADIUS, CAPSULE_LENGTH); 96 Shell = d.CreateCapsule(parent_scene.space, CAPSULE_RADIUS, CAPSULE_LENGTH);
96 d.MassSetCapsule(out ShellMass, 50.0f, 3, 0.4f, 1.0f); 97 d.MassSetCapsule(out ShellMass, m_density, 3, CAPSULE_RADIUS, CAPSULE_LENGTH);
97 Body = d.BodyCreate(parent_scene.world); 98 Body = d.BodyCreate(parent_scene.world);
98 d.BodySetMass(Body, ref ShellMass); 99 d.BodySetMass(Body, ref ShellMass);
99 d.BodySetPosition(Body, pos.X, pos.Y, pos.Z); 100 d.BodySetPosition(Body, pos.X, pos.Y, pos.Z);
@@ -273,7 +274,7 @@ namespace OpenSim.Region.Physics.OdePlugin
273 d.GeomDestroy(Shell); 274 d.GeomDestroy(Shell);
274 //MainLog.Instance.Verbose("PHYSICS", "Set Avatar Height To: " + (CAPSULE_RADIUS + CAPSULE_LENGTH)); 275 //MainLog.Instance.Verbose("PHYSICS", "Set Avatar Height To: " + (CAPSULE_RADIUS + CAPSULE_LENGTH));
275 Shell = d.CreateCapsule(_parent_scene.space, capsuleradius, CAPSULE_LENGTH); 276 Shell = d.CreateCapsule(_parent_scene.space, capsuleradius, CAPSULE_LENGTH);
276 d.MassSetCapsule(out ShellMass, 50.0f, 3, CAPSULE_RADIUS, CAPSULE_LENGTH); 277 d.MassSetCapsule(out ShellMass, m_density, 3, CAPSULE_RADIUS, CAPSULE_LENGTH);
277 Body = d.BodyCreate(_parent_scene.world); 278 Body = d.BodyCreate(_parent_scene.world);
278 d.BodySetMass(Body, ref ShellMass); 279 d.BodySetMass(Body, ref ShellMass);
279 d.BodySetPosition(Body, _position.X, _position.Y, _position.Z + Math.Abs(CAPSULE_LENGTH - prevCapsule)); 280 d.BodySetPosition(Body, _position.X, _position.Y, _position.Z + Math.Abs(CAPSULE_LENGTH - prevCapsule));
@@ -283,6 +284,29 @@ namespace OpenSim.Region.Physics.OdePlugin
283 _parent_scene.actor_name_map[Shell] = (PhysicsActor)this; 284 _parent_scene.actor_name_map[Shell] = (PhysicsActor)this;
284 } 285 }
285 } 286 }
287 public override float Mass
288 {
289 get {
290
291 float AVvolume = (float)(Math.PI * Math.Pow(CAPSULE_RADIUS, 2) * CAPSULE_LENGTH);
292 return m_density * AVvolume;
293 }
294 }
295
296 public override PhysicsVector Force
297 {
298 get { return new PhysicsVector(_target_velocity.X,_target_velocity.Y,_target_velocity.Z); }
299 }
300
301 public override PhysicsVector CenterOfMass
302 {
303 get { return PhysicsVector.Zero; }
304 }
305
306 public override PhysicsVector GeometricCenter
307 {
308 get { return PhysicsVector.Zero; }
309 }
286 310
287 public override PrimitiveBaseShape Shape 311 public override PrimitiveBaseShape Shape
288 { 312 {
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