aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs
diff options
context:
space:
mode:
authorSean Dague2007-07-16 15:40:11 +0000
committerSean Dague2007-07-16 15:40:11 +0000
commit2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6 (patch)
treee3f80ad51736cf17e856547b1bcf956010927434 /OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs
parent*Trunk compiles now (diff)
downloadopensim-SC_OLD-2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6.zip
opensim-SC_OLD-2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6.tar.gz
opensim-SC_OLD-2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6.tar.bz2
opensim-SC_OLD-2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6.tar.xz
changed to native line ending encoding
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs850
1 files changed, 425 insertions, 425 deletions
diff --git a/OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs b/OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs
index 4c82549..111d436 100644
--- a/OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs
+++ b/OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs
@@ -1,425 +1,425 @@
1/*/* 1/*/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.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*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
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 System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using OpenSim.Physics.Manager; 30using OpenSim.Physics.Manager;
31using PhysXWrapper; 31using PhysXWrapper;
32using Quaternion=Axiom.Math.Quaternion; 32using Quaternion=Axiom.Math.Quaternion;
33 33
34namespace OpenSim.Region.Physics.PhysXPlugin 34namespace OpenSim.Region.Physics.PhysXPlugin
35{ 35{
36 /// <summary> 36 /// <summary>
37 /// Will be the PhysX plugin but for now will be a very basic physics engine 37 /// Will be the PhysX plugin but for now will be a very basic physics engine
38 /// </summary> 38 /// </summary>
39 public class PhysXPlugin : IPhysicsPlugin 39 public class PhysXPlugin : IPhysicsPlugin
40 { 40 {
41 private PhysXScene _mScene; 41 private PhysXScene _mScene;
42 42
43 public PhysXPlugin() 43 public PhysXPlugin()
44 { 44 {
45 45
46 } 46 }
47 47
48 public bool Init() 48 public bool Init()
49 { 49 {
50 return true; 50 return true;
51 } 51 }
52 52
53 public PhysicsScene GetScene() 53 public PhysicsScene GetScene()
54 { 54 {
55 if(_mScene == null) 55 if(_mScene == null)
56 { 56 {
57 _mScene = new PhysXScene(); 57 _mScene = new PhysXScene();
58 } 58 }
59 return(_mScene); 59 return(_mScene);
60 } 60 }
61 61
62 public string GetName() 62 public string GetName()
63 { 63 {
64 return("RealPhysX"); 64 return("RealPhysX");
65 } 65 }
66 66
67 public void Dispose() 67 public void Dispose()
68 { 68 {
69 69
70 } 70 }
71 } 71 }
72 72
73 public class PhysXScene :PhysicsScene 73 public class PhysXScene :PhysicsScene
74 { 74 {
75 private List<PhysXCharacter> _characters = new List<PhysXCharacter>(); 75 private List<PhysXCharacter> _characters = new List<PhysXCharacter>();
76 private List<PhysXPrim> _prims = new List<PhysXPrim>(); 76 private List<PhysXPrim> _prims = new List<PhysXPrim>();
77 private float[] _heightMap = null; 77 private float[] _heightMap = null;
78 private NxPhysicsSDK mySdk; 78 private NxPhysicsSDK mySdk;
79 private NxScene scene; 79 private NxScene scene;
80 80
81 public PhysXScene() 81 public PhysXScene()
82 { 82 {
83 mySdk = NxPhysicsSDK.CreateSDK(); 83 mySdk = NxPhysicsSDK.CreateSDK();
84 Console.WriteLine("Sdk created - now creating scene"); 84 Console.WriteLine("Sdk created - now creating scene");
85 scene = mySdk.CreateScene(); 85 scene = mySdk.CreateScene();
86 86
87 } 87 }
88 88
89 public override PhysicsActor AddAvatar(PhysicsVector position) 89 public override PhysicsActor AddAvatar(PhysicsVector position)
90 { 90 {
91 Vec3 pos = new Vec3(); 91 Vec3 pos = new Vec3();
92 pos.X = position.X; 92 pos.X = position.X;
93 pos.Y = position.Y; 93 pos.Y = position.Y;
94 pos.Z = position.Z; 94 pos.Z = position.Z;
95 PhysXCharacter act = new PhysXCharacter( scene.AddCharacter(pos)); 95 PhysXCharacter act = new PhysXCharacter( scene.AddCharacter(pos));
96 act.Position = position; 96 act.Position = position;
97 _characters.Add(act); 97 _characters.Add(act);
98 return act; 98 return act;
99 } 99 }
100 100
101 public override void RemoveAvatar(PhysicsActor actor) 101 public override void RemoveAvatar(PhysicsActor actor)
102 { 102 {
103 103
104 } 104 }
105 105
106 public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size) 106 public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size)
107 { 107 {
108 Vec3 pos = new Vec3(); 108 Vec3 pos = new Vec3();
109 pos.X = position.X; 109 pos.X = position.X;
110 pos.Y = position.Y; 110 pos.Y = position.Y;
111 pos.Z = position.Z; 111 pos.Z = position.Z;
112 Vec3 siz = new Vec3(); 112 Vec3 siz = new Vec3();
113 siz.X = size.X; 113 siz.X = size.X;
114 siz.Y = size.Y; 114 siz.Y = size.Y;
115 siz.Z = size.Z; 115 siz.Z = size.Z;
116 PhysXPrim act = new PhysXPrim( scene.AddNewBox(pos, siz)); 116 PhysXPrim act = new PhysXPrim( scene.AddNewBox(pos, siz));
117 _prims.Add(act); 117 _prims.Add(act);
118 return act; 118 return act;
119 } 119 }
120 public override void Simulate(float timeStep) 120 public override void Simulate(float timeStep)
121 { 121 {
122 try 122 try
123 { 123 {
124 foreach (PhysXCharacter actor in _characters) 124 foreach (PhysXCharacter actor in _characters)
125 { 125 {
126 actor.Move(timeStep); 126 actor.Move(timeStep);
127 } 127 }
128 scene.Simulate(timeStep); 128 scene.Simulate(timeStep);
129 scene.FetchResults(); 129 scene.FetchResults();
130 scene.UpdateControllers(); 130 scene.UpdateControllers();
131 131
132 foreach (PhysXCharacter actor in _characters) 132 foreach (PhysXCharacter actor in _characters)
133 { 133 {
134 actor.UpdatePosition(); 134 actor.UpdatePosition();
135 } 135 }
136 } 136 }
137 catch (Exception e) 137 catch (Exception e)
138 { 138 {
139 Console.WriteLine(e.Message); 139 Console.WriteLine(e.Message);
140 } 140 }
141 141
142 } 142 }
143 143
144 public override void GetResults() 144 public override void GetResults()
145 { 145 {
146 146
147 } 147 }
148 148
149 public override bool IsThreaded 149 public override bool IsThreaded
150 { 150 {
151 get 151 get
152 { 152 {
153 return(false); // for now we won't be multithreaded 153 return(false); // for now we won't be multithreaded
154 } 154 }
155 } 155 }
156 156
157 public override void SetTerrain(float[] heightMap) 157 public override void SetTerrain(float[] heightMap)
158 { 158 {
159 if (this._heightMap != null) 159 if (this._heightMap != null)
160 { 160 {
161 Console.WriteLine("PhysX - deleting old terrain"); 161 Console.WriteLine("PhysX - deleting old terrain");
162 this.scene.DeleteTerrain(); 162 this.scene.DeleteTerrain();
163 } 163 }
164 this._heightMap = heightMap; 164 this._heightMap = heightMap;
165 this.scene.AddTerrain(heightMap); 165 this.scene.AddTerrain(heightMap);
166 } 166 }
167 167
168 public override void DeleteTerrain() 168 public override void DeleteTerrain()
169 { 169 {
170 this.scene.DeleteTerrain(); 170 this.scene.DeleteTerrain();
171 } 171 }
172 } 172 }
173 173
174 public class PhysXCharacter : PhysicsActor 174 public class PhysXCharacter : PhysicsActor
175 { 175 {
176 private PhysicsVector _position; 176 private PhysicsVector _position;
177 private PhysicsVector _velocity; 177 private PhysicsVector _velocity;
178 private PhysicsVector _acceleration; 178 private PhysicsVector _acceleration;
179 private NxCharacter _character; 179 private NxCharacter _character;
180 private bool flying; 180 private bool flying;
181 private float gravityAccel; 181 private float gravityAccel;
182 182
183 public PhysXCharacter(NxCharacter character) 183 public PhysXCharacter(NxCharacter character)
184 { 184 {
185 _velocity = new PhysicsVector(); 185 _velocity = new PhysicsVector();
186 _position = new PhysicsVector(); 186 _position = new PhysicsVector();
187 _acceleration = new PhysicsVector(); 187 _acceleration = new PhysicsVector();
188 _character = character; 188 _character = character;
189 } 189 }
190 190
191 public override bool Flying 191 public override bool Flying
192 { 192 {
193 get 193 get
194 { 194 {
195 return flying; 195 return flying;
196 } 196 }
197 set 197 set
198 { 198 {
199 flying = value; 199 flying = value;
200 } 200 }
201 } 201 }
202 202
203 public override PhysicsVector Position 203 public override PhysicsVector Position
204 { 204 {
205 get 205 get
206 { 206 {
207 return _position; 207 return _position;
208 } 208 }
209 set 209 set
210 { 210 {
211 _position = value; 211 _position = value;
212 Vec3 ps = new Vec3(); 212 Vec3 ps = new Vec3();
213 ps.X = value.X; 213 ps.X = value.X;
214 ps.Y = value.Y; 214 ps.Y = value.Y;
215 ps.Z = value.Z; 215 ps.Z = value.Z;
216 this._character.Position = ps; 216 this._character.Position = ps;
217 } 217 }
218 } 218 }
219 219
220 public override PhysicsVector Velocity 220 public override PhysicsVector Velocity
221 { 221 {
222 get 222 get
223 { 223 {
224 return _velocity; 224 return _velocity;
225 } 225 }
226 set 226 set
227 { 227 {
228 _velocity = value; 228 _velocity = value;
229 } 229 }
230 } 230 }
231 231
232 public override bool Kinematic 232 public override bool Kinematic
233 { 233 {
234 get 234 get
235 { 235 {
236 return false; 236 return false;
237 } 237 }
238 set 238 set
239 { 239 {
240 240
241 } 241 }
242 } 242 }
243 243
244 public override Quaternion Orientation 244 public override Quaternion Orientation
245 { 245 {
246 get 246 get
247 { 247 {
248 return Quaternion.Identity; 248 return Quaternion.Identity;
249 } 249 }
250 set 250 set
251 { 251 {
252 252
253 } 253 }
254 } 254 }
255 255
256 public override PhysicsVector Acceleration 256 public override PhysicsVector Acceleration
257 { 257 {
258 get 258 get
259 { 259 {
260 return _acceleration; 260 return _acceleration;
261 } 261 }
262 262
263 } 263 }
264 public void SetAcceleration (PhysicsVector accel) 264 public void SetAcceleration (PhysicsVector accel)
265 { 265 {
266 this._acceleration = accel; 266 this._acceleration = accel;
267 } 267 }
268 268
269 public override void AddForce(PhysicsVector force) 269 public override void AddForce(PhysicsVector force)
270 { 270 {
271 271
272 } 272 }
273 273
274 public override void SetMomentum(PhysicsVector momentum) 274 public override void SetMomentum(PhysicsVector momentum)
275 { 275 {
276 276
277 } 277 }
278 278
279 public void Move(float timeStep) 279 public void Move(float timeStep)
280 { 280 {
281 Vec3 vec = new Vec3(); 281 Vec3 vec = new Vec3();
282 vec.X = this._velocity.X * timeStep; 282 vec.X = this._velocity.X * timeStep;
283 vec.Y = this._velocity.Y * timeStep; 283 vec.Y = this._velocity.Y * timeStep;
284 if(flying) 284 if(flying)
285 { 285 {
286 vec.Z = ( this._velocity.Z) * timeStep; 286 vec.Z = ( this._velocity.Z) * timeStep;
287 } 287 }
288 else 288 else
289 { 289 {
290 gravityAccel+= -9.8f; 290 gravityAccel+= -9.8f;
291 vec.Z = (gravityAccel + this._velocity.Z) * timeStep; 291 vec.Z = (gravityAccel + this._velocity.Z) * timeStep;
292 } 292 }
293 int res = this._character.Move(vec); 293 int res = this._character.Move(vec);
294 if(res == 1) 294 if(res == 1)
295 { 295 {
296 gravityAccel = 0; 296 gravityAccel = 0;
297 } 297 }
298 } 298 }
299 299
300 public void UpdatePosition() 300 public void UpdatePosition()
301 { 301 {
302 Vec3 vec = this._character.Position; 302 Vec3 vec = this._character.Position;
303 this._position.X = vec.X; 303 this._position.X = vec.X;
304 this._position.Y = vec.Y; 304 this._position.Y = vec.Y;
305 this._position.Z = vec.Z; 305 this._position.Z = vec.Z;
306 } 306 }
307 } 307 }
308 308
309 public class PhysXPrim : PhysicsActor 309 public class PhysXPrim : PhysicsActor
310 { 310 {
311 private PhysicsVector _position; 311 private PhysicsVector _position;
312 private PhysicsVector _velocity; 312 private PhysicsVector _velocity;
313 private PhysicsVector _acceleration; 313 private PhysicsVector _acceleration;
314 private NxActor _prim; 314 private NxActor _prim;
315 315
316 public PhysXPrim(NxActor prim) 316 public PhysXPrim(NxActor prim)
317 { 317 {
318 _velocity = new PhysicsVector(); 318 _velocity = new PhysicsVector();
319 _position = new PhysicsVector(); 319 _position = new PhysicsVector();
320 _acceleration = new PhysicsVector(); 320 _acceleration = new PhysicsVector();
321 _prim = prim; 321 _prim = prim;
322 } 322 }
323 public override bool Flying 323 public override bool Flying
324 { 324 {
325 get 325 get
326 { 326 {
327 return false; //no flying prims for you 327 return false; //no flying prims for you
328 } 328 }
329 set 329 set
330 { 330 {
331 331
332 } 332 }
333 } 333 }
334 public override PhysicsVector Position 334 public override PhysicsVector Position
335 { 335 {
336 get 336 get
337 { 337 {
338 PhysicsVector pos = new PhysicsVector(); 338 PhysicsVector pos = new PhysicsVector();
339 Vec3 vec = this._prim.Position; 339 Vec3 vec = this._prim.Position;
340 pos.X = vec.X; 340 pos.X = vec.X;
341 pos.Y = vec.Y; 341 pos.Y = vec.Y;
342 pos.Z = vec.Z; 342 pos.Z = vec.Z;
343 return pos; 343 return pos;
344 344
345 } 345 }
346 set 346 set
347 { 347 {
348 PhysicsVector vec = value; 348 PhysicsVector vec = value;
349 Vec3 pos = new Vec3(); 349 Vec3 pos = new Vec3();
350 pos.X = vec.X; 350 pos.X = vec.X;
351 pos.Y = vec.Y; 351 pos.Y = vec.Y;
352 pos.Z = vec.Z; 352 pos.Z = vec.Z;
353 this._prim.Position = pos; 353 this._prim.Position = pos;
354 } 354 }
355 } 355 }
356 356
357 public override PhysicsVector Velocity 357 public override PhysicsVector Velocity
358 { 358 {
359 get 359 get
360 { 360 {
361 return _velocity; 361 return _velocity;
362 } 362 }
363 set 363 set
364 { 364 {
365 _velocity = value; 365 _velocity = value;
366 } 366 }
367 } 367 }
368 368
369 public override bool Kinematic 369 public override bool Kinematic
370 { 370 {
371 get 371 get
372 { 372 {
373 return this._prim.Kinematic; 373 return this._prim.Kinematic;
374 } 374 }
375 set 375 set
376 { 376 {
377 this._prim.Kinematic = value; 377 this._prim.Kinematic = value;
378 } 378 }
379 } 379 }
380 380
381 public override Quaternion Orientation 381 public override Quaternion Orientation
382 { 382 {
383 get 383 get
384 { 384 {
385 Quaternion res = new Quaternion(); 385 Quaternion res = new Quaternion();
386 PhysXWrapper.Quaternion quat = this._prim.GetOrientation(); 386 PhysXWrapper.Quaternion quat = this._prim.GetOrientation();
387 res.w = quat.W; 387 res.w = quat.W;
388 res.x = quat.X; 388 res.x = quat.X;
389 res.y = quat.Y; 389 res.y = quat.Y;
390 res.z = quat.Z; 390 res.z = quat.Z;
391 return res; 391 return res;
392 } 392 }
393 set 393 set
394 { 394 {
395 395
396 } 396 }
397 } 397 }
398 398
399 public override PhysicsVector Acceleration 399 public override PhysicsVector Acceleration
400 { 400 {
401 get 401 get
402 { 402 {
403 return _acceleration; 403 return _acceleration;
404 } 404 }
405 405
406 } 406 }
407 public void SetAcceleration (PhysicsVector accel) 407 public void SetAcceleration (PhysicsVector accel)
408 { 408 {
409 this._acceleration = accel; 409 this._acceleration = accel;
410 } 410 }
411 411
412 public override void AddForce(PhysicsVector force) 412 public override void AddForce(PhysicsVector force)
413 { 413 {
414 414
415 } 415 }
416 416
417 public override void SetMomentum(PhysicsVector momentum) 417 public override void SetMomentum(PhysicsVector momentum)
418 { 418 {
419 419
420 } 420 }
421 421
422 422
423 } 423 }
424 424
425} 425}