diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs | 58 |
1 files changed, 32 insertions, 26 deletions
diff --git a/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs b/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs index cc55f6e..c969f9a 100644 --- a/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs +++ b/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs | |||
@@ -29,13 +29,15 @@ | |||
29 | 29 | ||
30 | using System; | 30 | using System; |
31 | using System.Collections.Generic; | 31 | using System.Collections.Generic; |
32 | using OpenMetaverse; | ||
32 | using MonoXnaCompactMaths; | 33 | using MonoXnaCompactMaths; |
33 | using OpenSim.Framework; | 34 | using OpenSim.Framework; |
34 | using OpenSim.Region.Physics.Manager; | 35 | using OpenSim.Region.Physics.Manager; |
35 | using XnaDevRu.BulletX; | 36 | using XnaDevRu.BulletX; |
36 | using XnaDevRu.BulletX.Dynamics; | 37 | using XnaDevRu.BulletX.Dynamics; |
37 | using Nini.Config; | 38 | using Nini.Config; |
38 | using AxiomQuaternion = Axiom.Math.Quaternion; | 39 | using Vector3 = MonoXnaCompactMaths.Vector3; |
40 | using Quaternion = MonoXnaCompactMaths.Quaternion; | ||
39 | 41 | ||
40 | #endregion | 42 | #endregion |
41 | 43 | ||
@@ -61,14 +63,14 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
61 | } | 63 | } |
62 | 64 | ||
63 | //Quaternion | 65 | //Quaternion |
64 | public static Quaternion AxiomQuaternionToXnaQuaternion(AxiomQuaternion axiomQuaternion) | 66 | public static Quaternion QuaternionToXnaQuaternion(OpenMetaverse.Quaternion quaternion) |
65 | { | 67 | { |
66 | return new Quaternion(axiomQuaternion.x, axiomQuaternion.y, axiomQuaternion.z, axiomQuaternion.w); | 68 | return new Quaternion(quaternion.X, quaternion.Y, quaternion.Z, quaternion.W); |
67 | } | 69 | } |
68 | 70 | ||
69 | public static AxiomQuaternion XnaQuaternionToAxiomQuaternion(Quaternion xnaQuaternion) | 71 | public static OpenMetaverse.Quaternion XnaQuaternionToQuaternion(Quaternion xnaQuaternion) |
70 | { | 72 | { |
71 | return new AxiomQuaternion(xnaQuaternion.W, xnaQuaternion.X, xnaQuaternion.Y, xnaQuaternion.Z); | 73 | return new OpenMetaverse.Quaternion(xnaQuaternion.W, xnaQuaternion.X, xnaQuaternion.Y, xnaQuaternion.Z); |
72 | } | 74 | } |
73 | 75 | ||
74 | //Next methods are extracted from XnaDevRu.BulletX(See 3rd party license): | 76 | //Next methods are extracted from XnaDevRu.BulletX(See 3rd party license): |
@@ -92,7 +94,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
92 | 94 | ||
93 | internal static Quaternion GetRotation(Matrix m) | 95 | internal static Quaternion GetRotation(Matrix m) |
94 | { | 96 | { |
95 | Quaternion q = new Quaternion(); | 97 | Quaternion q; |
96 | 98 | ||
97 | float trace = m.M11 + m.M22 + m.M33; | 99 | float trace = m.M11 + m.M22 + m.M33; |
98 | 100 | ||
@@ -108,6 +110,8 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
108 | } | 110 | } |
109 | else | 111 | else |
110 | { | 112 | { |
113 | q.X = q.Y = q.Z = q.W = 0f; | ||
114 | |||
111 | int i = m.M11 < m.M22 | 115 | int i = m.M11 < m.M22 |
112 | ? | 116 | ? |
113 | (m.M22 < m.M33 ? 2 : 1) | 117 | (m.M22 < m.M33 ? 2 : 1) |
@@ -601,13 +605,13 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
601 | } | 605 | } |
602 | 606 | ||
603 | public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, | 607 | public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, |
604 | PhysicsVector size, AxiomQuaternion rotation) | 608 | PhysicsVector size, OpenMetaverse.Quaternion rotation) |
605 | { | 609 | { |
606 | return AddPrimShape(primName, pbs, position, size, rotation, false); | 610 | return AddPrimShape(primName, pbs, position, size, rotation, false); |
607 | } | 611 | } |
608 | 612 | ||
609 | public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, | 613 | public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, |
610 | PhysicsVector size, AxiomQuaternion rotation, bool isPhysical) | 614 | PhysicsVector size, OpenMetaverse.Quaternion rotation, bool isPhysical) |
611 | { | 615 | { |
612 | PhysicsActor result; | 616 | PhysicsActor result; |
613 | 617 | ||
@@ -634,7 +638,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
634 | return result; | 638 | return result; |
635 | } | 639 | } |
636 | 640 | ||
637 | public PhysicsActor AddPrim(String name, PhysicsVector position, PhysicsVector size, AxiomQuaternion rotation, | 641 | public PhysicsActor AddPrim(String name, PhysicsVector position, PhysicsVector size, OpenMetaverse.Quaternion rotation, |
638 | IMesh mesh, PrimitiveBaseShape pbs, bool isPhysical) | 642 | IMesh mesh, PrimitiveBaseShape pbs, bool isPhysical) |
639 | { | 643 | { |
640 | BulletXPrim newPrim = null; | 644 | BulletXPrim newPrim = null; |
@@ -680,7 +684,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
680 | //Try to remove garbage | 684 | //Try to remove garbage |
681 | RemoveForgottenRigidBodies(); | 685 | RemoveForgottenRigidBodies(); |
682 | //End of remove | 686 | //End of remove |
683 | MoveAllObjects(timeStep); | 687 | MoveAPrimitives(timeStep); |
684 | 688 | ||
685 | 689 | ||
686 | fps = (timeStep*simulationSubSteps); | 690 | fps = (timeStep*simulationSubSteps); |
@@ -694,7 +698,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
694 | return fps; | 698 | return fps; |
695 | } | 699 | } |
696 | 700 | ||
697 | private void MoveAllObjects(float timeStep) | 701 | private void MoveAPrimitives(float timeStep) |
698 | { | 702 | { |
699 | foreach (BulletXCharacter actor in _characters.Values) | 703 | foreach (BulletXCharacter actor in _characters.Values) |
700 | { | 704 | { |
@@ -867,7 +871,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
867 | protected PhysicsVector _velocity; | 871 | protected PhysicsVector _velocity; |
868 | protected PhysicsVector _size; | 872 | protected PhysicsVector _size; |
869 | protected PhysicsVector _acceleration; | 873 | protected PhysicsVector _acceleration; |
870 | protected AxiomQuaternion _orientation; | 874 | protected OpenMetaverse.Quaternion _orientation; |
871 | protected PhysicsVector m_rotationalVelocity = PhysicsVector.Zero; | 875 | protected PhysicsVector m_rotationalVelocity = PhysicsVector.Zero; |
872 | protected RigidBody rigidBody; | 876 | protected RigidBody rigidBody; |
873 | protected int m_PhysicsActorType; | 877 | protected int m_PhysicsActorType; |
@@ -972,7 +976,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
972 | get { return _acceleration; } | 976 | get { return _acceleration; } |
973 | } | 977 | } |
974 | 978 | ||
975 | public override AxiomQuaternion Orientation | 979 | public override OpenMetaverse.Quaternion Orientation |
976 | { | 980 | { |
977 | get { return _orientation; } | 981 | get { return _orientation; } |
978 | set | 982 | set |
@@ -1148,10 +1152,10 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
1148 | ReOrient(_orientation); | 1152 | ReOrient(_orientation); |
1149 | } | 1153 | } |
1150 | 1154 | ||
1151 | protected internal void ReOrient(AxiomQuaternion _newOrient) | 1155 | protected internal void ReOrient(OpenMetaverse.Quaternion _newOrient) |
1152 | { | 1156 | { |
1153 | Quaternion _newOrientation; | 1157 | Quaternion _newOrientation; |
1154 | _newOrientation = BulletXMaths.AxiomQuaternionToXnaQuaternion(_newOrient); | 1158 | _newOrientation = BulletXMaths.QuaternionToXnaQuaternion(_newOrient); |
1155 | Matrix _comTransform = rigidBody.CenterOfMassTransform; | 1159 | Matrix _comTransform = rigidBody.CenterOfMassTransform; |
1156 | BulletXMaths.SetRotation(ref _comTransform, _newOrientation); | 1160 | BulletXMaths.SetRotation(ref _comTransform, _newOrientation); |
1157 | rigidBody.CenterOfMassTransform = _comTransform; | 1161 | rigidBody.CenterOfMassTransform = _comTransform; |
@@ -1206,12 +1210,12 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
1206 | 1210 | ||
1207 | public BulletXCharacter(String avName, BulletXScene parent_scene, PhysicsVector pos) | 1211 | public BulletXCharacter(String avName, BulletXScene parent_scene, PhysicsVector pos) |
1208 | : this(avName, parent_scene, pos, new PhysicsVector(), new PhysicsVector(), new PhysicsVector(), | 1212 | : this(avName, parent_scene, pos, new PhysicsVector(), new PhysicsVector(), new PhysicsVector(), |
1209 | AxiomQuaternion.Identity) | 1213 | OpenMetaverse.Quaternion.Identity) |
1210 | { | 1214 | { |
1211 | } | 1215 | } |
1212 | 1216 | ||
1213 | public BulletXCharacter(String avName, BulletXScene parent_scene, PhysicsVector pos, PhysicsVector velocity, | 1217 | public BulletXCharacter(String avName, BulletXScene parent_scene, PhysicsVector pos, PhysicsVector velocity, |
1214 | PhysicsVector size, PhysicsVector acceleration, AxiomQuaternion orientation) | 1218 | PhysicsVector size, PhysicsVector acceleration, OpenMetaverse.Quaternion orientation) |
1215 | : base(avName) | 1219 | : base(avName) |
1216 | { | 1220 | { |
1217 | //This fields will be removed. They're temporal | 1221 | //This fields will be removed. They're temporal |
@@ -1289,7 +1293,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
1289 | get { return base.Acceleration; } | 1293 | get { return base.Acceleration; } |
1290 | } | 1294 | } |
1291 | 1295 | ||
1292 | public override AxiomQuaternion Orientation | 1296 | public override OpenMetaverse.Quaternion Orientation |
1293 | { | 1297 | { |
1294 | get { return base.Orientation; } | 1298 | get { return base.Orientation; } |
1295 | set { base.Orientation = value; } | 1299 | set { base.Orientation = value; } |
@@ -1404,7 +1408,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
1404 | 1408 | ||
1405 | 1409 | ||
1406 | public BulletXPrim(String primName, BulletXScene parent_scene, PhysicsVector pos, PhysicsVector size, | 1410 | public BulletXPrim(String primName, BulletXScene parent_scene, PhysicsVector pos, PhysicsVector size, |
1407 | AxiomQuaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, bool isPhysical) | 1411 | OpenMetaverse.Quaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, bool isPhysical) |
1408 | : this( | 1412 | : this( |
1409 | primName, parent_scene, pos, new PhysicsVector(), size, new PhysicsVector(), rotation, mesh, pbs, | 1413 | primName, parent_scene, pos, new PhysicsVector(), size, new PhysicsVector(), rotation, mesh, pbs, |
1410 | isPhysical) | 1414 | isPhysical) |
@@ -1413,12 +1417,14 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
1413 | 1417 | ||
1414 | public BulletXPrim(String primName, BulletXScene parent_scene, PhysicsVector pos, PhysicsVector velocity, | 1418 | public BulletXPrim(String primName, BulletXScene parent_scene, PhysicsVector pos, PhysicsVector velocity, |
1415 | PhysicsVector size, | 1419 | PhysicsVector size, |
1416 | PhysicsVector acceleration, AxiomQuaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, | 1420 | PhysicsVector acceleration, OpenMetaverse.Quaternion rotation, IMesh mesh, PrimitiveBaseShape pbs, |
1417 | bool isPhysical) | 1421 | bool isPhysical) |
1418 | : base(primName) | 1422 | : base(primName) |
1419 | { | 1423 | { |
1420 | if ((size.X == 0) || (size.Y == 0) || (size.Z == 0)) throw new Exception("Size 0"); | 1424 | if ((size.X == 0) || (size.Y == 0) || (size.Z == 0)) |
1421 | if (rotation.Norm == 0f) rotation = AxiomQuaternion.Identity; | 1425 | throw new Exception("Size 0"); |
1426 | if (OpenMetaverse.Quaternion.Normalize(rotation).Length() == 0f) | ||
1427 | rotation = OpenMetaverse.Quaternion.Identity; | ||
1422 | 1428 | ||
1423 | _position = pos; | 1429 | _position = pos; |
1424 | _physical = isPhysical; | 1430 | _physical = isPhysical; |
@@ -1468,7 +1474,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
1468 | get { return base.Acceleration; } | 1474 | get { return base.Acceleration; } |
1469 | } | 1475 | } |
1470 | 1476 | ||
1471 | public override AxiomQuaternion Orientation | 1477 | public override OpenMetaverse.Quaternion Orientation |
1472 | { | 1478 | { |
1473 | get { return base.Orientation; } | 1479 | get { return base.Orientation; } |
1474 | set { base.Orientation = value; } | 1480 | set { base.Orientation = value; } |
@@ -1565,7 +1571,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
1565 | _position = BulletXMaths.XnaVector3ToPhysicsVector(rigidBody.CenterOfMassPosition); | 1571 | _position = BulletXMaths.XnaVector3ToPhysicsVector(rigidBody.CenterOfMassPosition); |
1566 | 1572 | ||
1567 | _velocity = BulletXMaths.XnaVector3ToPhysicsVector(rigidBody.LinearVelocity); | 1573 | _velocity = BulletXMaths.XnaVector3ToPhysicsVector(rigidBody.LinearVelocity); |
1568 | _orientation = BulletXMaths.XnaQuaternionToAxiomQuaternion(rigidBody.Orientation); | 1574 | _orientation = BulletXMaths.XnaQuaternionToQuaternion(rigidBody.Orientation); |
1569 | 1575 | ||
1570 | if ((Math.Abs(m_prev_position.X - _position.X) < 0.03) | 1576 | if ((Math.Abs(m_prev_position.X - _position.X) < 0.03) |
1571 | && (Math.Abs(m_prev_position.Y - _position.Y) < 0.03) | 1577 | && (Math.Abs(m_prev_position.Y - _position.Y) < 0.03) |
@@ -1687,7 +1693,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
1687 | { | 1693 | { |
1688 | private PhysicsVector _staticPosition; | 1694 | private PhysicsVector _staticPosition; |
1689 | // private PhysicsVector _staticVelocity; | 1695 | // private PhysicsVector _staticVelocity; |
1690 | // private AxiomQuaternion _staticOrientation; | 1696 | // private OpenMetaverse.Quaternion _staticOrientation; |
1691 | private float _mass; | 1697 | private float _mass; |
1692 | // private BulletXScene _parentscene; | 1698 | // private BulletXScene _parentscene; |
1693 | internal float[] _heightField; | 1699 | internal float[] _heightField; |
@@ -1702,7 +1708,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin | |||
1702 | { | 1708 | { |
1703 | _staticPosition = new PhysicsVector(BulletXScene.MaxXY/2, BulletXScene.MaxXY/2, 0); | 1709 | _staticPosition = new PhysicsVector(BulletXScene.MaxXY/2, BulletXScene.MaxXY/2, 0); |
1704 | // _staticVelocity = new PhysicsVector(); | 1710 | // _staticVelocity = new PhysicsVector(); |
1705 | // _staticOrientation = AxiomQuaternion.Identity; | 1711 | // _staticOrientation = OpenMetaverse.Quaternion.Identity; |
1706 | _mass = 0; //No active | 1712 | _mass = 0; //No active |
1707 | // _parentscene = parent_scene; | 1713 | // _parentscene = parent_scene; |
1708 | _heightField = heightField; | 1714 | _heightField = heightField; |