aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs
diff options
context:
space:
mode:
authorlbsa712007-10-30 09:05:31 +0000
committerlbsa712007-10-30 09:05:31 +0000
commit67e12b95ea7b68f4904a7484d77ecfd787d16d0c (patch)
tree20b00d24c8a7617017960432ec044852e3ad5fa9 /OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs
parent* Deleted .user file (diff)
downloadopensim-SC-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.zip
opensim-SC-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.gz
opensim-SC-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.bz2
opensim-SC-67e12b95ea7b68f4904a7484d77ecfd787d16d0c.tar.xz
* Optimized usings
* Shortened type references * Removed redundant 'this' qualifier
Diffstat (limited to 'OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs')
-rw-r--r--OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs643
1 files changed, 284 insertions, 359 deletions
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}