aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Physics/OdePlugin/OdePlugin.cs274
1 files changed, 103 insertions, 171 deletions
diff --git a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
index a20452f..c9af6dd 100644
--- a/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
+++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs
@@ -25,19 +25,14 @@
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28
28using System; 29using System;
29using System.Threading;
30using System.Collections.Generic; 30using System.Collections.Generic;
31
32using libsecondlife;
33
34using Axiom.Math; 31using Axiom.Math;
35using Ode.NET; 32using Ode.NET;
36using OpenSim.Framework; 33using OpenSim.Framework;
37using OpenSim.Framework.Console;
38using OpenSim.Region.Physics.Manager; 34using OpenSim.Region.Physics.Manager;
39 35
40
41namespace OpenSim.Region.Physics.OdePlugin 36namespace OpenSim.Region.Physics.OdePlugin
42{ 37{
43 /// <summary> 38 /// <summary>
@@ -49,7 +44,6 @@ namespace OpenSim.Region.Physics.OdePlugin
49 44
50 public OdePlugin() 45 public OdePlugin()
51 { 46 {
52
53 } 47 }
54 48
55 public bool Init() 49 public bool Init()
@@ -73,7 +67,6 @@ namespace OpenSim.Region.Physics.OdePlugin
73 67
74 public void Dispose() 68 public void Dispose()
75 { 69 {
76
77 } 70 }
78 } 71 }
79 72
@@ -82,17 +75,17 @@ namespace OpenSim.Region.Physics.OdePlugin
82 private static float ODE_STEPSIZE = 0.004f; 75 private static float ODE_STEPSIZE = 0.004f;
83 private static bool RENDER_FLAG = false; 76 private static bool RENDER_FLAG = false;
84 private IntPtr contactgroup; 77 private IntPtr contactgroup;
85 private IntPtr LandGeom=(IntPtr)0; 78 private IntPtr LandGeom = (IntPtr) 0;
86 private double[] _heightmap; 79 private double[] _heightmap;
87 private d.NearCallback nearCallback; 80 private d.NearCallback nearCallback;
88 public d.TriCallback triCallback; 81 public d.TriCallback triCallback;
89 public d.TriArrayCallback triArrayCallback; 82 public d.TriArrayCallback triArrayCallback;
90 private List<OdeCharacter> _characters = new List<OdeCharacter>(); 83 private List<OdeCharacter> _characters = new List<OdeCharacter>();
91 private List<OdePrim> _prims = new List<OdePrim>(); 84 private List<OdePrim> _prims = new List<OdePrim>();
92 public Dictionary<IntPtr, String> geom_name_map=new Dictionary<IntPtr, String>(); 85 public Dictionary<IntPtr, String> geom_name_map = new Dictionary<IntPtr, String>();
93 private d.ContactGeom[] contacts = new d.ContactGeom[30]; 86 private d.ContactGeom[] contacts = new d.ContactGeom[30];
94 private d.Contact contact; 87 private d.Contact contact;
95 private float step_time=0.0f; 88 private float step_time = 0.0f;
96 public IntPtr world; 89 public IntPtr world;
97 public IntPtr space; 90 public IntPtr space;
98 public static Object OdeLock = new Object(); 91 public static Object OdeLock = new Object();
@@ -140,7 +133,7 @@ namespace OpenSim.Region.Physics.OdePlugin
140 return; 133 return;
141 134
142 d.GeomClassID id = d.GeomGetClass(g1); 135 d.GeomClassID id = d.GeomGetClass(g1);
143 if (id==d.GeomClassID.TriMeshClass) 136 if (id == d.GeomClassID.TriMeshClass)
144 { 137 {
145 String name1 = null; 138 String name1 = null;
146 String name2 = null; 139 String name2 = null;
@@ -163,7 +156,6 @@ namespace OpenSim.Region.Physics.OdePlugin
163 IntPtr joint = d.JointCreateContact(world, contactgroup, ref contact); 156 IntPtr joint = d.JointCreateContact(world, contactgroup, ref contact);
164 d.JointAttach(joint, b1, b2); 157 d.JointAttach(joint, b1, b2);
165 } 158 }
166
167 } 159 }
168 160
169 private void collision_optimized() 161 private void collision_optimized()
@@ -171,7 +163,8 @@ namespace OpenSim.Region.Physics.OdePlugin
171 foreach (OdeCharacter chr in _characters) 163 foreach (OdeCharacter chr in _characters)
172 { 164 {
173 d.SpaceCollide2(space, chr.Shell, IntPtr.Zero, nearCallback); 165 d.SpaceCollide2(space, chr.Shell, IntPtr.Zero, nearCallback);
174 foreach (OdeCharacter ch2 in _characters) /// should be a separate space -- lots of avatars will be N**2 slow 166 foreach (OdeCharacter ch2 in _characters)
167 /// should be a separate space -- lots of avatars will be N**2 slow
175 { 168 {
176 d.SpaceCollide2(chr.Shell, ch2.Shell, IntPtr.Zero, nearCallback); 169 d.SpaceCollide2(chr.Shell, ch2.Shell, IntPtr.Zero, nearCallback);
177 } 170 }
@@ -193,8 +186,8 @@ namespace OpenSim.Region.Physics.OdePlugin
193 { 186 {
194 lock (OdeLock) 187 lock (OdeLock)
195 { 188 {
196 ((OdeCharacter)actor).Destroy(); 189 ((OdeCharacter) actor).Destroy();
197 _characters.Remove((OdeCharacter)actor); 190 _characters.Remove((OdeCharacter) actor);
198 } 191 }
199 } 192 }
200 193
@@ -204,13 +197,14 @@ namespace OpenSim.Region.Physics.OdePlugin
204 { 197 {
205 lock (OdeLock) 198 lock (OdeLock)
206 { 199 {
207 d.GeomDestroy(((OdePrim)prim).prim_geom); 200 d.GeomDestroy(((OdePrim) prim).prim_geom);
208 _prims.Remove((OdePrim)prim); 201 _prims.Remove((OdePrim) prim);
209 } 202 }
210 } 203 }
211 } 204 }
212 205
213 PhysicsActor AddPrim(String name, PhysicsVector position, PhysicsVector size, Quaternion rotation, Mesh mesh, PrimitiveBaseShape pbs) 206 private PhysicsActor AddPrim(String name, PhysicsVector position, PhysicsVector size, Quaternion rotation,
207 Mesh mesh, PrimitiveBaseShape pbs)
214 { 208 {
215 PhysicsVector pos = new PhysicsVector(); 209 PhysicsVector pos = new PhysicsVector();
216 pos.X = position.X; 210 pos.X = position.X;
@@ -235,7 +229,7 @@ namespace OpenSim.Region.Physics.OdePlugin
235 } 229 }
236 230
237 231
238 public int TriArrayCallback(System.IntPtr trimesh, System.IntPtr refObject, int[] triangleIndex, int triCount) 232 public int TriArrayCallback(IntPtr trimesh, IntPtr refObject, int[] triangleIndex, int triCount)
239 { 233 {
240/* String name1 = null; 234/* String name1 = null;
241 String name2 = null; 235 String name2 = null;
@@ -254,15 +248,14 @@ namespace OpenSim.Region.Physics.OdePlugin
254 return 1; 248 return 1;
255 } 249 }
256 250
257 public int TriCallback(System.IntPtr trimesh, System.IntPtr refObject, int triangleIndex) 251 public int TriCallback(IntPtr trimesh, IntPtr refObject, int triangleIndex)
258 { 252 {
259
260 String name1 = null; 253 String name1 = null;
261 String name2 = null; 254 String name2 = null;
262 255
263 if (!geom_name_map.TryGetValue(trimesh, out name1)) 256 if (!geom_name_map.TryGetValue(trimesh, out name1))
264 { 257 {
265 name1 = "null"; 258 name1 = "null";
266 } 259 }
267 if (!geom_name_map.TryGetValue(refObject, out name2)) 260 if (!geom_name_map.TryGetValue(refObject, out name2))
268 { 261 {
@@ -282,11 +275,12 @@ namespace OpenSim.Region.Physics.OdePlugin
282 } 275 }
283 276
284 277
285 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, PhysicsVector size, Quaternion rotation) 278 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position,
279 PhysicsVector size, Quaternion rotation)
286 { 280 {
287 PhysicsActor result; 281 PhysicsActor result;
288 282
289 switch(pbs.ProfileShape) 283 switch (pbs.ProfileShape)
290 { 284 {
291 case ProfileShape.Square: 285 case ProfileShape.Square:
292 /// support simple box & hollow box now; later, more shapes 286 /// support simple box & hollow box now; later, more shapes
@@ -310,7 +304,6 @@ namespace OpenSim.Region.Physics.OdePlugin
310 } 304 }
311 305
312 306
313
314 public override void Simulate(float timeStep) 307 public override void Simulate(float timeStep)
315 { 308 {
316 step_time += timeStep; 309 step_time += timeStep;
@@ -327,11 +320,12 @@ namespace OpenSim.Region.Physics.OdePlugin
327 Vector3 rx, ry, rz; 320 Vector3 rx, ry, rz;
328 p.Orientation.ToAxes(out rx, out ry, out rz); 321 p.Orientation.ToAxes(out rx, out ry, out rz);
329 Console.WriteLine("RENDER: block; " + p.Size.X + ", " + p.Size.Y + ", " + p.Size.Z + "; " + 322 Console.WriteLine("RENDER: block; " + p.Size.X + ", " + p.Size.Y + ", " + p.Size.Z + "; " +
330 " 0, 0, 1; " + //shape, size, color 323 " 0, 0, 1; " + //shape, size, color
331 (p.Position.X - 128.0f) + ", " + (p.Position.Y - 128.0f) + ", " + (p.Position.Z - 33.0f) + "; " + // position 324 (p.Position.X - 128.0f) + ", " + (p.Position.Y - 128.0f) + ", " +
332 rx.x + "," + ry.x + "," + rz.x + ", " + // rotation 325 (p.Position.Z - 33.0f) + "; " + // position
333 rx.y + "," + ry.y + "," + rz.y + ", " + 326 rx.x + "," + ry.x + "," + rz.x + ", " + // rotation
334 rx.z + "," + ry.z + "," + rz.z); 327 rx.y + "," + ry.y + "," + rz.y + ", " +
328 rx.z + "," + ry.z + "," + rz.z);
335 } 329 }
336 } 330 }
337 int i = 0; 331 int i = 0;
@@ -357,22 +351,27 @@ namespace OpenSim.Region.Physics.OdePlugin
357 float Zoff = -33.0f; 351 float Zoff = -33.0f;
358 d.Matrix3 temp = d.BodyGetRotation(actor.Body); 352 d.Matrix3 temp = d.BodyGetRotation(actor.Body);
359 Console.WriteLine("RENDER: cylinder; " + // shape 353 Console.WriteLine("RENDER: cylinder; " + // shape
360 OdeCharacter.CAPSULE_RADIUS + ", " + OdeCharacter.CAPSULE_LENGTH + //size 354 OdeCharacter.CAPSULE_RADIUS + ", " + OdeCharacter.CAPSULE_LENGTH + //size
361 "; 0, 1, 0; " + // color 355 "; 0, 1, 0; " + // color
362 (actor.Position.X - 128.0f) + ", " + (actor.Position.Y - 128.0f) + ", " + (actor.Position.Z + Zoff) + "; " + // position 356 (actor.Position.X - 128.0f) + ", " + (actor.Position.Y - 128.0f) + ", " +
363 temp.M00 + "," + temp.M10 + "," + temp.M20 + ", " + // rotation 357 (actor.Position.Z + Zoff) + "; " + // position
364 temp.M01 + "," + temp.M11 + "," + temp.M21 + ", " + 358 temp.M00 + "," + temp.M10 + "," + temp.M20 + ", " + // rotation
365 temp.M02 + "," + temp.M12 + "," + temp.M22); 359 temp.M01 + "," + temp.M11 + "," + temp.M21 + ", " +
366 d.Vector3 caphead; d.BodyGetRelPointPos(actor.Body, 0, 0, OdeCharacter.CAPSULE_LENGTH * .5f, out caphead); 360 temp.M02 + "," + temp.M12 + "," + temp.M22);
367 d.Vector3 capfoot; d.BodyGetRelPointPos(actor.Body, 0, 0, -OdeCharacter.CAPSULE_LENGTH * .5f, out capfoot); 361 d.Vector3 caphead;
362 d.BodyGetRelPointPos(actor.Body, 0, 0, OdeCharacter.CAPSULE_LENGTH*.5f, out caphead);
363 d.Vector3 capfoot;
364 d.BodyGetRelPointPos(actor.Body, 0, 0, -OdeCharacter.CAPSULE_LENGTH*.5f, out capfoot);
368 Console.WriteLine("RENDER: sphere; " + OdeCharacter.CAPSULE_RADIUS + // shape, size 365 Console.WriteLine("RENDER: sphere; " + OdeCharacter.CAPSULE_RADIUS + // shape, size
369 "; 1, 0, 1; " + //color 366 "; 1, 0, 1; " + //color
370 (caphead.X - 128.0f) + ", " + (caphead.Y - 128.0f) + ", " + (caphead.Z + Zoff) + "; " + // position 367 (caphead.X - 128.0f) + ", " + (caphead.Y - 128.0f) + ", " + (caphead.Z + Zoff) +
371 "1,0,0, 0,1,0, 0,0,1"); // rotation 368 "; " + // position
369 "1,0,0, 0,1,0, 0,0,1"); // rotation
372 Console.WriteLine("RENDER: sphere; " + OdeCharacter.CAPSULE_RADIUS + // shape, size 370 Console.WriteLine("RENDER: sphere; " + OdeCharacter.CAPSULE_RADIUS + // shape, size
373 "; 1, 0, 0; " + //color 371 "; 1, 0, 0; " + //color
374 (capfoot.X - 128.0f) + ", " + (capfoot.Y - 128.0f) + ", " + (capfoot.Z + Zoff) + "; " + // position 372 (capfoot.X - 128.0f) + ", " + (capfoot.Y - 128.0f) + ", " + (capfoot.Z + Zoff) +
375 "1,0,0, 0,1,0, 0,0,1"); // rotation 373 "; " + // position
374 "1,0,0, 0,1,0, 0,0,1"); // rotation
376 } 375 }
377 } 376 }
378 } 377 }
@@ -380,14 +379,11 @@ namespace OpenSim.Region.Physics.OdePlugin
380 379
381 public override void GetResults() 380 public override void GetResults()
382 { 381 {
383
384 } 382 }
385 383
386 public override bool IsThreaded 384 public override bool IsThreaded
387 { 385 {
388 get 386 get { return (false); // for now we won't be multithreaded
389 {
390 return (false); // for now we won't be multithreaded
391 } 387 }
392 } 388 }
393 389
@@ -400,21 +396,21 @@ namespace OpenSim.Region.Physics.OdePlugin
400 { 396 {
401 for (int y = 0; y < 258; y++) 397 for (int y = 0; y < 258; y++)
402 { 398 {
403 int xx = x-1; 399 int xx = x - 1;
404 if (xx < 0) xx = 0; 400 if (xx < 0) xx = 0;
405 if (xx > 255) xx = 255; 401 if (xx > 255) xx = 255;
406 int yy = y-1; 402 int yy = y - 1;
407 if (yy < 0) yy = 0; 403 if (yy < 0) yy = 0;
408 if (yy > 255) yy = 255; 404 if (yy > 255) yy = 255;
409 405
410 double val = (double)heightMap[yy * 256 + xx]; 406 double val = (double) heightMap[yy*256 + xx];
411 _heightmap[x * 258 + y] = val; 407 _heightmap[x*258 + y] = val;
412 } 408 }
413 } 409 }
414 410
415 lock (OdeLock) 411 lock (OdeLock)
416 { 412 {
417 if (!(LandGeom == (IntPtr)0)) 413 if (!(LandGeom == (IntPtr) 0))
418 { 414 {
419 d.SpaceRemove(space, LandGeom); 415 d.SpaceRemove(space, LandGeom);
420 } 416 }
@@ -422,7 +418,7 @@ namespace OpenSim.Region.Physics.OdePlugin
422 d.GeomHeightfieldDataBuildDouble(HeightmapData, _heightmap, 0, 258, 258, 258, 258, 1.0f, 0.0f, 2.0f, 0); 418 d.GeomHeightfieldDataBuildDouble(HeightmapData, _heightmap, 0, 258, 258, 258, 258, 1.0f, 0.0f, 2.0f, 0);
423 d.GeomHeightfieldDataSetBounds(HeightmapData, 256, 256); 419 d.GeomHeightfieldDataSetBounds(HeightmapData, 256, 256);
424 LandGeom = d.CreateHeightfield(space, HeightmapData, 1); 420 LandGeom = d.CreateHeightfield(space, HeightmapData, 1);
425 this.geom_name_map[LandGeom]="Terrain"; 421 geom_name_map[LandGeom] = "Terrain";
426 422
427 d.Matrix3 R = new d.Matrix3(); 423 d.Matrix3 R = new d.Matrix3();
428 424
@@ -430,7 +426,7 @@ namespace OpenSim.Region.Physics.OdePlugin
430 Quaternion q2 = Quaternion.FromAngleAxis(1.5707f, new Vector3(0, 1, 0)); 426 Quaternion q2 = Quaternion.FromAngleAxis(1.5707f, new Vector3(0, 1, 0));
431 //Axiom.Math.Quaternion q3 = Axiom.Math.Quaternion.FromAngleAxis(3.14f, new Axiom.Math.Vector3(0, 0, 1)); 427 //Axiom.Math.Quaternion q3 = Axiom.Math.Quaternion.FromAngleAxis(3.14f, new Axiom.Math.Vector3(0, 0, 1));
432 428
433 q1 = q1 * q2; 429 q1 = q1*q2;
434 //q1 = q1 * q3; 430 //q1 = q1 * q3;
435 Vector3 v3 = new Vector3(); 431 Vector3 v3 = new Vector3();
436 float angle = 0; 432 float angle = 0;
@@ -444,7 +440,6 @@ namespace OpenSim.Region.Physics.OdePlugin
444 440
445 public override void DeleteTerrain() 441 public override void DeleteTerrain()
446 { 442 {
447
448 } 443 }
449 } 444 }
450 445
@@ -452,12 +447,12 @@ namespace OpenSim.Region.Physics.OdePlugin
452 { 447 {
453 private PhysicsVector _position; 448 private PhysicsVector _position;
454 private d.Vector3 _zeroPosition; 449 private d.Vector3 _zeroPosition;
455 private bool _zeroFlag=false; 450 private bool _zeroFlag = false;
456 private PhysicsVector _velocity; 451 private PhysicsVector _velocity;
457 private PhysicsVector _target_velocity; 452 private PhysicsVector _target_velocity;
458 private PhysicsVector _acceleration; 453 private PhysicsVector _acceleration;
459 private static float PID_D=4000.0f; 454 private static float PID_D = 4000.0f;
460 private static float PID_P=7000.0f; 455 private static float PID_P = 7000.0f;
461 private static float POSTURE_SERVO = 10000.0f; 456 private static float POSTURE_SERVO = 10000.0f;
462 public static float CAPSULE_RADIUS = 0.5f; 457 public static float CAPSULE_RADIUS = 0.5f;
463 public static float CAPSULE_LENGTH = 0.9f; 458 public static float CAPSULE_LENGTH = 0.9f;
@@ -484,28 +479,18 @@ namespace OpenSim.Region.Physics.OdePlugin
484 d.BodySetPosition(Body, pos.X, pos.Y, pos.Z); 479 d.BodySetPosition(Body, pos.X, pos.Y, pos.Z);
485 d.GeomSetBody(Shell, Body); 480 d.GeomSetBody(Shell, Body);
486 } 481 }
487 parent_scene.geom_name_map[Shell]=avName; 482 parent_scene.geom_name_map[Shell] = avName;
488
489 } 483 }
490 484
491 public override bool Flying 485 public override bool Flying
492 { 486 {
493 get 487 get { return flying; }
494 { 488 set { flying = value; }
495 return flying;
496 }
497 set
498 {
499 flying = value;
500 }
501 } 489 }
502 490
503 public override PhysicsVector Position 491 public override PhysicsVector Position
504 { 492 {
505 get 493 get { return _position; }
506 {
507 return _position;
508 }
509 set 494 set
510 { 495 {
511 lock (OdeScene.OdeLock) 496 lock (OdeScene.OdeLock)
@@ -518,60 +503,34 @@ namespace OpenSim.Region.Physics.OdePlugin
518 503
519 public override PhysicsVector Size 504 public override PhysicsVector Size
520 { 505 {
521 get 506 get { return new PhysicsVector(0, 0, 0); }
522 { 507 set { }
523 return new PhysicsVector(0,0,0);
524 }
525 set
526 {
527 }
528 } 508 }
529 509
530 510
531 public override PhysicsVector Velocity 511 public override PhysicsVector Velocity
532 { 512 {
533 get 513 get { return _velocity; }
534 { 514 set { _target_velocity = value; }
535 return _velocity;
536 }
537 set
538 {
539 _target_velocity = value;
540 }
541 } 515 }
542 516
543 public override bool Kinematic 517 public override bool Kinematic
544 { 518 {
545 get 519 get { return false; }
546 { 520 set { }
547 return false;
548 }
549 set
550 {
551
552 }
553 } 521 }
554 522
555 public override Quaternion Orientation 523 public override Quaternion Orientation
556 { 524 {
557 get 525 get { return Quaternion.Identity; }
558 { 526 set { }
559 return Quaternion.Identity;
560 }
561 set
562 {
563
564 }
565 } 527 }
566 528
567 public override PhysicsVector Acceleration 529 public override PhysicsVector Acceleration
568 { 530 {
569 get 531 get { return _acceleration; }
570 {
571 return _acceleration;
572 }
573
574 } 532 }
533
575 public void SetAcceleration(PhysicsVector accel) 534 public void SetAcceleration(PhysicsVector accel)
576 { 535 {
577 _acceleration = accel; 536 _acceleration = accel;
@@ -579,12 +538,10 @@ namespace OpenSim.Region.Physics.OdePlugin
579 538
580 public override void AddForce(PhysicsVector force) 539 public override void AddForce(PhysicsVector force)
581 { 540 {
582
583 } 541 }
584 542
585 public override void SetMomentum(PhysicsVector momentum) 543 public override void SetMomentum(PhysicsVector momentum)
586 { 544 {
587
588 } 545 }
589 546
590 public void Move(float timeStep) 547 public void Move(float timeStep)
@@ -603,28 +560,28 @@ namespace OpenSim.Region.Physics.OdePlugin
603 _zeroPosition = d.BodyGetPosition(Body); 560 _zeroPosition = d.BodyGetPosition(Body);
604 } 561 }
605 d.Vector3 pos = d.BodyGetPosition(Body); 562 d.Vector3 pos = d.BodyGetPosition(Body);
606 vec.X = (_target_velocity.X - vel.X) * PID_D + (_zeroPosition.X - pos.X) * PID_P; 563 vec.X = (_target_velocity.X - vel.X)*PID_D + (_zeroPosition.X - pos.X)*PID_P;
607 vec.Y = (_target_velocity.Y - vel.Y) * PID_D + (_zeroPosition.Y - pos.Y) * PID_P; 564 vec.Y = (_target_velocity.Y - vel.Y)*PID_D + (_zeroPosition.Y - pos.Y)*PID_P;
608 if (flying) 565 if (flying)
609 { 566 {
610 vec.Z = (_target_velocity.Z - vel.Z) * PID_D + (_zeroPosition.Z - pos.Z) * PID_P; 567 vec.Z = (_target_velocity.Z - vel.Z)*PID_D + (_zeroPosition.Z - pos.Z)*PID_P;
611 } 568 }
612 } 569 }
613 else 570 else
614 { 571 {
615 _zeroFlag = false; 572 _zeroFlag = false;
616 vec.X = (_target_velocity.X - vel.X) * PID_D; 573 vec.X = (_target_velocity.X - vel.X)*PID_D;
617 vec.Y = (_target_velocity.Y - vel.Y) * PID_D; 574 vec.Y = (_target_velocity.Y - vel.Y)*PID_D;
618 if (flying) 575 if (flying)
619 { 576 {
620 vec.Z = (_target_velocity.Z - vel.Z) * PID_D; 577 vec.Z = (_target_velocity.Z - vel.Z)*PID_D;
621 } 578 }
622 } 579 }
623 if (flying) 580 if (flying)
624 { 581 {
625 vec.Z += 10.0f; 582 vec.Z += 10.0f;
626 } 583 }
627 d.BodyAddForce(this.Body, vec.X, vec.Y, vec.Z); 584 d.BodyAddForce(Body, vec.X, vec.Y, vec.Z);
628 585
629 // ok -- let's stand up straight! 586 // ok -- let's stand up straight!
630 d.Vector3 feet; 587 d.Vector3 feet;
@@ -634,7 +591,7 @@ namespace OpenSim.Region.Physics.OdePlugin
634 float posture = head.Z - feet.Z; 591 float posture = head.Z - feet.Z;
635 592
636 // restoring force proportional to lack of posture: 593 // restoring force proportional to lack of posture:
637 float servo = (2.5f-posture) * POSTURE_SERVO; 594 float servo = (2.5f - posture)*POSTURE_SERVO;
638 d.BodyAddForceAtRelPos(Body, 0.0f, 0.0f, servo, 0.0f, 0.0f, 1.0f); 595 d.BodyAddForceAtRelPos(Body, 0.0f, 0.0f, servo, 0.0f, 0.0f, 1.0f);
639 d.BodyAddForceAtRelPos(Body, 0.0f, 0.0f, -servo, 0.0f, 0.0f, -1.0f); 596 d.BodyAddForceAtRelPos(Body, 0.0f, 0.0f, -servo, 0.0f, 0.0f, -1.0f);
640 } 597 }
@@ -650,9 +607,9 @@ namespace OpenSim.Region.Physics.OdePlugin
650 if (vec.X > 255.95f) vec.X = 255.95f; 607 if (vec.X > 255.95f) vec.X = 255.95f;
651 if (vec.Y > 255.95f) vec.Y = 255.95f; 608 if (vec.Y > 255.95f) vec.Y = 255.95f;
652 609
653 this._position.X = vec.X; 610 _position.X = vec.X;
654 this._position.Y = vec.Y; 611 _position.Y = vec.Y;
655 this._position.Z = vec.Z; 612 _position.Z = vec.Z;
656 613
657 if (_zeroFlag) 614 if (_zeroFlag)
658 { 615 {
@@ -673,9 +630,9 @@ namespace OpenSim.Region.Physics.OdePlugin
673 { 630 {
674 lock (OdeScene.OdeLock) 631 lock (OdeScene.OdeLock)
675 { 632 {
676 d.GeomDestroy(this.Shell); 633 d.GeomDestroy(Shell);
677 this._parent_scene.geom_name_map.Remove(this.Shell); 634 _parent_scene.geom_name_map.Remove(Shell);
678 d.BodyDestroy(this.Body); 635 d.BodyDestroy(Body);
679 } 636 }
680 } 637 }
681 } 638 }
@@ -693,7 +650,7 @@ namespace OpenSim.Region.Physics.OdePlugin
693 public IntPtr prim_geom; 650 public IntPtr prim_geom;
694 public IntPtr _triMeshData; 651 public IntPtr _triMeshData;
695 652
696 public OdePrim(String primName, OdeScene parent_scene, PhysicsVector pos, PhysicsVector size, 653 public OdePrim(String primName, OdeScene parent_scene, PhysicsVector pos, PhysicsVector size,
697 Quaternion rotation, Mesh mesh, PrimitiveBaseShape pbs) 654 Quaternion rotation, Mesh mesh, PrimitiveBaseShape pbs)
698 { 655 {
699 _velocity = new PhysicsVector(); 656 _velocity = new PhysicsVector();
@@ -707,7 +664,7 @@ namespace OpenSim.Region.Physics.OdePlugin
707 664
708 lock (OdeScene.OdeLock) 665 lock (OdeScene.OdeLock)
709 { 666 {
710 if (mesh!=null) 667 if (mesh != null)
711 { 668 {
712 setMesh(parent_scene, mesh); 669 setMesh(parent_scene, mesh);
713 } 670 }
@@ -723,20 +680,22 @@ namespace OpenSim.Region.Physics.OdePlugin
723 myrot.Y = rotation.y; 680 myrot.Y = rotation.y;
724 myrot.Z = rotation.z; 681 myrot.Z = rotation.z;
725 d.GeomSetQuaternion(prim_geom, ref myrot); 682 d.GeomSetQuaternion(prim_geom, ref myrot);
726 parent_scene.geom_name_map[prim_geom] = primName; // don't do .add() here; old geoms get recycled with the same hash 683 parent_scene.geom_name_map[prim_geom] = primName;
684 // don't do .add() here; old geoms get recycled with the same hash
727 } 685 }
728 } 686 }
729 687
730 public void setMesh(OdeScene parent_scene, Mesh mesh) 688 public void setMesh(OdeScene parent_scene, Mesh mesh)
731 { 689 {
732 float[] vertexList = mesh.getVertexListAsFloat(); // Note, that vertextList is pinned in memory 690 float[] vertexList = mesh.getVertexListAsFloat(); // Note, that vertextList is pinned in memory
733 int[] indexList = mesh.getIndexListAsInt(); // Also pinned, needs release after usage 691 int[] indexList = mesh.getIndexListAsInt(); // Also pinned, needs release after usage
734 int VertexCount = vertexList.GetLength(0) / 3; 692 int VertexCount = vertexList.GetLength(0)/3;
735 int IndexCount = indexList.GetLength(0); 693 int IndexCount = indexList.GetLength(0);
736 694
737 _triMeshData = d.GeomTriMeshDataCreate(); 695 _triMeshData = d.GeomTriMeshDataCreate();
738 696
739 d.GeomTriMeshDataBuildSimple(_triMeshData, vertexList, 3 * sizeof(float), VertexCount, indexList, IndexCount, 3 * sizeof(int)); 697 d.GeomTriMeshDataBuildSimple(_triMeshData, vertexList, 3*sizeof (float), VertexCount, indexList, IndexCount,
698 3*sizeof (int));
740 d.GeomTriMeshDataPreprocess(_triMeshData); 699 d.GeomTriMeshDataPreprocess(_triMeshData);
741 700
742 prim_geom = d.CreateTriMesh(parent_scene.space, _triMeshData, parent_scene.triCallback, null, null); 701 prim_geom = d.CreateTriMesh(parent_scene.space, _triMeshData, parent_scene.triCallback, null, null);
@@ -744,21 +703,14 @@ namespace OpenSim.Region.Physics.OdePlugin
744 703
745 public override bool Flying 704 public override bool Flying
746 { 705 {
747 get 706 get { return false; //no flying prims for you
748 {
749 return false; //no flying prims for you
750 }
751 set
752 {
753 } 707 }
708 set { }
754 } 709 }
755 710
756 public override PhysicsVector Position 711 public override PhysicsVector Position
757 { 712 {
758 get 713 get { return _position; }
759 {
760 return _position;
761 }
762 set 714 set
763 { 715 {
764 _position = value; 716 _position = value;
@@ -771,10 +723,7 @@ namespace OpenSim.Region.Physics.OdePlugin
771 723
772 public override PhysicsVector Size 724 public override PhysicsVector Size
773 { 725 {
774 get 726 get { return _size; }
775 {
776 return _size;
777 }
778 set 727 set
779 { 728 {
780 _size = value; 729 _size = value;
@@ -798,33 +747,19 @@ namespace OpenSim.Region.Physics.OdePlugin
798 747
799 public override PhysicsVector Velocity 748 public override PhysicsVector Velocity
800 { 749 {
801 get 750 get { return _velocity; }
802 { 751 set { _velocity = value; }
803 return _velocity;
804 }
805 set
806 {
807 _velocity = value;
808 }
809 } 752 }
810 753
811 public override bool Kinematic 754 public override bool Kinematic
812 { 755 {
813 get 756 get { return false; }
814 { 757 set { }
815 return false;
816 }
817 set
818 {
819 }
820 } 758 }
821 759
822 public override Quaternion Orientation 760 public override Quaternion Orientation
823 { 761 {
824 get 762 get { return _orientation; }
825 {
826 return _orientation;
827 }
828 set 763 set
829 { 764 {
830 _orientation = value; 765 _orientation = value;
@@ -842,15 +777,12 @@ namespace OpenSim.Region.Physics.OdePlugin
842 777
843 public override PhysicsVector Acceleration 778 public override PhysicsVector Acceleration
844 { 779 {
845 get 780 get { return _acceleration; }
846 {
847 return _acceleration;
848 }
849 } 781 }
850 782
851 public void SetAcceleration(PhysicsVector accel) 783 public void SetAcceleration(PhysicsVector accel)
852 { 784 {
853 this._acceleration = accel; 785 _acceleration = accel;
854 } 786 }
855 787
856 public override void AddForce(PhysicsVector force) 788 public override void AddForce(PhysicsVector force)
@@ -861,4 +793,4 @@ namespace OpenSim.Region.Physics.OdePlugin
861 { 793 {
862 } 794 }
863 } 795 }
864} 796} \ No newline at end of file