aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/OdePlugin
diff options
context:
space:
mode:
authorlbsa712007-12-27 21:41:48 +0000
committerlbsa712007-12-27 21:41:48 +0000
commitefd90b56b761219af6425b1c7a2cdd3b6ffb4de2 (patch)
treebf5b897e1e3c13211e3e2fc61d30508b94c928c0 /OpenSim/Region/Physics/OdePlugin
parent* removed always true if (diff)
downloadopensim-SC-efd90b56b761219af6425b1c7a2cdd3b6ffb4de2.zip
opensim-SC-efd90b56b761219af6425b1c7a2cdd3b6ffb4de2.tar.gz
opensim-SC-efd90b56b761219af6425b1c7a2cdd3b6ffb4de2.tar.bz2
opensim-SC-efd90b56b761219af6425b1c7a2cdd3b6ffb4de2.tar.xz
* Optimized usings
* shortened references * Removed redundant 'this' * Normalized EOF
Diffstat (limited to 'OpenSim/Region/Physics/OdePlugin')
-rw-r--r--OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs2
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODECharacter.cs114
-rw-r--r--OpenSim/Region/Physics/OdePlugin/ODEPrim.cs175
-rw-r--r--OpenSim/Region/Physics/OdePlugin/OdePlugin.cs336
4 files changed, 309 insertions, 318 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs b/OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs
index 1e5713b..1ea5458 100644
--- a/OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs
+++ b/OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs
@@ -55,4 +55,4 @@ using System.Runtime.InteropServices;
55// You can specify all values by your own or you can build default build and revision 55// You can specify all values by your own or you can build default build and revision
56// numbers with the '*' character (the default): 56// numbers with the '*' character (the default):
57 57
58[assembly : AssemblyVersion("1.0.*")] 58[assembly : AssemblyVersion("1.0.*")] \ No newline at end of file
diff --git a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
index 9676db4..a118e7c 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODECharacter.cs
@@ -27,11 +27,9 @@
27*/ 27*/
28 28
29using System; 29using System;
30using System.Collections.Generic;
31using Axiom.Math; 30using Axiom.Math;
32using Ode.NET; 31using Ode.NET;
33using OpenSim.Framework; 32using OpenSim.Framework;
34using OpenSim.Framework.Console;
35using OpenSim.Region.Physics.Manager; 33using OpenSim.Region.Physics.Manager;
36 34
37namespace OpenSim.Region.Physics.OdePlugin 35namespace OpenSim.Region.Physics.OdePlugin
@@ -87,7 +85,9 @@ namespace OpenSim.Region.Physics.OdePlugin
87 _acceleration = new PhysicsVector(); 85 _acceleration = new PhysicsVector();
88 _parent_scene = parent_scene; 86 _parent_scene = parent_scene;
89 87
90 m_StandUpRotation = new d.Matrix3(0.8184158f, -0.5744568f, -0.0139677f, 0.5744615f, 0.8185215f, -0.004074608f, 0.01377355f, -0.004689182f, 0.9998941f); 88 m_StandUpRotation =
89 new d.Matrix3(0.8184158f, -0.5744568f, -0.0139677f, 0.5744615f, 0.8185215f, -0.004074608f, 0.01377355f,
90 -0.004689182f, 0.9998941f);
91 91
92 for (int i = 0; i < 11; i++) 92 for (int i = 0; i < 11; i++)
93 { 93 {
@@ -105,12 +105,9 @@ namespace OpenSim.Region.Physics.OdePlugin
105 d.GeomSetBody(Shell, Body); 105 d.GeomSetBody(Shell, Body);
106 106
107 107
108
109
110 d.BodySetRotation(Body, ref m_StandUpRotation); 108 d.BodySetRotation(Body, ref m_StandUpRotation);
111 109
112 110
113
114 //Amotor = d.JointCreateAMotor(parent_scene.world, IntPtr.Zero); 111 //Amotor = d.JointCreateAMotor(parent_scene.world, IntPtr.Zero);
115 //d.JointAttach(Amotor, Body, IntPtr.Zero); 112 //d.JointAttach(Amotor, Body, IntPtr.Zero);
116 //d.JointSetAMotorMode(Amotor, dAMotorEuler); 113 //d.JointSetAMotorMode(Amotor, dAMotorEuler);
@@ -124,45 +121,47 @@ namespace OpenSim.Region.Physics.OdePlugin
124 //d.JointSetAMotorParam(Amotor, 0, -0); 121 //d.JointSetAMotorParam(Amotor, 0, -0);
125 //d.JointSetAMotorParam(Amotor, 0x200, -0); 122 //d.JointSetAMotorParam(Amotor, 0x200, -0);
126 //d.JointSetAMotorParam(Amotor, 0x100, -0); 123 //d.JointSetAMotorParam(Amotor, 0x100, -0);
127 // d.JointSetAMotorParam(Amotor, 0, 0); 124 // d.JointSetAMotorParam(Amotor, 0, 0);
128 // d.JointSetAMotorParam(Amotor, 3, 0); 125 // d.JointSetAMotorParam(Amotor, 3, 0);
129 // d.JointSetAMotorParam(Amotor, 2, 0); 126 // d.JointSetAMotorParam(Amotor, 2, 0);
130
131
132
133 } 127 }
134 m_name = avName; 128 m_name = avName;
135 parent_scene.geom_name_map[Shell] = avName; 129 parent_scene.geom_name_map[Shell] = avName;
136 parent_scene.actor_name_map[Shell] = (PhysicsActor)this; 130 parent_scene.actor_name_map[Shell] = (PhysicsActor) this;
137 } 131 }
132
138 public override int PhysicsActorType 133 public override int PhysicsActorType
139 { 134 {
140 get { return (int)ActorTypes.Agent; } 135 get { return (int) ActorTypes.Agent; }
141 set { return; } 136 set { return; }
142 } 137 }
138
143 public override bool SetAlwaysRun 139 public override bool SetAlwaysRun
144 { 140 {
145 get { return m_alwaysRun; } 141 get { return m_alwaysRun; }
146 set { m_alwaysRun = value; } 142 set { m_alwaysRun = value; }
147 } 143 }
144
148 public override bool IsPhysical 145 public override bool IsPhysical
149 { 146 {
150 get { return false; } 147 get { return false; }
151 set { return; } 148 set { return; }
152 } 149 }
150
153 public override bool ThrottleUpdates 151 public override bool ThrottleUpdates
154 { 152 {
155 get { return false; } 153 get { return false; }
156 set { return; } 154 set { return; }
157 } 155 }
156
158 public override bool Flying 157 public override bool Flying
159 { 158 {
160 get { return flying; } 159 get { return flying; }
161 set { flying = value; } 160 set { flying = value; }
162 } 161 }
162
163 public override bool IsColliding 163 public override bool IsColliding
164 { 164 {
165
166 get { return m_iscolliding; } 165 get { return m_iscolliding; }
167 set 166 set
168 { 167 {
@@ -193,24 +192,22 @@ namespace OpenSim.Region.Physics.OdePlugin
193 192
194 // Equal truecounts and false counts means we're colliding with something. 193 // Equal truecounts and false counts means we're colliding with something.
195 194
196 if (falsecount > 1.2 * truecount) 195 if (falsecount > 1.2*truecount)
197 { 196 {
198 m_iscolliding = false; 197 m_iscolliding = false;
199 } 198 }
200 else 199 else
201 { 200 {
202 m_iscolliding = true; 201 m_iscolliding = true;
203
204
205 } 202 }
206 if (m_wascolliding != m_iscolliding) 203 if (m_wascolliding != m_iscolliding)
207 { 204 {
208 //base.SendCollisionUpdate(new CollisionEventUpdate()); 205 //base.SendCollisionUpdate(new CollisionEventUpdate());
209
210 } 206 }
211 m_wascolliding = m_iscolliding; 207 m_wascolliding = m_iscolliding;
212 } 208 }
213 } 209 }
210
214 public override bool CollidingGround 211 public override bool CollidingGround
215 { 212 {
216 get { return m_iscollidingGround; } 213 get { return m_iscollidingGround; }
@@ -243,7 +240,7 @@ namespace OpenSim.Region.Physics.OdePlugin
243 240
244 // Equal truecounts and false counts means we're colliding with something. 241 // Equal truecounts and false counts means we're colliding with something.
245 242
246 if (falsecount > 1.2 * truecount) 243 if (falsecount > 1.2*truecount)
247 { 244 {
248 m_iscollidingGround = false; 245 m_iscollidingGround = false;
249 } 246 }
@@ -258,10 +255,12 @@ namespace OpenSim.Region.Physics.OdePlugin
258 m_wascollidingGround = m_iscollidingGround; 255 m_wascollidingGround = m_iscollidingGround;
259 } 256 }
260 } 257 }
258
261 public override bool CollidingObj 259 public override bool CollidingObj
262 { 260 {
263 get { return m_iscollidingObj; } 261 get { return m_iscollidingObj; }
264 set { 262 set
263 {
265 m_iscollidingObj = value; 264 m_iscollidingObj = value;
266 if (value) 265 if (value)
267 m_pidControllerActive = false; 266 m_pidControllerActive = false;
@@ -269,10 +268,12 @@ namespace OpenSim.Region.Physics.OdePlugin
269 m_pidControllerActive = true; 268 m_pidControllerActive = true;
270 } 269 }
271 } 270 }
271
272 public void SetPidStatus(bool status) 272 public void SetPidStatus(bool status)
273 { 273 {
274 m_pidControllerActive = status; 274 m_pidControllerActive = status;
275 } 275 }
276
276 public override PhysicsVector Position 277 public override PhysicsVector Position
277 { 278 {
278 get { return _position; } 279 get { return _position; }
@@ -285,14 +286,16 @@ namespace OpenSim.Region.Physics.OdePlugin
285 } 286 }
286 } 287 }
287 } 288 }
289
288 public override PhysicsVector RotationalVelocity 290 public override PhysicsVector RotationalVelocity
289 { 291 {
290 get { return m_rotationalVelocity; } 292 get { return m_rotationalVelocity; }
291 set { m_rotationalVelocity = value; } 293 set { m_rotationalVelocity = value; }
292 } 294 }
295
293 public override PhysicsVector Size 296 public override PhysicsVector Size
294 { 297 {
295 get { return new PhysicsVector(CAPSULE_RADIUS * 2, CAPSULE_RADIUS * 2, CAPSULE_LENGTH); } 298 get { return new PhysicsVector(CAPSULE_RADIUS*2, CAPSULE_RADIUS*2, CAPSULE_LENGTH); }
296 set 299 set
297 { 300 {
298 m_pidControllerActive = true; 301 m_pidControllerActive = true;
@@ -303,7 +306,7 @@ namespace OpenSim.Region.Physics.OdePlugin
303 float capsuleradius = CAPSULE_RADIUS; 306 float capsuleradius = CAPSULE_RADIUS;
304 capsuleradius = 0.2f; 307 capsuleradius = 0.2f;
305 308
306 CAPSULE_LENGTH = (SetSize.Z - ((SetSize.Z * 0.43f))); // subtract 43% of the size 309 CAPSULE_LENGTH = (SetSize.Z - ((SetSize.Z*0.43f))); // subtract 43% of the size
307 d.BodyDestroy(Body); 310 d.BodyDestroy(Body);
308 d.GeomDestroy(Shell); 311 d.GeomDestroy(Shell);
309 //MainLog.Instance.Verbose("PHYSICS", "Set Avatar Height To: " + (CAPSULE_RADIUS + CAPSULE_LENGTH)); 312 //MainLog.Instance.Verbose("PHYSICS", "Set Avatar Height To: " + (CAPSULE_RADIUS + CAPSULE_LENGTH));
@@ -311,25 +314,27 @@ namespace OpenSim.Region.Physics.OdePlugin
311 d.MassSetCapsule(out ShellMass, m_density, 3, CAPSULE_RADIUS, CAPSULE_LENGTH); 314 d.MassSetCapsule(out ShellMass, m_density, 3, CAPSULE_RADIUS, CAPSULE_LENGTH);
312 Body = d.BodyCreate(_parent_scene.world); 315 Body = d.BodyCreate(_parent_scene.world);
313 d.BodySetMass(Body, ref ShellMass); 316 d.BodySetMass(Body, ref ShellMass);
314 d.BodySetPosition(Body, _position.X, _position.Y, _position.Z + Math.Abs(CAPSULE_LENGTH - prevCapsule)); 317 d.BodySetPosition(Body, _position.X, _position.Y,
318 _position.Z + Math.Abs(CAPSULE_LENGTH - prevCapsule));
315 d.GeomSetBody(Shell, Body); 319 d.GeomSetBody(Shell, Body);
316 } 320 }
317 _parent_scene.geom_name_map[Shell] = m_name; 321 _parent_scene.geom_name_map[Shell] = m_name;
318 _parent_scene.actor_name_map[Shell] = (PhysicsActor)this; 322 _parent_scene.actor_name_map[Shell] = (PhysicsActor) this;
319 } 323 }
320 } 324 }
325
321 public override float Mass 326 public override float Mass
322 { 327 {
323 get { 328 get
324 329 {
325 float AVvolume = (float)(Math.PI * Math.Pow(CAPSULE_RADIUS, 2) * CAPSULE_LENGTH); 330 float AVvolume = (float) (Math.PI*Math.Pow(CAPSULE_RADIUS, 2)*CAPSULE_LENGTH);
326 return m_density * AVvolume; 331 return m_density*AVvolume;
327 } 332 }
328 } 333 }
329 334
330 public override PhysicsVector Force 335 public override PhysicsVector Force
331 { 336 {
332 get { return new PhysicsVector(_target_velocity.X,_target_velocity.Y,_target_velocity.Z); } 337 get { return new PhysicsVector(_target_velocity.X, _target_velocity.Y, _target_velocity.Z); }
333 } 338 }
334 339
335 public override PhysicsVector CenterOfMass 340 public override PhysicsVector CenterOfMass
@@ -344,18 +349,17 @@ namespace OpenSim.Region.Physics.OdePlugin
344 349
345 public override PrimitiveBaseShape Shape 350 public override PrimitiveBaseShape Shape
346 { 351 {
347 set 352 set { return; }
348 {
349 return;
350 }
351 } 353 }
352 354
353 public override PhysicsVector Velocity 355 public override PhysicsVector Velocity
354 { 356 {
355 get { return _velocity; } 357 get { return _velocity; }
356 set { 358 set
359 {
357 m_pidControllerActive = true; 360 m_pidControllerActive = true;
358 _target_velocity = value; } 361 _target_velocity = value;
362 }
359 } 363 }
360 364
361 public override bool Kinematic 365 public override bool Kinematic
@@ -390,6 +394,7 @@ namespace OpenSim.Region.Physics.OdePlugin
390 394
391 //m_lastUpdateSent = false; 395 //m_lastUpdateSent = false;
392 } 396 }
397
393 public void doForce(PhysicsVector force) 398 public void doForce(PhysicsVector force)
394 { 399 {
395 if (!collidelock) 400 if (!collidelock)
@@ -413,13 +418,11 @@ namespace OpenSim.Region.Physics.OdePlugin
413 //d.BodyAddForceAtRelPos(Body, 0.0f, 0.0f, -servo, 0.0f, 0.0f, -1.0f); 418 //d.BodyAddForceAtRelPos(Body, 0.0f, 0.0f, -servo, 0.0f, 0.0f, -1.0f);
414 419
415 //m_lastUpdateSent = false; 420 //m_lastUpdateSent = false;
416
417 } 421 }
418
419 } 422 }
423
420 public override void SetMomentum(PhysicsVector momentum) 424 public override void SetMomentum(PhysicsVector momentum)
421 { 425 {
422
423 } 426 }
424 427
425 public void Move(float timeStep) 428 public void Move(float timeStep)
@@ -442,7 +445,6 @@ namespace OpenSim.Region.Physics.OdePlugin
442 else 445 else
443 { 446 {
444 movementdivisor = 0.8f; 447 movementdivisor = 0.8f;
445
446 } 448 }
447 449
448 // if velocity is zero, use position control; otherwise, velocity control 450 // if velocity is zero, use position control; otherwise, velocity control
@@ -457,11 +459,11 @@ namespace OpenSim.Region.Physics.OdePlugin
457 if (m_pidControllerActive) 459 if (m_pidControllerActive)
458 { 460 {
459 d.Vector3 pos = d.BodyGetPosition(Body); 461 d.Vector3 pos = d.BodyGetPosition(Body);
460 vec.X = (_target_velocity.X - vel.X) * PID_D + (_zeroPosition.X - pos.X) * PID_P; 462 vec.X = (_target_velocity.X - vel.X)*PID_D + (_zeroPosition.X - pos.X)*PID_P;
461 vec.Y = (_target_velocity.Y - vel.Y) * PID_D + (_zeroPosition.Y - pos.Y) * PID_P; 463 vec.Y = (_target_velocity.Y - vel.Y)*PID_D + (_zeroPosition.Y - pos.Y)*PID_P;
462 if (flying) 464 if (flying)
463 { 465 {
464 vec.Z = (_target_velocity.Z - vel.Z) * (PID_D + 5100) + (_zeroPosition.Z - pos.Z) * PID_P; 466 vec.Z = (_target_velocity.Z - vel.Z)*(PID_D + 5100) + (_zeroPosition.Z - pos.Z)*PID_P;
465 } 467 }
466 } 468 }
467 //PidStatus = true; 469 //PidStatus = true;
@@ -472,21 +474,20 @@ namespace OpenSim.Region.Physics.OdePlugin
472 _zeroFlag = false; 474 _zeroFlag = false;
473 if (m_iscolliding || flying) 475 if (m_iscolliding || flying)
474 { 476 {
475 477 vec.X = ((_target_velocity.X/movementdivisor) - vel.X)*PID_D;
476 vec.X = ((_target_velocity.X / movementdivisor) - vel.X) * PID_D; 478 vec.Y = ((_target_velocity.Y/movementdivisor) - vel.Y)*PID_D;
477 vec.Y = ((_target_velocity.Y / movementdivisor) - vel.Y) * PID_D;
478 } 479 }
479 if (m_iscolliding && !flying && _target_velocity.Z > 0.0f) 480 if (m_iscolliding && !flying && _target_velocity.Z > 0.0f)
480 { 481 {
481 d.Vector3 pos = d.BodyGetPosition(Body); 482 d.Vector3 pos = d.BodyGetPosition(Body);
482 vec.Z = (_target_velocity.Z - vel.Z) * PID_D + (_zeroPosition.Z - pos.Z) * PID_P; 483 vec.Z = (_target_velocity.Z - vel.Z)*PID_D + (_zeroPosition.Z - pos.Z)*PID_P;
483 if (_target_velocity.X > 0) 484 if (_target_velocity.X > 0)
484 { 485 {
485 vec.X = ((_target_velocity.X - vel.X) / 1.2f) * PID_D; 486 vec.X = ((_target_velocity.X - vel.X)/1.2f)*PID_D;
486 } 487 }
487 if (_target_velocity.Y > 0) 488 if (_target_velocity.Y > 0)
488 { 489 {
489 vec.Y = ((_target_velocity.Y - vel.Y) / 1.2f) * PID_D; 490 vec.Y = ((_target_velocity.Y - vel.Y)/1.2f)*PID_D;
490 } 491 }
491 } 492 }
492 else if (!m_iscolliding && !flying) 493 else if (!m_iscolliding && !flying)
@@ -494,19 +495,18 @@ namespace OpenSim.Region.Physics.OdePlugin
494 d.Vector3 pos = d.BodyGetPosition(Body); 495 d.Vector3 pos = d.BodyGetPosition(Body);
495 if (_target_velocity.X > 0) 496 if (_target_velocity.X > 0)
496 { 497 {
497 vec.X = ((_target_velocity.X - vel.X) / 1.2f) * PID_D; 498 vec.X = ((_target_velocity.X - vel.X)/1.2f)*PID_D;
498 } 499 }
499 if (_target_velocity.Y > 0) 500 if (_target_velocity.Y > 0)
500 { 501 {
501 vec.Y = ((_target_velocity.Y - vel.Y) / 1.2f) * PID_D; 502 vec.Y = ((_target_velocity.Y - vel.Y)/1.2f)*PID_D;
502 } 503 }
503
504 } 504 }
505 505
506 506
507 if (flying) 507 if (flying)
508 { 508 {
509 vec.Z = (_target_velocity.Z - vel.Z) * (PID_D + 5100); 509 vec.Z = (_target_velocity.Z - vel.Z)*(PID_D + 5100);
510 } 510 }
511 } 511 }
512 if (flying) 512 if (flying)
@@ -546,13 +546,12 @@ namespace OpenSim.Region.Physics.OdePlugin
546 int[] arrayitem = _parent_scene.calculateSpaceArrayItemFromPos(_position); 546 int[] arrayitem = _parent_scene.calculateSpaceArrayItemFromPos(_position);
547 //if (primScenAvatarIn == "0") 547 //if (primScenAvatarIn == "0")
548 //{ 548 //{
549 //MainLog.Instance.Verbose("Physics", "Avatar " + m_name + " in space with no prim. Arr:':" + arrayitem[0].ToString() + "," + arrayitem[1].ToString()); 549 //MainLog.Instance.Verbose("Physics", "Avatar " + m_name + " in space with no prim. Arr:':" + arrayitem[0].ToString() + "," + arrayitem[1].ToString());
550 //} 550 //}
551 //else 551 //else
552 //{ 552 //{
553 // MainLog.Instance.Verbose("Physics", "Avatar " + m_name + " in Prim space':" + primScenAvatarIn + ". Arr:" + arrayitem[0].ToString() + "," + arrayitem[1].ToString()); 553 // MainLog.Instance.Verbose("Physics", "Avatar " + m_name + " in Prim space':" + primScenAvatarIn + ". Arr:" + arrayitem[0].ToString() + "," + arrayitem[1].ToString());
554 //} 554 //}
555
556 } 555 }
557 } 556 }
558 else 557 else
@@ -586,12 +585,11 @@ namespace OpenSim.Region.Physics.OdePlugin
586 { 585 {
587 lock (OdeScene.OdeLock) 586 lock (OdeScene.OdeLock)
588 { 587 {
589 // d.JointDestroy(Amotor); 588 // d.JointDestroy(Amotor);
590 d.GeomDestroy(Shell); 589 d.GeomDestroy(Shell);
591 _parent_scene.geom_name_map.Remove(Shell); 590 _parent_scene.geom_name_map.Remove(Shell);
592 d.BodyDestroy(Body); 591 d.BodyDestroy(Body);
593 } 592 }
594 } 593 }
595 } 594 }
596 595} \ No newline at end of file
597}
diff --git a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
index 35328b8..5fef47d 100644
--- a/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
+++ b/OpenSim/Region/Physics/OdePlugin/ODEPrim.cs
@@ -27,16 +27,13 @@
27*/ 27*/
28 28
29using System; 29using System;
30using System.Collections.Generic;
31using Axiom.Math; 30using Axiom.Math;
32using Ode.NET; 31using Ode.NET;
33using OpenSim.Framework; 32using OpenSim.Framework;
34using OpenSim.Framework.Console;
35using OpenSim.Region.Physics.Manager; 33using OpenSim.Region.Physics.Manager;
36 34
37namespace OpenSim.Region.Physics.OdePlugin 35namespace OpenSim.Region.Physics.OdePlugin
38{ 36{
39
40 public class OdePrim : PhysicsActor 37 public class OdePrim : PhysicsActor
41 { 38 {
42 public PhysicsVector _position; 39 public PhysicsVector _position;
@@ -57,7 +54,7 @@ namespace OpenSim.Region.Physics.OdePlugin
57 private IMesh _mesh; 54 private IMesh _mesh;
58 private PrimitiveBaseShape _pbs; 55 private PrimitiveBaseShape _pbs;
59 private OdeScene _parent_scene; 56 private OdeScene _parent_scene;
60 public IntPtr m_targetSpace = (IntPtr)0; 57 public IntPtr m_targetSpace = (IntPtr) 0;
61 public IntPtr prim_geom; 58 public IntPtr prim_geom;
62 public IntPtr _triMeshData; 59 public IntPtr _triMeshData;
63 private bool iscolliding = false; 60 private bool iscolliding = false;
@@ -65,18 +62,17 @@ namespace OpenSim.Region.Physics.OdePlugin
65 private bool m_throttleUpdates = false; 62 private bool m_throttleUpdates = false;
66 private int throttleCounter = 0; 63 private int throttleCounter = 0;
67 public bool outofBounds = false; 64 public bool outofBounds = false;
68 private float m_density = 10.000006836f;// Aluminum g/cm3; 65 private float m_density = 10.000006836f; // Aluminum g/cm3;
69 66
70
71 67
72 public bool _zeroFlag = false; 68 public bool _zeroFlag = false;
73 private bool m_lastUpdateSent = false; 69 private bool m_lastUpdateSent = false;
74 70
75 public IntPtr Body = (IntPtr)0; 71 public IntPtr Body = (IntPtr) 0;
76 private String m_primName; 72 private String m_primName;
77 private PhysicsVector _target_velocity; 73 private PhysicsVector _target_velocity;
78 public d.Mass pMass; 74 public d.Mass pMass;
79 75
80 private int debugcounter = 0; 76 private int debugcounter = 0;
81 77
82 public OdePrim(String primName, OdeScene parent_scene, IntPtr targetSpace, PhysicsVector pos, PhysicsVector size, 78 public OdePrim(String primName, OdeScene parent_scene, IntPtr targetSpace, PhysicsVector pos, PhysicsVector size,
@@ -123,7 +119,6 @@ namespace OpenSim.Region.Physics.OdePlugin
123 // linksets *should* be in a space together.. but are not currently 119 // linksets *should* be in a space together.. but are not currently
124 if (m_isphysical) 120 if (m_isphysical)
125 m_targetSpace = _parent_scene.space; 121 m_targetSpace = _parent_scene.space;
126
127 } 122 }
128 m_primName = primName; 123 m_primName = primName;
129 124
@@ -147,25 +142,28 @@ namespace OpenSim.Region.Physics.OdePlugin
147 d.GeomSetQuaternion(prim_geom, ref myrot); 142 d.GeomSetQuaternion(prim_geom, ref myrot);
148 143
149 144
150 if (m_isphysical && Body == (IntPtr)0) 145 if (m_isphysical && Body == (IntPtr) 0)
151 { 146 {
152 enableBody(); 147 enableBody();
153 } 148 }
154 parent_scene.geom_name_map[prim_geom] = primName; 149 parent_scene.geom_name_map[prim_geom] = primName;
155 parent_scene.actor_name_map[prim_geom] = (PhysicsActor)this; 150 parent_scene.actor_name_map[prim_geom] = (PhysicsActor) this;
156 // don't do .add() here; old geoms get recycled with the same hash 151 // don't do .add() here; old geoms get recycled with the same hash
157 } 152 }
158 } 153 }
154
159 public override int PhysicsActorType 155 public override int PhysicsActorType
160 { 156 {
161 get { return (int)ActorTypes.Prim; } 157 get { return (int) ActorTypes.Prim; }
162 set { return; } 158 set { return; }
163 } 159 }
160
164 public override bool SetAlwaysRun 161 public override bool SetAlwaysRun
165 { 162 {
166 get { return false; } 163 get { return false; }
167 set { return; } 164 set { return; }
168 } 165 }
166
169 public void enableBody() 167 public void enableBody()
170 { 168 {
171 // Sets the geom to a body 169 // Sets the geom to a body
@@ -185,13 +183,14 @@ namespace OpenSim.Region.Physics.OdePlugin
185 183
186 _parent_scene.addActivePrim(this); 184 _parent_scene.addActivePrim(this);
187 } 185 }
186
188 private float CalculateMass() 187 private float CalculateMass()
189 { 188 {
190 float volume = 0; 189 float volume = 0;
191 190
192 // No material is passed to the physics engines yet.. soo.. 191 // No material is passed to the physics engines yet.. soo..
193 // we're using the m_density constant in the class definition 192 // we're using the m_density constant in the class definition
194 193
195 194
196 float returnMass = 0; 195 float returnMass = 0;
197 196
@@ -199,17 +198,17 @@ namespace OpenSim.Region.Physics.OdePlugin
199 { 198 {
200 case ProfileShape.Square: 199 case ProfileShape.Square:
201 // Profile Volume 200 // Profile Volume
202 201
203 volume = _size.X * _size.Y * _size.Z; 202 volume = _size.X*_size.Y*_size.Z;
204 203
205 // If the user has 'hollowed out' 204 // If the user has 'hollowed out'
206 // ProfileHollow is one of those 0 to 50000 values :P 205 // ProfileHollow is one of those 0 to 50000 values :P
207 // we like percentages better.. so turning into a percentage 206 // we like percentages better.. so turning into a percentage
208 207
209 if (((float)_pbs.ProfileHollow / 50000f) > 0.0) 208 if (((float) _pbs.ProfileHollow/50000f) > 0.0)
210 { 209 {
211 float hollowAmount = (float)_pbs.ProfileHollow / 50000f; 210 float hollowAmount = (float) _pbs.ProfileHollow/50000f;
212 211
213 // calculate the hollow volume by it's shape compared to the prim shape 212 // calculate the hollow volume by it's shape compared to the prim shape
214 float hollowVolume = 0; 213 float hollowVolume = 0;
215 switch (_pbs.HollowShape) 214 switch (_pbs.HollowShape)
@@ -217,29 +216,29 @@ namespace OpenSim.Region.Physics.OdePlugin
217 case HollowShape.Square: 216 case HollowShape.Square:
218 case HollowShape.Same: 217 case HollowShape.Same:
219 // Cube Hollow volume calculation 218 // Cube Hollow volume calculation
220 float hollowsizex = _size.X * hollowAmount; 219 float hollowsizex = _size.X*hollowAmount;
221 float hollowsizey = _size.Y * hollowAmount; 220 float hollowsizey = _size.Y*hollowAmount;
222 float hollowsizez = _size.Z * hollowAmount; 221 float hollowsizez = _size.Z*hollowAmount;
223 hollowVolume = hollowsizex * hollowsizey * hollowsizez; 222 hollowVolume = hollowsizex*hollowsizey*hollowsizez;
224 break; 223 break;
225 224
226 case HollowShape.Circle: 225 case HollowShape.Circle:
227 // Hollow shape is a perfect cyllinder in respect to the cube's scale 226 // Hollow shape is a perfect cyllinder in respect to the cube's scale
228 // Cyllinder hollow volume calculation 227 // Cyllinder hollow volume calculation
229 float hRadius = _size.X / 2; 228 float hRadius = _size.X/2;
230 float hLength = _size.Z; 229 float hLength = _size.Z;
231 230
232 // pi * r2 * h 231 // pi * r2 * h
233 hollowVolume = ((float)(Math.PI * Math.Pow(hRadius, 2) * hLength) * hollowAmount); 232 hollowVolume = ((float) (Math.PI*Math.Pow(hRadius, 2)*hLength)*hollowAmount);
234 break; 233 break;
235 234
236 case HollowShape.Triangle: 235 case HollowShape.Triangle:
237 // Equilateral Triangular Prism volume hollow calculation 236 // Equilateral Triangular Prism volume hollow calculation
238 // Triangle is an Equilateral Triangular Prism with aLength = to _size.Y 237 // Triangle is an Equilateral Triangular Prism with aLength = to _size.Y
239 238
240 float aLength = _size.Y; 239 float aLength = _size.Y;
241 // 1/2 abh 240 // 1/2 abh
242 hollowVolume = (float)((0.5 * aLength * _size.X * _size.Z) * hollowAmount); 241 hollowVolume = (float) ((0.5*aLength*_size.X*_size.Z)*hollowAmount);
243 break; 242 break;
244 243
245 default: 244 default:
@@ -247,15 +246,14 @@ namespace OpenSim.Region.Physics.OdePlugin
247 break; 246 break;
248 } 247 }
249 volume = volume - hollowVolume; 248 volume = volume - hollowVolume;
250
251 } 249 }
252 250
253 break; 251 break;
254 252
255 default: 253 default:
256 // we don't have all of the volume formulas yet so 254 // we don't have all of the volume formulas yet so
257 // use the common volume formula for all 255 // use the common volume formula for all
258 volume = _size.X * _size.Y * _size.Z; 256 volume = _size.X*_size.Y*_size.Z;
259 break; 257 break;
260 } 258 }
261 259
@@ -273,70 +271,70 @@ namespace OpenSim.Region.Physics.OdePlugin
273 float PathCutStartAmount = _pbs.ProfileBegin; 271 float PathCutStartAmount = _pbs.ProfileBegin;
274 if (((PathCutStartAmount + PathCutEndAmount)/50000f) > 0.0f) 272 if (((PathCutStartAmount + PathCutEndAmount)/50000f) > 0.0f)
275 { 273 {
274 float pathCutAmount = ((PathCutStartAmount + PathCutEndAmount)/50000f);
276 275
277 float pathCutAmount = ((PathCutStartAmount + PathCutEndAmount) / 50000f);
278
279 // Check the return amount for sanity 276 // Check the return amount for sanity
280 if (pathCutAmount >= 0.99f) 277 if (pathCutAmount >= 0.99f)
281 pathCutAmount=0.99f; 278 pathCutAmount = 0.99f;
282 279
283 volume = volume - (volume * pathCutAmount); 280 volume = volume - (volume*pathCutAmount);
284 } 281 }
285 282
286 // Mass = density * volume 283 // Mass = density * volume
287 284
288 returnMass = m_density * volume; 285 returnMass = m_density*volume;
289 286
290 return returnMass; 287 return returnMass;
291 } 288 }
292 289
293 public void setMass() 290 public void setMass()
294 { 291 {
295 if (Body != (IntPtr)0) 292 if (Body != (IntPtr) 0)
296 { 293 {
297 d.MassSetBoxTotal(out pMass, CalculateMass(), _size.X, _size.Y, _size.Z); 294 d.MassSetBoxTotal(out pMass, CalculateMass(), _size.X, _size.Y, _size.Z);
298 d.BodySetMass(Body, ref pMass); 295 d.BodySetMass(Body, ref pMass);
299 } 296 }
300 } 297 }
301 298
302
303 299
304 public void disableBody() 300 public void disableBody()
305 { 301 {
306 //this kills the body so things like 'mesh' can re-create it. 302 //this kills the body so things like 'mesh' can re-create it.
307 if (Body != (IntPtr)0) 303 if (Body != (IntPtr) 0)
308 { 304 {
309 _parent_scene.remActivePrim(this); 305 _parent_scene.remActivePrim(this);
310 d.BodyDestroy(Body); 306 d.BodyDestroy(Body);
311 Body = (IntPtr)0; 307 Body = (IntPtr) 0;
312 } 308 }
313 } 309 }
310
314 public void setMesh(OdeScene parent_scene, IMesh mesh) 311 public void setMesh(OdeScene parent_scene, IMesh mesh)
315 { 312 {
316 //Kill Body so that mesh can re-make the geom 313 //Kill Body so that mesh can re-make the geom
317 if (IsPhysical && Body != (IntPtr)0) 314 if (IsPhysical && Body != (IntPtr) 0)
318 { 315 {
319 disableBody(); 316 disableBody();
320 } 317 }
321 float[] vertexList = mesh.getVertexListAsFloatLocked(); // Note, that vertextList is pinned in memory 318 float[] vertexList = mesh.getVertexListAsFloatLocked(); // Note, that vertextList is pinned in memory
322 int[] indexList = mesh.getIndexListAsIntLocked(); // Also pinned, needs release after usage 319 int[] indexList = mesh.getIndexListAsIntLocked(); // Also pinned, needs release after usage
323 int VertexCount = vertexList.GetLength(0) / 3; 320 int VertexCount = vertexList.GetLength(0)/3;
324 int IndexCount = indexList.GetLength(0); 321 int IndexCount = indexList.GetLength(0);
325 322
326 _triMeshData = d.GeomTriMeshDataCreate(); 323 _triMeshData = d.GeomTriMeshDataCreate();
327 324
328 d.GeomTriMeshDataBuildSimple(_triMeshData, vertexList, 3 * sizeof(float), VertexCount, indexList, IndexCount, 325 d.GeomTriMeshDataBuildSimple(_triMeshData, vertexList, 3*sizeof (float), VertexCount, indexList, IndexCount,
329 3 * sizeof(int)); 326 3*sizeof (int));
330 d.GeomTriMeshDataPreprocess(_triMeshData); 327 d.GeomTriMeshDataPreprocess(_triMeshData);
331 328
332 prim_geom = d.CreateTriMesh(m_targetSpace, _triMeshData, parent_scene.triCallback, null, null); 329 prim_geom = d.CreateTriMesh(m_targetSpace, _triMeshData, parent_scene.triCallback, null, null);
333 330
334 if (IsPhysical && Body == (IntPtr)0) 331 if (IsPhysical && Body == (IntPtr) 0)
335 { 332 {
336 // Recreate the body 333 // Recreate the body
337 enableBody(); 334 enableBody();
338 } 335 }
339 } 336 }
337
340 public void ProcessTaints(float timestep) 338 public void ProcessTaints(float timestep)
341 { 339 {
342 if (m_taintposition != _position) 340 if (m_taintposition != _position)
@@ -357,14 +355,14 @@ namespace OpenSim.Region.Physics.OdePlugin
357 if (m_taintshape) 355 if (m_taintshape)
358 changeshape(timestep); 356 changeshape(timestep);
359 // 357 //
360
361 } 358 }
359
362 public void Move(float timestep) 360 public void Move(float timestep)
363 { 361 {
364 if (m_isphysical) 362 if (m_isphysical)
365 { 363 {
366 // This is a fallback.. May no longer be necessary. 364 // This is a fallback.. May no longer be necessary.
367 if (Body == (IntPtr)0) 365 if (Body == (IntPtr) 0)
368 enableBody(); 366 enableBody();
369 //Prim auto disable after 20 frames, 367 //Prim auto disable after 20 frames,
370 ///if you move it, re-enable the prim manually. 368 ///if you move it, re-enable the prim manually.
@@ -382,35 +380,35 @@ namespace OpenSim.Region.Physics.OdePlugin
382 380
383 m_taintposition = _position; 381 m_taintposition = _position;
384 } 382 }
383
385 public void rotate(float timestep) 384 public void rotate(float timestep)
386 { 385 {
387
388 d.Quaternion myrot = new d.Quaternion(); 386 d.Quaternion myrot = new d.Quaternion();
389 myrot.W = _orientation.w; 387 myrot.W = _orientation.w;
390 myrot.X = _orientation.x; 388 myrot.X = _orientation.x;
391 myrot.Y = _orientation.y; 389 myrot.Y = _orientation.y;
392 myrot.Z = _orientation.z; 390 myrot.Z = _orientation.z;
393 d.GeomSetQuaternion(prim_geom, ref myrot); 391 d.GeomSetQuaternion(prim_geom, ref myrot);
394 if (m_isphysical && Body != (IntPtr)0) 392 if (m_isphysical && Body != (IntPtr) 0)
395 { 393 {
396 d.BodySetQuaternion(Body, ref myrot); 394 d.BodySetQuaternion(Body, ref myrot);
397 } 395 }
398 396
399 m_taintrot = _orientation; 397 m_taintrot = _orientation;
400 } 398 }
399
401 public void changePhysicsStatus(float timestap) 400 public void changePhysicsStatus(float timestap)
402 { 401 {
403 if (m_isphysical == true) 402 if (m_isphysical == true)
404 { 403 {
405 if (Body == (IntPtr)0) 404 if (Body == (IntPtr) 0)
406 { 405 {
407 enableBody(); 406 enableBody();
408 } 407 }
409
410 } 408 }
411 else 409 else
412 { 410 {
413 if (Body != (IntPtr)0) 411 if (Body != (IntPtr) 0)
414 { 412 {
415 disableBody(); 413 disableBody();
416 } 414 }
@@ -419,6 +417,7 @@ namespace OpenSim.Region.Physics.OdePlugin
419 417
420 m_taintPhysics = m_isphysical; 418 m_taintPhysics = m_isphysical;
421 } 419 }
420
422 public void changesize(float timestamp) 421 public void changesize(float timestamp)
423 { 422 {
424 string oldname = _parent_scene.geom_name_map[prim_geom]; 423 string oldname = _parent_scene.geom_name_map[prim_geom];
@@ -429,7 +428,7 @@ namespace OpenSim.Region.Physics.OdePlugin
429 // Cleanup meshing here 428 // Cleanup meshing here
430 } 429 }
431 //kill body to rebuild 430 //kill body to rebuild
432 if (IsPhysical && Body != (IntPtr)0) 431 if (IsPhysical && Body != (IntPtr) 0)
433 { 432 {
434 disableBody(); 433 disableBody();
435 } 434 }
@@ -442,10 +441,8 @@ namespace OpenSim.Region.Physics.OdePlugin
442 // we don't need to do space calculation because the client sends a position update also. 441 // we don't need to do space calculation because the client sends a position update also.
443 442
444 // Construction of new prim 443 // Construction of new prim
445 if (this._parent_scene.needsMeshing(_pbs)) 444 if (_parent_scene.needsMeshing(_pbs))
446 { 445 {
447
448
449 // Don't need to re-enable body.. it's done in SetMesh 446 // Don't need to re-enable body.. it's done in SetMesh
450 IMesh mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size); 447 IMesh mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size);
451 // createmesh returns null when it's a shape that isn't a cube. 448 // createmesh returns null when it's a shape that isn't a cube.
@@ -463,8 +460,6 @@ namespace OpenSim.Region.Physics.OdePlugin
463 myrot.Y = _orientation.y; 460 myrot.Y = _orientation.y;
464 myrot.Z = _orientation.z; 461 myrot.Z = _orientation.z;
465 d.GeomSetQuaternion(prim_geom, ref myrot); 462 d.GeomSetQuaternion(prim_geom, ref myrot);
466
467
468 } 463 }
469 } 464 }
470 else 465 else
@@ -480,7 +475,7 @@ namespace OpenSim.Region.Physics.OdePlugin
480 475
481 476
482 //d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z); 477 //d.GeomBoxSetLengths(prim_geom, _size.X, _size.Y, _size.Z);
483 if (IsPhysical && Body == (IntPtr)0) 478 if (IsPhysical && Body == (IntPtr) 0)
484 { 479 {
485 // Re creates body on size. 480 // Re creates body on size.
486 // EnableBody also does setMass() 481 // EnableBody also does setMass()
@@ -493,12 +488,13 @@ namespace OpenSim.Region.Physics.OdePlugin
493 488
494 m_taintsize = _size; 489 m_taintsize = _size;
495 } 490 }
491
496 public void changeshape(float timestamp) 492 public void changeshape(float timestamp)
497 { 493 {
498 string oldname = _parent_scene.geom_name_map[prim_geom]; 494 string oldname = _parent_scene.geom_name_map[prim_geom];
499 495
500 // Cleanup of old prim geometry and Bodies 496 // Cleanup of old prim geometry and Bodies
501 if (IsPhysical && Body != (IntPtr)0) 497 if (IsPhysical && Body != (IntPtr) 0)
502 { 498 {
503 disableBody(); 499 disableBody();
504 } 500 }
@@ -509,7 +505,7 @@ namespace OpenSim.Region.Physics.OdePlugin
509 } 505 }
510 506
511 // Construction of new prim 507 // Construction of new prim
512 if (this._parent_scene.needsMeshing(_pbs)) 508 if (_parent_scene.needsMeshing(_pbs))
513 { 509 {
514 IMesh mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size); 510 IMesh mesh = _parent_scene.mesher.CreateMesh(oldname, _pbs, _size);
515 if (mesh != null) 511 if (mesh != null)
@@ -525,7 +521,7 @@ namespace OpenSim.Region.Physics.OdePlugin
525 { 521 {
526 prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z); 522 prim_geom = d.CreateBox(m_targetSpace, _size.X, _size.Y, _size.Z);
527 } 523 }
528 if (IsPhysical && Body == (IntPtr)0) 524 if (IsPhysical && Body == (IntPtr) 0)
529 { 525 {
530 //re-create new body 526 //re-create new body
531 enableBody(); 527 enableBody();
@@ -544,11 +540,13 @@ namespace OpenSim.Region.Physics.OdePlugin
544 540
545 m_taintshape = false; 541 m_taintshape = false;
546 } 542 }
543
547 public override bool IsPhysical 544 public override bool IsPhysical
548 { 545 {
549 get { return m_isphysical; } 546 get { return m_isphysical; }
550 set { m_isphysical = value; } 547 set { m_isphysical = value; }
551 } 548 }
549
552 public void setPrimForRemoval() 550 public void setPrimForRemoval()
553 { 551 {
554 m_taintremove = true; 552 m_taintremove = true;
@@ -556,9 +554,7 @@ namespace OpenSim.Region.Physics.OdePlugin
556 554
557 public override bool Flying 555 public override bool Flying
558 { 556 {
559 get 557 get { return false; //no flying prims for you
560 {
561 return false; //no flying prims for you
562 } 558 }
563 set { } 559 set { }
564 } 560 }
@@ -568,16 +564,19 @@ namespace OpenSim.Region.Physics.OdePlugin
568 get { return iscolliding; } 564 get { return iscolliding; }
569 set { iscolliding = value; } 565 set { iscolliding = value; }
570 } 566 }
567
571 public override bool CollidingGround 568 public override bool CollidingGround
572 { 569 {
573 get { return false; } 570 get { return false; }
574 set { return; } 571 set { return; }
575 } 572 }
573
576 public override bool CollidingObj 574 public override bool CollidingObj
577 { 575 {
578 get { return false; } 576 get { return false; }
579 set { return; } 577 set { return; }
580 } 578 }
579
581 public override bool ThrottleUpdates 580 public override bool ThrottleUpdates
582 { 581 {
583 get { return m_throttleUpdates; } 582 get { return m_throttleUpdates; }
@@ -588,20 +587,13 @@ namespace OpenSim.Region.Physics.OdePlugin
588 { 587 {
589 get { return _position; } 588 get { return _position; }
590 589
591 set 590 set { _position = value; }
592 {
593 _position = value;
594
595 }
596 } 591 }
597 592
598 public override PhysicsVector Size 593 public override PhysicsVector Size
599 { 594 {
600 get { return _size; } 595 get { return _size; }
601 set 596 set { _size = value; }
602 {
603 _size = value;
604 }
605 } 597 }
606 598
607 public override float Mass 599 public override float Mass
@@ -626,10 +618,7 @@ namespace OpenSim.Region.Physics.OdePlugin
626 618
627 public override PrimitiveBaseShape Shape 619 public override PrimitiveBaseShape Shape
628 { 620 {
629 set 621 set { _pbs = value; }
630 {
631 _pbs = value;
632 }
633 } 622 }
634 623
635 public override PhysicsVector Velocity 624 public override PhysicsVector Velocity
@@ -639,9 +628,9 @@ namespace OpenSim.Region.Physics.OdePlugin
639 // Averate previous velocity with the new one so 628 // Averate previous velocity with the new one so
640 // client object interpolation works a 'little' better 629 // client object interpolation works a 'little' better
641 PhysicsVector returnVelocity = new PhysicsVector(); 630 PhysicsVector returnVelocity = new PhysicsVector();
642 returnVelocity.X = (m_lastVelocity.X + _velocity.X) / 2; 631 returnVelocity.X = (m_lastVelocity.X + _velocity.X)/2;
643 returnVelocity.Y = (m_lastVelocity.Y + _velocity.Y) / 2; 632 returnVelocity.Y = (m_lastVelocity.Y + _velocity.Y)/2;
644 returnVelocity.Z = (m_lastVelocity.Z + _velocity.Z) / 2; 633 returnVelocity.Z = (m_lastVelocity.Z + _velocity.Z)/2;
645 return returnVelocity; 634 return returnVelocity;
646 } 635 }
647 set { _velocity = value; } 636 set { _velocity = value; }
@@ -656,11 +645,7 @@ namespace OpenSim.Region.Physics.OdePlugin
656 public override Quaternion Orientation 645 public override Quaternion Orientation
657 { 646 {
658 get { return _orientation; } 647 get { return _orientation; }
659 set 648 set { _orientation = value; }
660 {
661 _orientation = value;
662
663 }
664 } 649 }
665 650
666 public override PhysicsVector Acceleration 651 public override PhysicsVector Acceleration
@@ -688,7 +673,7 @@ namespace OpenSim.Region.Physics.OdePlugin
688 { 673 {
689 // no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit! 674 // no lock; called from Simulate() -- if you call this from elsewhere, gotta lock or do Monitor.Enter/Exit!
690 675
691 if (Body != (IntPtr)0) 676 if (Body != (IntPtr) 0)
692 { 677 {
693 d.Vector3 vec = d.BodyGetPosition(Body); 678 d.Vector3 vec = d.BodyGetPosition(Body);
694 d.Quaternion ori = d.BodyGetQuaternion(Body); 679 d.Quaternion ori = d.BodyGetQuaternion(Body);
@@ -715,8 +700,6 @@ namespace OpenSim.Region.Physics.OdePlugin
715 // It's a hack and will generate a console message if it fails. 700 // It's a hack and will generate a console message if it fails.
716 701
717 702
718
719
720 //IsPhysical = false; 703 //IsPhysical = false;
721 base.RaiseOutOfBounds(_position); 704 base.RaiseOutOfBounds(_position);
722 _velocity.X = 0; 705 _velocity.X = 0;
@@ -736,7 +719,6 @@ namespace OpenSim.Region.Physics.OdePlugin
736 && (Math.Abs(m_lastposition.Y - l_position.Y) < 0.02) 719 && (Math.Abs(m_lastposition.Y - l_position.Y) < 0.02)
737 && (Math.Abs(m_lastposition.Z - l_position.Z) < 0.02)) 720 && (Math.Abs(m_lastposition.Z - l_position.Z) < 0.02))
738 { 721 {
739
740 _zeroFlag = true; 722 _zeroFlag = true;
741 } 723 }
742 else 724 else
@@ -746,7 +728,6 @@ namespace OpenSim.Region.Physics.OdePlugin
746 } 728 }
747 729
748 730
749
750 if (_zeroFlag) 731 if (_zeroFlag)
751 { 732 {
752 // Supposedly this is supposed to tell SceneObjectGroup that 733 // Supposedly this is supposed to tell SceneObjectGroup that
@@ -811,10 +792,10 @@ namespace OpenSim.Region.Physics.OdePlugin
811 m_rotationalVelocity.Z = 0; 792 m_rotationalVelocity.Z = 0;
812 _zeroFlag = true; 793 _zeroFlag = true;
813 } 794 }
814
815 } 795 }
796
816 public override void SetMomentum(PhysicsVector momentum) 797 public override void SetMomentum(PhysicsVector momentum)
817 { 798 {
818 } 799 }
819 } 800 }
820} 801} \ No newline at end of file
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index 8bb822e..f2c9b57 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -28,6 +28,7 @@
28 28
29using System; 29using System;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Runtime.InteropServices;
31using Axiom.Math; 32using Axiom.Math;
32using Ode.NET; 33using Ode.NET;
33using OpenSim.Framework; 34using OpenSim.Framework;
@@ -99,17 +100,17 @@ namespace OpenSim.Region.Physics.OdePlugin
99 private d.Contact TerrainContact; 100 private d.Contact TerrainContact;
100 private d.Contact AvatarMovementprimContact; 101 private d.Contact AvatarMovementprimContact;
101 private d.Contact AvatarMovementTerrainContact; 102 private d.Contact AvatarMovementTerrainContact;
102 103
103 private int m_physicsiterations = 10; 104 private int m_physicsiterations = 10;
104 private float m_SkipFramesAtms = 0.40f; // Drop frames gracefully at a 400 ms lag 105 private float m_SkipFramesAtms = 0.40f; // Drop frames gracefully at a 400 ms lag
105 private PhysicsActor PANull = new NullPhysicsActor(); 106 private PhysicsActor PANull = new NullPhysicsActor();
106 private float step_time = 0.0f; 107 private float step_time = 0.0f;
107 public IntPtr world; 108 public IntPtr world;
108 109
109 public IntPtr space; 110 public IntPtr space;
110 // split static geometry collision handling into spaces of 30 meters 111 // split static geometry collision handling into spaces of 30 meters
111 public IntPtr[,] staticPrimspace = new IntPtr[(int)(300/metersInSpace),(int)(300/metersInSpace)]; 112 public IntPtr[,] staticPrimspace = new IntPtr[(int) (300/metersInSpace),(int) (300/metersInSpace)];
112 113
113 public static Object OdeLock = new Object(); 114 public static Object OdeLock = new Object();
114 115
115 public IMesher mesher; 116 public IMesher mesher;
@@ -126,7 +127,7 @@ namespace OpenSim.Region.Physics.OdePlugin
126 contact.surface.soft_erp = 0.005f; 127 contact.surface.soft_erp = 0.005f;
127 contact.surface.soft_cfm = 0.00003f; 128 contact.surface.soft_cfm = 0.00003f;
128 */ 129 */
129 130
130 contact.surface.mu = 250.0f; 131 contact.surface.mu = 250.0f;
131 contact.surface.bounce = 0.2f; 132 contact.surface.bounce = 0.2f;
132 133
@@ -151,7 +152,7 @@ namespace OpenSim.Region.Physics.OdePlugin
151 contactgroup = d.JointGroupCreate(0); 152 contactgroup = d.JointGroupCreate(0);
152 //contactgroup 153 //contactgroup
153 154
154 155
155 d.WorldSetGravity(world, 0.0f, 0.0f, -10.0f); 156 d.WorldSetGravity(world, 0.0f, 0.0f, -10.0f);
156 d.WorldSetAutoDisableFlag(world, false); 157 d.WorldSetAutoDisableFlag(world, false);
157 d.WorldSetContactSurfaceLayer(world, 0.001f); 158 d.WorldSetContactSurfaceLayer(world, 0.001f);
@@ -165,10 +166,9 @@ namespace OpenSim.Region.Physics.OdePlugin
165 { 166 {
166 for (int j = 0; j < staticPrimspace.GetLength(1); j++) 167 for (int j = 0; j < staticPrimspace.GetLength(1); j++)
167 { 168 {
168 staticPrimspace[i,j] = IntPtr.Zero; 169 staticPrimspace[i, j] = IntPtr.Zero;
169 } 170 }
170 } 171 }
171
172 } 172 }
173 173
174 public override void Initialise(IMesher meshmerizer) 174 public override void Initialise(IMesher meshmerizer)
@@ -184,25 +184,25 @@ namespace OpenSim.Region.Physics.OdePlugin
184 private void near(IntPtr space, IntPtr g1, IntPtr g2) 184 private void near(IntPtr space, IntPtr g1, IntPtr g2)
185 { 185 {
186 // no lock here! It's invoked from within Simulate(), which is thread-locked 186 // no lock here! It's invoked from within Simulate(), which is thread-locked
187 if (d.GeomIsSpace(g1) || d.GeomIsSpace(g2) ) 187 if (d.GeomIsSpace(g1) || d.GeomIsSpace(g2))
188 { 188 {
189 // Separating static prim geometry spaces. 189 // Separating static prim geometry spaces.
190 // We'll be calling near recursivly if one 190 // We'll be calling near recursivly if one
191 // of them is a space to find all of the 191 // of them is a space to find all of the
192 // contact points in the space 192 // contact points in the space
193 193
194 d.SpaceCollide2(g1, g2, IntPtr.Zero, nearCallback); 194 d.SpaceCollide2(g1, g2, IntPtr.Zero, nearCallback);
195 //Colliding a space or a geom with a space or a geom. 195 //Colliding a space or a geom with a space or a geom.
196 196
197 //Collide all geoms in each space.. 197 //Collide all geoms in each space..
198 //if (d.GeomIsSpace(g1)) d.SpaceCollide(g1, IntPtr.Zero, nearCallback); 198 //if (d.GeomIsSpace(g1)) d.SpaceCollide(g1, IntPtr.Zero, nearCallback);
199 //if (d.GeomIsSpace(g2)) d.SpaceCollide(g2, IntPtr.Zero, nearCallback); 199 //if (d.GeomIsSpace(g2)) d.SpaceCollide(g2, IntPtr.Zero, nearCallback);
200 } 200 }
201 else 201 else
202 { 202 {
203 // Colliding Geom To Geom 203 // Colliding Geom To Geom
204 // This portion of the function 'was' blatantly ripped off from BoxStack.cs 204 // This portion of the function 'was' blatantly ripped off from BoxStack.cs
205 205
206 IntPtr b1 = d.GeomGetBody(g1); 206 IntPtr b1 = d.GeomGetBody(g1);
207 IntPtr b2 = d.GeomGetBody(g2); 207 IntPtr b2 = d.GeomGetBody(g2);
208 208
@@ -213,7 +213,7 @@ namespace OpenSim.Region.Physics.OdePlugin
213 return; 213 return;
214 214
215 d.GeomClassID id = d.GeomGetClass(g1); 215 d.GeomClassID id = d.GeomGetClass(g1);
216 216
217 String name1 = null; 217 String name1 = null;
218 String name2 = null; 218 String name2 = null;
219 219
@@ -228,21 +228,22 @@ namespace OpenSim.Region.Physics.OdePlugin
228 228
229 if (id == d.GeomClassID.TriMeshClass) 229 if (id == d.GeomClassID.TriMeshClass)
230 { 230 {
231 // MainLog.Instance.Verbose("near: A collision was detected between {1} and {2}", 0, name1, name2); 231 // MainLog.Instance.Verbose("near: A collision was detected between {1} and {2}", 0, name1, name2);
232 //System.Console.WriteLine("near: A collision was detected between {1} and {2}", 0, name1, name2); 232 //System.Console.WriteLine("near: A collision was detected between {1} and {2}", 0, name1, name2);
233 } 233 }
234 234
235 int count = 0; 235 int count = 0;
236 try 236 try
237 { 237 {
238 count = d.Collide(g1, g2, contacts.GetLength(0), contacts, d.ContactGeom.SizeOf); 238 count = d.Collide(g1, g2, contacts.GetLength(0), contacts, d.ContactGeom.SizeOf);
239 } 239 }
240 catch (System.Runtime.InteropServices.SEHException) 240 catch (SEHException)
241 { 241 {
242 MainLog.Instance.Error("PHYSICS", "The Operating system shut down ODE because of corrupt memory. This could be a result of really irregular terrain. If this repeats continuously, restart using Basic Physics and terrain fill your terrain. Restarting the sim."); 242 MainLog.Instance.Error("PHYSICS",
243 "The Operating system shut down ODE because of corrupt memory. This could be a result of really irregular terrain. If this repeats continuously, restart using Basic Physics and terrain fill your terrain. Restarting the sim.");
243 base.TriggerPhysicsBasedRestart(); 244 base.TriggerPhysicsBasedRestart();
244 } 245 }
245 246
246 for (int i = 0; i < count; i++) 247 for (int i = 0; i < count; i++)
247 { 248 {
248 IntPtr joint; 249 IntPtr joint;
@@ -263,17 +264,17 @@ namespace OpenSim.Region.Physics.OdePlugin
263 // We only need to test p2 for 'jump crouch purposes' 264 // We only need to test p2 for 'jump crouch purposes'
264 p2.IsColliding = true; 265 p2.IsColliding = true;
265 266
266
267 267
268 switch(p1.PhysicsActorType) { 268 switch (p1.PhysicsActorType)
269 case (int)ActorTypes.Agent: 269 {
270 case (int) ActorTypes.Agent:
270 p2.CollidingObj = true; 271 p2.CollidingObj = true;
271 break; 272 break;
272 case (int)ActorTypes.Prim: 273 case (int) ActorTypes.Prim:
273 if (p2.Velocity.X >0 || p2.Velocity.Y > 0 || p2.Velocity.Z > 0) 274 if (p2.Velocity.X > 0 || p2.Velocity.Y > 0 || p2.Velocity.Z > 0)
274 p2.CollidingObj = true; 275 p2.CollidingObj = true;
275 break; 276 break;
276 case (int)ActorTypes.Unknown: 277 case (int) ActorTypes.Unknown:
277 p2.CollidingGround = true; 278 p2.CollidingGround = true;
278 break; 279 break;
279 default: 280 default:
@@ -282,7 +283,9 @@ namespace OpenSim.Region.Physics.OdePlugin
282 } 283 }
283 284
284 // we don't want prim or avatar to explode 285 // we don't want prim or avatar to explode
286
285 #region InterPenetration Handling - Unintended physics explosions 287 #region InterPenetration Handling - Unintended physics explosions
288
286 if (contacts[i].depth >= 0.08f) 289 if (contacts[i].depth >= 0.08f)
287 { 290 {
288 if (contacts[i].depth >= 1.00f) 291 if (contacts[i].depth >= 1.00f)
@@ -290,30 +293,31 @@ namespace OpenSim.Region.Physics.OdePlugin
290 //MainLog.Instance.Debug("PHYSICS",contacts[i].depth.ToString()); 293 //MainLog.Instance.Debug("PHYSICS",contacts[i].depth.ToString());
291 } 294 }
292 // If you interpenetrate a prim with an agent 295 // If you interpenetrate a prim with an agent
293 if ((p2.PhysicsActorType == (int)ActorTypes.Agent && p1.PhysicsActorType == (int)ActorTypes.Prim) || (p1.PhysicsActorType == (int)ActorTypes.Agent && p2.PhysicsActorType == (int)ActorTypes.Prim)) 296 if ((p2.PhysicsActorType == (int) ActorTypes.Agent &&
297 p1.PhysicsActorType == (int) ActorTypes.Prim) ||
298 (p1.PhysicsActorType == (int) ActorTypes.Agent &&
299 p2.PhysicsActorType == (int) ActorTypes.Prim))
294 { 300 {
295 301 if (p2.PhysicsActorType == (int) ActorTypes.Agent)
296 if (p2.PhysicsActorType == (int)ActorTypes.Agent)
297 { 302 {
298 p2.CollidingObj = true; 303 p2.CollidingObj = true;
299 //contacts[i].depth = 0.003f; 304 //contacts[i].depth = 0.003f;
300 p2.Velocity = p2.Velocity + new PhysicsVector(0, 0, 2.5f); 305 p2.Velocity = p2.Velocity + new PhysicsVector(0, 0, 2.5f);
301 OdeCharacter character = (OdeCharacter)p2; 306 OdeCharacter character = (OdeCharacter) p2;
302 character.SetPidStatus(true); 307 character.SetPidStatus(true);
303 //contacts[i].pos = new d.Vector3(contacts[i].pos.X + (p1.Size.X / 2), contacts[i].pos.Y + (p1.Size.Y / 2), contacts[i].pos.Z + (p1.Size.Z / 2)); 308 //contacts[i].pos = new d.Vector3(contacts[i].pos.X + (p1.Size.X / 2), contacts[i].pos.Y + (p1.Size.Y / 2), contacts[i].pos.Z + (p1.Size.Z / 2));
304
305 } 309 }
306 else 310 else
307 { 311 {
308 contacts[i].depth = 0.0000000f; 312 contacts[i].depth = 0.0000000f;
309 } 313 }
310 if (p1.PhysicsActorType == (int)ActorTypes.Agent) 314 if (p1.PhysicsActorType == (int) ActorTypes.Agent)
311 { 315 {
312 p1.CollidingObj = true; 316 p1.CollidingObj = true;
313 //contacts[i].depth = 0.003f; 317 //contacts[i].depth = 0.003f;
314 p1.Velocity = p1.Velocity + new PhysicsVector(0, 0, 2.5f); 318 p1.Velocity = p1.Velocity + new PhysicsVector(0, 0, 2.5f);
315 //contacts[i].pos = new d.Vector3(contacts[i].pos.X + (p2.Size.X / 2), contacts[i].pos.Y + (p2.Size.Y / 2), contacts[i].pos.Z + (p2.Size.Z / 2)); 319 //contacts[i].pos = new d.Vector3(contacts[i].pos.X + (p2.Size.X / 2), contacts[i].pos.Y + (p2.Size.Y / 2), contacts[i].pos.Z + (p2.Size.Z / 2));
316 OdeCharacter character = (OdeCharacter)p2; 320 OdeCharacter character = (OdeCharacter) p2;
317 character.SetPidStatus(true); 321 character.SetPidStatus(true);
318 } 322 }
319 else 323 else
@@ -322,39 +326,45 @@ namespace OpenSim.Region.Physics.OdePlugin
322 } 326 }
323 } 327 }
324 // If you interpenetrate a prim with another prim 328 // If you interpenetrate a prim with another prim
325 if (p1.PhysicsActorType == (int)ActorTypes.Prim && p2.PhysicsActorType == (int)ActorTypes.Prim) 329 if (p1.PhysicsActorType == (int) ActorTypes.Prim && p2.PhysicsActorType == (int) ActorTypes.Prim)
326 { 330 {
327 // Don't collide, one or both prim will explode. 331 // Don't collide, one or both prim will explode.
328 contacts[i].depth = -1f; 332 contacts[i].depth = -1f;
329 } 333 }
330 if (contacts[i].depth >= 1.00f) 334 if (contacts[i].depth >= 1.00f)
331 { 335 {
332 if ((p2.PhysicsActorType == (int)ActorTypes.Agent && p1.PhysicsActorType == (int)ActorTypes.Unknown) || (p1.PhysicsActorType == (int)ActorTypes.Agent && p2.PhysicsActorType == (int)ActorTypes.Unknown)) 336 if ((p2.PhysicsActorType == (int) ActorTypes.Agent &&
337 p1.PhysicsActorType == (int) ActorTypes.Unknown) ||
338 (p1.PhysicsActorType == (int) ActorTypes.Agent &&
339 p2.PhysicsActorType == (int) ActorTypes.Unknown))
333 { 340 {
334 341 if (p2.PhysicsActorType == (int) ActorTypes.Agent)
335 if (p2.PhysicsActorType == (int)ActorTypes.Agent)
336 { 342 {
337 OdeCharacter character = (OdeCharacter)p2; 343 OdeCharacter character = (OdeCharacter) p2;
338 344
339 //p2.CollidingObj = true; 345 //p2.CollidingObj = true;
340 contacts[i].depth = 0.003f; 346 contacts[i].depth = 0.003f;
341 p2.Velocity = p2.Velocity + new PhysicsVector(0, 0, 0.5f); 347 p2.Velocity = p2.Velocity + new PhysicsVector(0, 0, 0.5f);
342 contacts[i].pos = new d.Vector3(contacts[i].pos.X + (p1.Size.X / 2), contacts[i].pos.Y + (p1.Size.Y / 2), contacts[i].pos.Z + (p1.Size.Z / 2)); 348 contacts[i].pos =
349 new d.Vector3(contacts[i].pos.X + (p1.Size.X/2),
350 contacts[i].pos.Y + (p1.Size.Y/2),
351 contacts[i].pos.Z + (p1.Size.Z/2));
343 character.SetPidStatus(true); 352 character.SetPidStatus(true);
344
345 } 353 }
346 else 354 else
347 { 355 {
348
349 } 356 }
350 if (p1.PhysicsActorType == (int)ActorTypes.Agent) 357 if (p1.PhysicsActorType == (int) ActorTypes.Agent)
351 { 358 {
352 OdeCharacter character = (OdeCharacter)p2; 359 OdeCharacter character = (OdeCharacter) p2;
353 360
354 //p2.CollidingObj = true; 361 //p2.CollidingObj = true;
355 contacts[i].depth = 0.003f; 362 contacts[i].depth = 0.003f;
356 p2.Velocity = p2.Velocity + new PhysicsVector(0, 0, 0.5f); 363 p2.Velocity = p2.Velocity + new PhysicsVector(0, 0, 0.5f);
357 contacts[i].pos = new d.Vector3(contacts[i].pos.X + (p1.Size.X / 2), contacts[i].pos.Y + (p1.Size.Y / 2), contacts[i].pos.Z + (p1.Size.Z / 2)); 364 contacts[i].pos =
365 new d.Vector3(contacts[i].pos.X + (p1.Size.X/2),
366 contacts[i].pos.Y + (p1.Size.Y/2),
367 contacts[i].pos.Z + (p1.Size.Z/2));
358 character.SetPidStatus(true); 368 character.SetPidStatus(true);
359 } 369 }
360 else 370 else
@@ -364,18 +374,18 @@ namespace OpenSim.Region.Physics.OdePlugin
364 } 374 }
365 } 375 }
366 } 376 }
377
367 #endregion 378 #endregion
368 379
369 if (contacts[i].depth >= 0f) 380 if (contacts[i].depth >= 0f)
370 { 381 {
371 if (name1 == "Terrain" || name2 == "Terrain") 382 if (name1 == "Terrain" || name2 == "Terrain")
372 { 383 {
373 384 if ((p2.PhysicsActorType == (int) ActorTypes.Agent) &&
374 if ((p2.PhysicsActorType == (int)ActorTypes.Agent) && (Math.Abs(p2.Velocity.X) > 0.01f || Math.Abs(p2.Velocity.Y) > 0.01f)) 385 (Math.Abs(p2.Velocity.X) > 0.01f || Math.Abs(p2.Velocity.Y) > 0.01f))
375 { 386 {
376 AvatarMovementTerrainContact.geom = contacts[i]; 387 AvatarMovementTerrainContact.geom = contacts[i];
377 joint = d.JointCreateContact(world, contactgroup, ref AvatarMovementTerrainContact); 388 joint = d.JointCreateContact(world, contactgroup, ref AvatarMovementTerrainContact);
378
379 } 389 }
380 else 390 else
381 { 391 {
@@ -385,11 +395,11 @@ namespace OpenSim.Region.Physics.OdePlugin
385 } 395 }
386 else 396 else
387 { 397 {
388 if ((p2.PhysicsActorType == (int)ActorTypes.Agent) && (Math.Abs(p2.Velocity.X) > 0.01f || Math.Abs(p2.Velocity.Y) > 0.01f)) 398 if ((p2.PhysicsActorType == (int) ActorTypes.Agent) &&
399 (Math.Abs(p2.Velocity.X) > 0.01f || Math.Abs(p2.Velocity.Y) > 0.01f))
389 { 400 {
390 AvatarMovementprimContact.geom = contacts[i]; 401 AvatarMovementprimContact.geom = contacts[i];
391 joint = d.JointCreateContact(world, contactgroup, ref AvatarMovementprimContact); 402 joint = d.JointCreateContact(world, contactgroup, ref AvatarMovementprimContact);
392
393 } 403 }
394 else 404 else
395 { 405 {
@@ -399,7 +409,7 @@ namespace OpenSim.Region.Physics.OdePlugin
399 } 409 }
400 d.JointAttach(joint, b1, b2); 410 d.JointAttach(joint, b1, b2);
401 } 411 }
402 412
403 if (count > 3) 413 if (count > 3)
404 { 414 {
405 p2.ThrottleUpdates = true; 415 p2.ThrottleUpdates = true;
@@ -421,7 +431,7 @@ namespace OpenSim.Region.Physics.OdePlugin
421 } 431 }
422 // If the sim is running slow this frame, 432 // If the sim is running slow this frame,
423 // don't process collision for prim! 433 // don't process collision for prim!
424 if (timeStep < (m_SkipFramesAtms / 3)) 434 if (timeStep < (m_SkipFramesAtms/3))
425 { 435 {
426 foreach (OdePrim chr in _activeprims) 436 foreach (OdePrim chr in _activeprims)
427 { 437 {
@@ -432,16 +442,16 @@ namespace OpenSim.Region.Physics.OdePlugin
432 //foreach (OdePrim ch2 in _prims) 442 //foreach (OdePrim ch2 in _prims)
433 /// should be a separate space -- lots of avatars will be N**2 slow 443 /// should be a separate space -- lots of avatars will be N**2 slow
434 //{ 444 //{
435 //if (ch2.IsPhysical && d.BodyIsEnabled(ch2.Body)) 445 //if (ch2.IsPhysical && d.BodyIsEnabled(ch2.Body))
436 //{ 446 //{
437 // Only test prim that are 0.03 meters away in one direction. 447 // Only test prim that are 0.03 meters away in one direction.
438 // This should be Optimized! 448 // This should be Optimized!
439 449
440 //if ((Math.Abs(ch2.Position.X - chr.Position.X) < 0.03) || (Math.Abs(ch2.Position.Y - chr.Position.Y) < 0.03) || (Math.Abs(ch2.Position.X - chr.Position.X) < 0.03)) 450 //if ((Math.Abs(ch2.Position.X - chr.Position.X) < 0.03) || (Math.Abs(ch2.Position.Y - chr.Position.Y) < 0.03) || (Math.Abs(ch2.Position.X - chr.Position.X) < 0.03))
441 //{ 451 //{
442 //d.SpaceCollide2(chr.prim_geom, ch2.prim_geom, IntPtr.Zero, nearCallback); 452 //d.SpaceCollide2(chr.prim_geom, ch2.prim_geom, IntPtr.Zero, nearCallback);
443 //} 453 //}
444 //} 454 //}
445 //} 455 //}
446 } 456 }
447 } 457 }
@@ -456,7 +466,6 @@ namespace OpenSim.Region.Physics.OdePlugin
456 if (d.BodyIsEnabled(chr.Body)) 466 if (d.BodyIsEnabled(chr.Body))
457 { 467 {
458 d.SpaceCollide2(LandGeom, chr.prim_geom, IntPtr.Zero, nearCallback); 468 d.SpaceCollide2(LandGeom, chr.prim_geom, IntPtr.Zero, nearCallback);
459
460 } 469 }
461 } 470 }
462 } 471 }
@@ -492,7 +501,6 @@ namespace OpenSim.Region.Physics.OdePlugin
492 501
493 p.setPrimForRemoval(); 502 p.setPrimForRemoval();
494 AddPhysicsActorTaint(prim); 503 AddPhysicsActorTaint(prim);
495
496 } 504 }
497 } 505 }
498 } 506 }
@@ -519,13 +527,14 @@ namespace OpenSim.Region.Physics.OdePlugin
519 } 527 }
520 else 528 else
521 { 529 {
522 MainLog.Instance.Verbose("Physics", "Invalid Scene passed to 'removeprim from scene':" + ((OdePrim)prim).m_targetSpace.ToString()); 530 MainLog.Instance.Verbose("Physics",
531 "Invalid Scene passed to 'removeprim from scene':" +
532 ((OdePrim) prim).m_targetSpace.ToString());
523 } 533 }
524 } 534 }
525 } 535 }
526 536
527 537
528
529 //If there are no more geometries in the sub-space, we don't need it in the main space anymore 538 //If there are no more geometries in the sub-space, we don't need it in the main space anymore
530 if (d.SpaceGetNumGeoms(prim.m_targetSpace) == 0) 539 if (d.SpaceGetNumGeoms(prim.m_targetSpace) == 0)
531 { 540 {
@@ -541,17 +550,18 @@ namespace OpenSim.Region.Physics.OdePlugin
541 } 550 }
542 else 551 else
543 { 552 {
544 MainLog.Instance.Verbose("Physics", "Invalid Scene passed to 'removeprim from scene':" + ((OdePrim)prim).m_targetSpace.ToString()); 553 MainLog.Instance.Verbose("Physics",
554 "Invalid Scene passed to 'removeprim from scene':" +
555 ((OdePrim) prim).m_targetSpace.ToString());
545 } 556 }
546 } 557 }
547 } 558 }
548 } 559 }
549 560
550 d.GeomDestroy(prim.prim_geom); 561 d.GeomDestroy(prim.prim_geom);
551 562
552 _prims.Remove(prim); 563 _prims.Remove(prim);
553 } 564 }
554
555 } 565 }
556 566
557 public void resetSpaceArrayItemToZero(IntPtr space) 567 public void resetSpaceArrayItemToZero(IntPtr space)
@@ -566,7 +576,7 @@ namespace OpenSim.Region.Physics.OdePlugin
566 } 576 }
567 } 577 }
568 578
569 public void resetSpaceArrayItemToZero(int arrayitemX,int arrayitemY) 579 public void resetSpaceArrayItemToZero(int arrayitemX, int arrayitemY)
570 { 580 {
571 staticPrimspace[arrayitemX, arrayitemY] = IntPtr.Zero; 581 staticPrimspace[arrayitemX, arrayitemY] = IntPtr.Zero;
572 } 582 }
@@ -582,16 +592,17 @@ namespace OpenSim.Region.Physics.OdePlugin
582 // never be called if the prim is physical(active) 592 // never be called if the prim is physical(active)
583 if (currentspace != space) 593 if (currentspace != space)
584 { 594 {
585 if (d.SpaceQuery(currentspace, geom) && currentspace != (IntPtr)0) 595 if (d.SpaceQuery(currentspace, geom) && currentspace != (IntPtr) 0)
586 { 596 {
587 if (d.GeomIsSpace(currentspace)) 597 if (d.GeomIsSpace(currentspace))
588 { 598 {
589
590 d.SpaceRemove(currentspace, geom); 599 d.SpaceRemove(currentspace, geom);
591 } 600 }
592 else 601 else
593 { 602 {
594 MainLog.Instance.Verbose("Physics", "Invalid Scene passed to 'recalculatespace':" + currentspace.ToString() + " Geom:" + geom.ToString()); 603 MainLog.Instance.Verbose("Physics",
604 "Invalid Scene passed to 'recalculatespace':" + currentspace.ToString() +
605 " Geom:" + geom.ToString());
595 } 606 }
596 } 607 }
597 else 608 else
@@ -599,7 +610,7 @@ namespace OpenSim.Region.Physics.OdePlugin
599 IntPtr sGeomIsIn = d.GeomGetSpace(geom); 610 IntPtr sGeomIsIn = d.GeomGetSpace(geom);
600 if (!(sGeomIsIn.Equals(null))) 611 if (!(sGeomIsIn.Equals(null)))
601 { 612 {
602 if (sGeomIsIn != (IntPtr)0) 613 if (sGeomIsIn != (IntPtr) 0)
603 { 614 {
604 if (d.GeomIsSpace(currentspace)) 615 if (d.GeomIsSpace(currentspace))
605 { 616 {
@@ -607,7 +618,9 @@ namespace OpenSim.Region.Physics.OdePlugin
607 } 618 }
608 else 619 else
609 { 620 {
610 MainLog.Instance.Verbose("Physics", "Invalid Scene passed to 'recalculatespace':" + sGeomIsIn.ToString() + " Geom:" + geom.ToString()); 621 MainLog.Instance.Verbose("Physics",
622 "Invalid Scene passed to 'recalculatespace':" +
623 sGeomIsIn.ToString() + " Geom:" + geom.ToString());
611 } 624 }
612 } 625 }
613 } 626 }
@@ -617,7 +630,7 @@ namespace OpenSim.Region.Physics.OdePlugin
617 //If there are no more geometries in the sub-space, we don't need it in the main space anymore 630 //If there are no more geometries in the sub-space, we don't need it in the main space anymore
618 if (d.SpaceGetNumGeoms(currentspace) == 0) 631 if (d.SpaceGetNumGeoms(currentspace) == 0)
619 { 632 {
620 if (currentspace != (IntPtr)0) 633 if (currentspace != (IntPtr) 0)
621 { 634 {
622 if (d.GeomIsSpace(currentspace)) 635 if (d.GeomIsSpace(currentspace))
623 { 636 {
@@ -628,9 +641,10 @@ namespace OpenSim.Region.Physics.OdePlugin
628 } 641 }
629 else 642 else
630 { 643 {
631 MainLog.Instance.Verbose("Physics", "Invalid Scene passed to 'recalculatespace':" + currentspace.ToString() + " Geom:" + geom.ToString()); 644 MainLog.Instance.Verbose("Physics",
645 "Invalid Scene passed to 'recalculatespace':" +
646 currentspace.ToString() + " Geom:" + geom.ToString());
632 } 647 }
633
634 } 648 }
635 } 649 }
636 } 650 }
@@ -639,15 +653,16 @@ namespace OpenSim.Region.Physics.OdePlugin
639 // this is a physical object that got disabled. ;.; 653 // this is a physical object that got disabled. ;.;
640 if (d.SpaceQuery(currentspace, geom)) 654 if (d.SpaceQuery(currentspace, geom))
641 { 655 {
642 if (currentspace != (IntPtr)0) 656 if (currentspace != (IntPtr) 0)
643 if (d.GeomIsSpace(currentspace)) 657 if (d.GeomIsSpace(currentspace))
644 { 658 {
645 d.SpaceRemove(currentspace, geom); 659 d.SpaceRemove(currentspace, geom);
646 } 660 }
647 else 661 else
648 { 662 {
649 MainLog.Instance.Verbose("Physics", "Invalid Scene passed to 'recalculatespace':" + currentspace.ToString() + " Geom:" + geom.ToString()); 663 MainLog.Instance.Verbose("Physics",
650 664 "Invalid Scene passed to 'recalculatespace':" +
665 currentspace.ToString() + " Geom:" + geom.ToString());
651 } 666 }
652 } 667 }
653 else 668 else
@@ -655,7 +670,7 @@ namespace OpenSim.Region.Physics.OdePlugin
655 IntPtr sGeomIsIn = d.GeomGetSpace(geom); 670 IntPtr sGeomIsIn = d.GeomGetSpace(geom);
656 if (!(sGeomIsIn.Equals(null))) 671 if (!(sGeomIsIn.Equals(null)))
657 { 672 {
658 if (sGeomIsIn != (IntPtr)0) 673 if (sGeomIsIn != (IntPtr) 0)
659 { 674 {
660 if (d.GeomIsSpace(sGeomIsIn)) 675 if (d.GeomIsSpace(sGeomIsIn))
661 { 676 {
@@ -663,14 +678,16 @@ namespace OpenSim.Region.Physics.OdePlugin
663 } 678 }
664 else 679 else
665 { 680 {
666 MainLog.Instance.Verbose("Physics", "Invalid Scene passed to 'recalculatespace':" + sGeomIsIn.ToString() + " Geom:" + geom.ToString()); 681 MainLog.Instance.Verbose("Physics",
682 "Invalid Scene passed to 'recalculatespace':" +
683 sGeomIsIn.ToString() + " Geom:" + geom.ToString());
667 } 684 }
668 } 685 }
669 } 686 }
670 } 687 }
671 } 688 }
672 689
673 690
674 // The routines in the Position and Size sections do the 'inserting' into the space, 691 // The routines in the Position and Size sections do the 'inserting' into the space,
675 // so all we have to do is make sure that the space that we're putting the prim into 692 // so all we have to do is make sure that the space that we're putting the prim into
676 // is in the 'main' space. 693 // is in the 'main' space.
@@ -679,17 +696,18 @@ namespace OpenSim.Region.Physics.OdePlugin
679 696
680 if (newspace == IntPtr.Zero) 697 if (newspace == IntPtr.Zero)
681 { 698 {
682 newspace = createprimspace(iprimspaceArrItem[0],iprimspaceArrItem[1]); 699 newspace = createprimspace(iprimspaceArrItem[0], iprimspaceArrItem[1]);
683 d.HashSpaceSetLevels(newspace, -4, 66); 700 d.HashSpaceSetLevels(newspace, -4, 66);
684 } 701 }
685 702
686 return newspace; 703 return newspace;
687 } 704 }
688 705
689 public IntPtr createprimspace(int iprimspaceArrItemX, int iprimspaceArrItemY) { 706 public IntPtr createprimspace(int iprimspaceArrItemX, int iprimspaceArrItemY)
707 {
690 // creating a new space for prim and inserting it into main space. 708 // creating a new space for prim and inserting it into main space.
691 staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY] = d.HashSpaceCreate(IntPtr.Zero); 709 staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY] = d.HashSpaceCreate(IntPtr.Zero);
692 d.SpaceAdd(space, staticPrimspace[iprimspaceArrItemX,iprimspaceArrItemY]); 710 d.SpaceAdd(space, staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY]);
693 return staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY]; 711 return staticPrimspace[iprimspaceArrItemX, iprimspaceArrItemY];
694 } 712 }
695 713
@@ -697,7 +715,7 @@ namespace OpenSim.Region.Physics.OdePlugin
697 { 715 {
698 int[] xyspace = calculateSpaceArrayItemFromPos(pos); 716 int[] xyspace = calculateSpaceArrayItemFromPos(pos);
699 //MainLog.Instance.Verbose("Physics", "Attempting to use arrayItem: " + xyspace[0].ToString() + "," + xyspace[1].ToString()); 717 //MainLog.Instance.Verbose("Physics", "Attempting to use arrayItem: " + xyspace[0].ToString() + "," + xyspace[1].ToString());
700 IntPtr locationbasedspace = staticPrimspace[xyspace[0],xyspace[1]]; 718 IntPtr locationbasedspace = staticPrimspace[xyspace[0], xyspace[1]];
701 719
702 //locationbasedspace = space; 720 //locationbasedspace = space;
703 return locationbasedspace; 721 return locationbasedspace;
@@ -706,17 +724,17 @@ namespace OpenSim.Region.Physics.OdePlugin
706 public int[] calculateSpaceArrayItemFromPos(PhysicsVector pos) 724 public int[] calculateSpaceArrayItemFromPos(PhysicsVector pos)
707 { 725 {
708 int[] returnint = new int[2]; 726 int[] returnint = new int[2];
709 727
710 returnint[0] = (int)(pos.X / metersInSpace); 728 returnint[0] = (int) (pos.X/metersInSpace);
711 729
712 if (returnint[0] > ((int)(259f / metersInSpace))) 730 if (returnint[0] > ((int) (259f/metersInSpace)))
713 returnint[0] = ((int)(259f / metersInSpace)); 731 returnint[0] = ((int) (259f/metersInSpace));
714 if (returnint[0] < 0) 732 if (returnint[0] < 0)
715 returnint[0] = 0; 733 returnint[0] = 0;
716 734
717 returnint[1] = (int)(pos.Y / metersInSpace); 735 returnint[1] = (int) (pos.Y/metersInSpace);
718 if (returnint[0] > ((int)(259f / metersInSpace))) 736 if (returnint[0] > ((int) (259f/metersInSpace)))
719 returnint[0] = ((int)(259f / metersInSpace)); 737 returnint[0] = ((int) (259f/metersInSpace));
720 if (returnint[0] < 0) 738 if (returnint[0] < 0)
721 returnint[0] = 0; 739 returnint[0] = 0;
722 740
@@ -726,7 +744,6 @@ namespace OpenSim.Region.Physics.OdePlugin
726 private PhysicsActor AddPrim(String name, PhysicsVector position, PhysicsVector size, Quaternion rotation, 744 private PhysicsActor AddPrim(String name, PhysicsVector position, PhysicsVector size, Quaternion rotation,
727 IMesh mesh, PrimitiveBaseShape pbs, bool isphysical) 745 IMesh mesh, PrimitiveBaseShape pbs, bool isphysical)
728 { 746 {
729
730 PhysicsVector pos = new PhysicsVector(); 747 PhysicsVector pos = new PhysicsVector();
731 pos.X = position.X; 748 pos.X = position.X;
732 pos.Y = position.Y; 749 pos.Y = position.Y;
@@ -741,21 +758,21 @@ namespace OpenSim.Region.Physics.OdePlugin
741 rot.y = rotation.y; 758 rot.y = rotation.y;
742 rot.z = rotation.z; 759 rot.z = rotation.z;
743 760
744 761
745 int[] iprimspaceArrItem = calculateSpaceArrayItemFromPos(pos); 762 int[] iprimspaceArrItem = calculateSpaceArrayItemFromPos(pos);
746 IntPtr targetspace = calculateSpaceForGeom(pos); 763 IntPtr targetspace = calculateSpaceForGeom(pos);
747 764
748 if (targetspace == IntPtr.Zero) 765 if (targetspace == IntPtr.Zero)
749 targetspace = createprimspace(iprimspaceArrItem[0],iprimspaceArrItem[1]); 766 targetspace = createprimspace(iprimspaceArrItem[0], iprimspaceArrItem[1]);
750 767
751 OdePrim newPrim; 768 OdePrim newPrim;
752 lock (OdeLock) 769 lock (OdeLock)
753 { 770 {
754 newPrim = new OdePrim(name, this, targetspace, pos, siz, rot, mesh, pbs, isphysical); 771 newPrim = new OdePrim(name, this, targetspace, pos, siz, rot, mesh, pbs, isphysical);
755 772
756 _prims.Add(newPrim); 773 _prims.Add(newPrim);
757 } 774 }
758 775
759 return newPrim; 776 return newPrim;
760 } 777 }
761 778
@@ -763,16 +780,14 @@ namespace OpenSim.Region.Physics.OdePlugin
763 { 780 {
764 // adds active prim.. (ones that should be iterated over in collisions_optimized 781 // adds active prim.. (ones that should be iterated over in collisions_optimized
765 782
766 _activeprims.Add(activatePrim); 783 _activeprims.Add(activatePrim);
767
768 } 784 }
785
769 public void remActivePrim(OdePrim deactivatePrim) 786 public void remActivePrim(OdePrim deactivatePrim)
770 { 787 {
771 788 _activeprims.Remove(deactivatePrim);
772 _activeprims.Remove(deactivatePrim);
773
774
775 } 789 }
790
776 public int TriArrayCallback(IntPtr trimesh, IntPtr refObject, int[] triangleIndex, int triCount) 791 public int TriArrayCallback(IntPtr trimesh, IntPtr refObject, int[] triangleIndex, int triCount)
777 { 792 {
778/* String name1 = null; 793/* String name1 = null;
@@ -818,7 +833,7 @@ namespace OpenSim.Region.Physics.OdePlugin
818 return 1; 833 return 1;
819 } 834 }
820 835
821 836
822 public bool needsMeshing(PrimitiveBaseShape pbs) 837 public bool needsMeshing(PrimitiveBaseShape pbs)
823 { 838 {
824 if (pbs.ProfileHollow != 0) 839 if (pbs.ProfileHollow != 0)
@@ -833,7 +848,7 @@ namespace OpenSim.Region.Physics.OdePlugin
833 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, 848 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position,
834 PhysicsVector size, Quaternion rotation) //To be removed 849 PhysicsVector size, Quaternion rotation) //To be removed
835 { 850 {
836 return this.AddPrimShape(primName, pbs, position, size, rotation, false); 851 return AddPrimShape(primName, pbs, position, size, rotation, false);
837 } 852 }
838 853
839 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, 854 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position,
@@ -848,12 +863,12 @@ namespace OpenSim.Region.Physics.OdePlugin
848 /// support simple box & hollow box now; later, more shapes 863 /// support simple box & hollow box now; later, more shapes
849 if (needsMeshing(pbs)) 864 if (needsMeshing(pbs))
850 { 865 {
851 mesh = mesher.CreateMesh(primName, pbs, size); 866 mesh = mesher.CreateMesh(primName, pbs, size);
852 } 867 }
853 868
854 break; 869 break;
855 } 870 }
856 871
857 result = AddPrim(primName, position, size, rotation, mesh, pbs, isPhysical); 872 result = AddPrim(primName, position, size, rotation, mesh, pbs, isPhysical);
858 873
859 874
@@ -864,10 +879,9 @@ namespace OpenSim.Region.Physics.OdePlugin
864 { 879 {
865 if (prim is OdePrim) 880 if (prim is OdePrim)
866 { 881 {
867 OdePrim taintedprim = ((OdePrim)prim); 882 OdePrim taintedprim = ((OdePrim) prim);
868 if (!(_taintedPrim.Contains(taintedprim))) 883 if (!(_taintedPrim.Contains(taintedprim)))
869 _taintedPrim.Add(taintedprim); 884 _taintedPrim.Add(taintedprim);
870
871 } 885 }
872 } 886 }
873 887
@@ -877,19 +891,18 @@ namespace OpenSim.Region.Physics.OdePlugin
877 891
878 step_time += timeStep; 892 step_time += timeStep;
879 893
880 894
881 // If We're loaded down by something else, 895 // If We're loaded down by something else,
882 // or debugging with the Visual Studio project on pause 896 // or debugging with the Visual Studio project on pause
883 // skip a few frames to catch up gracefully. 897 // skip a few frames to catch up gracefully.
884 // without shooting the physicsactors all over the place 898 // without shooting the physicsactors all over the place
885
886 899
887 900
888 if (step_time >= m_SkipFramesAtms) 901 if (step_time >= m_SkipFramesAtms)
889 { 902 {
890 // Instead of trying to catch up, it'll do one physics frame only 903 // Instead of trying to catch up, it'll do one physics frame only
891 step_time = ODE_STEPSIZE; 904 step_time = ODE_STEPSIZE;
892 this.m_physicsiterations = 5; 905 m_physicsiterations = 5;
893 } 906 }
894 else 907 else
895 { 908 {
@@ -897,35 +910,36 @@ namespace OpenSim.Region.Physics.OdePlugin
897 } 910 }
898 lock (OdeLock) 911 lock (OdeLock)
899 { 912 {
900 // Process 10 frames if the sim is running normal.. 913 // Process 10 frames if the sim is running normal..
901 // process 5 frames if the sim is running slow 914 // process 5 frames if the sim is running slow
902 try{ 915 try
916 {
903 d.WorldSetQuickStepNumIterations(world, m_physicsiterations); 917 d.WorldSetQuickStepNumIterations(world, m_physicsiterations);
904 } 918 }
905 catch (System.StackOverflowException) 919 catch (StackOverflowException)
906 { 920 {
907 MainLog.Instance.Error("PHYSICS", "The operating system wasn't able to allocate enough memory for the simulation. Restarting the sim."); 921 MainLog.Instance.Error("PHYSICS",
922 "The operating system wasn't able to allocate enough memory for the simulation. Restarting the sim.");
908 base.TriggerPhysicsBasedRestart(); 923 base.TriggerPhysicsBasedRestart();
909 } 924 }
910 925
911 int i = 0; 926 int i = 0;
912 927
913 928
914 // Figure out the Frames Per Second we're going at. 929 // Figure out the Frames Per Second we're going at.
915 930
916 fps = (((step_time / ODE_STEPSIZE * m_physicsiterations)*2)* 10); 931 fps = (((step_time/ODE_STEPSIZE*m_physicsiterations)*2)*10);
917 932
918 933
919 while (step_time > 0.0f) 934 while (step_time > 0.0f)
920 { 935 {
921
922 foreach (OdeCharacter actor in _characters) 936 foreach (OdeCharacter actor in _characters)
923 { 937 {
924 actor.Move(timeStep); 938 actor.Move(timeStep);
925 actor.collidelock = true; 939 actor.collidelock = true;
926 } 940 }
927 941
928 942
929 collision_optimized(timeStep); 943 collision_optimized(timeStep);
930 d.WorldQuickStep(world, ODE_STEPSIZE); 944 d.WorldQuickStep(world, ODE_STEPSIZE);
931 d.JointGroupEmpty(contactgroup); 945 d.JointGroupEmpty(contactgroup);
@@ -933,7 +947,7 @@ namespace OpenSim.Region.Physics.OdePlugin
933 { 947 {
934 actor.collidelock = false; 948 actor.collidelock = false;
935 } 949 }
936 950
937 step_time -= ODE_STEPSIZE; 951 step_time -= ODE_STEPSIZE;
938 i++; 952 i++;
939 } 953 }
@@ -941,7 +955,6 @@ namespace OpenSim.Region.Physics.OdePlugin
941 foreach (OdeCharacter actor in _characters) 955 foreach (OdeCharacter actor in _characters)
942 { 956 {
943 actor.UpdatePositionAndVelocity(); 957 actor.UpdatePositionAndVelocity();
944
945 } 958 }
946 bool processedtaints = false; 959 bool processedtaints = false;
947 foreach (OdePrim prim in _taintedPrim) 960 foreach (OdePrim prim in _taintedPrim)
@@ -963,7 +976,6 @@ namespace OpenSim.Region.Physics.OdePlugin
963 if (actor.IsPhysical && (d.BodyIsEnabled(actor.Body) || !actor._zeroFlag)) 976 if (actor.IsPhysical && (d.BodyIsEnabled(actor.Body) || !actor._zeroFlag))
964 { 977 {
965 actor.UpdatePositionAndVelocity(); 978 actor.UpdatePositionAndVelocity();
966
967 } 979 }
968 } 980 }
969 } 981 }
@@ -984,25 +996,25 @@ namespace OpenSim.Region.Physics.OdePlugin
984 public float[] ResizeTerrain512(float[] heightMap) 996 public float[] ResizeTerrain512(float[] heightMap)
985 { 997 {
986 float[] returnarr = new float[262144]; 998 float[] returnarr = new float[262144];
987 float[,] resultarr = new float[m_regionWidth, m_regionHeight]; 999 float[,] resultarr = new float[m_regionWidth,m_regionHeight];
988 1000
989 // Filling out the array into it's multi-dimentional components 1001 // Filling out the array into it's multi-dimentional components
990 for (int y = 0; y < m_regionHeight; y++) 1002 for (int y = 0; y < m_regionHeight; y++)
991 { 1003 {
992 for (int x = 0; x < m_regionWidth; x++) 1004 for (int x = 0; x < m_regionWidth; x++)
993 { 1005 {
994 resultarr[y,x] = heightMap[y * m_regionWidth + x]; 1006 resultarr[y, x] = heightMap[y*m_regionWidth + x];
995 } 1007 }
996 } 1008 }
997 1009
998 // Resize using interpolation 1010 // Resize using interpolation
999 1011
1000 // This particular way is quick but it only works on a multiple of the original 1012 // This particular way is quick but it only works on a multiple of the original
1001 1013
1002 // The idea behind this method can be described with the following diagrams 1014 // The idea behind this method can be described with the following diagrams
1003 // second pass and third pass happen in the same loop really.. just separated 1015 // second pass and third pass happen in the same loop really.. just separated
1004 // them to show what this does. 1016 // them to show what this does.
1005 1017
1006 // First Pass 1018 // First Pass
1007 // ResultArr: 1019 // ResultArr:
1008 // 1,1,1,1,1,1 1020 // 1,1,1,1,1,1
@@ -1054,12 +1066,12 @@ namespace OpenSim.Region.Physics.OdePlugin
1054 // 4th # 1066 // 4th #
1055 // on single loop. 1067 // on single loop.
1056 1068
1057 float[,] resultarr2 = new float[512, 512]; 1069 float[,] resultarr2 = new float[512,512];
1058 for (int y = 0; y < m_regionHeight; y++) 1070 for (int y = 0; y < m_regionHeight; y++)
1059 { 1071 {
1060 for (int x = 0; x < m_regionWidth; x++) 1072 for (int x = 0; x < m_regionWidth; x++)
1061 { 1073 {
1062 resultarr2[y*2,x*2] = resultarr[y,x]; 1074 resultarr2[y*2, x*2] = resultarr[y, x];
1063 1075
1064 if (y < m_regionHeight) 1076 if (y < m_regionHeight)
1065 { 1077 {
@@ -1067,16 +1079,17 @@ namespace OpenSim.Region.Physics.OdePlugin
1067 { 1079 {
1068 if (x + 1 < m_regionWidth) 1080 if (x + 1 < m_regionWidth)
1069 { 1081 {
1070 resultarr2[(y * 2) + 1, x * 2] = ((resultarr[y, x] + resultarr[y + 1, x] + resultarr[y, x+1] + resultarr[y+1, x+1])/4); 1082 resultarr2[(y*2) + 1, x*2] = ((resultarr[y, x] + resultarr[y + 1, x] +
1083 resultarr[y, x + 1] + resultarr[y + 1, x + 1])/4);
1071 } 1084 }
1072 else 1085 else
1073 { 1086 {
1074 resultarr2[(y * 2) + 1, x * 2] = ((resultarr[y, x] + resultarr[y + 1, x]) / 2); 1087 resultarr2[(y*2) + 1, x*2] = ((resultarr[y, x] + resultarr[y + 1, x])/2);
1075 } 1088 }
1076 } 1089 }
1077 else 1090 else
1078 { 1091 {
1079 resultarr2[(y * 2) + 1, x * 2] = resultarr[y, x]; 1092 resultarr2[(y*2) + 1, x*2] = resultarr[y, x];
1080 } 1093 }
1081 } 1094 }
1082 if (x < m_regionWidth) 1095 if (x < m_regionWidth)
@@ -1085,31 +1098,32 @@ namespace OpenSim.Region.Physics.OdePlugin
1085 { 1098 {
1086 if (y + 1 < m_regionHeight) 1099 if (y + 1 < m_regionHeight)
1087 { 1100 {
1088 resultarr2[y * 2, (x * 2) + 1] = ((resultarr[y, x] + resultarr[y + 1, x] + resultarr[y, x + 1] + resultarr[y + 1, x + 1]) / 4); 1101 resultarr2[y*2, (x*2) + 1] = ((resultarr[y, x] + resultarr[y + 1, x] +
1102 resultarr[y, x + 1] + resultarr[y + 1, x + 1])/4);
1089 } 1103 }
1090 else 1104 else
1091 { 1105 {
1092 resultarr2[y * 2, (x * 2) + 1] = ((resultarr[y, x] + resultarr[y, x + 1]) / 2); 1106 resultarr2[y*2, (x*2) + 1] = ((resultarr[y, x] + resultarr[y, x + 1])/2);
1093 } 1107 }
1094 } 1108 }
1095 else 1109 else
1096 { 1110 {
1097 resultarr2[y * 2, (x * 2) + 1] = resultarr[y, x]; 1111 resultarr2[y*2, (x*2) + 1] = resultarr[y, x];
1098 } 1112 }
1099 } 1113 }
1100 if (x < m_regionWidth && y < m_regionHeight) 1114 if (x < m_regionWidth && y < m_regionHeight)
1101 { 1115 {
1102 if ((x + 1 < m_regionWidth) && (y + 1 < m_regionHeight)) 1116 if ((x + 1 < m_regionWidth) && (y + 1 < m_regionHeight))
1103 { 1117 {
1104 resultarr2[(y * 2) + 1, (x * 2) + 1] = ((resultarr[y, x] + resultarr[y + 1, x] + resultarr[y, x + 1] + resultarr[y + 1, x + 1]) / 4); 1118 resultarr2[(y*2) + 1, (x*2) + 1] = ((resultarr[y, x] + resultarr[y + 1, x] +
1119 resultarr[y, x + 1] + resultarr[y + 1, x + 1])/4);
1105 } 1120 }
1106 else 1121 else
1107 { 1122 {
1108 resultarr2[(y * 2) + 1, (x * 2) + 1] = resultarr[y, x]; 1123 resultarr2[(y*2) + 1, (x*2) + 1] = resultarr[y, x];
1109 } 1124 }
1110 } 1125 }
1111 } 1126 }
1112
1113 } 1127 }
1114 //Flatten out the array 1128 //Flatten out the array
1115 int i = 0; 1129 int i = 0;
@@ -1119,7 +1133,7 @@ namespace OpenSim.Region.Physics.OdePlugin
1119 { 1133 {
1120 if (resultarr2[y, x] <= 0) 1134 if (resultarr2[y, x] <= 0)
1121 returnarr[i] = 0.0000001f; 1135 returnarr[i] = 0.0000001f;
1122 else 1136 else
1123 returnarr[i] = resultarr2[y, x]; 1137 returnarr[i] = resultarr2[y, x];
1124 1138
1125 i++; 1139 i++;
@@ -1127,8 +1141,8 @@ namespace OpenSim.Region.Physics.OdePlugin
1127 } 1141 }
1128 1142
1129 return returnarr; 1143 return returnarr;
1130
1131 } 1144 }
1145
1132 public override void SetTerrain(float[] heightMap) 1146 public override void SetTerrain(float[] heightMap)
1133 { 1147 {
1134 // this._heightmap[i] = (double)heightMap[i]; 1148 // this._heightmap[i] = (double)heightMap[i];
@@ -1137,8 +1151,8 @@ namespace OpenSim.Region.Physics.OdePlugin
1137 1151
1138 const uint heightmapWidth = m_regionWidth + 2; 1152 const uint heightmapWidth = m_regionWidth + 2;
1139 const uint heightmapHeight = m_regionHeight + 2; 1153 const uint heightmapHeight = m_regionHeight + 2;
1140 const uint heightmapWidthSamples = 2 * m_regionWidth + 2; 1154 const uint heightmapWidthSamples = 2*m_regionWidth + 2;
1141 const uint heightmapHeightSamples = 2 * m_regionHeight + 2; 1155 const uint heightmapHeightSamples = 2*m_regionHeight + 2;
1142 const float scale = 1.0f; 1156 const float scale = 1.0f;
1143 const float offset = 0.0f; 1157 const float offset = 0.0f;
1144 const float thickness = 2.0f; 1158 const float thickness = 2.0f;
@@ -1166,7 +1180,8 @@ namespace OpenSim.Region.Physics.OdePlugin
1166 } 1180 }
1167 IntPtr HeightmapData = d.GeomHeightfieldDataCreate(); 1181 IntPtr HeightmapData = d.GeomHeightfieldDataCreate();
1168 d.GeomHeightfieldDataBuildDouble(HeightmapData, _heightmap, 0, heightmapWidth, heightmapHeight, 1182 d.GeomHeightfieldDataBuildDouble(HeightmapData, _heightmap, 0, heightmapWidth, heightmapHeight,
1169 (int) heightmapWidthSamples, (int) heightmapHeightSamples, scale, offset, thickness, wrap); 1183 (int) heightmapWidthSamples, (int) heightmapHeightSamples, scale,
1184 offset, thickness, wrap);
1170 d.GeomHeightfieldDataSetBounds(HeightmapData, m_regionWidth, m_regionHeight); 1185 d.GeomHeightfieldDataSetBounds(HeightmapData, m_regionWidth, m_regionHeight);
1171 LandGeom = d.CreateHeightfield(space, HeightmapData, 1); 1186 LandGeom = d.CreateHeightfield(space, HeightmapData, 1);
1172 geom_name_map[LandGeom] = "Terrain"; 1187 geom_name_map[LandGeom] = "Terrain";
@@ -1193,7 +1208,4 @@ namespace OpenSim.Region.Physics.OdePlugin
1193 { 1208 {
1194 } 1209 }
1195 } 1210 }
1196 1211} \ No newline at end of file
1197
1198
1199}