aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics')
-rw-r--r--OpenSim/Region/Physics/BasicPhysicsPlugin/AssemblyInfo.cs22
-rw-r--r--OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs106
-rw-r--r--OpenSim/Region/Physics/BulletXPlugin/AssemblyInfo.cs24
-rw-r--r--OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs589
-rw-r--r--OpenSim/Region/Physics/Manager/AssemblyInfo.cs22
-rw-r--r--OpenSim/Region/Physics/Manager/PhysicsActor.cs110
-rw-r--r--OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs143
-rw-r--r--OpenSim/Region/Physics/Manager/PhysicsScene.cs26
-rw-r--r--OpenSim/Region/Physics/Manager/PhysicsVector.cs5
-rw-r--r--OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs22
-rw-r--r--OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs72
-rw-r--r--OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs256
-rw-r--r--OpenSim/Region/Physics/OdePlugin/OdePlugin.cs274
-rw-r--r--OpenSim/Region/Physics/PhysXPlugin/AssemblyInfo.cs22
-rw-r--r--OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs643
15 files changed, 1068 insertions, 1268 deletions
diff --git a/OpenSim/Region/Physics/BasicPhysicsPlugin/AssemblyInfo.cs b/OpenSim/Region/Physics/BasicPhysicsPlugin/AssemblyInfo.cs
index 2d4d898..a8f1de1 100644
--- a/OpenSim/Region/Physics/BasicPhysicsPlugin/AssemblyInfo.cs
+++ b/OpenSim/Region/Physics/BasicPhysicsPlugin/AssemblyInfo.cs
@@ -27,24 +27,26 @@
27*/ 27*/
28using System.Reflection; 28using System.Reflection;
29using System.Runtime.InteropServices; 29using System.Runtime.InteropServices;
30
30// Information about this assembly is defined by the following 31// Information about this assembly is defined by the following
31// attributes. 32// attributes.
32// 33//
33// change them to the information which is associated with the assembly 34// change them to the information which is associated with the assembly
34// you compile. 35// you compile.
35 36
36[assembly: AssemblyTitle("PhysXplugin")] 37[assembly : AssemblyTitle("PhysXplugin")]
37[assembly: AssemblyDescription("")] 38[assembly : AssemblyDescription("")]
38[assembly: AssemblyConfiguration("")] 39[assembly : AssemblyConfiguration("")]
39[assembly: AssemblyCompany("")] 40[assembly : AssemblyCompany("")]
40[assembly: AssemblyProduct("PhysXplugin")] 41[assembly : AssemblyProduct("PhysXplugin")]
41[assembly: AssemblyCopyright("")] 42[assembly : AssemblyCopyright("")]
42[assembly: AssemblyTrademark("")] 43[assembly : AssemblyTrademark("")]
43[assembly: AssemblyCulture("")] 44[assembly : AssemblyCulture("")]
44 45
45// This sets the default COM visibility of types in the assembly to invisible. 46// This sets the default COM visibility of types in the assembly to invisible.
46// If you need to expose a type to COM, use [ComVisible(true)] on that type. 47// If you need to expose a type to COM, use [ComVisible(true)] on that type.
47[assembly: ComVisible(false)] 48
49[assembly : ComVisible(false)]
48 50
49// The assembly version has following format : 51// The assembly version has following format :
50// 52//
@@ -53,4 +55,4 @@ using System.Runtime.InteropServices;
53// 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
54// numbers with the '*' character (the default): 56// numbers with the '*' character (the default):
55 57
56[assembly: AssemblyVersion("1.0.*")] 58[assembly : AssemblyVersion("1.0.*")] \ No newline at end of file
diff --git a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs
index 95e6095..b412818 100644
--- a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs
+++ b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs
@@ -39,7 +39,6 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
39 { 39 {
40 public BasicPhysicsPlugin() 40 public BasicPhysicsPlugin()
41 { 41 {
42
43 } 42 }
44 43
45 public bool Init() 44 public bool Init()
@@ -59,7 +58,6 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
59 58
60 public void Dispose() 59 public void Dispose()
61 { 60 {
62
63 } 61 }
64 } 62 }
65 63
@@ -70,7 +68,6 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
70 68
71 public BasicScene() 69 public BasicScene()
72 { 70 {
73
74 } 71 }
75 72
76 public override PhysicsActor AddAvatar(string avName, PhysicsVector position) 73 public override PhysicsActor AddAvatar(string avName, PhysicsVector position)
@@ -83,17 +80,15 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
83 80
84 public override void RemovePrim(PhysicsActor prim) 81 public override void RemovePrim(PhysicsActor prim)
85 { 82 {
86
87 } 83 }
88 84
89 public override void RemoveAvatar(PhysicsActor actor) 85 public override void RemoveAvatar(PhysicsActor actor)
90 { 86 {
91 BasicActor act = (BasicActor)actor; 87 BasicActor act = (BasicActor) actor;
92 if (_actors.Contains(act)) 88 if (_actors.Contains(act))
93 { 89 {
94 _actors.Remove(act); 90 _actors.Remove(act);
95 } 91 }
96
97 } 92 }
98 93
99/* 94/*
@@ -102,7 +97,9 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
102 return null; 97 return null;
103 } 98 }
104*/ 99*/
105 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, PhysicsVector size, Quaternion rotation) 100
101 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position,
102 PhysicsVector size, Quaternion rotation)
106 { 103 {
107 return null; 104 return null;
108 } 105 }
@@ -112,8 +109,8 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
112 { 109 {
113 foreach (BasicActor actor in _actors) 110 foreach (BasicActor actor in _actors)
114 { 111 {
115 actor.Position.X = actor.Position.X + (actor.Velocity.X * timeStep); 112 actor.Position.X = actor.Position.X + (actor.Velocity.X*timeStep);
116 actor.Position.Y = actor.Position.Y + (actor.Velocity.Y * timeStep); 113 actor.Position.Y = actor.Position.Y + (actor.Velocity.Y*timeStep);
117 if (actor.Position.Y < 0) 114 if (actor.Position.Y < 0)
118 { 115 {
119 actor.Position.Y = 0.1F; 116 actor.Position.Y = 0.1F;
@@ -132,17 +129,18 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
132 actor.Position.X = 255.9F; 129 actor.Position.X = 255.9F;
133 } 130 }
134 131
135 float height = _heightMap[(int)actor.Position.Y * 256 + (int)actor.Position.X] + 1.0f; 132 float height = _heightMap[(int) actor.Position.Y*256 + (int) actor.Position.X] + 1.0f;
136 if (actor.Flying) 133 if (actor.Flying)
137 { 134 {
138 if (actor.Position.Z + (actor.Velocity.Z * timeStep) < _heightMap[(int)actor.Position.Y * 256 + (int)actor.Position.X] + 2) 135 if (actor.Position.Z + (actor.Velocity.Z*timeStep) <
136 _heightMap[(int) actor.Position.Y*256 + (int) actor.Position.X] + 2)
139 { 137 {
140 actor.Position.Z = height; 138 actor.Position.Z = height;
141 actor.Velocity.Z = 0; 139 actor.Velocity.Z = 0;
142 } 140 }
143 else 141 else
144 { 142 {
145 actor.Position.Z = actor.Position.Z + (actor.Velocity.Z * timeStep); 143 actor.Position.Z = actor.Position.Z + (actor.Velocity.Z*timeStep);
146 } 144 }
147 } 145 }
148 else 146 else
@@ -150,32 +148,26 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
150 actor.Position.Z = height; 148 actor.Position.Z = height;
151 actor.Velocity.Z = 0; 149 actor.Velocity.Z = 0;
152 } 150 }
153
154
155 } 151 }
156 } 152 }
157 153
158 public override void GetResults() 154 public override void GetResults()
159 { 155 {
160
161 } 156 }
162 157
163 public override bool IsThreaded 158 public override bool IsThreaded
164 { 159 {
165 get 160 get { return (false); // for now we won't be multithreaded
166 {
167 return (false); // for now we won't be multithreaded
168 } 161 }
169 } 162 }
170 163
171 public override void SetTerrain(float[] heightMap) 164 public override void SetTerrain(float[] heightMap)
172 { 165 {
173 this._heightMap = heightMap; 166 _heightMap = heightMap;
174 } 167 }
175 168
176 public override void DeleteTerrain() 169 public override void DeleteTerrain()
177 { 170 {
178
179 } 171 }
180 } 172 }
181 173
@@ -185,6 +177,7 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
185 private PhysicsVector _velocity; 177 private PhysicsVector _velocity;
186 private PhysicsVector _acceleration; 178 private PhysicsVector _acceleration;
187 private bool flying; 179 private bool flying;
180
188 public BasicActor() 181 public BasicActor()
189 { 182 {
190 _velocity = new PhysicsVector(); 183 _velocity = new PhysicsVector();
@@ -194,97 +187,56 @@ namespace OpenSim.Region.Physics.BasicPhysicsPlugin
194 187
195 public override bool Flying 188 public override bool Flying
196 { 189 {
197 get 190 get { return flying; }
198 { 191 set { flying = value; }
199 return flying;
200 }
201 set
202 {
203 flying = value;
204 }
205 } 192 }
206 193
207 public override PhysicsVector Position 194 public override PhysicsVector Position
208 { 195 {
209 get 196 get { return _position; }
210 { 197 set { _position = value; }
211 return _position;
212 }
213 set
214 {
215 _position = value;
216 }
217 } 198 }
218 199
219 public override PhysicsVector Size 200 public override PhysicsVector Size
220 { 201 {
221 get 202 get { return new PhysicsVector(0, 0, 0); }
222 { 203 set { }
223 return new PhysicsVector(0, 0, 0);
224 }
225 set
226 {
227 }
228 } 204 }
229 205
230 public override PhysicsVector Velocity 206 public override PhysicsVector Velocity
231 { 207 {
232 get 208 get { return _velocity; }
233 { 209 set { _velocity = value; }
234 return _velocity;
235 }
236 set
237 {
238 _velocity = value;
239 }
240 } 210 }
241 211
242 public override Quaternion Orientation 212 public override Quaternion Orientation
243 { 213 {
244 get 214 get { return Quaternion.Identity; }
245 { 215 set { }
246 return Quaternion.Identity;
247 }
248 set
249 {
250
251 }
252 } 216 }
253 217
254 public override PhysicsVector Acceleration 218 public override PhysicsVector Acceleration
255 { 219 {
256 get 220 get { return _acceleration; }
257 {
258 return _acceleration;
259 }
260
261 } 221 }
262 222
263 public override bool Kinematic 223 public override bool Kinematic
264 { 224 {
265 get 225 get { return true; }
266 { 226 set { }
267 return true;
268 }
269 set
270 {
271
272 }
273 } 227 }
228
274 public void SetAcceleration(PhysicsVector accel) 229 public void SetAcceleration(PhysicsVector accel)
275 { 230 {
276 this._acceleration = accel; 231 _acceleration = accel;
277 } 232 }
278 233
279 public override void AddForce(PhysicsVector force) 234 public override void AddForce(PhysicsVector force)
280 { 235 {
281
282 } 236 }
283 237
284 public override void SetMomentum(PhysicsVector momentum) 238 public override void SetMomentum(PhysicsVector momentum)
285 { 239 {
286
287 } 240 }
288 } 241 }
289 242} \ No newline at end of file
290}
diff --git a/OpenSim/Region/Physics/BulletXPlugin/AssemblyInfo.cs b/OpenSim/Region/Physics/BulletXPlugin/AssemblyInfo.cs
index 0180917..c8596f7 100644
--- a/OpenSim/Region/Physics/BulletXPlugin/AssemblyInfo.cs
+++ b/OpenSim/Region/Physics/BulletXPlugin/AssemblyInfo.cs
@@ -1,4 +1,4 @@
1/* 1/*
2* Copyright (c) Contributors, http://opensimulator.org/ 2* Copyright (c) Contributors, http://opensimulator.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
@@ -27,24 +27,26 @@
27*/ 27*/
28using System.Reflection; 28using System.Reflection;
29using System.Runtime.InteropServices; 29using System.Runtime.InteropServices;
30
30// Information about this assembly is defined by the following 31// Information about this assembly is defined by the following
31// attributes. 32// attributes.
32// 33//
33// change them to the information which is associated with the assembly 34// change them to the information which is associated with the assembly
34// you compile. 35// you compile.
35 36
36[assembly: AssemblyTitle("BulletXPlugin")] 37[assembly : AssemblyTitle("BulletXPlugin")]
37[assembly: AssemblyDescription("")] 38[assembly : AssemblyDescription("")]
38[assembly: AssemblyConfiguration("")] 39[assembly : AssemblyConfiguration("")]
39[assembly: AssemblyCompany("")] 40[assembly : AssemblyCompany("")]
40[assembly: AssemblyProduct("BulletXPlugin")] 41[assembly : AssemblyProduct("BulletXPlugin")]
41[assembly: AssemblyCopyright("")] 42[assembly : AssemblyCopyright("")]
42[assembly: AssemblyTrademark("")] 43[assembly : AssemblyTrademark("")]
43[assembly: AssemblyCulture("")] 44[assembly : AssemblyCulture("")]
44 45
45// This sets the default COM visibility of types in the assembly to invisible. 46// This sets the default COM visibility of types in the assembly to invisible.
46// If you need to expose a type to COM, use [ComVisible(true)] on that type. 47// If you need to expose a type to COM, use [ComVisible(true)] on that type.
47[assembly: ComVisible(false)] 48
49[assembly : ComVisible(false)]
48 50
49// The assembly version has following format : 51// The assembly version has following format :
50// 52//
@@ -53,4 +55,4 @@ using System.Runtime.InteropServices;
53// 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
54// numbers with the '*' character (the default): 56// numbers with the '*' character (the default):
55 57
56[assembly: AssemblyVersion("1.0.0.0")] 58[assembly : AssemblyVersion("1.0.0.0")] \ No newline at end of file
diff --git a/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs b/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs
index 9fdc017..1658e2d 100644
--- a/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs
+++ b/OpenSim/Region/Physics/BulletXPlugin/BulletXPlugin.cs
@@ -27,6 +27,7 @@
27*/ 27*/
28 28
29#region Copyright 29#region Copyright
30
30/* 31/*
31* Copyright (c) Contributors, http://www.openmetaverse.org/ 32* Copyright (c) Contributors, http://www.openmetaverse.org/
32* See CONTRIBUTORS.TXT for a full list of copyright holders. 33* See CONTRIBUTORS.TXT for a full list of copyright holders.
@@ -54,18 +55,21 @@
54* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 55* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55* 56*
56*/ 57*/
58
57#endregion 59#endregion
60
58#region References 61#region References
62
59using System; 63using System;
60using System.Collections.Generic; 64using System.Collections.Generic;
61using OpenSim.Region.Physics.Manager;
62using OpenSim.Framework;
63using Axiom.Math;
64using AxiomQuaternion = Axiom.Math.Quaternion;
65//Specific References for BulletXPlugin
66using MonoXnaCompactMaths; 65using MonoXnaCompactMaths;
66using OpenSim.Framework;
67using OpenSim.Region.Physics.Manager;
67using XnaDevRu.BulletX; 68using XnaDevRu.BulletX;
68using XnaDevRu.BulletX.Dynamics; 69using XnaDevRu.BulletX.Dynamics;
70using AxiomQuaternion = Axiom.Math.Quaternion;
71using BoxShape=XnaDevRu.BulletX.BoxShape;
72//Specific References for BulletXPlugin
69 73
70#endregion 74#endregion
71 75
@@ -80,27 +84,31 @@ namespace OpenSim.Region.Physics.BulletXPlugin
80 { 84 {
81 } 85 }
82 } 86 }
87
83 /// <summary> 88 /// <summary>
84 /// BulletXConversions are called now BulletXMaths 89 /// BulletXConversions are called now BulletXMaths
85 /// This Class converts objects and types for BulletX and give some operations 90 /// This Class converts objects and types for BulletX and give some operations
86 /// </summary> 91 /// </summary>
87 public class BulletXMaths 92 public class BulletXMaths
88 { 93 {
89 //Vector3 94 //Vector3
90 public static MonoXnaCompactMaths.Vector3 PhysicsVectorToXnaVector3(PhysicsVector physicsVector) 95 public static Vector3 PhysicsVectorToXnaVector3(PhysicsVector physicsVector)
91 { 96 {
92 return new MonoXnaCompactMaths.Vector3(physicsVector.X, physicsVector.Y, physicsVector.Z); 97 return new Vector3(physicsVector.X, physicsVector.Y, physicsVector.Z);
93 } 98 }
94 public static PhysicsVector XnaVector3ToPhysicsVector(MonoXnaCompactMaths.Vector3 xnaVector3) 99
100 public static PhysicsVector XnaVector3ToPhysicsVector(Vector3 xnaVector3)
95 { 101 {
96 return new PhysicsVector(xnaVector3.X, xnaVector3.Y, xnaVector3.Z); 102 return new PhysicsVector(xnaVector3.X, xnaVector3.Y, xnaVector3.Z);
97 } 103 }
104
98 //Quaternion 105 //Quaternion
99 public static MonoXnaCompactMaths.Quaternion AxiomQuaternionToXnaQuaternion(AxiomQuaternion axiomQuaternion) 106 public static Quaternion AxiomQuaternionToXnaQuaternion(AxiomQuaternion axiomQuaternion)
100 { 107 {
101 return new MonoXnaCompactMaths.Quaternion(axiomQuaternion.x, axiomQuaternion.y, axiomQuaternion.z, axiomQuaternion.w); 108 return new Quaternion(axiomQuaternion.x, axiomQuaternion.y, axiomQuaternion.z, axiomQuaternion.w);
102 } 109 }
103 public static AxiomQuaternion XnaQuaternionToAxiomQuaternion(MonoXnaCompactMaths.Quaternion xnaQuaternion) 110
111 public static AxiomQuaternion XnaQuaternionToAxiomQuaternion(Quaternion xnaQuaternion)
104 { 112 {
105 return new AxiomQuaternion(xnaQuaternion.W, xnaQuaternion.X, xnaQuaternion.Y, xnaQuaternion.Z); 113 return new AxiomQuaternion(xnaQuaternion.W, xnaQuaternion.X, xnaQuaternion.Y, xnaQuaternion.Z);
106 } 114 }
@@ -110,70 +118,79 @@ namespace OpenSim.Region.Physics.BulletXPlugin
110 //- GetRotation (class MatrixOperations) 118 //- GetRotation (class MatrixOperations)
111 //- GetElement (class MathHelper) 119 //- GetElement (class MathHelper)
112 //- SetElement (class MathHelper) 120 //- SetElement (class MathHelper)
113 internal static void SetRotation(ref Matrix m, MonoXnaCompactMaths.Quaternion q) 121 internal static void SetRotation(ref Matrix m, Quaternion q)
114 { 122 {
115 float d = q.LengthSquared(); 123 float d = q.LengthSquared();
116 float s = 2f / d; 124 float s = 2f/d;
117 float xs = q.X * s, ys = q.Y * s, zs = q.Z * s; 125 float xs = q.X*s, ys = q.Y*s, zs = q.Z*s;
118 float wx = q.W * xs, wy = q.W * ys, wz = q.W * zs; 126 float wx = q.W*xs, wy = q.W*ys, wz = q.W*zs;
119 float xx = q.X * xs, xy = q.X * ys, xz = q.X * zs; 127 float xx = q.X*xs, xy = q.X*ys, xz = q.X*zs;
120 float yy = q.Y * ys, yz = q.Y * zs, zz = q.Z * zs; 128 float yy = q.Y*ys, yz = q.Y*zs, zz = q.Z*zs;
121 m = new Matrix(1 - (yy + zz), xy - wz, xz + wy, 0, 129 m = new Matrix(1 - (yy + zz), xy - wz, xz + wy, 0,
122 xy + wz, 1 - (xx + zz), yz - wx, 0, 130 xy + wz, 1 - (xx + zz), yz - wx, 0,
123 xz - wy, yz + wx, 1 - (xx + yy), 0, 131 xz - wy, yz + wx, 1 - (xx + yy), 0,
124 m.M41, m.M42, m.M43, 1); 132 m.M41, m.M42, m.M43, 1);
125 } 133 }
126 internal static MonoXnaCompactMaths.Quaternion GetRotation(Matrix m) 134
135 internal static Quaternion GetRotation(Matrix m)
127 { 136 {
128 MonoXnaCompactMaths.Quaternion q = new MonoXnaCompactMaths.Quaternion(); 137 Quaternion q = new Quaternion();
129 138
130 float trace = m.M11 + m.M22 + m.M33; 139 float trace = m.M11 + m.M22 + m.M33;
131 140
132 if (trace > 0) 141 if (trace > 0)
133 { 142 {
134 float s = (float)Math.Sqrt(trace + 1); 143 float s = (float) Math.Sqrt(trace + 1);
135 q.W = s * 0.5f; 144 q.W = s*0.5f;
136 s = 0.5f / s; 145 s = 0.5f/s;
137 146
138 q.X = (m.M32 - m.M23) * s; 147 q.X = (m.M32 - m.M23)*s;
139 q.Y = (m.M13 - m.M31) * s; 148 q.Y = (m.M13 - m.M31)*s;
140 q.Z = (m.M21 - m.M12) * s; 149 q.Z = (m.M21 - m.M12)*s;
141 } 150 }
142 else 151 else
143 { 152 {
144 int i = m.M11 < m.M22 ? 153 int i = m.M11 < m.M22
145 (m.M22 < m.M33 ? 2 : 1) : 154 ?
146 (m.M11 < m.M33 ? 2 : 0); 155 (m.M22 < m.M33 ? 2 : 1)
147 int j = (i + 1) % 3; 156 :
148 int k = (i + 2) % 3; 157 (m.M11 < m.M33 ? 2 : 0);
149 158 int j = (i + 1)%3;
150 float s = (float)Math.Sqrt(GetElement(m, i, i) - GetElement(m, j, j) - GetElement(m, k, k) + 1); 159 int k = (i + 2)%3;
151 SetElement(ref q, i, s * 0.5f); 160
152 s = 0.5f / s; 161 float s = (float) Math.Sqrt(GetElement(m, i, i) - GetElement(m, j, j) - GetElement(m, k, k) + 1);
153 162 SetElement(ref q, i, s*0.5f);
154 q.W = (GetElement(m, k, j) - GetElement(m, j, k)) * s; 163 s = 0.5f/s;
155 SetElement(ref q, j, (GetElement(m, j, i) + GetElement(m, i, j)) * s); 164
156 SetElement(ref q, k, (GetElement(m, k, i) + GetElement(m, i, k)) * s); 165 q.W = (GetElement(m, k, j) - GetElement(m, j, k))*s;
166 SetElement(ref q, j, (GetElement(m, j, i) + GetElement(m, i, j))*s);
167 SetElement(ref q, k, (GetElement(m, k, i) + GetElement(m, i, k))*s);
157 } 168 }
158 169
159 return q; 170 return q;
160 } 171 }
161 internal static float SetElement(ref MonoXnaCompactMaths.Quaternion q, int index, float value) 172
173 internal static float SetElement(ref Quaternion q, int index, float value)
162 { 174 {
163 switch (index) 175 switch (index)
164 { 176 {
165 case 0: 177 case 0:
166 q.X = value; break; 178 q.X = value;
179 break;
167 case 1: 180 case 1:
168 q.Y = value; break; 181 q.Y = value;
182 break;
169 case 2: 183 case 2:
170 q.Z = value; break; 184 q.Z = value;
185 break;
171 case 3: 186 case 3:
172 q.W = value; break; 187 q.W = value;
188 break;
173 } 189 }
174 190
175 return 0; 191 return 0;
176 } 192 }
193
177 internal static float GetElement(Matrix mat, int row, int col) 194 internal static float GetElement(Matrix mat, int row, int col)
178 { 195 {
179 switch (row) 196 switch (row)
@@ -187,7 +204,8 @@ namespace OpenSim.Region.Physics.BulletXPlugin
187 return mat.M12; 204 return mat.M12;
188 case 2: 205 case 2:
189 return mat.M13; 206 return mat.M13;
190 } break; 207 }
208 break;
191 case 1: 209 case 1:
192 switch (col) 210 switch (col)
193 { 211 {
@@ -197,7 +215,8 @@ namespace OpenSim.Region.Physics.BulletXPlugin
197 return mat.M22; 215 return mat.M22;
198 case 2: 216 case 2:
199 return mat.M23; 217 return mat.M23;
200 } break; 218 }
219 break;
201 case 2: 220 case 2:
202 switch (col) 221 switch (col)
203 { 222 {
@@ -207,12 +226,14 @@ namespace OpenSim.Region.Physics.BulletXPlugin
207 return mat.M32; 226 return mat.M32;
208 case 2: 227 case 2:
209 return mat.M33; 228 return mat.M33;
210 } break; 229 }
230 break;
211 } 231 }
212 232
213 return 0; 233 return 0;
214 } 234 }
215 } 235 }
236
216 /// <summary> 237 /// <summary>
217 /// PhysicsPlugin Class for BulletX 238 /// PhysicsPlugin Class for BulletX
218 /// </summary> 239 /// </summary>
@@ -223,10 +244,12 @@ namespace OpenSim.Region.Physics.BulletXPlugin
223 public BulletXPlugin() 244 public BulletXPlugin()
224 { 245 {
225 } 246 }
247
226 public bool Init() 248 public bool Init()
227 { 249 {
228 return true; 250 return true;
229 } 251 }
252
230 public PhysicsScene GetScene() 253 public PhysicsScene GetScene()
231 { 254 {
232 if (_mScene == null) 255 if (_mScene == null)
@@ -235,20 +258,24 @@ namespace OpenSim.Region.Physics.BulletXPlugin
235 } 258 }
236 return (_mScene); 259 return (_mScene);
237 } 260 }
261
238 public string GetName() 262 public string GetName()
239 { 263 {
240 return ("modified_BulletX");//Changed!! "BulletXEngine" To "modified_BulletX" 264 return ("modified_BulletX"); //Changed!! "BulletXEngine" To "modified_BulletX"
241 } 265 }
266
242 public void Dispose() 267 public void Dispose()
243 { 268 {
244 } 269 }
245 } 270 }
271
246 /// <summary> 272 /// <summary>
247 /// PhysicsScene Class for BulletX 273 /// PhysicsScene Class for BulletX
248 /// </summary> 274 /// </summary>
249 public class BulletXScene : PhysicsScene 275 public class BulletXScene : PhysicsScene
250 { 276 {
251 #region BulletXScene Fields 277 #region BulletXScene Fields
278
252 public DiscreteDynamicsWorld ddWorld; 279 public DiscreteDynamicsWorld ddWorld;
253 private CollisionDispatcher cDispatcher; 280 private CollisionDispatcher cDispatcher;
254 private OverlappingPairCache opCache; 281 private OverlappingPairCache opCache;
@@ -271,33 +298,58 @@ namespace OpenSim.Region.Physics.BulletXPlugin
271 private List<BulletXCharacter> _characters = new List<BulletXCharacter>(); 298 private List<BulletXCharacter> _characters = new List<BulletXCharacter>();
272 private List<BulletXPrim> _prims = new List<BulletXPrim>(); 299 private List<BulletXPrim> _prims = new List<BulletXPrim>();
273 300
274 public static float Gravity { get { return gravity; } } 301 public static float Gravity
275 public static float HeightLevel0 { get { return heightLevel0; } } 302 {
276 public static float HeightLevel1 { get { return heightLevel1; } } 303 get { return gravity; }
277 public static float LowGravityFactor { get { return lowGravityFactor; } } 304 }
278 public static int MaxXY { get { return maxXY; } } 305
279 public static int MaxZ { get { return maxZ; } } 306 public static float HeightLevel0
307 {
308 get { return heightLevel0; }
309 }
310
311 public static float HeightLevel1
312 {
313 get { return heightLevel1; }
314 }
315
316 public static float LowGravityFactor
317 {
318 get { return lowGravityFactor; }
319 }
320
321 public static int MaxXY
322 {
323 get { return maxXY; }
324 }
325
326 public static int MaxZ
327 {
328 get { return maxZ; }
329 }
280 330
281 private List<RigidBody> _forgottenRigidBodies = new List<RigidBody>(); 331 private List<RigidBody> _forgottenRigidBodies = new List<RigidBody>();
282 internal string is_ex_message = "Can't remove rigidBody!: "; 332 internal string is_ex_message = "Can't remove rigidBody!: ";
333
283 #endregion 334 #endregion
284 335
285 public BulletXScene() 336 public BulletXScene()
286 { 337 {
287 cDispatcher = new CollisionDispatcher(); 338 cDispatcher = new CollisionDispatcher();
288 MonoXnaCompactMaths.Vector3 worldMinDim = new MonoXnaCompactMaths.Vector3((float)minXY, (float)minXY, (float)minZ); 339 Vector3 worldMinDim = new Vector3((float) minXY, (float) minXY, (float) minZ);
289 MonoXnaCompactMaths.Vector3 worldMaxDim = new MonoXnaCompactMaths.Vector3((float)maxXY, (float)maxXY, (float)maxZ); 340 Vector3 worldMaxDim = new Vector3((float) maxXY, (float) maxXY, (float) maxZ);
290 opCache = new AxisSweep3(worldMinDim, worldMaxDim, maxHandles); 341 opCache = new AxisSweep3(worldMinDim, worldMaxDim, maxHandles);
291 sicSolver = new SequentialImpulseConstraintSolver(); 342 sicSolver = new SequentialImpulseConstraintSolver();
292 343
293 lock (BulletXLock) 344 lock (BulletXLock)
294 { 345 {
295 ddWorld = new DiscreteDynamicsWorld(cDispatcher, opCache, sicSolver); 346 ddWorld = new DiscreteDynamicsWorld(cDispatcher, opCache, sicSolver);
296 ddWorld.Gravity = new MonoXnaCompactMaths.Vector3(0, 0, -gravity); 347 ddWorld.Gravity = new Vector3(0, 0, -gravity);
297 } 348 }
298 //this._heightmap = new float[65536]; 349 //this._heightmap = new float[65536];
299 } 350 }
300 public override PhysicsActor AddAvatar(string avName, PhysicsVector position) 351
352 public override PhysicsActor AddAvatar(string avName, PhysicsVector position)
301 { 353 {
302 PhysicsVector pos = new PhysicsVector(); 354 PhysicsVector pos = new PhysicsVector();
303 pos.X = position.X; 355 pos.X = position.X;
@@ -311,6 +363,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin
311 } 363 }
312 return newAv; 364 return newAv;
313 } 365 }
366
314 public override void RemoveAvatar(PhysicsActor actor) 367 public override void RemoveAvatar(PhysicsActor actor)
315 { 368 {
316 if (actor is BulletXCharacter) 369 if (actor is BulletXCharacter)
@@ -319,20 +372,22 @@ namespace OpenSim.Region.Physics.BulletXPlugin
319 { 372 {
320 try 373 try
321 { 374 {
322 ddWorld.RemoveRigidBody(((BulletXCharacter)actor).RigidBody); 375 ddWorld.RemoveRigidBody(((BulletXCharacter) actor).RigidBody);
323 } 376 }
324 catch (Exception ex) 377 catch (Exception ex)
325 { 378 {
326 BulletXMessage(is_ex_message + ex.Message, true); 379 BulletXMessage(is_ex_message + ex.Message, true);
327 ((BulletXCharacter)actor).RigidBody.ActivationState = ActivationState.DisableSimulation; 380 ((BulletXCharacter) actor).RigidBody.ActivationState = ActivationState.DisableSimulation;
328 AddForgottenRigidBody(((BulletXCharacter)actor).RigidBody); 381 AddForgottenRigidBody(((BulletXCharacter) actor).RigidBody);
329 } 382 }
330 _characters.Remove((BulletXCharacter)actor); 383 _characters.Remove((BulletXCharacter) actor);
331 } 384 }
332 GC.Collect(); 385 GC.Collect();
333 } 386 }
334 } 387 }
335 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, PhysicsVector size, AxiomQuaternion rotation) 388
389 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position,
390 PhysicsVector size, AxiomQuaternion rotation)
336 { 391 {
337 PhysicsActor result; 392 PhysicsActor result;
338 393
@@ -358,11 +413,14 @@ namespace OpenSim.Region.Physics.BulletXPlugin
358 413
359 return result; 414 return result;
360 } 415 }
361 public PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size, Axiom.Math.Quaternion rotation) 416
417 public PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size, AxiomQuaternion rotation)
362 { 418 {
363 return AddPrim("", position, size, rotation, null, null); 419 return AddPrim("", position, size, rotation, null, null);
364 } 420 }
365 public PhysicsActor AddPrim(String name, PhysicsVector position, PhysicsVector size, AxiomQuaternion rotation, Mesh mesh, PrimitiveBaseShape pbs) 421
422 public PhysicsActor AddPrim(String name, PhysicsVector position, PhysicsVector size, AxiomQuaternion rotation,
423 Mesh mesh, PrimitiveBaseShape pbs)
366 { 424 {
367 BulletXPrim newPrim = null; 425 BulletXPrim newPrim = null;
368 lock (BulletXLock) 426 lock (BulletXLock)
@@ -372,6 +430,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin
372 } 430 }
373 return newPrim; 431 return newPrim;
374 } 432 }
433
375 public override void RemovePrim(PhysicsActor prim) 434 public override void RemovePrim(PhysicsActor prim)
376 { 435 {
377 if (prim is BulletXPrim) 436 if (prim is BulletXPrim)
@@ -380,19 +439,20 @@ namespace OpenSim.Region.Physics.BulletXPlugin
380 { 439 {
381 try 440 try
382 { 441 {
383 ddWorld.RemoveRigidBody(((BulletXPrim)prim).RigidBody); 442 ddWorld.RemoveRigidBody(((BulletXPrim) prim).RigidBody);
384 } 443 }
385 catch (Exception ex) 444 catch (Exception ex)
386 { 445 {
387 BulletXMessage(is_ex_message + ex.Message, true); 446 BulletXMessage(is_ex_message + ex.Message, true);
388 ((BulletXPrim)prim).RigidBody.ActivationState = ActivationState.DisableSimulation; 447 ((BulletXPrim) prim).RigidBody.ActivationState = ActivationState.DisableSimulation;
389 AddForgottenRigidBody(((BulletXPrim)prim).RigidBody); 448 AddForgottenRigidBody(((BulletXPrim) prim).RigidBody);
390 } 449 }
391 _prims.Remove((BulletXPrim)prim); 450 _prims.Remove((BulletXPrim) prim);
392 } 451 }
393 GC.Collect(); 452 GC.Collect();
394 } 453 }
395 } 454 }
455
396 public override void Simulate(float timeStep) 456 public override void Simulate(float timeStep)
397 { 457 {
398 lock (BulletXLock) 458 lock (BulletXLock)
@@ -408,6 +468,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin
408 UpdateKineticsForAll(); 468 UpdateKineticsForAll();
409 } 469 }
410 } 470 }
471
411 private void MoveAllObjects(float timeStep) 472 private void MoveAllObjects(float timeStep)
412 { 473 {
413 foreach (BulletXCharacter actor in _characters) 474 foreach (BulletXCharacter actor in _characters)
@@ -418,6 +479,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin
418 { 479 {
419 } 480 }
420 } 481 }
482
421 private void ValidateHeightForAll() 483 private void ValidateHeightForAll()
422 { 484 {
423 float _height; 485 float _height;
@@ -431,7 +493,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin
431 foreach (BulletXPrim prim in _prims) 493 foreach (BulletXPrim prim in _prims)
432 { 494 {
433 //_height = HeightValue(prim.RigidBodyPosition); 495 //_height = HeightValue(prim.RigidBodyPosition);
434 _height = _simFlatPlanet.HeightValue(prim.RigidBodyPosition); 496 _height = _simFlatPlanet.HeightValue(prim.RigidBodyPosition);
435 prim.ValidateHeight(_height); 497 prim.ValidateHeight(_height);
436 //if (_simFlatPlanet.heightIsNotValid(prim.RigidBodyPosition, out _height)) prim.ValidateHeight(_height); 498 //if (_simFlatPlanet.heightIsNotValid(prim.RigidBodyPosition, out _height)) prim.ValidateHeight(_height);
437 } 499 }
@@ -444,6 +506,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin
444 // prim.ValidateHeight(0); 506 // prim.ValidateHeight(0);
445 //} 507 //}
446 } 508 }
509
447 private void UpdateKineticsForAll() 510 private void UpdateKineticsForAll()
448 { 511 {
449 //UpdatePosition > UpdateKinetics. 512 //UpdatePosition > UpdateKinetics.
@@ -458,17 +521,17 @@ namespace OpenSim.Region.Physics.BulletXPlugin
458 } 521 }
459 //if(this._simFlatPlanet!=null) this._simFlatPlanet.Restore(); 522 //if(this._simFlatPlanet!=null) this._simFlatPlanet.Restore();
460 } 523 }
524
461 public override void GetResults() 525 public override void GetResults()
462 { 526 {
463
464 } 527 }
528
465 public override bool IsThreaded 529 public override bool IsThreaded
466 { 530 {
467 get 531 get { return (false); // for now we won't be multithreaded
468 {
469 return (false); // for now we won't be multithreaded
470 } 532 }
471 } 533 }
534
472 public override void SetTerrain(float[] heightMap) 535 public override void SetTerrain(float[] heightMap)
473 { 536 {
474 ////As the same as ODE, heightmap (x,y) must be swapped for BulletX 537 ////As the same as ODE, heightmap (x,y) must be swapped for BulletX
@@ -494,41 +557,44 @@ namespace OpenSim.Region.Physics.BulletXPlugin
494 DeleteTerrain(); 557 DeleteTerrain();
495 //There is a BulletXLock inside the constructor of BulletXPlanet 558 //There is a BulletXLock inside the constructor of BulletXPlanet
496 //this._simFlatPlanet = new BulletXPlanet(this, swappedHeightMap); 559 //this._simFlatPlanet = new BulletXPlanet(this, swappedHeightMap);
497 this._simFlatPlanet = new BulletXPlanet(this, heightMap); 560 _simFlatPlanet = new BulletXPlanet(this, heightMap);
498 //this._heightmap = heightMap; 561 //this._heightmap = heightMap;
499 } 562 }
563
500 public override void DeleteTerrain() 564 public override void DeleteTerrain()
501 { 565 {
502 if (this._simFlatPlanet != null) 566 if (_simFlatPlanet != null)
503 { 567 {
504 lock (BulletXLock) 568 lock (BulletXLock)
505 { 569 {
506 try 570 try
507 { 571 {
508 ddWorld.RemoveRigidBody(this._simFlatPlanet.RigidBody); 572 ddWorld.RemoveRigidBody(_simFlatPlanet.RigidBody);
509 } 573 }
510 catch (Exception ex) 574 catch (Exception ex)
511 { 575 {
512 BulletXMessage(is_ex_message + ex.Message, true); 576 BulletXMessage(is_ex_message + ex.Message, true);
513 this._simFlatPlanet.RigidBody.ActivationState = ActivationState.DisableSimulation; 577 _simFlatPlanet.RigidBody.ActivationState = ActivationState.DisableSimulation;
514 AddForgottenRigidBody(this._simFlatPlanet.RigidBody); 578 AddForgottenRigidBody(_simFlatPlanet.RigidBody);
515 } 579 }
516 } 580 }
517 this._simFlatPlanet = null; 581 _simFlatPlanet = null;
518 GC.Collect(); 582 GC.Collect();
519 BulletXMessage("Terrain erased!", false); 583 BulletXMessage("Terrain erased!", false);
520 } 584 }
521 //this._heightmap = null; 585 //this._heightmap = null;
522 } 586 }
587
523 internal void AddForgottenRigidBody(RigidBody forgottenRigidBody) 588 internal void AddForgottenRigidBody(RigidBody forgottenRigidBody)
524 { 589 {
525 _forgottenRigidBodies.Add(forgottenRigidBody); 590 _forgottenRigidBodies.Add(forgottenRigidBody);
526 } 591 }
592
527 private void RemoveForgottenRigidBodies() 593 private void RemoveForgottenRigidBodies()
528 { 594 {
529 RigidBody forgottenRigidBody; 595 RigidBody forgottenRigidBody;
530 int nRigidBodies = _forgottenRigidBodies.Count; 596 int nRigidBodies = _forgottenRigidBodies.Count;
531 for(int i = nRigidBodies - 1; i >= 0; i--) 597 for (int i = nRigidBodies - 1; i >= 0; i--)
532 { 598 {
533 forgottenRigidBody = _forgottenRigidBodies[i]; 599 forgottenRigidBody = _forgottenRigidBodies[i];
534 try 600 try
@@ -544,10 +610,12 @@ namespace OpenSim.Region.Physics.BulletXPlugin
544 } 610 }
545 GC.Collect(); 611 GC.Collect();
546 } 612 }
613
547 internal void BulletXMessage(string message, bool isWarning) 614 internal void BulletXMessage(string message, bool isWarning)
548 { 615 {
549 PhysicsPluginManager.PhysicsPluginMessage("[Modified BulletX]:\t" + message, isWarning); 616 PhysicsPluginManager.PhysicsPluginMessage("[Modified BulletX]:\t" + message, isWarning);
550 } 617 }
618
551 //temp 619 //temp
552 //private float HeightValue(MonoXnaCompactMaths.Vector3 position) 620 //private float HeightValue(MonoXnaCompactMaths.Vector3 position)
553 //{ 621 //{
@@ -559,10 +627,11 @@ namespace OpenSim.Region.Physics.BulletXPlugin
559 // height = this._heightmap[li_y * 256 + li_x]; 627 // height = this._heightmap[li_y * 256 + li_x];
560 // if (height < 0) height = 0; 628 // if (height < 0) height = 0;
561 // else if (height > maxZ) height = maxZ; 629 // else if (height > maxZ) height = maxZ;
562 630
563 // return height; 631 // return height;
564 //} 632 //}
565 } 633 }
634
566 /// <summary> 635 /// <summary>
567 /// PhysicsActor Character Class for BulletX 636 /// PhysicsActor Character Class for BulletX
568 /// </summary> 637 /// </summary>
@@ -576,21 +645,24 @@ namespace OpenSim.Region.Physics.BulletXPlugin
576 private bool flying; 645 private bool flying;
577 private RigidBody rigidBody; 646 private RigidBody rigidBody;
578 647
579 public MonoXnaCompactMaths.Vector3 RigidBodyPosition 648 public Vector3 RigidBodyPosition
580 { 649 {
581 get { return this.rigidBody.CenterOfMassPosition; } 650 get { return rigidBody.CenterOfMassPosition; }
582 } 651 }
652
583 public BulletXCharacter(BulletXScene parent_scene, PhysicsVector pos) 653 public BulletXCharacter(BulletXScene parent_scene, PhysicsVector pos)
584 : this("", parent_scene, pos) 654 : this("", parent_scene, pos)
585 { 655 {
586 } 656 }
657
587 public BulletXCharacter(String avName, BulletXScene parent_scene, PhysicsVector pos) 658 public BulletXCharacter(String avName, BulletXScene parent_scene, PhysicsVector pos)
588 : this(avName, parent_scene, pos, new PhysicsVector(), new PhysicsVector(), new PhysicsVector(), 659 : this(avName, parent_scene, pos, new PhysicsVector(), new PhysicsVector(), new PhysicsVector(),
589 AxiomQuaternion.Identity) 660 AxiomQuaternion.Identity)
590 { 661 {
591 } 662 }
663
592 public BulletXCharacter(String avName, BulletXScene parent_scene, PhysicsVector pos, PhysicsVector velocity, 664 public BulletXCharacter(String avName, BulletXScene parent_scene, PhysicsVector pos, PhysicsVector velocity,
593 PhysicsVector size, PhysicsVector acceleration, AxiomQuaternion orientation) 665 PhysicsVector size, PhysicsVector acceleration, AxiomQuaternion orientation)
594 { 666 {
595 //This fields will be removed. They're temporal 667 //This fields will be removed. They're temporal
596 float _sizeX = 0.5f; 668 float _sizeX = 0.5f;
@@ -622,23 +694,23 @@ namespace OpenSim.Region.Physics.BulletXPlugin
622 //For now, like ODE, collisionShape = sphere of radious = 1.0 694 //For now, like ODE, collisionShape = sphere of radious = 1.0
623 CollisionShape _collisionShape = new SphereShape(1.0f); 695 CollisionShape _collisionShape = new SphereShape(1.0f);
624 DefaultMotionState _motionState = new DefaultMotionState(_startTransform, _centerOfMassOffset); 696 DefaultMotionState _motionState = new DefaultMotionState(_startTransform, _centerOfMassOffset);
625 MonoXnaCompactMaths.Vector3 _localInertia = new MonoXnaCompactMaths.Vector3(); 697 Vector3 _localInertia = new Vector3();
626 _collisionShape.CalculateLocalInertia(_mass, out _localInertia); //Always when mass > 0 698 _collisionShape.CalculateLocalInertia(_mass, out _localInertia); //Always when mass > 0
627 rigidBody = new RigidBody(_mass, _motionState, _collisionShape, _localInertia, _linearDamping, _angularDamping, _friction, _restitution); 699 rigidBody =
700 new RigidBody(_mass, _motionState, _collisionShape, _localInertia, _linearDamping, _angularDamping,
701 _friction, _restitution);
628 //rigidBody.ActivationState = ActivationState.DisableDeactivation; 702 //rigidBody.ActivationState = ActivationState.DisableDeactivation;
629 //It's seems that there are a bug with rigidBody constructor and its CenterOfMassPosition 703 //It's seems that there are a bug with rigidBody constructor and its CenterOfMassPosition
630 MonoXnaCompactMaths.Vector3 _vDebugTranslation; 704 Vector3 _vDebugTranslation;
631 _vDebugTranslation = _startTransform.Translation - rigidBody.CenterOfMassPosition; 705 _vDebugTranslation = _startTransform.Translation - rigidBody.CenterOfMassPosition;
632 rigidBody.Translate(_vDebugTranslation); 706 rigidBody.Translate(_vDebugTranslation);
633 parent_scene.ddWorld.AddRigidBody(rigidBody); 707 parent_scene.ddWorld.AddRigidBody(rigidBody);
634 } 708 }
635 } 709 }
710
636 public override PhysicsVector Position 711 public override PhysicsVector Position
637 { 712 {
638 get 713 get { return _position; }
639 {
640 return _position;
641 }
642 set 714 set
643 { 715 {
644 lock (BulletXScene.BulletXLock) 716 lock (BulletXScene.BulletXLock)
@@ -648,12 +720,10 @@ namespace OpenSim.Region.Physics.BulletXPlugin
648 } 720 }
649 } 721 }
650 } 722 }
723
651 public override PhysicsVector Velocity 724 public override PhysicsVector Velocity
652 { 725 {
653 get 726 get { return _velocity; }
654 {
655 return _velocity;
656 }
657 set 727 set
658 { 728 {
659 lock (BulletXScene.BulletXLock) 729 lock (BulletXScene.BulletXLock)
@@ -663,12 +733,10 @@ namespace OpenSim.Region.Physics.BulletXPlugin
663 } 733 }
664 } 734 }
665 } 735 }
736
666 public override PhysicsVector Size 737 public override PhysicsVector Size
667 { 738 {
668 get 739 get { return _size; }
669 {
670 return _size;
671 }
672 set 740 set
673 { 741 {
674 lock (BulletXScene.BulletXLock) 742 lock (BulletXScene.BulletXLock)
@@ -677,19 +745,15 @@ namespace OpenSim.Region.Physics.BulletXPlugin
677 } 745 }
678 } 746 }
679 } 747 }
748
680 public override PhysicsVector Acceleration 749 public override PhysicsVector Acceleration
681 { 750 {
682 get 751 get { return _acceleration; }
683 {
684 return _acceleration;
685 }
686 } 752 }
753
687 public override AxiomQuaternion Orientation 754 public override AxiomQuaternion Orientation
688 { 755 {
689 get 756 get { return _orientation; }
690 {
691 return _orientation;
692 }
693 set 757 set
694 { 758 {
695 lock (BulletXScene.BulletXLock) 759 lock (BulletXScene.BulletXLock)
@@ -698,24 +762,18 @@ namespace OpenSim.Region.Physics.BulletXPlugin
698 } 762 }
699 } 763 }
700 } 764 }
765
701 public RigidBody RigidBody 766 public RigidBody RigidBody
702 { 767 {
703 get 768 get { return rigidBody; }
704 {
705 return rigidBody;
706 }
707 } 769 }
770
708 public override bool Flying 771 public override bool Flying
709 { 772 {
710 get 773 get { return flying; }
711 { 774 set { flying = value; }
712 return flying;
713 }
714 set
715 {
716 flying = value;
717 }
718 } 775 }
776
719 public void SetAcceleration(PhysicsVector accel) 777 public void SetAcceleration(PhysicsVector accel)
720 { 778 {
721 lock (BulletXScene.BulletXLock) 779 lock (BulletXScene.BulletXLock)
@@ -723,116 +781,121 @@ namespace OpenSim.Region.Physics.BulletXPlugin
723 _acceleration = accel; 781 _acceleration = accel;
724 } 782 }
725 } 783 }
784
726 public override bool Kinematic 785 public override bool Kinematic
727 { 786 {
728 get 787 get { return false; }
729 { 788 set { }
730 return false;
731 }
732 set
733 {
734
735 }
736 } 789 }
790
737 public override void AddForce(PhysicsVector force) 791 public override void AddForce(PhysicsVector force)
738 { 792 {
739
740 } 793 }
794
741 public override void SetMomentum(PhysicsVector momentum) 795 public override void SetMomentum(PhysicsVector momentum)
742 { 796 {
743
744 } 797 }
798
745 internal void Move(float timeStep) 799 internal void Move(float timeStep)
746 { 800 {
747 MonoXnaCompactMaths.Vector3 vec = new MonoXnaCompactMaths.Vector3(); 801 Vector3 vec = new Vector3();
748 //At this point it's supossed that: 802 //At this point it's supossed that:
749 //_velocity == rigidBody.LinearVelocity 803 //_velocity == rigidBody.LinearVelocity
750 vec.X = this._velocity.X; 804 vec.X = _velocity.X;
751 vec.Y = this._velocity.Y; 805 vec.Y = _velocity.Y;
752 vec.Z = this._velocity.Z; 806 vec.Z = _velocity.Z;
753 if ((vec.X != 0.0f) || (vec.Y != 0.0f) || (vec.Z != 0.0f)) rigidBody.Activate(); 807 if ((vec.X != 0.0f) || (vec.Y != 0.0f) || (vec.Z != 0.0f)) rigidBody.Activate();
754 if (flying) 808 if (flying)
755 { 809 {
756 //Antigravity with movement 810 //Antigravity with movement
757 if (this._position.Z <= BulletXScene.HeightLevel0) 811 if (_position.Z <= BulletXScene.HeightLevel0)
758 { 812 {
759 vec.Z += BulletXScene.Gravity * timeStep; 813 vec.Z += BulletXScene.Gravity*timeStep;
760 } 814 }
761 //Lowgravity with movement 815 //Lowgravity with movement
762 else if ((this._position.Z > BulletXScene.HeightLevel0) 816 else if ((_position.Z > BulletXScene.HeightLevel0)
763 && (this._position.Z <= BulletXScene.HeightLevel1)) 817 && (_position.Z <= BulletXScene.HeightLevel1))
764 { 818 {
765 vec.Z += BulletXScene.Gravity * timeStep * (1.0f - BulletXScene.LowGravityFactor); 819 vec.Z += BulletXScene.Gravity*timeStep*(1.0f - BulletXScene.LowGravityFactor);
766 } 820 }
767 //Lowgravity with... 821 //Lowgravity with...
768 else if (this._position.Z > BulletXScene.HeightLevel1) 822 else if (_position.Z > BulletXScene.HeightLevel1)
769 { 823 {
770 if (vec.Z > 0) //no movement 824 if (vec.Z > 0) //no movement
771 vec.Z = BulletXScene.Gravity * timeStep * (1.0f - BulletXScene.LowGravityFactor); 825 vec.Z = BulletXScene.Gravity*timeStep*(1.0f - BulletXScene.LowGravityFactor);
772 else 826 else
773 vec.Z += BulletXScene.Gravity * timeStep * (1.0f - BulletXScene.LowGravityFactor); 827 vec.Z += BulletXScene.Gravity*timeStep*(1.0f - BulletXScene.LowGravityFactor);
774
775 } 828 }
776 } 829 }
777 rigidBody.LinearVelocity = vec; 830 rigidBody.LinearVelocity = vec;
778 } 831 }
832
779 //This validation is very basic 833 //This validation is very basic
780 internal void ValidateHeight(float heighmapPositionValue) 834 internal void ValidateHeight(float heighmapPositionValue)
781 { 835 {
782 if (rigidBody.CenterOfMassPosition.Z < heighmapPositionValue + _size.Z / 2.0f) 836 if (rigidBody.CenterOfMassPosition.Z < heighmapPositionValue + _size.Z/2.0f)
783 { 837 {
784 Matrix m = rigidBody.WorldTransform; 838 Matrix m = rigidBody.WorldTransform;
785 MonoXnaCompactMaths.Vector3 v3 = m.Translation; 839 Vector3 v3 = m.Translation;
786 v3.Z = heighmapPositionValue + _size.Z / 2.0f; 840 v3.Z = heighmapPositionValue + _size.Z/2.0f;
787 m.Translation = v3; 841 m.Translation = v3;
788 rigidBody.WorldTransform = m; 842 rigidBody.WorldTransform = m;
789 //When an Avie touch the ground it's vertical velocity it's reduced to ZERO 843 //When an Avie touch the ground it's vertical velocity it's reduced to ZERO
790 Speed(new PhysicsVector(this.rigidBody.LinearVelocity.X, this.rigidBody.LinearVelocity.Y, 0.0f)); 844 Speed(new PhysicsVector(rigidBody.LinearVelocity.X, rigidBody.LinearVelocity.Y, 0.0f));
791 } 845 }
792 } 846 }
847
793 internal void UpdateKinetics() 848 internal void UpdateKinetics()
794 { 849 {
795 this._position = BulletXMaths.XnaVector3ToPhysicsVector(rigidBody.CenterOfMassPosition); 850 _position = BulletXMaths.XnaVector3ToPhysicsVector(rigidBody.CenterOfMassPosition);
796 this._velocity = BulletXMaths.XnaVector3ToPhysicsVector(rigidBody.LinearVelocity); 851 _velocity = BulletXMaths.XnaVector3ToPhysicsVector(rigidBody.LinearVelocity);
797 //Orientation it seems that it will be the default. 852 //Orientation it seems that it will be the default.
798 ReOrient(); 853 ReOrient();
799 } 854 }
800 855
801 #region Methods for updating values of RigidBody 856 #region Methods for updating values of RigidBody
857
802 private void Translate() 858 private void Translate()
803 { 859 {
804 Translate(this._position); 860 Translate(_position);
805 } 861 }
862
806 private void Translate(PhysicsVector _newPos) 863 private void Translate(PhysicsVector _newPos)
807 { 864 {
808 MonoXnaCompactMaths.Vector3 _translation; 865 Vector3 _translation;
809 _translation = BulletXMaths.PhysicsVectorToXnaVector3(_newPos) - rigidBody.CenterOfMassPosition; 866 _translation = BulletXMaths.PhysicsVectorToXnaVector3(_newPos) - rigidBody.CenterOfMassPosition;
810 rigidBody.Translate(_translation); 867 rigidBody.Translate(_translation);
811 } 868 }
869
812 private void Speed() 870 private void Speed()
813 { 871 {
814 Speed(this._velocity); 872 Speed(_velocity);
815 } 873 }
874
816 private void Speed(PhysicsVector _newSpeed) 875 private void Speed(PhysicsVector _newSpeed)
817 { 876 {
818 MonoXnaCompactMaths.Vector3 _speed; 877 Vector3 _speed;
819 _speed = BulletXMaths.PhysicsVectorToXnaVector3(_newSpeed); 878 _speed = BulletXMaths.PhysicsVectorToXnaVector3(_newSpeed);
820 rigidBody.LinearVelocity = _speed; 879 rigidBody.LinearVelocity = _speed;
821 } 880 }
881
822 private void ReOrient() 882 private void ReOrient()
823 { 883 {
824 ReOrient(this._orientation); 884 ReOrient(_orientation);
825 } 885 }
886
826 private void ReOrient(AxiomQuaternion _newOrient) 887 private void ReOrient(AxiomQuaternion _newOrient)
827 { 888 {
828 MonoXnaCompactMaths.Quaternion _newOrientation; 889 Quaternion _newOrientation;
829 _newOrientation = BulletXMaths.AxiomQuaternionToXnaQuaternion(_newOrient); 890 _newOrientation = BulletXMaths.AxiomQuaternionToXnaQuaternion(_newOrient);
830 Matrix _comTransform = rigidBody.CenterOfMassTransform; 891 Matrix _comTransform = rigidBody.CenterOfMassTransform;
831 BulletXMaths.SetRotation(ref _comTransform, _newOrientation); 892 BulletXMaths.SetRotation(ref _comTransform, _newOrientation);
832 rigidBody.CenterOfMassTransform = _comTransform; 893 rigidBody.CenterOfMassTransform = _comTransform;
833 } 894 }
895
834 #endregion 896 #endregion
835 } 897 }
898
836 /// <summary> 899 /// <summary>
837 /// PhysicsActor Prim Class for BulletX 900 /// PhysicsActor Prim Class for BulletX
838 /// </summary> 901 /// </summary>
@@ -851,27 +914,32 @@ namespace OpenSim.Region.Physics.BulletXPlugin
851 //_physical value will be linked with the prim object value 914 //_physical value will be linked with the prim object value
852 private Boolean _physical = false; 915 private Boolean _physical = false;
853 916
854 public MonoXnaCompactMaths.Vector3 RigidBodyPosition 917 public Vector3 RigidBodyPosition
855 { 918 {
856 get { return this.rigidBody.CenterOfMassPosition; } 919 get { return rigidBody.CenterOfMassPosition; }
857 } 920 }
921
858 public BulletXPrim(BulletXScene parent_scene, PhysicsVector pos, PhysicsVector size, AxiomQuaternion rotation) 922 public BulletXPrim(BulletXScene parent_scene, PhysicsVector pos, PhysicsVector size, AxiomQuaternion rotation)
859 : this("", parent_scene, pos, new PhysicsVector(), size, new PhysicsVector(), rotation, null, null) 923 : this("", parent_scene, pos, new PhysicsVector(), size, new PhysicsVector(), rotation, null, null)
860 { 924 {
861 } 925 }
862 public BulletXPrim(String primName, BulletXScene parent_scene, PhysicsVector pos, PhysicsVector size, 926
863 AxiomQuaternion rotation, Mesh mesh, PrimitiveBaseShape pbs) 927 public BulletXPrim(String primName, BulletXScene parent_scene, PhysicsVector pos, PhysicsVector size,
928 AxiomQuaternion rotation, Mesh mesh, PrimitiveBaseShape pbs)
864 : this(primName, parent_scene, pos, new PhysicsVector(), size, new PhysicsVector(), rotation, mesh, pbs) 929 : this(primName, parent_scene, pos, new PhysicsVector(), size, new PhysicsVector(), rotation, mesh, pbs)
865 { 930 {
866 } 931 }
867 public BulletXPrim(String primName, BulletXScene parent_scene, PhysicsVector pos, PhysicsVector velocity, PhysicsVector size, 932
868 PhysicsVector aceleration, AxiomQuaternion rotation, Mesh mesh, PrimitiveBaseShape pbs) 933 public BulletXPrim(String primName, BulletXScene parent_scene, PhysicsVector pos, PhysicsVector velocity,
934 PhysicsVector size,
935 PhysicsVector aceleration, AxiomQuaternion rotation, Mesh mesh, PrimitiveBaseShape pbs)
869 { 936 {
870 if ((size.X == 0) || (size.Y == 0) || (size.Z == 0)) throw new Exception("Size 0"); 937 if ((size.X == 0) || (size.Y == 0) || (size.Z == 0)) throw new Exception("Size 0");
871 if (rotation.Norm == 0f) rotation = AxiomQuaternion.Identity; 938 if (rotation.Norm == 0f) rotation = AxiomQuaternion.Identity;
872 939
873 _position = pos; 940 _position = pos;
874 if (_physical) _velocity = velocity; else _velocity = new PhysicsVector(); 941 if (_physical) _velocity = velocity;
942 else _velocity = new PhysicsVector();
875 _size = size; 943 _size = size;
876 _acceleration = aceleration; 944 _acceleration = aceleration;
877 _orientation = rotation; 945 _orientation = rotation;
@@ -889,26 +957,26 @@ namespace OpenSim.Region.Physics.BulletXPlugin
889 { 957 {
890 _startTransform.Translation = BulletXMaths.PhysicsVectorToXnaVector3(pos); 958 _startTransform.Translation = BulletXMaths.PhysicsVectorToXnaVector3(pos);
891 //For now all prims are boxes 959 //For now all prims are boxes
892 CollisionShape _collisionShape = new XnaDevRu.BulletX.BoxShape(BulletXMaths.PhysicsVectorToXnaVector3(_size) / 2.0f); 960 CollisionShape _collisionShape = new BoxShape(BulletXMaths.PhysicsVectorToXnaVector3(_size)/2.0f);
893 DefaultMotionState _motionState = new DefaultMotionState(_startTransform, _centerOfMassOffset); 961 DefaultMotionState _motionState = new DefaultMotionState(_startTransform, _centerOfMassOffset);
894 MonoXnaCompactMaths.Vector3 _localInertia = new MonoXnaCompactMaths.Vector3(); 962 Vector3 _localInertia = new Vector3();
895 if(_physical) _collisionShape.CalculateLocalInertia(Mass, out _localInertia); //Always when mass > 0 963 if (_physical) _collisionShape.CalculateLocalInertia(Mass, out _localInertia); //Always when mass > 0
896 rigidBody = new RigidBody(Mass, _motionState, _collisionShape, _localInertia, _linearDamping, _angularDamping, _friction, _restitution); 964 rigidBody =
965 new RigidBody(Mass, _motionState, _collisionShape, _localInertia, _linearDamping, _angularDamping,
966 _friction, _restitution);
897 //rigidBody.ActivationState = ActivationState.DisableDeactivation; 967 //rigidBody.ActivationState = ActivationState.DisableDeactivation;
898 //It's seems that there are a bug with rigidBody constructor and its CenterOfMassPosition 968 //It's seems that there are a bug with rigidBody constructor and its CenterOfMassPosition
899 MonoXnaCompactMaths.Vector3 _vDebugTranslation; 969 Vector3 _vDebugTranslation;
900 _vDebugTranslation = _startTransform.Translation - rigidBody.CenterOfMassPosition; 970 _vDebugTranslation = _startTransform.Translation - rigidBody.CenterOfMassPosition;
901 rigidBody.Translate(_vDebugTranslation); 971 rigidBody.Translate(_vDebugTranslation);
902 //--- 972 //---
903 parent_scene.ddWorld.AddRigidBody(rigidBody); 973 parent_scene.ddWorld.AddRigidBody(rigidBody);
904 } 974 }
905 } 975 }
976
906 public override PhysicsVector Position 977 public override PhysicsVector Position
907 { 978 {
908 get 979 get { return _position; }
909 {
910 return _position;
911 }
912 set 980 set
913 { 981 {
914 lock (BulletXScene.BulletXLock) 982 lock (BulletXScene.BulletXLock)
@@ -918,12 +986,10 @@ namespace OpenSim.Region.Physics.BulletXPlugin
918 } 986 }
919 } 987 }
920 } 988 }
989
921 public override PhysicsVector Velocity 990 public override PhysicsVector Velocity
922 { 991 {
923 get 992 get { return _velocity; }
924 {
925 return _velocity;
926 }
927 set 993 set
928 { 994 {
929 lock (BulletXScene.BulletXLock) 995 lock (BulletXScene.BulletXLock)
@@ -941,12 +1007,10 @@ namespace OpenSim.Region.Physics.BulletXPlugin
941 } 1007 }
942 } 1008 }
943 } 1009 }
1010
944 public override PhysicsVector Size 1011 public override PhysicsVector Size
945 { 1012 {
946 get 1013 get { return _size; }
947 {
948 return _size;
949 }
950 set 1014 set
951 { 1015 {
952 lock (BulletXScene.BulletXLock) 1016 lock (BulletXScene.BulletXLock)
@@ -956,19 +1020,15 @@ namespace OpenSim.Region.Physics.BulletXPlugin
956 } 1020 }
957 } 1021 }
958 } 1022 }
1023
959 public override PhysicsVector Acceleration 1024 public override PhysicsVector Acceleration
960 { 1025 {
961 get 1026 get { return _acceleration; }
962 {
963 return _acceleration;
964 }
965 } 1027 }
1028
966 public override AxiomQuaternion Orientation 1029 public override AxiomQuaternion Orientation
967 { 1030 {
968 get 1031 get { return _orientation; }
969 {
970 return _orientation;
971 }
972 set 1032 set
973 { 1033 {
974 lock (BulletXScene.BulletXLock) 1034 lock (BulletXScene.BulletXLock)
@@ -978,43 +1038,34 @@ namespace OpenSim.Region.Physics.BulletXPlugin
978 } 1038 }
979 } 1039 }
980 } 1040 }
1041
981 public float Mass 1042 public float Mass
982 { 1043 {
983 get 1044 get
984 { 1045 {
985 //For now all prims are boxes 1046 //For now all prims are boxes
986 return (_physical ? 1 : 0) * _density * _size.X * _size.Y * _size.Z; 1047 return (_physical ? 1 : 0)*_density*_size.X*_size.Y*_size.Z;
987 } 1048 }
988 } 1049 }
1050
989 public RigidBody RigidBody 1051 public RigidBody RigidBody
990 { 1052 {
991 get 1053 get { return rigidBody; }
992 {
993 return rigidBody;
994 }
995 } 1054 }
1055
996 public override bool Flying 1056 public override bool Flying
997 { 1057 {
998 get 1058 get { return false; //no flying prims for you
999 {
1000 return false; //no flying prims for you
1001 }
1002 set
1003 {
1004
1005 } 1059 }
1060 set { }
1006 } 1061 }
1062
1007 public Boolean Physical 1063 public Boolean Physical
1008 { 1064 {
1009 get 1065 get { return _physical; }
1010 { 1066 set { _physical = value; }
1011 return _physical;
1012 }
1013 set
1014 {
1015 _physical = value;
1016 }
1017 } 1067 }
1068
1018 public void SetAcceleration(PhysicsVector accel) 1069 public void SetAcceleration(PhysicsVector accel)
1019 { 1070 {
1020 lock (BulletXScene.BulletXLock) 1071 lock (BulletXScene.BulletXLock)
@@ -1022,6 +1073,7 @@ namespace OpenSim.Region.Physics.BulletXPlugin
1022 _acceleration = accel; 1073 _acceleration = accel;
1023 } 1074 }
1024 } 1075 }
1076
1025 public override bool Kinematic 1077 public override bool Kinematic
1026 { 1078 {
1027 get 1079 get
@@ -1034,36 +1086,38 @@ namespace OpenSim.Region.Physics.BulletXPlugin
1034 //this._prim.Kinematic = value; 1086 //this._prim.Kinematic = value;
1035 } 1087 }
1036 } 1088 }
1089
1037 public override void AddForce(PhysicsVector force) 1090 public override void AddForce(PhysicsVector force)
1038 { 1091 {
1039
1040 } 1092 }
1093
1041 public override void SetMomentum(PhysicsVector momentum) 1094 public override void SetMomentum(PhysicsVector momentum)
1042 { 1095 {
1043
1044 } 1096 }
1097
1045 internal void ValidateHeight(float heighmapPositionValue) 1098 internal void ValidateHeight(float heighmapPositionValue)
1046 { 1099 {
1047 if (rigidBody.CenterOfMassPosition.Z < heighmapPositionValue + _size.Z / 2.0f) 1100 if (rigidBody.CenterOfMassPosition.Z < heighmapPositionValue + _size.Z/2.0f)
1048 { 1101 {
1049 Matrix m = rigidBody.WorldTransform; 1102 Matrix m = rigidBody.WorldTransform;
1050 MonoXnaCompactMaths.Vector3 v3 = m.Translation; 1103 Vector3 v3 = m.Translation;
1051 v3.Z = heighmapPositionValue + _size.Z / 2.0f; 1104 v3.Z = heighmapPositionValue + _size.Z/2.0f;
1052 m.Translation = v3; 1105 m.Translation = v3;
1053 rigidBody.WorldTransform = m; 1106 rigidBody.WorldTransform = m;
1054 //When a Prim touch the ground it's vertical velocity it's reduced to ZERO 1107 //When a Prim touch the ground it's vertical velocity it's reduced to ZERO
1055 //Static objects don't have linear velocity 1108 //Static objects don't have linear velocity
1056 if(_physical) 1109 if (_physical)
1057 Speed(new PhysicsVector(this.rigidBody.LinearVelocity.X, this.rigidBody.LinearVelocity.Y, 0.0f)); 1110 Speed(new PhysicsVector(rigidBody.LinearVelocity.X, rigidBody.LinearVelocity.Y, 0.0f));
1058 } 1111 }
1059 } 1112 }
1113
1060 internal void UpdateKinetics() 1114 internal void UpdateKinetics()
1061 { 1115 {
1062 if (_physical) //Updates properties. Prim updates its properties physically 1116 if (_physical) //Updates properties. Prim updates its properties physically
1063 { 1117 {
1064 this._position = BulletXMaths.XnaVector3ToPhysicsVector(rigidBody.CenterOfMassPosition); 1118 _position = BulletXMaths.XnaVector3ToPhysicsVector(rigidBody.CenterOfMassPosition);
1065 this._velocity = BulletXMaths.XnaVector3ToPhysicsVector(rigidBody.LinearVelocity); 1119 _velocity = BulletXMaths.XnaVector3ToPhysicsVector(rigidBody.LinearVelocity);
1066 this._orientation = BulletXMaths.XnaQuaternionToAxiomQuaternion(rigidBody.Orientation); 1120 _orientation = BulletXMaths.XnaQuaternionToAxiomQuaternion(rigidBody.Orientation);
1067 } 1121 }
1068 else //Doesn't updates properties. That's a cancel 1122 else //Doesn't updates properties. That's a cancel
1069 { 1123 {
@@ -1074,35 +1128,41 @@ namespace OpenSim.Region.Physics.BulletXPlugin
1074 } 1128 }
1075 1129
1076 #region Methods for updating values of RigidBody 1130 #region Methods for updating values of RigidBody
1131
1077 private void Translate() 1132 private void Translate()
1078 { 1133 {
1079 Translate(this._position); 1134 Translate(_position);
1080 } 1135 }
1136
1081 private void Translate(PhysicsVector _newPos) 1137 private void Translate(PhysicsVector _newPos)
1082 { 1138 {
1083 MonoXnaCompactMaths.Vector3 _translation; 1139 Vector3 _translation;
1084 _translation = BulletXMaths.PhysicsVectorToXnaVector3(_newPos) - rigidBody.CenterOfMassPosition; 1140 _translation = BulletXMaths.PhysicsVectorToXnaVector3(_newPos) - rigidBody.CenterOfMassPosition;
1085 rigidBody.Translate(_translation); 1141 rigidBody.Translate(_translation);
1086 } 1142 }
1143
1087 private void Speed() 1144 private void Speed()
1088 { 1145 {
1089 Speed(this._velocity); 1146 Speed(_velocity);
1090 } 1147 }
1148
1091 private void Speed(PhysicsVector _newSpeed) 1149 private void Speed(PhysicsVector _newSpeed)
1092 { 1150 {
1093 MonoXnaCompactMaths.Vector3 _speed; 1151 Vector3 _speed;
1094 _speed = BulletXMaths.PhysicsVectorToXnaVector3(_newSpeed); 1152 _speed = BulletXMaths.PhysicsVectorToXnaVector3(_newSpeed);
1095 rigidBody.LinearVelocity = _speed; 1153 rigidBody.LinearVelocity = _speed;
1096 } 1154 }
1155
1097 private void ReSize() 1156 private void ReSize()
1098 { 1157 {
1099 ReSize(this._size); 1158 ReSize(_size);
1100 } 1159 }
1160
1101 private void ReSize(PhysicsVector _newSize) 1161 private void ReSize(PhysicsVector _newSize)
1102 { 1162 {
1103 //I wonder to know how to resize with a simple instruction in BulletX. It seems that for now there isn't 1163 //I wonder to know how to resize with a simple instruction in BulletX. It seems that for now there isn't
1104 //so i have to do it manually. That's recreating rigidbody 1164 //so i have to do it manually. That's recreating rigidbody
1105 MonoXnaCompactMaths.Vector3 _newsize; 1165 Vector3 _newsize;
1106 _newsize = BulletXMaths.PhysicsVectorToXnaVector3(_newSize); 1166 _newsize = BulletXMaths.PhysicsVectorToXnaVector3(_newSize);
1107 if ((_newsize.X == 0) || (_newsize.Y == 0) || (_newsize.Z == 0)) throw new Exception("Size 0"); 1167 if ((_newsize.X == 0) || (_newsize.Y == 0) || (_newsize.Z == 0)) throw new Exception("Size 0");
1108 1168
@@ -1114,67 +1174,77 @@ namespace OpenSim.Region.Physics.BulletXPlugin
1114 Matrix _startTransform = Matrix.Identity; 1174 Matrix _startTransform = Matrix.Identity;
1115 Matrix _centerOfMassOffset = Matrix.Identity; 1175 Matrix _centerOfMassOffset = Matrix.Identity;
1116 RigidBody _tmpRigidBody; 1176 RigidBody _tmpRigidBody;
1117 _startTransform.Translation = BulletXMaths.PhysicsVectorToXnaVector3(this._position); 1177 _startTransform.Translation = BulletXMaths.PhysicsVectorToXnaVector3(_position);
1118 //For now all prims are boxes 1178 //For now all prims are boxes
1119 CollisionShape _collisionShape = new XnaDevRu.BulletX.BoxShape(BulletXMaths.PhysicsVectorToXnaVector3(_newSize) / 2.0f); 1179 CollisionShape _collisionShape = new BoxShape(BulletXMaths.PhysicsVectorToXnaVector3(_newSize)/2.0f);
1120 DefaultMotionState _motionState = new DefaultMotionState(_startTransform, _centerOfMassOffset); 1180 DefaultMotionState _motionState = new DefaultMotionState(_startTransform, _centerOfMassOffset);
1121 MonoXnaCompactMaths.Vector3 _localInertia = new MonoXnaCompactMaths.Vector3(); 1181 Vector3 _localInertia = new Vector3();
1122 if (_physical) _collisionShape.CalculateLocalInertia(Mass, out _localInertia); //Always when mass > 0 1182 if (_physical) _collisionShape.CalculateLocalInertia(Mass, out _localInertia); //Always when mass > 0
1123 _tmpRigidBody = new RigidBody(Mass, _motionState, _collisionShape, _localInertia, _linearDamping, _angularDamping, _friction, _restitution); 1183 _tmpRigidBody =
1184 new RigidBody(Mass, _motionState, _collisionShape, _localInertia, _linearDamping, _angularDamping,
1185 _friction, _restitution);
1124 //rigidBody.ActivationState = ActivationState.DisableDeactivation; 1186 //rigidBody.ActivationState = ActivationState.DisableDeactivation;
1125 //It's seems that there are a bug with rigidBody constructor and its CenterOfMassPosition 1187 //It's seems that there are a bug with rigidBody constructor and its CenterOfMassPosition
1126 MonoXnaCompactMaths.Vector3 _vDebugTranslation; 1188 Vector3 _vDebugTranslation;
1127 _vDebugTranslation = _startTransform.Translation - rigidBody.CenterOfMassPosition; 1189 _vDebugTranslation = _startTransform.Translation - rigidBody.CenterOfMassPosition;
1128 _tmpRigidBody.Translate(_vDebugTranslation); 1190 _tmpRigidBody.Translate(_vDebugTranslation);
1129 //--- 1191 //---
1130 //There is a bug when trying to remove a rigidBody that is colliding with something.. 1192 //There is a bug when trying to remove a rigidBody that is colliding with something..
1131 try 1193 try
1132 { 1194 {
1133 this._parent_scene.ddWorld.RemoveRigidBody(rigidBody); 1195 _parent_scene.ddWorld.RemoveRigidBody(rigidBody);
1134 } 1196 }
1135 catch(Exception ex) 1197 catch (Exception ex)
1136 { 1198 {
1137 this._parent_scene.BulletXMessage(this._parent_scene.is_ex_message + ex.Message, true); 1199 _parent_scene.BulletXMessage(_parent_scene.is_ex_message + ex.Message, true);
1138 rigidBody.ActivationState = ActivationState.DisableSimulation; 1200 rigidBody.ActivationState = ActivationState.DisableSimulation;
1139 this._parent_scene.AddForgottenRigidBody(rigidBody); 1201 _parent_scene.AddForgottenRigidBody(rigidBody);
1140 } 1202 }
1141 rigidBody = _tmpRigidBody; 1203 rigidBody = _tmpRigidBody;
1142 this._parent_scene.ddWorld.AddRigidBody(rigidBody); 1204 _parent_scene.ddWorld.AddRigidBody(rigidBody);
1143 if (_physical) Speed();//Static objects don't have linear velocity 1205 if (_physical) Speed(); //Static objects don't have linear velocity
1144 ReOrient(); 1206 ReOrient();
1145 GC.Collect(); 1207 GC.Collect();
1146 } 1208 }
1209
1147 private void ReOrient() 1210 private void ReOrient()
1148 { 1211 {
1149 ReOrient(this._orientation); 1212 ReOrient(_orientation);
1150 } 1213 }
1214
1151 private void ReOrient(AxiomQuaternion _newOrient) 1215 private void ReOrient(AxiomQuaternion _newOrient)
1152 { 1216 {
1153 MonoXnaCompactMaths.Quaternion _newOrientation; 1217 Quaternion _newOrientation;
1154 _newOrientation = BulletXMaths.AxiomQuaternionToXnaQuaternion(_newOrient); 1218 _newOrientation = BulletXMaths.AxiomQuaternionToXnaQuaternion(_newOrient);
1155 Matrix _comTransform = rigidBody.CenterOfMassTransform; 1219 Matrix _comTransform = rigidBody.CenterOfMassTransform;
1156 BulletXMaths.SetRotation(ref _comTransform, _newOrientation); 1220 BulletXMaths.SetRotation(ref _comTransform, _newOrientation);
1157 rigidBody.CenterOfMassTransform = _comTransform; 1221 rigidBody.CenterOfMassTransform = _comTransform;
1158 } 1222 }
1159 #endregion
1160 1223
1224 #endregion
1161 } 1225 }
1226
1162 /// <summary> 1227 /// <summary>
1163 /// This Class manage a HeighField as a RigidBody. This is for to be added in the BulletXScene 1228 /// This Class manage a HeighField as a RigidBody. This is for to be added in the BulletXScene
1164 /// </summary> 1229 /// </summary>
1165 internal class BulletXPlanet 1230 internal class BulletXPlanet
1166 { 1231 {
1167 private PhysicsVector _staticPosition; 1232 private PhysicsVector _staticPosition;
1168 private PhysicsVector _staticVelocity; 1233 private PhysicsVector _staticVelocity;
1169 private AxiomQuaternion _staticOrientation; 1234 private AxiomQuaternion _staticOrientation;
1170 private float _mass; 1235 private float _mass;
1171 private BulletXScene _parentscene; 1236 private BulletXScene _parentscene;
1172 internal float[] _heightField; 1237 internal float[] _heightField;
1173 private RigidBody _flatPlanet; 1238 private RigidBody _flatPlanet;
1174 internal RigidBody RigidBody { get { return _flatPlanet; } } 1239
1240 internal RigidBody RigidBody
1241 {
1242 get { return _flatPlanet; }
1243 }
1244
1175 internal BulletXPlanet(BulletXScene parent_scene, float[] heightField) 1245 internal BulletXPlanet(BulletXScene parent_scene, float[] heightField)
1176 { 1246 {
1177 _staticPosition = new PhysicsVector(BulletXScene.MaxXY / 2, BulletXScene.MaxXY/2, 0); 1247 _staticPosition = new PhysicsVector(BulletXScene.MaxXY/2, BulletXScene.MaxXY/2, 0);
1178 _staticVelocity = new PhysicsVector(); 1248 _staticVelocity = new PhysicsVector();
1179 _staticOrientation = AxiomQuaternion.Identity; 1249 _staticOrientation = AxiomQuaternion.Identity;
1180 _mass = 0; //No active 1250 _mass = 0; //No active
@@ -1193,40 +1263,45 @@ namespace OpenSim.Region.Physics.BulletXPlugin
1193 try 1263 try
1194 { 1264 {
1195 _startTransform.Translation = BulletXMaths.PhysicsVectorToXnaVector3(_staticPosition); 1265 _startTransform.Translation = BulletXMaths.PhysicsVectorToXnaVector3(_staticPosition);
1196 CollisionShape _collisionShape = new HeightfieldTerrainShape(BulletXScene.MaxXY, BulletXScene.MaxXY, _heightField, (float)BulletXScene.MaxZ, 2, true, false); 1266 CollisionShape _collisionShape =
1267 new HeightfieldTerrainShape(BulletXScene.MaxXY, BulletXScene.MaxXY, _heightField,
1268 (float) BulletXScene.MaxZ, 2, true, false);
1197 DefaultMotionState _motionState = new DefaultMotionState(_startTransform, _centerOfMassOffset); 1269 DefaultMotionState _motionState = new DefaultMotionState(_startTransform, _centerOfMassOffset);
1198 MonoXnaCompactMaths.Vector3 _localInertia = new MonoXnaCompactMaths.Vector3(); 1270 Vector3 _localInertia = new Vector3();
1199 //_collisionShape.CalculateLocalInertia(_mass, out _localInertia); //Always when mass > 0 1271 //_collisionShape.CalculateLocalInertia(_mass, out _localInertia); //Always when mass > 0
1200 _flatPlanet = new RigidBody(_mass, _motionState, _collisionShape, _localInertia, _linearDamping, _angularDamping, _friction, _restitution); 1272 _flatPlanet =
1273 new RigidBody(_mass, _motionState, _collisionShape, _localInertia, _linearDamping,
1274 _angularDamping, _friction, _restitution);
1201 //It's seems that there are a bug with rigidBody constructor and its CenterOfMassPosition 1275 //It's seems that there are a bug with rigidBody constructor and its CenterOfMassPosition
1202 MonoXnaCompactMaths.Vector3 _vDebugTranslation; 1276 Vector3 _vDebugTranslation;
1203 _vDebugTranslation = _startTransform.Translation - _flatPlanet.CenterOfMassPosition; 1277 _vDebugTranslation = _startTransform.Translation - _flatPlanet.CenterOfMassPosition;
1204 _flatPlanet.Translate(_vDebugTranslation); 1278 _flatPlanet.Translate(_vDebugTranslation);
1205 parent_scene.ddWorld.AddRigidBody(_flatPlanet); 1279 parent_scene.ddWorld.AddRigidBody(_flatPlanet);
1206 } 1280 }
1207 catch (Exception ex) 1281 catch (Exception ex)
1208 { 1282 {
1209 this._parentscene.BulletXMessage(ex.Message, true); 1283 _parentscene.BulletXMessage(ex.Message, true);
1210 } 1284 }
1211 } 1285 }
1212 this._parentscene.BulletXMessage("BulletXPlanet created.", false); 1286 _parentscene.BulletXMessage("BulletXPlanet created.", false);
1213 } 1287 }
1214 internal float HeightValue(MonoXnaCompactMaths.Vector3 position) 1288
1289 internal float HeightValue(Vector3 position)
1215 { 1290 {
1216 int li_x, li_y; 1291 int li_x, li_y;
1217 float height; 1292 float height;
1218 li_x = (int)Math.Round(position.X); 1293 li_x = (int) Math.Round(position.X);
1219 if (li_x < 0) li_x = 0; 1294 if (li_x < 0) li_x = 0;
1220 if (li_x >= BulletXScene.MaxXY) li_x = BulletXScene.MaxXY - 1; 1295 if (li_x >= BulletXScene.MaxXY) li_x = BulletXScene.MaxXY - 1;
1221 li_y = (int)Math.Round(position.Y); 1296 li_y = (int) Math.Round(position.Y);
1222 if (li_y < 0) li_y = 0; 1297 if (li_y < 0) li_y = 0;
1223 if (li_y >= BulletXScene.MaxXY) li_y = BulletXScene.MaxXY - 1; 1298 if (li_y >= BulletXScene.MaxXY) li_y = BulletXScene.MaxXY - 1;
1224 1299
1225 height = ((HeightfieldTerrainShape)this._flatPlanet.CollisionShape).getHeightFieldValue(li_x, li_y); 1300 height = ((HeightfieldTerrainShape) _flatPlanet.CollisionShape).getHeightFieldValue(li_x, li_y);
1226 if (height < 0) height = 0; 1301 if (height < 0) height = 0;
1227 else if (height > BulletXScene.MaxZ) height = BulletXScene.MaxZ; 1302 else if (height > BulletXScene.MaxZ) height = BulletXScene.MaxZ;
1228 1303
1229 return height; 1304 return height;
1230 } 1305 }
1231 } 1306 }
1232} 1307} \ No newline at end of file
diff --git a/OpenSim/Region/Physics/Manager/AssemblyInfo.cs b/OpenSim/Region/Physics/Manager/AssemblyInfo.cs
index 2355e91..c213b64 100644
--- a/OpenSim/Region/Physics/Manager/AssemblyInfo.cs
+++ b/OpenSim/Region/Physics/Manager/AssemblyInfo.cs
@@ -27,24 +27,26 @@
27*/ 27*/
28using System.Reflection; 28using System.Reflection;
29using System.Runtime.InteropServices; 29using System.Runtime.InteropServices;
30
30// Information about this assembly is defined by the following 31// Information about this assembly is defined by the following
31// attributes. 32// attributes.
32// 33//
33// change them to the information which is associated with the assembly 34// change them to the information which is associated with the assembly
34// you compile. 35// you compile.
35 36
36[assembly: AssemblyTitle("PhysicsManager")] 37[assembly : AssemblyTitle("PhysicsManager")]
37[assembly: AssemblyDescription("")] 38[assembly : AssemblyDescription("")]
38[assembly: AssemblyConfiguration("")] 39[assembly : AssemblyConfiguration("")]
39[assembly: AssemblyCompany("")] 40[assembly : AssemblyCompany("")]
40[assembly: AssemblyProduct("PhysicsManager")] 41[assembly : AssemblyProduct("PhysicsManager")]
41[assembly: AssemblyCopyright("")] 42[assembly : AssemblyCopyright("")]
42[assembly: AssemblyTrademark("")] 43[assembly : AssemblyTrademark("")]
43[assembly: AssemblyCulture("")] 44[assembly : AssemblyCulture("")]
44 45
45// This sets the default COM visibility of types in the assembly to invisible. 46// This sets the default COM visibility of types in the assembly to invisible.
46// If you need to expose a type to COM, use [ComVisible(true)] on that type. 47// If you need to expose a type to COM, use [ComVisible(true)] on that type.
47[assembly: ComVisible(false)] 48
49[assembly : ComVisible(false)]
48 50
49// The assembly version has following format : 51// The assembly version has following format :
50// 52//
@@ -53,4 +55,4 @@ using System.Runtime.InteropServices;
53// 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
54// numbers with the '*' character (the default): 56// numbers with the '*' character (the default):
55 57
56[assembly: AssemblyVersion("1.0.*")] 58[assembly : AssemblyVersion("1.0.*")] \ No newline at end of file
diff --git a/OpenSim/Region/Physics/Manager/PhysicsActor.cs b/OpenSim/Region/Physics/Manager/PhysicsActor.cs
index 0fa7455..b59c13a 100644
--- a/OpenSim/Region/Physics/Manager/PhysicsActor.cs
+++ b/OpenSim/Region/Physics/Manager/PhysicsActor.cs
@@ -30,7 +30,9 @@ using Axiom.Math;
30namespace OpenSim.Region.Physics.Manager 30namespace OpenSim.Region.Physics.Manager
31{ 31{
32 public delegate void PositionUpdate(PhysicsVector position); 32 public delegate void PositionUpdate(PhysicsVector position);
33
33 public delegate void VelocityUpdate(PhysicsVector velocity); 34 public delegate void VelocityUpdate(PhysicsVector velocity);
35
34 public delegate void OrientationUpdate(Quaternion orientation); 36 public delegate void OrientationUpdate(Quaternion orientation);
35 37
36 public abstract class PhysicsActor 38 public abstract class PhysicsActor
@@ -43,52 +45,22 @@ namespace OpenSim.Region.Physics.Manager
43 45
44 public static PhysicsActor Null 46 public static PhysicsActor Null
45 { 47 {
46 get 48 get { return new NullPhysicsActor(); }
47 {
48 return new NullPhysicsActor();
49 }
50 } 49 }
51 50
52 public abstract PhysicsVector Size 51 public abstract PhysicsVector Size { get; set; }
53 {
54 get;
55 set;
56 }
57 52
58 public abstract PhysicsVector Position 53 public abstract PhysicsVector Position { get; set; }
59 {
60 get;
61 set;
62 }
63 54
64 public abstract PhysicsVector Velocity 55 public abstract PhysicsVector Velocity { get; set; }
65 {
66 get;
67 set;
68 }
69 56
70 public abstract PhysicsVector Acceleration 57 public abstract PhysicsVector Acceleration { get; }
71 {
72 get;
73 }
74 58
75 public abstract Quaternion Orientation 59 public abstract Quaternion Orientation { get; set; }
76 {
77 get;
78 set;
79 }
80 60
81 public abstract bool Flying 61 public abstract bool Flying { get; set; }
82 {
83 get;
84 set;
85 }
86 62
87 public abstract bool Kinematic 63 public abstract bool Kinematic { get; set; }
88 {
89 get;
90 set;
91 }
92 64
93 public abstract void AddForce(PhysicsVector force); 65 public abstract void AddForce(PhysicsVector force);
94 66
@@ -99,50 +71,26 @@ namespace OpenSim.Region.Physics.Manager
99 { 71 {
100 public override PhysicsVector Position 72 public override PhysicsVector Position
101 { 73 {
102 get 74 get { return PhysicsVector.Zero; }
103 { 75 set { return; }
104 return PhysicsVector.Zero;
105 }
106 set
107 {
108 return;
109 }
110 } 76 }
111 77
112 public override PhysicsVector Size 78 public override PhysicsVector Size
113 { 79 {
114 get 80 get { return PhysicsVector.Zero; }
115 { 81 set { return; }
116 return PhysicsVector.Zero;
117 }
118 set
119 {
120 return;
121 }
122 } 82 }
123 83
124 public override PhysicsVector Velocity 84 public override PhysicsVector Velocity
125 { 85 {
126 get 86 get { return PhysicsVector.Zero; }
127 { 87 set { return; }
128 return PhysicsVector.Zero;
129 }
130 set
131 {
132 return;
133 }
134 } 88 }
135 89
136 public override Quaternion Orientation 90 public override Quaternion Orientation
137 { 91 {
138 get 92 get { return Quaternion.Identity; }
139 { 93 set { }
140 return Quaternion.Identity;
141 }
142 set
143 {
144
145 }
146 } 94 }
147 95
148 public override PhysicsVector Acceleration 96 public override PhysicsVector Acceleration
@@ -152,26 +100,14 @@ namespace OpenSim.Region.Physics.Manager
152 100
153 public override bool Flying 101 public override bool Flying
154 { 102 {
155 get 103 get { return false; }
156 { 104 set { return; }
157 return false;
158 }
159 set
160 {
161 return;
162 }
163 } 105 }
164 106
165 public override bool Kinematic 107 public override bool Kinematic
166 { 108 {
167 get 109 get { return true; }
168 { 110 set { return; }
169 return true;
170 }
171 set
172 {
173 return;
174 }
175 } 111 }
176 112
177 public override void AddForce(PhysicsVector force) 113 public override void AddForce(PhysicsVector force)
@@ -184,4 +120,4 @@ namespace OpenSim.Region.Physics.Manager
184 return; 120 return;
185 } 121 }
186 } 122 }
187} 123} \ No newline at end of file
diff --git a/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs b/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs
index 81bc938..09ebf29 100644
--- a/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs
+++ b/OpenSim/Region/Physics/Manager/PhysicsPluginManager.cs
@@ -33,77 +33,77 @@ using OpenSim.Framework.Console;
33 33
34namespace OpenSim.Region.Physics.Manager 34namespace OpenSim.Region.Physics.Manager
35{ 35{
36 /// <summary> 36 /// <summary>
37 /// Description of MyClass. 37 /// Description of MyClass.
38 /// </summary> 38 /// </summary>
39 public class PhysicsPluginManager 39 public class PhysicsPluginManager
40 { 40 {
41 private Dictionary<string, IPhysicsPlugin> _plugins=new Dictionary<string, IPhysicsPlugin>(); 41 private Dictionary<string, IPhysicsPlugin> _plugins = new Dictionary<string, IPhysicsPlugin>();
42 42
43 public PhysicsPluginManager() 43 public PhysicsPluginManager()
44 { 44 {
45 45 }
46 } 46
47 47 public PhysicsScene GetPhysicsScene(string engineName)
48 public PhysicsScene GetPhysicsScene(string engineName) 48 {
49 {
50 if (String.IsNullOrEmpty(engineName)) 49 if (String.IsNullOrEmpty(engineName))
51 { 50 {
52 return PhysicsScene.Null; 51 return PhysicsScene.Null;
53 } 52 }
54 53
55 if(_plugins.ContainsKey(engineName)) 54 if (_plugins.ContainsKey(engineName))
56 { 55 {
57 MainLog.Instance.Verbose("PHYSICS","creating "+engineName); 56 MainLog.Instance.Verbose("PHYSICS", "creating " + engineName);
58 return _plugins[engineName].GetScene(); 57 return _plugins[engineName].GetScene();
59 } 58 }
60 else 59 else
61 { 60 {
62 MainLog.Instance.Warn("PHYSICS", "couldn't find physicsEngine: {0}", engineName); 61 MainLog.Instance.Warn("PHYSICS", "couldn't find physicsEngine: {0}", engineName);
63 throw new ArgumentException(String.Format("couldn't find physicsEngine: {0}",engineName)); 62 throw new ArgumentException(String.Format("couldn't find physicsEngine: {0}", engineName));
64 } 63 }
65 } 64 }
66 65
67 public void LoadPlugins() 66 public void LoadPlugins()
68 { 67 {
69 string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory ,"Physics"); 68 string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Physics");
70 string[] pluginFiles = Directory.GetFiles(path, "*.dll"); 69 string[] pluginFiles = Directory.GetFiles(path, "*.dll");
71 70
72 71
73 for(int i= 0; i<pluginFiles.Length; i++) 72 for (int i = 0; i < pluginFiles.Length; i++)
74 { 73 {
75 this.AddPlugin(pluginFiles[i]); 74 AddPlugin(pluginFiles[i]);
76 } 75 }
77 } 76 }
78 77
79 private void AddPlugin(string FileName) 78 private void AddPlugin(string FileName)
80 { 79 {
81 Assembly pluginAssembly = Assembly.LoadFrom(FileName); 80 Assembly pluginAssembly = Assembly.LoadFrom(FileName);
82 81
83 foreach (Type pluginType in pluginAssembly.GetTypes()) 82 foreach (Type pluginType in pluginAssembly.GetTypes())
84 { 83 {
85 if (pluginType.IsPublic) 84 if (pluginType.IsPublic)
86 { 85 {
87 if (!pluginType.IsAbstract) 86 if (!pluginType.IsAbstract)
88 { 87 {
89 Type typeInterface = pluginType.GetInterface("IPhysicsPlugin", true); 88 Type typeInterface = pluginType.GetInterface("IPhysicsPlugin", true);
90 89
91 if (typeInterface != null) 90 if (typeInterface != null)
92 { 91 {
93 IPhysicsPlugin plug = (IPhysicsPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); 92 IPhysicsPlugin plug =
94 plug.Init(); 93 (IPhysicsPlugin) Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
95 this._plugins.Add(plug.GetName(),plug); 94 plug.Init();
96 OpenSim.Framework.Console.MainLog.Instance.Verbose("PHYSICS","Added physics engine: " + plug.GetName()); 95 _plugins.Add(plug.GetName(), plug);
97 96 MainLog.Instance.Verbose("PHYSICS", "Added physics engine: " + plug.GetName());
98 } 97 }
99 98
100 typeInterface = null; 99 typeInterface = null;
101 } 100 }
102 } 101 }
103 } 102 }
104 103
105 pluginAssembly = null; 104 pluginAssembly = null;
106 } 105 }
106
107 //--- 107 //---
108 public static void PhysicsPluginMessage(string message, bool isWarning) 108 public static void PhysicsPluginMessage(string message, bool isWarning)
109 { 109 {
@@ -116,14 +116,15 @@ namespace OpenSim.Region.Physics.Manager
116 MainLog.Instance.Verbose("PHYSICS", message); 116 MainLog.Instance.Verbose("PHYSICS", message);
117 } 117 }
118 } 118 }
119
119 //--- 120 //---
120 } 121 }
121 122
122 public interface IPhysicsPlugin 123 public interface IPhysicsPlugin
123 { 124 {
124 bool Init(); 125 bool Init();
125 PhysicsScene GetScene(); 126 PhysicsScene GetScene();
126 string GetName(); 127 string GetName();
127 void Dispose(); 128 void Dispose();
128 } 129 }
129} 130} \ No newline at end of file
diff --git a/OpenSim/Region/Physics/Manager/PhysicsScene.cs b/OpenSim/Region/Physics/Manager/PhysicsScene.cs
index 9ab2997..3f08234 100644
--- a/OpenSim/Region/Physics/Manager/PhysicsScene.cs
+++ b/OpenSim/Region/Physics/Manager/PhysicsScene.cs
@@ -25,9 +25,9 @@
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*/
28using Axiom.Math;
28using OpenSim.Framework; 29using OpenSim.Framework;
29using OpenSim.Framework.Console; 30using OpenSim.Framework.Console;
30using Axiom.Math;
31 31
32namespace OpenSim.Region.Physics.Manager 32namespace OpenSim.Region.Physics.Manager
33{ 33{
@@ -35,10 +35,7 @@ namespace OpenSim.Region.Physics.Manager
35 { 35 {
36 public static PhysicsScene Null 36 public static PhysicsScene Null
37 { 37 {
38 get 38 get { return new NullPhysicsScene(); }
39 {
40 return new NullPhysicsScene();
41 }
42 } 39 }
43 40
44 public abstract PhysicsActor AddAvatar(string avName, PhysicsVector position); 41 public abstract PhysicsActor AddAvatar(string avName, PhysicsVector position);
@@ -47,7 +44,8 @@ namespace OpenSim.Region.Physics.Manager
47 44
48 public abstract void RemovePrim(PhysicsActor prim); 45 public abstract void RemovePrim(PhysicsActor prim);
49 46
50 public abstract PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, PhysicsVector size, Quaternion rotation); 47 public abstract PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position,
48 PhysicsVector size, Quaternion rotation);
51 49
52 public abstract void Simulate(float timeStep); 50 public abstract void Simulate(float timeStep);
53 51
@@ -57,10 +55,7 @@ namespace OpenSim.Region.Physics.Manager
57 55
58 public abstract void DeleteTerrain(); 56 public abstract void DeleteTerrain();
59 57
60 public abstract bool IsThreaded 58 public abstract bool IsThreaded { get; }
61 {
62 get;
63 }
64 59
65 private class NullPhysicsScene : PhysicsScene 60 private class NullPhysicsScene : PhysicsScene
66 { 61 {
@@ -74,12 +69,10 @@ namespace OpenSim.Region.Physics.Manager
74 69
75 public override void RemoveAvatar(PhysicsActor actor) 70 public override void RemoveAvatar(PhysicsActor actor)
76 { 71 {
77
78 } 72 }
79 73
80 public override void RemovePrim(PhysicsActor prim) 74 public override void RemovePrim(PhysicsActor prim)
81 { 75 {
82
83 } 76 }
84 77
85/* 78/*
@@ -89,7 +82,9 @@ namespace OpenSim.Region.Physics.Manager
89 return PhysicsActor.Null; 82 return PhysicsActor.Null;
90 } 83 }
91*/ 84*/
92 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, PhysicsVector size, Quaternion rotation) 85
86 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position,
87 PhysicsVector size, Quaternion rotation)
93 { 88 {
94 MainLog.Instance.Verbose("NullPhysicsScene : AddPrim({0},{1})", position, size); 89 MainLog.Instance.Verbose("NullPhysicsScene : AddPrim({0},{1})", position, size);
95 return PhysicsActor.Null; 90 return PhysicsActor.Null;
@@ -97,7 +92,7 @@ namespace OpenSim.Region.Physics.Manager
97 92
98 public override void Simulate(float timeStep) 93 public override void Simulate(float timeStep)
99 { 94 {
100 m_workIndicator = (m_workIndicator + 1) % 10; 95 m_workIndicator = (m_workIndicator + 1)%10;
101 96
102 //OpenSim.Framework.Console.MainLog.Instance.SetStatus(m_workIndicator.ToString()); 97 //OpenSim.Framework.Console.MainLog.Instance.SetStatus(m_workIndicator.ToString());
103 } 98 }
@@ -114,7 +109,6 @@ namespace OpenSim.Region.Physics.Manager
114 109
115 public override void DeleteTerrain() 110 public override void DeleteTerrain()
116 { 111 {
117
118 } 112 }
119 113
120 public override bool IsThreaded 114 public override bool IsThreaded
@@ -123,4 +117,4 @@ namespace OpenSim.Region.Physics.Manager
123 } 117 }
124 } 118 }
125 } 119 }
126} 120} \ No newline at end of file
diff --git a/OpenSim/Region/Physics/Manager/PhysicsVector.cs b/OpenSim/Region/Physics/Manager/PhysicsVector.cs
index 722c5dd..7de37e4 100644
--- a/OpenSim/Region/Physics/Manager/PhysicsVector.cs
+++ b/OpenSim/Region/Physics/Manager/PhysicsVector.cs
@@ -35,7 +35,6 @@ namespace OpenSim.Region.Physics.Manager
35 35
36 public PhysicsVector() 36 public PhysicsVector()
37 { 37 {
38
39 } 38 }
40 39
41 public PhysicsVector(float x, float y, float z) 40 public PhysicsVector(float x, float y, float z)
@@ -49,7 +48,7 @@ namespace OpenSim.Region.Physics.Manager
49 48
50 public override string ToString() 49 public override string ToString()
51 { 50 {
52 return "<" + this.X + "," + this.Y + "," + this.Z + ">"; 51 return "<" + X + "," + Y + "," + Z + ">";
53 } 52 }
54 } 53 }
55} 54} \ No newline at end of file
diff --git a/OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs b/OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs
index 3f840cc..d110a17 100644
--- a/OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs
+++ b/OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs
@@ -27,24 +27,26 @@
27*/ 27*/
28using System.Reflection; 28using System.Reflection;
29using System.Runtime.InteropServices; 29using System.Runtime.InteropServices;
30
30// Information about this assembly is defined by the following 31// Information about this assembly is defined by the following
31// attributes. 32// attributes.
32// 33//
33// change them to the information which is associated with the assembly 34// change them to the information which is associated with the assembly
34// you compile. 35// you compile.
35 36
36[assembly: AssemblyTitle("RealPhysXplugin")] 37[assembly : AssemblyTitle("RealPhysXplugin")]
37[assembly: AssemblyDescription("")] 38[assembly : AssemblyDescription("")]
38[assembly: AssemblyConfiguration("")] 39[assembly : AssemblyConfiguration("")]
39[assembly: AssemblyCompany("")] 40[assembly : AssemblyCompany("")]
40[assembly: AssemblyProduct("RealPhysXplugin")] 41[assembly : AssemblyProduct("RealPhysXplugin")]
41[assembly: AssemblyCopyright("")] 42[assembly : AssemblyCopyright("")]
42[assembly: AssemblyTrademark("")] 43[assembly : AssemblyTrademark("")]
43[assembly: AssemblyCulture("")] 44[assembly : AssemblyCulture("")]
44 45
45// This sets the default COM visibility of types in the assembly to invisible. 46// This sets the default COM visibility of types in the assembly to invisible.
46// If you need to expose a type to COM, use [ComVisible(true)] on that type. 47// If you need to expose a type to COM, use [ComVisible(true)] on that type.
47[assembly: ComVisible(false)] 48
49[assembly : ComVisible(false)]
48 50
49// The assembly version has following format : 51// The assembly version has following format :
50// 52//
@@ -53,4 +55,4 @@ using System.Runtime.InteropServices;
53// 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
54// numbers with the '*' character (the default): 56// numbers with the '*' character (the default):
55 57
56[assembly: AssemblyVersion("1.0.*")] 58[assembly : AssemblyVersion("1.0.*")] \ No newline at end of file
diff --git a/OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs b/OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs
index 2ace097..13184e2 100644
--- a/OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs
+++ b/OpenSim/Region/Physics/OdePlugin/Meshing/HelperTypes.cs
@@ -27,10 +27,9 @@
27*/ 27*/
28 28
29using System; 29using System;
30using System.Globalization;
31using System.Diagnostics;
32using System.Collections.Generic; 30using System.Collections.Generic;
33 31using System.Diagnostics;
32using System.Globalization;
34using OpenSim.Region.Physics.Manager; 33using OpenSim.Region.Physics.Manager;
35 34
36public class Vertex : IComparable<Vertex> 35public class Vertex : IComparable<Vertex>
@@ -76,8 +75,6 @@ public class Vertex : IComparable<Vertex>
76 { 75 {
77 return me.CompareTo(other) < 0; 76 return me.CompareTo(other) < 0;
78 } 77 }
79
80
81} 78}
82 79
83public class Simplex : IComparable<Simplex> 80public class Simplex : IComparable<Simplex>
@@ -122,8 +119,7 @@ public class Simplex : IComparable<Simplex>
122 119
123 return 0; 120 return 0;
124 } 121 }
125 122} ;
126};
127 123
128public class Triangle 124public class Triangle
129{ 125{
@@ -131,9 +127,9 @@ public class Triangle
131 public Vertex v2; 127 public Vertex v2;
132 public Vertex v3; 128 public Vertex v3;
133 129
134 float radius_square; 130 private float radius_square;
135 float cx; 131 private float cx;
136 float cy; 132 private float cy;
137 133
138 public Triangle(Vertex _v1, Vertex _v2, Vertex _v3) 134 public Triangle(Vertex _v1, Vertex _v2, Vertex _v3)
139 { 135 {
@@ -149,18 +145,18 @@ public class Triangle
149 float dx, dy; 145 float dx, dy;
150 float dd; 146 float dd;
151 147
152 dx = x - this.cx; 148 dx = x - cx;
153 dy = y - this.cy; 149 dy = y - cy;
154 150
155 dd = dx * dx + dy * dy; 151 dd = dx*dx + dy*dy;
156 if (dd < this.radius_square) 152 if (dd < radius_square)
157 return true; 153 return true;
158 else 154 else
159 return false; 155 return false;
160 } 156 }
161 157
162 158
163 void CalcCircle() 159 private void CalcCircle()
164 { 160 {
165 // Calculate the center and the radius of a circle given by three points p1, p2, p3 161 // Calculate the center and the radius of a circle given by three points p1, p2, p3
166 // It is assumed, that the triangles vertices are already set correctly 162 // It is assumed, that the triangles vertices are already set correctly
@@ -198,8 +194,8 @@ public class Triangle
198 p3y = v3.point.Y; 194 p3y = v3.point.Y;
199 195
200 /* calc helping values first */ 196 /* calc helping values first */
201 c1 = (p1x * p1x + p1y * p1y - p2x * p2x - p2y * p2y) / 2; 197 c1 = (p1x*p1x + p1y*p1y - p2x*p2x - p2y*p2y)/2;
202 c2 = (p1x * p1x + p1y * p1y - p3x * p3x - p3y * p3y) / 2; 198 c2 = (p1x*p1x + p1y*p1y - p3x*p3x - p3y*p3y)/2;
203 199
204 v1x = p1x - p2x; 200 v1x = p1x - p2x;
205 v1y = p1y - p2y; 201 v1y = p1y - p2y;
@@ -207,35 +203,34 @@ public class Triangle
207 v2x = p1x - p3x; 203 v2x = p1x - p3x;
208 v2y = p1y - p3y; 204 v2y = p1y - p3y;
209 205
210 z = (c1 * v2x - c2 * v1x); 206 z = (c1*v2x - c2*v1x);
211 n = (v1y * v2x - v2y * v1x); 207 n = (v1y*v2x - v2y*v1x);
212 208
213 if (n == 0.0) // This is no triangle, i.e there are (at least) two points at the same location 209 if (n == 0.0) // This is no triangle, i.e there are (at least) two points at the same location
214 { 210 {
215 radius_square = 0.0f; 211 radius_square = 0.0f;
216 return; 212 return;
217 } 213 }
218 214
219 this.cy = (float)(z / n); 215 cy = (float) (z/n);
220 216
221 if (v2x != 0.0) 217 if (v2x != 0.0)
222 { 218 {
223 this.cx = (float)((c2 - v2y * this.cy) / v2x); 219 cx = (float) ((c2 - v2y*cy)/v2x);
224 } 220 }
225 else if (v1x != 0.0) 221 else if (v1x != 0.0)
226 { 222 {
227 this.cx = (float)((c1 - v1y * this.cy) / v1x); 223 cx = (float) ((c1 - v1y*cy)/v1x);
228 } 224 }
229 else 225 else
230 { 226 {
231 Debug.Assert(false, "Malformed triangle"); /* Both terms zero means nothing good */ 227 Debug.Assert(false, "Malformed triangle"); /* Both terms zero means nothing good */
232 } 228 }
233 229
234 rx = (p1x - this.cx); 230 rx = (p1x - cx);
235 ry = (p1y - this.cy); 231 ry = (p1y - cy);
236
237 this.radius_square = (float)(rx * rx + ry * ry);
238 232
233 radius_square = (float) (rx*rx + ry*ry);
239 } 234 }
240 235
241 public List<Simplex> GetSimplices() 236 public List<Simplex> GetSimplices()
@@ -254,17 +249,18 @@ public class Triangle
254 249
255 public override String ToString() 250 public override String ToString()
256 { 251 {
257
258 NumberFormatInfo nfi = new NumberFormatInfo(); 252 NumberFormatInfo nfi = new NumberFormatInfo();
259 nfi.CurrencyDecimalDigits = 2; 253 nfi.CurrencyDecimalDigits = 2;
260 nfi.CurrencyDecimalSeparator = "."; 254 nfi.CurrencyDecimalSeparator = ".";
261 255
262 String s1 = "<" + v1.point.X.ToString(nfi) + "," + v1.point.Y.ToString(nfi) + "," + v1.point.Z.ToString(nfi) + ">"; 256 String s1 = "<" + v1.point.X.ToString(nfi) + "," + v1.point.Y.ToString(nfi) + "," + v1.point.Z.ToString(nfi) +
263 String s2 = "<" + v2.point.X.ToString(nfi) + "," + v2.point.Y.ToString(nfi) + "," + v2.point.Z.ToString(nfi) + ">"; 257 ">";
264 String s3 = "<" + v3.point.X.ToString(nfi) + "," + v3.point.Y.ToString(nfi) + "," + v3.point.Z.ToString(nfi) + ">"; 258 String s2 = "<" + v2.point.X.ToString(nfi) + "," + v2.point.Y.ToString(nfi) + "," + v2.point.Z.ToString(nfi) +
259 ">";
260 String s3 = "<" + v3.point.X.ToString(nfi) + "," + v3.point.Y.ToString(nfi) + "," + v3.point.Z.ToString(nfi) +
261 ">";
265 262
266 return s1 + ";" + s2 + ";" + s3; 263 return s1 + ";" + s2 + ";" + s3;
267
268 } 264 }
269 265
270 public PhysicsVector getNormal() 266 public PhysicsVector getNormal()
@@ -281,12 +277,12 @@ public class Triangle
281 // Cross product for normal 277 // Cross product for normal
282 PhysicsVector n = new PhysicsVector(); 278 PhysicsVector n = new PhysicsVector();
283 float nx, ny, nz; 279 float nx, ny, nz;
284 n.X = e1.Y * e2.Z - e1.Z * e2.Y; 280 n.X = e1.Y*e2.Z - e1.Z*e2.Y;
285 n.Y = e1.Z * e2.X - e1.X * e2.Z; 281 n.Y = e1.Z*e2.X - e1.X*e2.Z;
286 n.Z = e1.X * e2.Y - e1.Y * e2.X; 282 n.Z = e1.X*e2.Y - e1.Y*e2.X;
287 283
288 // Length 284 // Length
289 float l = (float)Math.Sqrt(n.X * n.X + n.Y * n.Y + n.Z * n.Z); 285 float l = (float) Math.Sqrt(n.X*n.X + n.Y*n.Y + n.Z*n.Z);
290 286
291 // Normalized "normal" 287 // Normalized "normal"
292 n.X /= l; 288 n.X /= l;
@@ -303,6 +299,4 @@ public class Triangle
303 v1 = v2; 299 v1 = v2;
304 v2 = vt; 300 v2 = vt;
305 } 301 }
306} 302} \ No newline at end of file
307
308
diff --git a/OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs b/OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs
index dd18e24..46de15e 100644
--- a/OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs
+++ b/OpenSim/Region/Physics/OdePlugin/Meshing/Meshmerizer.cs
@@ -27,12 +27,8 @@
27*/ 27*/
28 28
29using System; 29using System;
30using System.Globalization;
31using System.Diagnostics;
32using System.Collections.Generic; 30using System.Collections.Generic;
33using System.Text;
34using System.Runtime.InteropServices; 31using System.Runtime.InteropServices;
35
36using OpenSim.Framework; 32using OpenSim.Framework;
37using OpenSim.Region.Physics.Manager; 33using OpenSim.Region.Physics.Manager;
38 34
@@ -75,14 +71,14 @@ namespace OpenSim.Region.Physics.OdePlugin
75 71
76 public float[] getVertexListAsFloat() 72 public float[] getVertexListAsFloat()
77 { 73 {
78 float[] result = new float[vertices.Count * 3]; 74 float[] result = new float[vertices.Count*3];
79 for (int i = 0; i < vertices.Count; i++) 75 for (int i = 0; i < vertices.Count; i++)
80 { 76 {
81 Vertex v = vertices[i]; 77 Vertex v = vertices[i];
82 PhysicsVector point = v.point; 78 PhysicsVector point = v.point;
83 result[3 * i + 0] = point.X; 79 result[3*i + 0] = point.X;
84 result[3 * i + 1] = point.Y; 80 result[3*i + 1] = point.Y;
85 result[3 * i + 2] = point.Z; 81 result[3*i + 2] = point.Z;
86 } 82 }
87 GCHandle.Alloc(result, GCHandleType.Pinned); 83 GCHandle.Alloc(result, GCHandleType.Pinned);
88 return result; 84 return result;
@@ -90,13 +86,13 @@ namespace OpenSim.Region.Physics.OdePlugin
90 86
91 public int[] getIndexListAsInt() 87 public int[] getIndexListAsInt()
92 { 88 {
93 int[] result = new int[triangles.Count * 3]; 89 int[] result = new int[triangles.Count*3];
94 for (int i = 0; i < triangles.Count; i++) 90 for (int i = 0; i < triangles.Count; i++)
95 { 91 {
96 Triangle t = triangles[i]; 92 Triangle t = triangles[i];
97 result[3 * i + 0] = vertices.IndexOf(t.v1); 93 result[3*i + 0] = vertices.IndexOf(t.v1);
98 result[3 * i + 1] = vertices.IndexOf(t.v2); 94 result[3*i + 1] = vertices.IndexOf(t.v2);
99 result[3 * i + 2] = vertices.IndexOf(t.v3); 95 result[3*i + 2] = vertices.IndexOf(t.v3);
100 } 96 }
101 GCHandle.Alloc(result, GCHandleType.Pinned); 97 GCHandle.Alloc(result, GCHandleType.Pinned);
102 return result; 98 return result;
@@ -110,16 +106,13 @@ namespace OpenSim.Region.Physics.OdePlugin
110 106
111 foreach (Triangle t in newMesh.triangles) 107 foreach (Triangle t in newMesh.triangles)
112 Add(t); 108 Add(t);
113
114 } 109 }
115 } 110 }
116 111
117 112
118
119 public class Meshmerizer 113 public class Meshmerizer
120 { 114 {
121 115 private static List<Triangle> FindInfluencedTriangles(List<Triangle> triangles, Vertex v)
122 static List<Triangle> FindInfluencedTriangles(List<Triangle> triangles, Vertex v)
123 { 116 {
124 List<Triangle> influenced = new List<Triangle>(); 117 List<Triangle> influenced = new List<Triangle>();
125 foreach (Triangle t in triangles) 118 foreach (Triangle t in triangles)
@@ -133,9 +126,10 @@ namespace OpenSim.Region.Physics.OdePlugin
133 } 126 }
134 return influenced; 127 return influenced;
135 } 128 }
136 129
137 130
138 static void InsertVertices(List<Vertex> vertices, int usedForSeed, List<Triangle> triangles, List<int> innerBorders) 131 private static void InsertVertices(List<Vertex> vertices, int usedForSeed, List<Triangle> triangles,
132 List<int> innerBorders)
139 { 133 {
140 // This is a variant of the delaunay algorithm 134 // This is a variant of the delaunay algorithm
141 // each time a new vertex is inserted, all triangles that are influenced by it are deleted 135 // each time a new vertex is inserted, all triangles that are influenced by it are deleted
@@ -143,7 +137,7 @@ namespace OpenSim.Region.Physics.OdePlugin
143 // It is not very time efficient but easy to implement. 137 // It is not very time efficient but easy to implement.
144 138
145 int iCurrentVertex; 139 int iCurrentVertex;
146 int iMaxVertex=vertices.Count; 140 int iMaxVertex = vertices.Count;
147 for (iCurrentVertex = usedForSeed; iCurrentVertex < iMaxVertex; iCurrentVertex++) 141 for (iCurrentVertex = usedForSeed; iCurrentVertex < iMaxVertex; iCurrentVertex++)
148 { 142 {
149 // Background: A triangle mesh fulfills the delaunay condition if (iff!) 143 // Background: A triangle mesh fulfills the delaunay condition if (iff!)
@@ -154,8 +148,8 @@ namespace OpenSim.Region.Physics.OdePlugin
154 // do not fulfill this condition with respect to the new triangle 148 // do not fulfill this condition with respect to the new triangle
155 149
156 // Find the triangles that are influenced by the new vertex 150 // Find the triangles that are influenced by the new vertex
157 Vertex v=vertices[iCurrentVertex]; 151 Vertex v = vertices[iCurrentVertex];
158 List<Triangle> influencedTriangles=FindInfluencedTriangles(triangles, v); 152 List<Triangle> influencedTriangles = FindInfluencedTriangles(triangles, v);
159 153
160 List<Simplex> simplices = new List<Simplex>(); 154 List<Simplex> simplices = new List<Simplex>();
161 155
@@ -175,10 +169,10 @@ namespace OpenSim.Region.Physics.OdePlugin
175 // Look for duplicate simplices here. 169 // Look for duplicate simplices here.
176 // Remember, they are directly side by side in the list right now 170 // Remember, they are directly side by side in the list right now
177 int iSimplex; 171 int iSimplex;
178 List<Simplex> innerSimplices=new List<Simplex>(); 172 List<Simplex> innerSimplices = new List<Simplex>();
179 for (iSimplex = 1; iSimplex < simplices.Count; iSimplex++) // Startindex=1, so we can refer backwards 173 for (iSimplex = 1; iSimplex < simplices.Count; iSimplex++) // Startindex=1, so we can refer backwards
180 { 174 {
181 if (simplices[iSimplex - 1].CompareTo(simplices[iSimplex])==0) 175 if (simplices[iSimplex - 1].CompareTo(simplices[iSimplex]) == 0)
182 { 176 {
183 innerSimplices.Add(simplices[iSimplex - 1]); 177 innerSimplices.Add(simplices[iSimplex - 1]);
184 innerSimplices.Add(simplices[iSimplex]); 178 innerSimplices.Add(simplices[iSimplex]);
@@ -187,7 +181,7 @@ namespace OpenSim.Region.Physics.OdePlugin
187 181
188 foreach (Simplex s in innerSimplices) 182 foreach (Simplex s in innerSimplices)
189 { 183 {
190 simplices.Remove(s); 184 simplices.Remove(s);
191 } 185 }
192 186
193 // each simplex still in the list belongs to the hull of the region in question 187 // each simplex still in the list belongs to the hull of the region in question
@@ -210,7 +204,7 @@ namespace OpenSim.Region.Physics.OdePlugin
210 foreach (Triangle t in triangles) 204 foreach (Triangle t in triangles)
211 { 205 {
212 if ( 206 if (
213 innerBorders.Contains(vertices.IndexOf(t.v1)) 207 innerBorders.Contains(vertices.IndexOf(t.v1))
214 && innerBorders.Contains(vertices.IndexOf(t.v2)) 208 && innerBorders.Contains(vertices.IndexOf(t.v2))
215 && innerBorders.Contains(vertices.IndexOf(t.v3)) 209 && innerBorders.Contains(vertices.IndexOf(t.v3))
216 ) 210 )
@@ -223,18 +217,18 @@ namespace OpenSim.Region.Physics.OdePlugin
223 } 217 }
224 218
225 219
226 static Mesh CreateBoxMeshX(PrimitiveBaseShape primShape, PhysicsVector size) 220 private static Mesh CreateBoxMeshX(PrimitiveBaseShape primShape, PhysicsVector size)
227 // Builds the x (+ and -) surfaces of a box shaped prim 221 // Builds the x (+ and -) surfaces of a box shaped prim
228 { 222 {
229 UInt16 hollowFactor = primShape.ProfileHollow; 223 UInt16 hollowFactor = primShape.ProfileHollow;
230 Mesh meshMX = new Mesh(); 224 Mesh meshMX = new Mesh();
231 225
232 226
233 // Surface 0, -X 227 // Surface 0, -X
234 meshMX.Add(new Vertex("-X-Y-Z", -size.X / 2.0f, -size.Y / 2.0f, -size.Z / 2.0f)); 228 meshMX.Add(new Vertex("-X-Y-Z", -size.X/2.0f, -size.Y/2.0f, -size.Z/2.0f));
235 meshMX.Add(new Vertex("-X+Y-Z", -size.X / 2.0f, +size.Y / 2.0f, -size.Z / 2.0f)); 229 meshMX.Add(new Vertex("-X+Y-Z", -size.X/2.0f, +size.Y/2.0f, -size.Z/2.0f));
236 meshMX.Add(new Vertex("-X-Y+Z", -size.X / 2.0f, -size.Y / 2.0f, +size.Z / 2.0f)); 230 meshMX.Add(new Vertex("-X-Y+Z", -size.X/2.0f, -size.Y/2.0f, +size.Z/2.0f));
237 meshMX.Add(new Vertex("-X+Y+Z", -size.X / 2.0f, +size.Y / 2.0f, +size.Z / 2.0f)); 231 meshMX.Add(new Vertex("-X+Y+Z", -size.X/2.0f, +size.Y/2.0f, +size.Z/2.0f));
238 232
239 meshMX.Add(new Triangle(meshMX.vertices[0], meshMX.vertices[2], meshMX.vertices[1])); 233 meshMX.Add(new Triangle(meshMX.vertices[0], meshMX.vertices[2], meshMX.vertices[1]));
240 meshMX.Add(new Triangle(meshMX.vertices[1], meshMX.vertices[2], meshMX.vertices[3])); 234 meshMX.Add(new Triangle(meshMX.vertices[1], meshMX.vertices[2], meshMX.vertices[3]));
@@ -242,10 +236,10 @@ namespace OpenSim.Region.Physics.OdePlugin
242 236
243 Mesh meshPX = new Mesh(); 237 Mesh meshPX = new Mesh();
244 // Surface 1, +X 238 // Surface 1, +X
245 meshPX.Add(new Vertex("+X-Y-Z", +size.X / 2.0f, -size.Y / 2.0f, -size.Z / 2.0f)); 239 meshPX.Add(new Vertex("+X-Y-Z", +size.X/2.0f, -size.Y/2.0f, -size.Z/2.0f));
246 meshPX.Add(new Vertex("+X+Y-Z", +size.X / 2.0f, +size.Y / 2.0f, -size.Z / 2.0f)); 240 meshPX.Add(new Vertex("+X+Y-Z", +size.X/2.0f, +size.Y/2.0f, -size.Z/2.0f));
247 meshPX.Add(new Vertex("+X-Y+Z", +size.X / 2.0f, -size.Y / 2.0f, +size.Z / 2.0f)); 241 meshPX.Add(new Vertex("+X-Y+Z", +size.X/2.0f, -size.Y/2.0f, +size.Z/2.0f));
248 meshPX.Add(new Vertex("+X+Y+Z", +size.X / 2.0f, +size.Y / 2.0f, +size.Z / 2.0f)); 242 meshPX.Add(new Vertex("+X+Y+Z", +size.X/2.0f, +size.Y/2.0f, +size.Z/2.0f));
249 243
250 244
251 meshPX.Add(new Triangle(meshPX.vertices[0], meshPX.vertices[1], meshPX.vertices[2])); 245 meshPX.Add(new Triangle(meshPX.vertices[0], meshPX.vertices[1], meshPX.vertices[2]));
@@ -254,17 +248,17 @@ namespace OpenSim.Region.Physics.OdePlugin
254 248
255 if (hollowFactor > 0) 249 if (hollowFactor > 0)
256 { 250 {
257 float hollowFactorF = (float)hollowFactor / (float)50000; 251 float hollowFactorF = (float) hollowFactor/(float) 50000;
258 252
259 Vertex IPP; 253 Vertex IPP;
260 Vertex IPM; 254 Vertex IPM;
261 Vertex IMP; 255 Vertex IMP;
262 Vertex IMM; 256 Vertex IMM;
263 257
264 IPP = new Vertex("Inner-X+Y+Z", -size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, +size.Z / 2.0f); 258 IPP = new Vertex("Inner-X+Y+Z", -size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, +size.Z/2.0f);
265 IPM = new Vertex("Inner-X+Y-Z", -size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, -size.Z / 2.0f); 259 IPM = new Vertex("Inner-X+Y-Z", -size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, -size.Z/2.0f);
266 IMP = new Vertex("Inner-X-Y+Z", -size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, +size.Z / 2.0f); 260 IMP = new Vertex("Inner-X-Y+Z", -size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, +size.Z/2.0f);
267 IMM = new Vertex("Inner-X-Y-Z", -size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, -size.Z / 2.0f); 261 IMM = new Vertex("Inner-X-Y-Z", -size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, -size.Z/2.0f);
268 262
269 meshMX.Add(IPP); 263 meshMX.Add(IPP);
270 meshMX.Add(IPM); 264 meshMX.Add(IPM);
@@ -280,11 +274,10 @@ namespace OpenSim.Region.Physics.OdePlugin
280 } 274 }
281 275
282 276
283 277 IPP = new Vertex("Inner+X+Y+Z", +size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, +size.Z/2.0f);
284 IPP = new Vertex("Inner+X+Y+Z", +size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, +size.Z / 2.0f); 278 IPM = new Vertex("Inner+X+Y-Z", +size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, -size.Z/2.0f);
285 IPM = new Vertex("Inner+X+Y-Z", +size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, -size.Z / 2.0f); 279 IMP = new Vertex("Inner+X-Y+Z", +size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, +size.Z/2.0f);
286 IMP = new Vertex("Inner+X-Y+Z", +size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, +size.Z / 2.0f); 280 IMM = new Vertex("Inner+X-Y-Z", +size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, -size.Z/2.0f);
287 IMM = new Vertex("Inner+X-Y-Z", +size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, -size.Z / 2.0f);
288 281
289 meshPX.Add(IPP); 282 meshPX.Add(IPP);
290 meshPX.Add(IPM); 283 meshPX.Add(IPM);
@@ -308,18 +301,17 @@ namespace OpenSim.Region.Physics.OdePlugin
308 } 301 }
309 302
310 303
311 304 private static Mesh CreateBoxMeshY(PrimitiveBaseShape primShape, PhysicsVector size)
312 static Mesh CreateBoxMeshY(PrimitiveBaseShape primShape, PhysicsVector size) 305 // Builds the y (+ and -) surfaces of a box shaped prim
313 // Builds the y (+ and -) surfaces of a box shaped prim
314 { 306 {
315 UInt16 hollowFactor = primShape.ProfileHollow; 307 UInt16 hollowFactor = primShape.ProfileHollow;
316 308
317 // (M)inus Y 309 // (M)inus Y
318 Mesh MeshMY = new Mesh(); 310 Mesh MeshMY = new Mesh();
319 MeshMY.Add(new Vertex("-X-Y-Z", -size.X / 2.0f, -size.Y / 2.0f, -size.Z / 2.0f)); 311 MeshMY.Add(new Vertex("-X-Y-Z", -size.X/2.0f, -size.Y/2.0f, -size.Z/2.0f));
320 MeshMY.Add(new Vertex("+X-Y-Z", +size.X / 2.0f, -size.Y / 2.0f, -size.Z / 2.0f)); 312 MeshMY.Add(new Vertex("+X-Y-Z", +size.X/2.0f, -size.Y/2.0f, -size.Z/2.0f));
321 MeshMY.Add(new Vertex("-X-Y+Z", -size.X / 2.0f, -size.Y / 2.0f, +size.Z / 2.0f)); 313 MeshMY.Add(new Vertex("-X-Y+Z", -size.X/2.0f, -size.Y/2.0f, +size.Z/2.0f));
322 MeshMY.Add(new Vertex("+X-Y+Z", +size.X / 2.0f, -size.Y / 2.0f, +size.Z / 2.0f)); 314 MeshMY.Add(new Vertex("+X-Y+Z", +size.X/2.0f, -size.Y/2.0f, +size.Z/2.0f));
323 315
324 MeshMY.Add(new Triangle(MeshMY.vertices[0], MeshMY.vertices[1], MeshMY.vertices[2])); 316 MeshMY.Add(new Triangle(MeshMY.vertices[0], MeshMY.vertices[1], MeshMY.vertices[2]));
325 MeshMY.Add(new Triangle(MeshMY.vertices[2], MeshMY.vertices[1], MeshMY.vertices[3])); 317 MeshMY.Add(new Triangle(MeshMY.vertices[2], MeshMY.vertices[1], MeshMY.vertices[3]));
@@ -327,27 +319,27 @@ namespace OpenSim.Region.Physics.OdePlugin
327 // (P)lus Y 319 // (P)lus Y
328 Mesh MeshPY = new Mesh(); 320 Mesh MeshPY = new Mesh();
329 321
330 MeshPY.Add(new Vertex("-X+Y-Z", -size.X / 2.0f, +size.Y / 2.0f, -size.Z / 2.0f)); 322 MeshPY.Add(new Vertex("-X+Y-Z", -size.X/2.0f, +size.Y/2.0f, -size.Z/2.0f));
331 MeshPY.Add(new Vertex("+X+Y-Z", +size.X / 2.0f, +size.Y / 2.0f, -size.Z / 2.0f)); 323 MeshPY.Add(new Vertex("+X+Y-Z", +size.X/2.0f, +size.Y/2.0f, -size.Z/2.0f));
332 MeshPY.Add(new Vertex("-X+Y+Z", -size.X / 2.0f, +size.Y / 2.0f, +size.Z / 2.0f)); 324 MeshPY.Add(new Vertex("-X+Y+Z", -size.X/2.0f, +size.Y/2.0f, +size.Z/2.0f));
333 MeshPY.Add(new Vertex("+X+Y+Z", +size.X / 2.0f, +size.Y / 2.0f, +size.Z / 2.0f)); 325 MeshPY.Add(new Vertex("+X+Y+Z", +size.X/2.0f, +size.Y/2.0f, +size.Z/2.0f));
334 326
335 MeshPY.Add(new Triangle(MeshPY.vertices[1], MeshPY.vertices[0], MeshPY.vertices[2])); 327 MeshPY.Add(new Triangle(MeshPY.vertices[1], MeshPY.vertices[0], MeshPY.vertices[2]));
336 MeshPY.Add(new Triangle(MeshPY.vertices[1], MeshPY.vertices[2], MeshPY.vertices[3])); 328 MeshPY.Add(new Triangle(MeshPY.vertices[1], MeshPY.vertices[2], MeshPY.vertices[3]));
337 329
338 if (hollowFactor > 0) 330 if (hollowFactor > 0)
339 { 331 {
340 float hollowFactorF = (float)hollowFactor / (float)50000; 332 float hollowFactorF = (float) hollowFactor/(float) 50000;
341 333
342 Vertex IPP; 334 Vertex IPP;
343 Vertex IPM; 335 Vertex IPM;
344 Vertex IMP; 336 Vertex IMP;
345 Vertex IMM; 337 Vertex IMM;
346 338
347 IPP = new Vertex("Inner+X-Y+Z", +size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, +size.Z / 2.0f); 339 IPP = new Vertex("Inner+X-Y+Z", +size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, +size.Z/2.0f);
348 IPM = new Vertex("Inner+X-Y-Z", +size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, -size.Z / 2.0f); 340 IPM = new Vertex("Inner+X-Y-Z", +size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, -size.Z/2.0f);
349 IMP = new Vertex("Inner-X-Y+Z", -size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, +size.Z / 2.0f); 341 IMP = new Vertex("Inner-X-Y+Z", -size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, +size.Z/2.0f);
350 IMM = new Vertex("Inner-X-Y-Z", -size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, -size.Z / 2.0f); 342 IMM = new Vertex("Inner-X-Y-Z", -size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, -size.Z/2.0f);
351 343
352 MeshMY.Add(IPP); 344 MeshMY.Add(IPP);
353 MeshMY.Add(IPM); 345 MeshMY.Add(IPM);
@@ -363,11 +355,10 @@ namespace OpenSim.Region.Physics.OdePlugin
363 } 355 }
364 356
365 357
366 358 IPP = new Vertex("Inner+X+Y+Z", +size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, +size.Z/2.0f);
367 IPP = new Vertex("Inner+X+Y+Z", +size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, +size.Z / 2.0f); 359 IPM = new Vertex("Inner+X+Y-Z", +size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, -size.Z/2.0f);
368 IPM=new Vertex("Inner+X+Y-Z", +size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, -size.Z / 2.0f); 360 IMP = new Vertex("Inner-X+Y+Z", -size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, +size.Z/2.0f);
369 IMP=new Vertex("Inner-X+Y+Z", -size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, +size.Z / 2.0f); 361 IMM = new Vertex("Inner-X+Y-Z", -size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, -size.Z/2.0f);
370 IMM=new Vertex("Inner-X+Y-Z", -size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, -size.Z / 2.0f);
371 362
372 MeshPY.Add(IPP); 363 MeshPY.Add(IPP);
373 MeshPY.Add(IPM); 364 MeshPY.Add(IPM);
@@ -381,9 +372,6 @@ namespace OpenSim.Region.Physics.OdePlugin
381 { 372 {
382 PhysicsVector n = t.getNormal(); 373 PhysicsVector n = t.getNormal();
383 } 374 }
384
385
386
387 } 375 }
388 376
389 377
@@ -393,9 +381,9 @@ namespace OpenSim.Region.Physics.OdePlugin
393 381
394 return result; 382 return result;
395 } 383 }
396 384
397 static Mesh CreateBoxMeshZ(PrimitiveBaseShape primShape, PhysicsVector size) 385 private static Mesh CreateBoxMeshZ(PrimitiveBaseShape primShape, PhysicsVector size)
398 // Builds the z (+ and -) surfaces of a box shaped prim 386 // Builds the z (+ and -) surfaces of a box shaped prim
399 { 387 {
400 UInt16 hollowFactor = primShape.ProfileHollow; 388 UInt16 hollowFactor = primShape.ProfileHollow;
401 389
@@ -403,10 +391,10 @@ namespace OpenSim.Region.Physics.OdePlugin
403 // (M)inus Z 391 // (M)inus Z
404 Mesh MZ = new Mesh(); 392 Mesh MZ = new Mesh();
405 393
406 MZ.Add(new Vertex("-X-Y-Z", -size.X / 2.0f, -size.Y / 2.0f, -size.Z / 2.0f)); 394 MZ.Add(new Vertex("-X-Y-Z", -size.X/2.0f, -size.Y/2.0f, -size.Z/2.0f));
407 MZ.Add(new Vertex("+X-Y-Z", +size.X / 2.0f, -size.Y / 2.0f, -size.Z / 2.0f)); 395 MZ.Add(new Vertex("+X-Y-Z", +size.X/2.0f, -size.Y/2.0f, -size.Z/2.0f));
408 MZ.Add(new Vertex("-X+Y-Z", -size.X / 2.0f, +size.Y / 2.0f, -size.Z / 2.0f)); 396 MZ.Add(new Vertex("-X+Y-Z", -size.X/2.0f, +size.Y/2.0f, -size.Z/2.0f));
409 MZ.Add(new Vertex("+X+Y-Z", +size.X / 2.0f, +size.Y / 2.0f, -size.Z / 2.0f)); 397 MZ.Add(new Vertex("+X+Y-Z", +size.X/2.0f, +size.Y/2.0f, -size.Z/2.0f));
410 398
411 399
412 MZ.Add(new Triangle(MZ.vertices[1], MZ.vertices[0], MZ.vertices[2])); 400 MZ.Add(new Triangle(MZ.vertices[1], MZ.vertices[0], MZ.vertices[2]));
@@ -415,10 +403,10 @@ namespace OpenSim.Region.Physics.OdePlugin
415 // (P)lus Z 403 // (P)lus Z
416 Mesh PZ = new Mesh(); 404 Mesh PZ = new Mesh();
417 405
418 PZ.Add(new Vertex("-X-Y+Z", -size.X / 2.0f, -size.Y / 2.0f, 0.0f)); 406 PZ.Add(new Vertex("-X-Y+Z", -size.X/2.0f, -size.Y/2.0f, 0.0f));
419 PZ.Add(new Vertex("+X-Y+Z", +size.X / 2.0f, -size.Y / 2.0f, 0.0f)); 407 PZ.Add(new Vertex("+X-Y+Z", +size.X/2.0f, -size.Y/2.0f, 0.0f));
420 PZ.Add(new Vertex("-X+Y+Z", -size.X / 2.0f, +size.Y / 2.0f, 0.0f)); 408 PZ.Add(new Vertex("-X+Y+Z", -size.X/2.0f, +size.Y/2.0f, 0.0f));
421 PZ.Add(new Vertex("+X+Y+Z", +size.X / 2.0f, +size.Y / 2.0f, 0.0f)); 409 PZ.Add(new Vertex("+X+Y+Z", +size.X/2.0f, +size.Y/2.0f, 0.0f));
422 410
423 // Surface 5, +Z 411 // Surface 5, +Z
424 PZ.Add(new Triangle(PZ.vertices[0], PZ.vertices[1], PZ.vertices[2])); 412 PZ.Add(new Triangle(PZ.vertices[0], PZ.vertices[1], PZ.vertices[2]));
@@ -426,12 +414,12 @@ namespace OpenSim.Region.Physics.OdePlugin
426 414
427 if (hollowFactor > 0) 415 if (hollowFactor > 0)
428 { 416 {
429 float hollowFactorF = (float)hollowFactor / (float)50000; 417 float hollowFactorF = (float) hollowFactor/(float) 50000;
430 418
431 MZ.Add(new Vertex("-X-Y-Z", -size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, 0.0f)); 419 MZ.Add(new Vertex("-X-Y-Z", -size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, 0.0f));
432 MZ.Add(new Vertex("-X+Y-Z", +size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, 0.0f)); 420 MZ.Add(new Vertex("-X+Y-Z", +size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, 0.0f));
433 MZ.Add(new Vertex("-X-Y+Z", -size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, 0.0f)); 421 MZ.Add(new Vertex("-X-Y+Z", -size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, 0.0f));
434 MZ.Add(new Vertex("-X+Y+Z", +size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, 0.0f)); 422 MZ.Add(new Vertex("-X+Y+Z", +size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, 0.0f));
435 423
436 List<int> innerBorders = new List<int>(); 424 List<int> innerBorders = new List<int>();
437 innerBorders.Add(4); 425 innerBorders.Add(4);
@@ -441,10 +429,10 @@ namespace OpenSim.Region.Physics.OdePlugin
441 429
442 InsertVertices(MZ.vertices, 4, MZ.triangles, innerBorders); 430 InsertVertices(MZ.vertices, 4, MZ.triangles, innerBorders);
443 431
444 PZ.Add(new Vertex("-X-Y-Z", -size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, 0.0f)); 432 PZ.Add(new Vertex("-X-Y-Z", -size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, 0.0f));
445 PZ.Add(new Vertex("-X+Y-Z", +size.X * hollowFactorF / 2.0f, -size.Y * hollowFactorF / 2.0f, 0.0f)); 433 PZ.Add(new Vertex("-X+Y-Z", +size.X*hollowFactorF/2.0f, -size.Y*hollowFactorF/2.0f, 0.0f));
446 PZ.Add(new Vertex("-X-Y+Z", -size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, 0.0f)); 434 PZ.Add(new Vertex("-X-Y+Z", -size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, 0.0f));
447 PZ.Add(new Vertex("-X+Y+Z", +size.X * hollowFactorF / 2.0f, +size.Y * hollowFactorF / 2.0f, 0.0f)); 435 PZ.Add(new Vertex("-X+Y+Z", +size.X*hollowFactorF/2.0f, +size.Y*hollowFactorF/2.0f, 0.0f));
448 436
449 innerBorders = new List<int>(); 437 innerBorders = new List<int>();
450 innerBorders.Add(4); 438 innerBorders.Add(4);
@@ -453,16 +441,15 @@ namespace OpenSim.Region.Physics.OdePlugin
453 innerBorders.Add(7); 441 innerBorders.Add(7);
454 442
455 InsertVertices(PZ.vertices, 4, PZ.triangles, innerBorders); 443 InsertVertices(PZ.vertices, 4, PZ.triangles, innerBorders);
456
457 } 444 }
458 445
459 foreach (Vertex v in PZ.vertices) 446 foreach (Vertex v in PZ.vertices)
460 { 447 {
461 v.point.Z = size.Z / 2.0f; 448 v.point.Z = size.Z/2.0f;
462 } 449 }
463 foreach (Vertex v in MZ.vertices) 450 foreach (Vertex v in MZ.vertices)
464 { 451 {
465 v.point.Z = -size.Z / 2.0f; 452 v.point.Z = -size.Z/2.0f;
466 } 453 }
467 454
468 foreach (Triangle t in MZ.triangles) 455 foreach (Triangle t in MZ.triangles)
@@ -486,15 +473,14 @@ namespace OpenSim.Region.Physics.OdePlugin
486 return result; 473 return result;
487 } 474 }
488 475
489 static Mesh CreateBoxMesh(PrimitiveBaseShape primShape, PhysicsVector size) 476 private static Mesh CreateBoxMesh(PrimitiveBaseShape primShape, PhysicsVector size)
490 { 477 {
491 Mesh result = new Mesh(); 478 Mesh result = new Mesh();
492 479
493 480
494 481 Mesh MeshX = CreateBoxMeshX(primShape, size);
495 Mesh MeshX = Meshmerizer.CreateBoxMeshX(primShape, size); 482 Mesh MeshY = CreateBoxMeshY(primShape, size);
496 Mesh MeshY = Meshmerizer.CreateBoxMeshY(primShape, size); 483 Mesh MeshZ = CreateBoxMeshZ(primShape, size);
497 Mesh MeshZ = Meshmerizer.CreateBoxMeshZ(primShape, size);
498 484
499 result.Append(MeshX); 485 result.Append(MeshX);
500 result.Append(MeshY); 486 result.Append(MeshY);
@@ -504,64 +490,63 @@ namespace OpenSim.Region.Physics.OdePlugin
504 } 490 }
505 491
506 492
507 public static void CalcNormals(Mesh mesh) 493 public static void CalcNormals(Mesh mesh)
508 { 494 {
509 int iTriangles = mesh.triangles.Count; 495 int iTriangles = mesh.triangles.Count;
510 496
511 mesh.normals = new float[iTriangles*3]; 497 mesh.normals = new float[iTriangles*3];
512 498
513 int i=0; 499 int i = 0;
514 foreach (Triangle t in mesh.triangles) 500 foreach (Triangle t in mesh.triangles)
515 { 501 {
516
517 float ux, uy, uz; 502 float ux, uy, uz;
518 float vx, vy, vz; 503 float vx, vy, vz;
519 float wx, wy, wz; 504 float wx, wy, wz;
520 505
521 ux = t.v1.point.X; 506 ux = t.v1.point.X;
522 uy = t.v1.point.Y; 507 uy = t.v1.point.Y;
523 uz = t.v1.point.Z; 508 uz = t.v1.point.Z;
524 509
525 vx = t.v2.point.X; 510 vx = t.v2.point.X;
526 vy = t.v2.point.Y; 511 vy = t.v2.point.Y;
527 vz = t.v2.point.Z; 512 vz = t.v2.point.Z;
528 513
529 wx = t.v3.point.X; 514 wx = t.v3.point.X;
530 wy = t.v3.point.Y; 515 wy = t.v3.point.Y;
531 wz = t.v3.point.Z; 516 wz = t.v3.point.Z;
532 517
533 // Vectors for edges 518 // Vectors for edges
534 float e1x, e1y, e1z; 519 float e1x, e1y, e1z;
535 float e2x, e2y, e2z; 520 float e2x, e2y, e2z;
536 521
537 e1x = ux - vx; 522 e1x = ux - vx;
538 e1y = uy - vy; 523 e1y = uy - vy;
539 e1z = uz - vz; 524 e1z = uz - vz;
540 525
541 e2x = ux - wx; 526 e2x = ux - wx;
542 e2y = uy - wy; 527 e2y = uy - wy;
543 e2z = uz - wz; 528 e2z = uz - wz;
544 529
545 530
546 // Cross product for normal 531 // Cross product for normal
547 float nx, ny, nz; 532 float nx, ny, nz;
548 nx = e1y * e2z - e1z * e2y; 533 nx = e1y*e2z - e1z*e2y;
549 ny = e1z * e2x - e1x * e2z; 534 ny = e1z*e2x - e1x*e2z;
550 nz = e1x * e2y - e1y * e2x; 535 nz = e1x*e2y - e1y*e2x;
551 536
552 // Length 537 // Length
553 float l = (float)Math.Sqrt(nx * nx + ny * ny + nz * nz); 538 float l = (float) Math.Sqrt(nx*nx + ny*ny + nz*nz);
554 539
555 // Normalized "normal" 540 // Normalized "normal"
556 nx /= l; 541 nx /= l;
557 ny /= l; 542 ny /= l;
558 nz /= l; 543 nz /= l;
559 544
560 mesh.normals[i] = nx; 545 mesh.normals[i] = nx;
561 mesh.normals[i + 1] = ny; 546 mesh.normals[i + 1] = ny;
562 mesh.normals[i + 2] = nz; 547 mesh.normals[i + 2] = nz;
563 548
564 i+=3; 549 i += 3;
565 } 550 }
566 } 551 }
567 552
@@ -572,18 +557,15 @@ namespace OpenSim.Region.Physics.OdePlugin
572 switch (primShape.ProfileShape) 557 switch (primShape.ProfileShape)
573 { 558 {
574 case ProfileShape.Square: 559 case ProfileShape.Square:
575 mesh=CreateBoxMesh(primShape, size); 560 mesh = CreateBoxMesh(primShape, size);
576 CalcNormals(mesh); 561 CalcNormals(mesh);
577 break; 562 break;
578 default: 563 default:
579 mesh=null; 564 mesh = null;
580 break; 565 break;
581 } 566 }
582 567
583 return mesh; 568 return mesh;
584
585 } 569 }
586 } 570 }
587} 571} \ No newline at end of file
588
589
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
diff --git a/OpenSim/Region/Physics/PhysXPlugin/AssemblyInfo.cs b/OpenSim/Region/Physics/PhysXPlugin/AssemblyInfo.cs
index 3f840cc..d110a17 100644
--- a/OpenSim/Region/Physics/PhysXPlugin/AssemblyInfo.cs
+++ b/OpenSim/Region/Physics/PhysXPlugin/AssemblyInfo.cs
@@ -27,24 +27,26 @@
27*/ 27*/
28using System.Reflection; 28using System.Reflection;
29using System.Runtime.InteropServices; 29using System.Runtime.InteropServices;
30
30// Information about this assembly is defined by the following 31// Information about this assembly is defined by the following
31// attributes. 32// attributes.
32// 33//
33// change them to the information which is associated with the assembly 34// change them to the information which is associated with the assembly
34// you compile. 35// you compile.
35 36
36[assembly: AssemblyTitle("RealPhysXplugin")] 37[assembly : AssemblyTitle("RealPhysXplugin")]
37[assembly: AssemblyDescription("")] 38[assembly : AssemblyDescription("")]
38[assembly: AssemblyConfiguration("")] 39[assembly : AssemblyConfiguration("")]
39[assembly: AssemblyCompany("")] 40[assembly : AssemblyCompany("")]
40[assembly: AssemblyProduct("RealPhysXplugin")] 41[assembly : AssemblyProduct("RealPhysXplugin")]
41[assembly: AssemblyCopyright("")] 42[assembly : AssemblyCopyright("")]
42[assembly: AssemblyTrademark("")] 43[assembly : AssemblyTrademark("")]
43[assembly: AssemblyCulture("")] 44[assembly : AssemblyCulture("")]
44 45
45// This sets the default COM visibility of types in the assembly to invisible. 46// This sets the default COM visibility of types in the assembly to invisible.
46// If you need to expose a type to COM, use [ComVisible(true)] on that type. 47// If you need to expose a type to COM, use [ComVisible(true)] on that type.
47[assembly: ComVisible(false)] 48
49[assembly : ComVisible(false)]
48 50
49// The assembly version has following format : 51// The assembly version has following format :
50// 52//
@@ -53,4 +55,4 @@ using System.Runtime.InteropServices;
53// 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
54// numbers with the '*' character (the default): 56// numbers with the '*' character (the default):
55 57
56[assembly: AssemblyVersion("1.0.*")] 58[assembly : AssemblyVersion("1.0.*")] \ No newline at end of file
diff --git a/OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs b/OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs
index a7cef88..4896359 100644
--- a/OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs
+++ b/OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs
@@ -34,102 +34,99 @@ using Quaternion=Axiom.Math.Quaternion;
34 34
35namespace OpenSim.Region.Physics.PhysXPlugin 35namespace OpenSim.Region.Physics.PhysXPlugin
36{ 36{
37 /// <summary> 37 /// <summary>
38 /// Will be the PhysX plugin but for now will be a very basic physics engine 38 /// Will be the PhysX plugin but for now will be a very basic physics engine
39 /// </summary> 39 /// </summary>
40 public class PhysXPlugin : IPhysicsPlugin 40 public class PhysXPlugin : IPhysicsPlugin
41 { 41 {
42 private PhysXScene _mScene; 42 private PhysXScene _mScene;
43 43
44 public PhysXPlugin() 44 public PhysXPlugin()
45 { 45 {
46 46 }
47 } 47
48 48 public bool Init()
49 public bool Init() 49 {
50 { 50 return true;
51 return true; 51 }
52 } 52
53 53 public PhysicsScene GetScene()
54 public PhysicsScene GetScene() 54 {
55 { 55 if (_mScene == null)
56 if(_mScene == null) 56 {
57 { 57 _mScene = new PhysXScene();
58 _mScene = new PhysXScene(); 58 }
59 } 59 return (_mScene);
60 return(_mScene); 60 }
61 } 61
62 62 public string GetName()
63 public string GetName() 63 {
64 { 64 return ("RealPhysX");
65 return("RealPhysX"); 65 }
66 } 66
67 67 public void Dispose()
68 public void Dispose() 68 {
69 { 69 }
70 70 }
71 } 71
72 } 72 public class PhysXScene : PhysicsScene
73 73 {
74 public class PhysXScene :PhysicsScene 74 private List<PhysXCharacter> _characters = new List<PhysXCharacter>();
75 { 75 private List<PhysXPrim> _prims = new List<PhysXPrim>();
76 private List<PhysXCharacter> _characters = new List<PhysXCharacter>(); 76 private float[] _heightMap = null;
77 private List<PhysXPrim> _prims = new List<PhysXPrim>(); 77 private NxPhysicsSDK mySdk;
78 private float[] _heightMap = null; 78 private NxScene scene;
79 private NxPhysicsSDK mySdk; 79
80 private NxScene scene; 80 public PhysXScene()
81 81 {
82 public PhysXScene() 82 mySdk = NxPhysicsSDK.CreateSDK();
83 { 83 Console.WriteLine("Sdk created - now creating scene");
84 mySdk = NxPhysicsSDK.CreateSDK(); 84 scene = mySdk.CreateScene();
85 Console.WriteLine("Sdk created - now creating scene"); 85 }
86 scene = mySdk.CreateScene(); 86
87 87 public override PhysicsActor AddAvatar(string avName, PhysicsVector position)
88 } 88 {
89 89 Vec3 pos = new Vec3();
90 public override PhysicsActor AddAvatar(string avName, PhysicsVector position) 90 pos.X = position.X;
91 { 91 pos.Y = position.Y;
92 Vec3 pos = new Vec3(); 92 pos.Z = position.Z;
93 pos.X = position.X; 93 PhysXCharacter act = new PhysXCharacter(scene.AddCharacter(pos));
94 pos.Y = position.Y;
95 pos.Z = position.Z;
96 PhysXCharacter act = new PhysXCharacter( scene.AddCharacter(pos));
97 act.Position = position; 94 act.Position = position;
98 _characters.Add(act); 95 _characters.Add(act);
99 return act; 96 return act;
100 } 97 }
101 98
102 public override void RemovePrim(PhysicsActor prim) 99 public override void RemovePrim(PhysicsActor prim)
103 { 100 {
104
105 } 101 }
106 102
107 public override void RemoveAvatar(PhysicsActor actor) 103 public override void RemoveAvatar(PhysicsActor actor)
108 { 104 {
105 }
109 106
107 private PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size, Quaternion rotation)
108 {
109 Vec3 pos = new Vec3();
110 pos.X = position.X;
111 pos.Y = position.Y;
112 pos.Z = position.Z;
113 Vec3 siz = new Vec3();
114 siz.X = size.X;
115 siz.Y = size.Y;
116 siz.Z = size.Z;
117 PhysXPrim act = new PhysXPrim(scene.AddNewBox(pos, siz));
118 _prims.Add(act);
119 return act;
110 } 120 }
111 121
112 PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size, Quaternion rotation) 122 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position,
113 { 123 PhysicsVector size, Quaternion rotation)
114 Vec3 pos = new Vec3();
115 pos.X = position.X;
116 pos.Y = position.Y;
117 pos.Z = position.Z;
118 Vec3 siz = new Vec3();
119 siz.X = size.X;
120 siz.Y = size.Y;
121 siz.Z = size.Z;
122 PhysXPrim act = new PhysXPrim( scene.AddNewBox(pos, siz));
123 _prims.Add(act);
124 return act;
125 }
126 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, PhysicsVector size, Quaternion rotation)
127 { 124 {
128 return AddPrim(position, size, rotation); 125 return AddPrim(position, size, rotation);
129 } 126 }
130 127
131 public override void Simulate(float timeStep) 128 public override void Simulate(float timeStep)
132 { 129 {
133 try 130 try
134 { 131 {
135 foreach (PhysXCharacter actor in _characters) 132 foreach (PhysXCharacter actor in _characters)
@@ -149,309 +146,237 @@ namespace OpenSim.Region.Physics.PhysXPlugin
149 { 146 {
150 Console.WriteLine(e.Message); 147 Console.WriteLine(e.Message);
151 } 148 }
152 149 }
153 } 150
154 151 public override void GetResults()
155 public override void GetResults() 152 {
156 { 153 }
157 154
158 } 155 public override bool IsThreaded
159 156 {
160 public override bool IsThreaded 157 get { return (false); // for now we won't be multithreaded
161 { 158 }
162 get 159 }
163 { 160
164 return(false); // for now we won't be multithreaded 161 public override void SetTerrain(float[] heightMap)
165 } 162 {
166 } 163 if (_heightMap != null)
167
168 public override void SetTerrain(float[] heightMap)
169 {
170 if (this._heightMap != null)
171 { 164 {
172 Console.WriteLine("PhysX - deleting old terrain"); 165 Console.WriteLine("PhysX - deleting old terrain");
173 this.scene.DeleteTerrain(); 166 scene.DeleteTerrain();
174 } 167 }
175 this._heightMap = heightMap; 168 _heightMap = heightMap;
176 this.scene.AddTerrain(heightMap); 169 scene.AddTerrain(heightMap);
177 } 170 }
178 171
179 public override void DeleteTerrain() 172 public override void DeleteTerrain()
180 { 173 {
181 this.scene.DeleteTerrain(); 174 scene.DeleteTerrain();
182 } 175 }
183 } 176 }
184 177
185 public class PhysXCharacter : PhysicsActor 178 public class PhysXCharacter : PhysicsActor
186 { 179 {
187 private PhysicsVector _position; 180 private PhysicsVector _position;
188 private PhysicsVector _velocity; 181 private PhysicsVector _velocity;
189 private PhysicsVector _acceleration; 182 private PhysicsVector _acceleration;
190 private NxCharacter _character; 183 private NxCharacter _character;
191 private bool flying; 184 private bool flying;
192 private float gravityAccel; 185 private float gravityAccel;
193 186
194 public PhysXCharacter(NxCharacter character) 187 public PhysXCharacter(NxCharacter character)
195 { 188 {
196 _velocity = new PhysicsVector(); 189 _velocity = new PhysicsVector();
197 _position = new PhysicsVector(); 190 _position = new PhysicsVector();
198 _acceleration = new PhysicsVector(); 191 _acceleration = new PhysicsVector();
199 _character = character; 192 _character = character;
200 } 193 }
201 194
202 public override bool Flying 195 public override bool Flying
203 { 196 {
204 get 197 get { return flying; }
205 { 198 set { flying = value; }
206 return flying; 199 }
207 } 200
208 set 201 public override PhysicsVector Position
209 { 202 {
210 flying = value; 203 get { return _position; }
211 } 204 set
212 } 205 {
213 206 _position = value;
214 public override PhysicsVector Position
215 {
216 get
217 {
218 return _position;
219 }
220 set
221 {
222 _position = value;
223 Vec3 ps = new Vec3(); 207 Vec3 ps = new Vec3();
224 ps.X = value.X; 208 ps.X = value.X;
225 ps.Y = value.Y; 209 ps.Y = value.Y;
226 ps.Z = value.Z; 210 ps.Z = value.Z;
227 this._character.Position = ps; 211 _character.Position = ps;
228 } 212 }
229 } 213 }
230 214
231 public override PhysicsVector Size 215 public override PhysicsVector Size
232 { 216 {
233 get 217 get { return new PhysicsVector(0, 0, 0); }
218 set { }
219 }
220
221 public override PhysicsVector Velocity
222 {
223 get { return _velocity; }
224 set { _velocity = value; }
225 }
226
227 public override bool Kinematic
228 {
229 get { return false; }
230 set { }
231 }
232
233 public override Quaternion Orientation
234 {
235 get { return Quaternion.Identity; }
236 set { }
237 }
238
239 public override PhysicsVector Acceleration
240 {
241 get { return _acceleration; }
242 }
243
244 public void SetAcceleration(PhysicsVector accel)
245 {
246 _acceleration = accel;
247 }
248
249 public override void AddForce(PhysicsVector force)
250 {
251 }
252
253 public override void SetMomentum(PhysicsVector momentum)
254 {
255 }
256
257 public void Move(float timeStep)
258 {
259 Vec3 vec = new Vec3();
260 vec.X = _velocity.X*timeStep;
261 vec.Y = _velocity.Y*timeStep;
262 if (flying)
234 { 263 {
235 return new PhysicsVector(0,0,0); 264 vec.Z = (_velocity.Z)*timeStep;
236 } 265 }
237 set 266 else
267 {
268 gravityAccel += -9.8f;
269 vec.Z = (gravityAccel + _velocity.Z)*timeStep;
270 }
271 int res = _character.Move(vec);
272 if (res == 1)
238 { 273 {
274 gravityAccel = 0;
239 } 275 }
240 } 276 }
241 public override PhysicsVector Velocity
242 {
243 get
244 {
245 return _velocity;
246 }
247 set
248 {
249 _velocity = value;
250 }
251 }
252
253 public override bool Kinematic
254 {
255 get
256 {
257 return false;
258 }
259 set
260 {
261
262 }
263 }
264
265 public override Quaternion Orientation
266 {
267 get
268 {
269 return Quaternion.Identity;
270 }
271 set
272 {
273
274 }
275 }
276
277 public override PhysicsVector Acceleration
278 {
279 get
280 {
281 return _acceleration;
282 }
283
284 }
285 public void SetAcceleration (PhysicsVector accel)
286 {
287 this._acceleration = accel;
288 }
289
290 public override void AddForce(PhysicsVector force)
291 {
292
293 }
294
295 public override void SetMomentum(PhysicsVector momentum)
296 {
297
298 }
299
300 public void Move(float timeStep)
301 {
302 Vec3 vec = new Vec3();
303 vec.X = this._velocity.X * timeStep;
304 vec.Y = this._velocity.Y * timeStep;
305 if(flying)
306 {
307 vec.Z = ( this._velocity.Z) * timeStep;
308 }
309 else
310 {
311 gravityAccel+= -9.8f;
312 vec.Z = (gravityAccel + this._velocity.Z) * timeStep;
313 }
314 int res = this._character.Move(vec);
315 if(res == 1)
316 {
317 gravityAccel = 0;
318 }
319 }
320
321 public void UpdatePosition()
322 {
323 Vec3 vec = this._character.Position;
324 this._position.X = vec.X;
325 this._position.Y = vec.Y;
326 this._position.Z = vec.Z;
327 }
328 }
329
330 public class PhysXPrim : PhysicsActor
331 {
332 private PhysicsVector _position;
333 private PhysicsVector _velocity;
334 private PhysicsVector _acceleration;
335 private NxActor _prim;
336
337 public PhysXPrim(NxActor prim)
338 {
339 _velocity = new PhysicsVector();
340 _position = new PhysicsVector();
341 _acceleration = new PhysicsVector();
342 _prim = prim;
343 }
344 public override bool Flying
345 {
346 get
347 {
348 return false; //no flying prims for you
349 }
350 set
351 {
352
353 }
354 }
355 public override PhysicsVector Position
356 {
357 get
358 {
359 PhysicsVector pos = new PhysicsVector();
360 Vec3 vec = this._prim.Position;
361 pos.X = vec.X;
362 pos.Y = vec.Y;
363 pos.Z = vec.Z;
364 return pos;
365
366 }
367 set
368 {
369 PhysicsVector vec = value;
370 Vec3 pos = new Vec3();
371 pos.X = vec.X;
372 pos.Y = vec.Y;
373 pos.Z = vec.Z;
374 this._prim.Position = pos;
375 }
376 }
377 277
378 public override PhysicsVector Size 278 public void UpdatePosition()
279 {
280 Vec3 vec = _character.Position;
281 _position.X = vec.X;
282 _position.Y = vec.Y;
283 _position.Z = vec.Z;
284 }
285 }
286
287 public class PhysXPrim : PhysicsActor
288 {
289 private PhysicsVector _position;
290 private PhysicsVector _velocity;
291 private PhysicsVector _acceleration;
292 private NxActor _prim;
293
294 public PhysXPrim(NxActor prim)
295 {
296 _velocity = new PhysicsVector();
297 _position = new PhysicsVector();
298 _acceleration = new PhysicsVector();
299 _prim = prim;
300 }
301
302 public override bool Flying
303 {
304 get { return false; //no flying prims for you
305 }
306 set { }
307 }
308
309 public override PhysicsVector Position
379 { 310 {
380 get 311 get
381 { 312 {
382 return new PhysicsVector(0, 0, 0); 313 PhysicsVector pos = new PhysicsVector();
314 Vec3 vec = _prim.Position;
315 pos.X = vec.X;
316 pos.Y = vec.Y;
317 pos.Z = vec.Z;
318 return pos;
383 } 319 }
384 set 320 set
385 { 321 {
322 PhysicsVector vec = value;
323 Vec3 pos = new Vec3();
324 pos.X = vec.X;
325 pos.Y = vec.Y;
326 pos.Z = vec.Z;
327 _prim.Position = pos;
386 } 328 }
387 } 329 }
388 330
389 public override PhysicsVector Velocity 331 public override PhysicsVector Size
390 { 332 {
391 get 333 get { return new PhysicsVector(0, 0, 0); }
392 { 334 set { }
393 return _velocity; 335 }
394 } 336
395 set 337 public override PhysicsVector Velocity
396 { 338 {
397 _velocity = value; 339 get { return _velocity; }
398 } 340 set { _velocity = value; }
399 } 341 }
400 342
401 public override bool Kinematic 343 public override bool Kinematic
402 { 344 {
403 get 345 get { return _prim.Kinematic; }
404 { 346 set { _prim.Kinematic = value; }
405 return this._prim.Kinematic; 347 }
406 } 348
407 set 349 public override Quaternion Orientation
408 { 350 {
409 this._prim.Kinematic = value; 351 get
410 } 352 {
411 } 353 Quaternion res = new Quaternion();
412 354 PhysXWrapper.Quaternion quat = _prim.GetOrientation();
413 public override Quaternion Orientation 355 res.w = quat.W;
414 { 356 res.x = quat.X;
415 get 357 res.y = quat.Y;
416 { 358 res.z = quat.Z;
417 Quaternion res = new Quaternion(); 359 return res;
418 PhysXWrapper.Quaternion quat = this._prim.GetOrientation(); 360 }
419 res.w = quat.W; 361 set { }
420 res.x = quat.X; 362 }
421 res.y = quat.Y; 363
422 res.z = quat.Z; 364 public override PhysicsVector Acceleration
423 return res; 365 {
424 } 366 get { return _acceleration; }
425 set 367 }
426 { 368
427 369 public void SetAcceleration(PhysicsVector accel)
428 } 370 {
429 } 371 _acceleration = accel;
430 372 }
431 public override PhysicsVector Acceleration 373
432 { 374 public override void AddForce(PhysicsVector force)
433 get 375 {
434 { 376 }
435 return _acceleration; 377
436 } 378 public override void SetMomentum(PhysicsVector momentum)
437 379 {
438 } 380 }
439 public void SetAcceleration (PhysicsVector accel) 381 }
440 { 382} \ No newline at end of file
441 this._acceleration = accel;
442 }
443
444 public override void AddForce(PhysicsVector force)
445 {
446
447 }
448
449 public override void SetMomentum(PhysicsVector momentum)
450 {
451
452 }
453
454
455 }
456
457}