aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/BulletXPlugin
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/BulletXPlugin')
-rw-r--r--OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs250
1 files changed, 115 insertions, 135 deletions
diff --git a/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs b/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs
index b38eea0..57a6092 100644
--- a/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs
+++ b/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs
@@ -1,9 +1,11 @@
1#region Copyright
1/* 2/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 3* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 4* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 5*
5* Redistribution and use in source and binary forms, with or without 6* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 7* modification, are permitted provided that the following conditions are
8met:
7* * Redistributions of source code must retain the above copyright 9* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 10* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 11* * Redistributions in binary form must reproduce the above copyright
@@ -11,27 +13,33 @@
11* documentation and/or other materials provided with the distribution. 13* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 14* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 15* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 16* derived from this software without specific prior written
17permission.
15* 18*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 19* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 22* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25SERVICES;
26* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 32*
27*/ 33*/
34#endregion
28#region References 35#region References
29using System; 36using System;
30using System.Collections.Generic; 37using System.Collections.Generic;
31using OpenSim.Region.Physics.Manager; 38using OpenSim.Region.Physics.Manager;
32using Axiom.Math; 39using Axiom.Math;
40using AxiomQuaternion = Axiom.Math.Quaternion;
33//Specific References for BulletXPlugin 41//Specific References for BulletXPlugin
34using MonoXnaCompactMaths; 42using MonoXnaCompactMaths; //Called as MXCM
35using XnaDevRu.BulletX; 43using XnaDevRu.BulletX;
36using XnaDevRu.BulletX.Dynamics; 44using XnaDevRu.BulletX.Dynamics;
37#endregion 45#endregion
@@ -43,37 +51,24 @@ namespace OpenSim.Region.Physics.BulletXPlugin
43 /// </summary> 51 /// </summary>
44 public class BulletXConversions 52 public class BulletXConversions
45 { 53 {
54 //Vector3
46 public static MonoXnaCompactMaths.Vector3 PhysicsVectorToXnaVector3(PhysicsVector physicsVector) 55 public static MonoXnaCompactMaths.Vector3 PhysicsVectorToXnaVector3(PhysicsVector physicsVector)
47 { 56 {
48 return new MonoXnaCompactMaths.Vector3(physicsVector.X, physicsVector.Y, physicsVector.Z); 57 return new MonoXnaCompactMaths.Vector3(physicsVector.X, physicsVector.Y, physicsVector.Z);
49 } 58 }
50 public static void PhysicsVectorToXnaVector3(PhysicsVector physicsVector, out MonoXnaCompactMaths.Vector3 XnaVector3)
51 {
52 XnaVector3.X = physicsVector.X;
53 XnaVector3.Y = physicsVector.Y;
54 XnaVector3.Z = physicsVector.Z;
55 }
56 public static PhysicsVector XnaVector3ToPhysicsVector(MonoXnaCompactMaths.Vector3 xnaVector3) 59 public static PhysicsVector XnaVector3ToPhysicsVector(MonoXnaCompactMaths.Vector3 xnaVector3)
57 { 60 {
58 return new PhysicsVector(xnaVector3.X, xnaVector3.Y, xnaVector3.Z); 61 return new PhysicsVector(xnaVector3.X, xnaVector3.Y, xnaVector3.Z);
59 } 62 }
60 /*public static void XnaVector3ToPhysicsVector(MonoXnaCompactMaths.Vector3 xnaVector3, out PhysicsVector physicsVector) 63 //Quaternion
61 { 64 public static MonoXnaCompactMaths.Quaternion AxiomQuaternionToXnaQuaternion(AxiomQuaternion axiomQuaternion)
62 xnaVector3.X = physicsVector.X; 65 {
63 xnaVector3.Y = physicsVector.Y; 66 return new MonoXnaCompactMaths.Quaternion(axiomQuaternion.x, axiomQuaternion.y, axiomQuaternion.z, axiomQuaternion.w);
64 xnaVector3.Z = physicsVector.Z; 67 }
65 }*/ 68 public static AxiomQuaternion XnaQuaternionToAxiomQuaternion(MonoXnaCompactMaths.Quaternion xnaQuaternion)
66 #region Axiom and Xna 69 {
67 ///// <summary> 70 return new AxiomQuaternion(xnaQuaternion.W, xnaQuaternion.X, xnaQuaternion.Y, xnaQuaternion.Z);
68 ///// BTW maybe some conversions will be a simply converion that it doesn't require this class, but i don't know 71 }
69 ///// </summary>
70 ///// <param name="AxiomVector3"></param>
71 ///// <returns></returns>
72 //public static MonoXnaCompactMaths.Vector3 Vector3AxiomToXna(Axiom.Math.Vector3 AxiomVector3)
73 //{
74 // return new MonoXnaCompactMaths.Vector3(AxiomVector3.x, AxiomVector3.y, AxiomVector3.z);
75 //}
76 #endregion
77 } 72 }
78 /// <summary> 73 /// <summary>
79 /// PhysicsPlugin Class for BulletX 74 /// PhysicsPlugin Class for BulletX
@@ -127,6 +122,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin
127 122
128 private float[] _heightmap; 123 private float[] _heightmap;
129 private List<BulletXCharacter> _characters = new List<BulletXCharacter>(); 124 private List<BulletXCharacter> _characters = new List<BulletXCharacter>();
125 private List<BulletXPrim> _prims = new List<BulletXPrim>();
130 126
131 public static float Gravity { get { return gravity; } } 127 public static float Gravity { get { return gravity; } }
132 public static float HeightLevel0 { get { return heightLevel0; } } 128 public static float HeightLevel0 { get { return heightLevel0; } }
@@ -146,7 +142,6 @@ namespace OpenSim.Region.Physics.BulletXPlugin
146 142
147 this._heightmap = new float[65536]; 143 this._heightmap = new float[65536];
148 } 144 }
149
150 public override PhysicsActor AddAvatar(PhysicsVector position) 145 public override PhysicsActor AddAvatar(PhysicsVector position)
151 { 146 {
152 PhysicsVector pos = new PhysicsVector(); 147 PhysicsVector pos = new PhysicsVector();
@@ -154,31 +149,26 @@ namespace OpenSim.Region.Physics.BulletXPlugin
154 pos.Y = position.Y; 149 pos.Y = position.Y;
155 pos.Z = position.Z + 20; 150 pos.Z = position.Z + 20;
156 BulletXCharacter newAv = new BulletXCharacter(this, pos); 151 BulletXCharacter newAv = new BulletXCharacter(this, pos);
157 this._characters.Add(newAv); 152 _characters.Add(newAv);
158 return newAv; 153 return newAv;
159 } 154 }
160
161 public override void RemoveAvatar(PhysicsActor actor) 155 public override void RemoveAvatar(PhysicsActor actor)
162 { 156 {
163 157 if (actor is BulletXCharacter)
158 {
159 _characters.Remove((BulletXCharacter)actor);
160 }
164 } 161 }
165 162 public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size, AxiomQuaternion rotation)
166 public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size, Axiom.Math.Quaternion rotation)
167 { 163 {
168 PhysicsVector pos = new PhysicsVector(); 164 return new BulletXPrim(this, position, size, rotation);
169 pos.X = position.X;
170 pos.Y = position.Y;
171 pos.Z = position.Z;
172 PhysicsVector siz = new PhysicsVector();
173 siz.X = size.X;
174 siz.Y = size.Y;
175 siz.Z = size.Z;
176 return new BulletXPrim();
177 } 165 }
178
179 public override void RemovePrim(PhysicsActor prim) 166 public override void RemovePrim(PhysicsActor prim)
180 { 167 {
181 throw new Exception("The method or operation is not implemented."); 168 if (prim is BulletXPrim)
169 {
170 _prims.Remove((BulletXPrim)prim);
171 }
182 } 172 }
183 public override void Simulate(float timeStep) 173 public override void Simulate(float timeStep)
184 { 174 {
@@ -200,12 +190,10 @@ namespace OpenSim.Region.Physics.BulletXPlugin
200 } 190 }
201 191
202 } 192 }
203
204 public override void GetResults() 193 public override void GetResults()
205 { 194 {
206 195
207 } 196 }
208
209 public override bool IsThreaded 197 public override bool IsThreaded
210 { 198 {
211 get 199 get
@@ -213,7 +201,6 @@ namespace OpenSim.Region.Physics.BulletXPlugin
213 return (false); // for now we won't be multithreaded 201 return (false); // for now we won't be multithreaded
214 } 202 }
215 } 203 }
216
217 public override void SetTerrain(float[] heightMap) 204 public override void SetTerrain(float[] heightMap)
218 { 205 {
219 //As the same as ODE, heightmap (x,y) must be swapped for BulletX 206 //As the same as ODE, heightmap (x,y) must be swapped for BulletX
@@ -226,7 +213,6 @@ namespace OpenSim.Region.Physics.BulletXPlugin
226 this._heightmap[i] = heightMap[x * 256 + y]; 213 this._heightmap[i] = heightMap[x * 256 + y];
227 } 214 }
228 } 215 }
229
230 public override void DeleteTerrain() 216 public override void DeleteTerrain()
231 { 217 {
232 218
@@ -239,7 +225,9 @@ namespace OpenSim.Region.Physics.BulletXPlugin
239 { 225 {
240 private PhysicsVector _position; 226 private PhysicsVector _position;
241 private PhysicsVector _velocity; 227 private PhysicsVector _velocity;
228 private PhysicsVector _size;
242 private PhysicsVector _acceleration; 229 private PhysicsVector _acceleration;
230 private AxiomQuaternion _orientation;
243 private bool flying; 231 private bool flying;
244 private RigidBody rigidBody; 232 private RigidBody rigidBody;
245 public Axiom.Math.Vector2 RigidBodyHorizontalPosition 233 public Axiom.Math.Vector2 RigidBodyHorizontalPosition
@@ -250,10 +238,18 @@ namespace OpenSim.Region.Physics.BulletXPlugin
250 } 238 }
251 } 239 }
252 public BulletXCharacter(BulletXScene parent_scene, PhysicsVector pos) 240 public BulletXCharacter(BulletXScene parent_scene, PhysicsVector pos)
241 : this(parent_scene, pos, new PhysicsVector(), new PhysicsVector(), new PhysicsVector(),
242 AxiomQuaternion.Identity)
243 {
244 }
245 public BulletXCharacter(BulletXScene parent_scene, PhysicsVector pos, PhysicsVector velocity,
246 PhysicsVector size, PhysicsVector acceleration, AxiomQuaternion orientation)
253 { 247 {
254 _velocity = new PhysicsVector();
255 _position = pos; 248 _position = pos;
256 _acceleration = new PhysicsVector(); 249 _velocity = velocity;
250 _size = size;
251 _acceleration = acceleration;
252 _orientation = orientation;
257 float _mass = 50.0f; //This depends of avatar's dimensions 253 float _mass = 50.0f; //This depends of avatar's dimensions
258 Matrix _startTransform = Matrix.Identity; 254 Matrix _startTransform = Matrix.Identity;
259 _startTransform.Translation = BulletXConversions.PhysicsVectorToXnaVector3(pos); 255 _startTransform.Translation = BulletXConversions.PhysicsVectorToXnaVector3(pos);
@@ -275,102 +271,91 @@ namespace OpenSim.Region.Physics.BulletXPlugin
275 271
276 parent_scene.ddWorld.AddRigidBody(rigidBody); 272 parent_scene.ddWorld.AddRigidBody(rigidBody);
277 } 273 }
278 274 public override PhysicsVector Position
279 public override bool Flying
280 { 275 {
281 get 276 get
282 { 277 {
283 return flying; 278 return _position;
284 } 279 }
285 set 280 set
286 { 281 {
287 flying = value; 282 _position = value;
288 } 283 }
289 } 284 }
290 285 public override PhysicsVector Velocity
291 public override PhysicsVector Size
292 { 286 {
293 get 287 get
294 { 288 {
295 throw new Exception("The method or operation is not implemented."); 289 return _velocity;
296 } 290 }
297 set 291 set
298 { 292 {
299 throw new Exception("The method or operation is not implemented."); 293 _velocity = value;
300 } 294 }
301 } 295 }
302 296 public override PhysicsVector Size
303 public override PhysicsVector Position
304 { 297 {
305 get 298 get
306 { 299 {
307 return _position; 300 return _size;
308 } 301 }
309 set 302 set
310 { 303 {
311 _position = value; 304 _size = value;
312 } 305 }
313 } 306 }
314 307 public override PhysicsVector Acceleration
315 public override PhysicsVector Velocity
316 { 308 {
317 get 309 get
318 { 310 {
319 return _velocity; 311 return _acceleration;
320 }
321 set
322 {
323 _velocity = value;
324 } 312 }
325 } 313 }
326 314 public override AxiomQuaternion Orientation
327 public override bool Kinematic
328 { 315 {
329 get 316 get
330 { 317 {
331 return false; 318 return _orientation;
332 } 319 }
333 set 320 set
334 { 321 {
335 322 _orientation = value;
336 } 323 }
337 } 324 }
338 325 public override bool Flying
339 public override Axiom.Math.Quaternion Orientation
340 { 326 {
341 get 327 get
342 { 328 {
343 return Axiom.Math.Quaternion.Identity; 329 return flying;
344 } 330 }
345 set 331 set
346 { 332 {
347 333 flying = value;
348 } 334 }
349 } 335 }
350 336 public void SetAcceleration(PhysicsVector accel)
351 public override PhysicsVector Acceleration 337 {
338 _acceleration = accel;
339 }
340 public override bool Kinematic
352 { 341 {
353 get 342 get
354 { 343 {
355 return _acceleration; 344 return false;
356 } 345 }
346 set
347 {
357 348
349 }
358 } 350 }
359 public void SetAcceleration(PhysicsVector accel)
360 {
361 this._acceleration = accel;
362 }
363
364 public override void AddForce(PhysicsVector force) 351 public override void AddForce(PhysicsVector force)
365 { 352 {
366 353
367 } 354 }
368
369 public override void SetMomentum(PhysicsVector momentum) 355 public override void SetMomentum(PhysicsVector momentum)
370 { 356 {
371 357
372 } 358 }
373
374 public void Move(float timeStep) 359 public void Move(float timeStep)
375 { 360 {
376 MonoXnaCompactMaths.Vector3 vec = new MonoXnaCompactMaths.Vector3(); 361 MonoXnaCompactMaths.Vector3 vec = new MonoXnaCompactMaths.Vector3();
@@ -419,12 +404,10 @@ namespace OpenSim.Region.Physics.BulletXPlugin
419 } 404 }
420 rigidBody.LinearVelocity = vec; 405 rigidBody.LinearVelocity = vec;
421 } 406 }
422
423 public void UpdatePosition() 407 public void UpdatePosition()
424 { 408 {
425 this._position = BulletXConversions.XnaVector3ToPhysicsVector(rigidBody.CenterOfMassPosition); 409 this._position = BulletXConversions.XnaVector3ToPhysicsVector(rigidBody.CenterOfMassPosition);
426 } 410 }
427
428 //This validation is very basic 411 //This validation is very basic
429 internal void ValidateHeight(float heighmapPositionValue) 412 internal void ValidateHeight(float heighmapPositionValue)
430 { 413 {
@@ -445,104 +428,101 @@ namespace OpenSim.Region.Physics.BulletXPlugin
445 { 428 {
446 private PhysicsVector _position; 429 private PhysicsVector _position;
447 private PhysicsVector _velocity; 430 private PhysicsVector _velocity;
431 private PhysicsVector _size;
448 private PhysicsVector _acceleration; 432 private PhysicsVector _acceleration;
433 private AxiomQuaternion _orientation;
449 434
450 public BulletXPrim() 435 public BulletXPrim(BulletXScene parent_scene, PhysicsVector pos, PhysicsVector size, AxiomQuaternion rotation)
436 : this(parent_scene, pos, new PhysicsVector(), size, new PhysicsVector(), rotation)
451 { 437 {
452 _velocity = new PhysicsVector();
453 _position = new PhysicsVector();
454 _acceleration = new PhysicsVector();
455 } 438 }
456 public override bool Flying 439 public BulletXPrim(BulletXScene parent_scene, PhysicsVector pos, PhysicsVector velocity, PhysicsVector size,
440 PhysicsVector aceleration, AxiomQuaternion rotation)
441 {
442 _position = pos;
443 _velocity = velocity;
444 _size = size;
445 _acceleration = aceleration;
446 _orientation = rotation;
447 }
448 public override PhysicsVector Position
457 { 449 {
458 get 450 get
459 { 451 {
460 return false; //no flying prims for you 452 return _position;
453
461 } 454 }
462 set 455 set
463 { 456 {
464 457 _position = value;
465 } 458 }
466 } 459 }
467 public override PhysicsVector Size 460 public override PhysicsVector Velocity
468 { 461 {
469 get 462 get
470 { 463 {
471 throw new Exception("The method or operation is not implemented."); 464 return _velocity;
472 } 465 }
473 set 466 set
474 { 467 {
475 throw new Exception("The method or operation is not implemented."); 468 _velocity = value;
476 } 469 }
477 } 470 }
478 public override PhysicsVector Position 471 public override PhysicsVector Size
479 { 472 {
480 get 473 get
481 { 474 {
482 PhysicsVector pos = new PhysicsVector(); 475 return _size;
483 // PhysicsVector vec = this._prim.Position;
484 //pos.X = vec.X;
485 //pos.Y = vec.Y;
486 //pos.Z = vec.Z;
487 return pos;
488
489 } 476 }
490 set 477 set
491 { 478 {
492 /*PhysicsVector vec = value; 479 _size = value;
493 PhysicsVector pos = new PhysicsVector();
494 pos.X = vec.X;
495 pos.Y = vec.Y;
496 pos.Z = vec.Z;
497 this._prim.Position = pos;*/
498 } 480 }
499 } 481 }
500 public override PhysicsVector Velocity 482 public override PhysicsVector Acceleration
501 { 483 {
502 get 484 get
503 { 485 {
504 return _velocity; 486 return _acceleration;
505 }
506 set
507 {
508 _velocity = value;
509 } 487 }
510 } 488 }
511 public override bool Kinematic 489 public override AxiomQuaternion Orientation
512 { 490 {
513 get 491 get
514 { 492 {
515 return false; 493 return _orientation;
516 //return this._prim.Kinematic;
517 } 494 }
518 set 495 set
519 { 496 {
520 //this._prim.Kinematic = value; 497 _orientation = value;
521 } 498 }
522 } 499 }
523 public override Axiom.Math.Quaternion Orientation 500 public override bool Flying
524 { 501 {
525 get 502 get
526 { 503 {
527 Axiom.Math.Quaternion res = new Axiom.Math.Quaternion(); 504 return false; //no flying prims for you
528 return res;
529 } 505 }
530 set 506 set
531 { 507 {
532 508
533 } 509 }
534 } 510 }
535 public override PhysicsVector Acceleration 511 public void SetAcceleration(PhysicsVector accel)
512 {
513 _acceleration = accel;
514 }
515 public override bool Kinematic
536 { 516 {
537 get 517 get
538 { 518 {
539 return _acceleration; 519 return false;
520 //return this._prim.Kinematic;
521 }
522 set
523 {
524 //this._prim.Kinematic = value;
540 } 525 }
541
542 }
543 public void SetAcceleration(PhysicsVector accel)
544 {
545 this._acceleration = accel;
546 } 526 }
547 public override void AddForce(PhysicsVector force) 527 public override void AddForce(PhysicsVector force)
548 { 528 {