aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs')
-rw-r--r--OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs861
1 files changed, 0 insertions, 861 deletions
diff --git a/OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs b/OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs
deleted file mode 100644
index e54065c..0000000
--- a/OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs
+++ /dev/null
@@ -1,861 +0,0 @@
1/*/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using Nini.Config;
31using OpenSim.Framework;
32using OpenSim.Region.Physics.Manager;
33using PhysXWrapper;
34using Quaternion=OpenMetaverse.Quaternion;
35using System.Reflection;
36using log4net;
37using OpenMetaverse;
38
39namespace OpenSim.Region.Physics.PhysXPlugin
40{
41 /// <summary>
42 /// Will be the PhysX plugin but for now will be a very basic physics engine
43 /// </summary>
44 public class PhysXPlugin : IPhysicsPlugin
45 {
46 //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47 private PhysXScene _mScene;
48
49 public PhysXPlugin()
50 {
51 }
52
53 public bool Init()
54 {
55 return true;
56 }
57
58 public PhysicsScene GetScene(string sceneIdentifier)
59 {
60 if (_mScene == null)
61 {
62 _mScene = new PhysXScene(sceneIdentifier);
63 }
64 return (_mScene);
65 }
66
67 public string GetName()
68 {
69 return ("RealPhysX");
70 }
71
72 public void Dispose()
73 {
74 }
75 }
76
77 public class PhysXScene : PhysicsScene
78 {
79 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
80 private List<PhysXCharacter> _characters = new List<PhysXCharacter>();
81 private List<PhysXPrim> _prims = new List<PhysXPrim>();
82 private float[] _heightMap = null;
83 private NxPhysicsSDK mySdk;
84 private NxScene scene;
85
86 // protected internal string sceneIdentifier;
87 public PhysXScene(string _sceneIdentifier)
88 {
89 //sceneIdentifier = _sceneIdentifier;
90
91 mySdk = NxPhysicsSDK.CreateSDK();
92 m_log.Info("Sdk created - now creating scene");
93 scene = mySdk.CreateScene();
94 }
95
96 public override void Initialise(IMesher meshmerizer, IConfigSource config)
97 {
98 // Does nothing right now
99 }
100 public override void Dispose()
101 {
102
103 }
104
105 public override void SetWaterLevel(float baseheight)
106 {
107
108 }
109
110 public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying)
111 {
112 Vec3 pos = new Vec3();
113 pos.X = position.X;
114 pos.Y = position.Y;
115 pos.Z = position.Z;
116 PhysXCharacter act = new PhysXCharacter(scene.AddCharacter(pos));
117 act.Flying = isFlying;
118 act.Position = position;
119 _characters.Add(act);
120 return act;
121 }
122
123 public override void RemovePrim(PhysicsActor prim)
124 {
125 }
126
127 public override void RemoveAvatar(PhysicsActor actor)
128 {
129 }
130
131 private PhysicsActor AddPrim(Vector3 position, Vector3 size, Quaternion rotation)
132 {
133 Vec3 pos = new Vec3();
134 pos.X = position.X;
135 pos.Y = position.Y;
136 pos.Z = position.Z;
137 Vec3 siz = new Vec3();
138 siz.X = size.X;
139 siz.Y = size.Y;
140 siz.Z = size.Z;
141 PhysXPrim act = new PhysXPrim(scene.AddNewBox(pos, siz));
142 _prims.Add(act);
143 return act;
144 }
145
146 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
147 Vector3 size, Quaternion rotation) //To be removed
148 {
149 return AddPrimShape(primName, pbs, position, size, rotation, false);
150 }
151
152 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
153 Vector3 size, Quaternion rotation, bool isPhysical)
154 {
155 return AddPrim(position, size, rotation);
156 }
157
158 public override void AddPhysicsActorTaint(PhysicsActor prim)
159 {
160 }
161
162 public override float Simulate(float timeStep)
163 {
164 float fps = 0f;
165 try
166 {
167 foreach (PhysXCharacter actor in _characters)
168 {
169 actor.Move(timeStep);
170 }
171 scene.Simulate(timeStep);
172 scene.FetchResults();
173 scene.UpdateControllers();
174
175 foreach (PhysXCharacter actor in _characters)
176 {
177 actor.UpdatePosition();
178 }
179 }
180 catch (Exception e)
181 {
182 m_log.Error(e.Message);
183 }
184 return fps;
185 }
186
187 public override void GetResults()
188 {
189 }
190
191 public override bool IsThreaded
192 {
193 get { return (false); // for now we won't be multithreaded
194 }
195 }
196
197 public override void SetTerrain(float[] heightMap)
198 {
199 if (_heightMap != null)
200 {
201 m_log.Debug("PhysX - deleting old terrain");
202 scene.DeleteTerrain();
203 }
204 _heightMap = heightMap;
205 scene.AddTerrain(heightMap);
206 }
207
208 public override void DeleteTerrain()
209 {
210 scene.DeleteTerrain();
211 }
212
213 public override Dictionary<uint, float> GetTopColliders()
214 {
215 Dictionary<uint, float> returncolliders = new Dictionary<uint, float>();
216 return returncolliders;
217 }
218
219 }
220
221 public class PhysXCharacter : PhysicsActor
222 {
223 private Vector3 _position;
224 private Vector3 _velocity;
225 private Vector3 m_rotationalVelocity = Vector3.Zero;
226 private Vector3 _acceleration;
227 private NxCharacter _character;
228 private bool flying;
229 private bool iscolliding = false;
230 private float gravityAccel;
231
232 public PhysXCharacter(NxCharacter character)
233 {
234 _character = character;
235 }
236
237 public override int PhysicsActorType
238 {
239 get { return (int) ActorTypes.Agent; }
240 set { return; }
241 }
242
243 public override bool SetAlwaysRun
244 {
245 get { return false; }
246 set { return; }
247 }
248
249 public override uint LocalID
250 {
251 set { return; }
252 }
253
254 public override bool Grabbed
255 {
256 set { return; }
257 }
258
259 public override bool Selected
260 {
261 set { return; }
262 }
263
264 public override float Buoyancy
265 {
266 get { return 0f; }
267 set { return; }
268 }
269
270 public override bool FloatOnWater
271 {
272 set { return; }
273 }
274
275 public override bool IsPhysical
276 {
277 get { return false; }
278 set { return; }
279 }
280
281 public override bool ThrottleUpdates
282 {
283 get { return false; }
284 set { return; }
285 }
286
287 public override bool Flying
288 {
289 get { return flying; }
290 set { flying = value; }
291 }
292
293 public override bool IsColliding
294 {
295 get { return iscolliding; }
296 set { iscolliding = value; }
297 }
298
299 public override bool CollidingGround
300 {
301 get { return false; }
302 set { return; }
303 }
304
305 public override bool CollidingObj
306 {
307 get { return false; }
308 set { return; }
309 }
310
311 public override Vector3 RotationalVelocity
312 {
313 get { return m_rotationalVelocity; }
314 set { m_rotationalVelocity = value; }
315 }
316
317 public override bool Stopped
318 {
319 get { return false; }
320 }
321
322 public override Vector3 Position
323 {
324 get { return _position; }
325 set
326 {
327 _position = value;
328 Vec3 ps = new Vec3();
329 ps.X = value.X;
330 ps.Y = value.Y;
331 ps.Z = value.Z;
332 _character.Position = ps;
333 }
334 }
335
336 public override Vector3 Size
337 {
338 get { return Vector3.Zero; }
339 set { }
340 }
341
342 public override float Mass
343 {
344 get { return 0f; }
345 }
346
347 public override Vector3 Force
348 {
349 get { return Vector3.Zero; }
350 set { return; }
351 }
352
353 public override int VehicleType
354 {
355 get { return 0; }
356 set { return; }
357 }
358
359 public override void VehicleFloatParam(int param, float value)
360 {
361
362 }
363
364 public override void VehicleVectorParam(int param, Vector3 value)
365 {
366
367 }
368
369 public override void VehicleRotationParam(int param, Quaternion rotation)
370 {
371
372 }
373
374 public override void VehicleFlagsSet(int flags)
375 {
376
377 }
378
379 public override void VehicleFlagsRemove(int flags)
380 {
381
382 }
383
384 public override void SetVolumeDetect(int param)
385 {
386
387 }
388
389
390 public override Vector3 CenterOfMass
391 {
392 get { return Vector3.Zero; }
393 }
394
395 public override Vector3 GeometricCenter
396 {
397 get { return Vector3.Zero; }
398 }
399
400 public override Vector3 Velocity
401 {
402 get { return _velocity; }
403 set { _velocity = value; }
404 }
405
406 public override float CollisionScore
407 {
408 get { return 0f; }
409 set { }
410 }
411
412 public override bool Kinematic
413 {
414 get { return false; }
415 set { }
416 }
417
418 public override Quaternion Orientation
419 {
420 get { return Quaternion.Identity; }
421 set { }
422 }
423
424 public override Vector3 Acceleration
425 {
426 get { return _acceleration; }
427 }
428
429 public void SetAcceleration(Vector3 accel)
430 {
431 _acceleration = accel;
432 }
433
434 public override void AddForce(Vector3 force, bool pushforce)
435 {
436 }
437 public override Vector3 Torque
438 {
439 get { return Vector3.Zero; }
440 set { return; }
441 }
442 public override void AddAngularForce(Vector3 force, bool pushforce)
443 {
444 }
445
446 public override void link(PhysicsActor obj)
447 {
448
449 }
450
451 public override void delink()
452 {
453
454 }
455
456 public override void LockAngularMotion(Vector3 axis)
457 {
458
459 }
460
461 public override void SetMomentum(Vector3 momentum)
462 {
463 }
464
465 public void Move(float timeStep)
466 {
467 Vec3 vec = new Vec3();
468 vec.X = _velocity.X*timeStep;
469 vec.Y = _velocity.Y*timeStep;
470 if (flying)
471 {
472 vec.Z = (_velocity.Z)*timeStep;
473 }
474 else
475 {
476 gravityAccel += -9.8f;
477 vec.Z = (gravityAccel + _velocity.Z)*timeStep;
478 }
479 int res = _character.Move(vec);
480 if (res == 1)
481 {
482 gravityAccel = 0;
483 }
484 }
485
486 public override PrimitiveBaseShape Shape
487 {
488 set { return; }
489 }
490
491 public void UpdatePosition()
492 {
493 Vec3 vec = _character.Position;
494 _position.X = vec.X;
495 _position.Y = vec.Y;
496 _position.Z = vec.Z;
497 }
498 public override void CrossingFailure()
499 {
500
501 }
502
503 public override Vector3 PIDTarget { set { return; } }
504 public override bool PIDActive { set { return; } }
505 public override float PIDTau { set { return; } }
506
507 public override float PIDHoverHeight { set { return; } }
508 public override bool PIDHoverActive { set { return; } }
509 public override PIDHoverType PIDHoverType { set { return; } }
510 public override float PIDHoverTau { set { return; } }
511
512 public override Quaternion APIDTarget
513 {
514 set { return; }
515 }
516
517 public override bool APIDActive
518 {
519 set { return; }
520 }
521
522 public override float APIDStrength
523 {
524 set { return; }
525 }
526
527 public override float APIDDamping
528 {
529 set { return; }
530 }
531
532
533
534 public override void SubscribeEvents(int ms)
535 {
536
537 }
538 public override void UnSubscribeEvents()
539 {
540
541 }
542 public override bool SubscribedEvents()
543 {
544 return false;
545 }
546 }
547
548
549 public class PhysXPrim : PhysicsActor
550 {
551 private Vector3 _velocity;
552 private Vector3 _acceleration;
553 private Vector3 m_rotationalVelocity;
554 private NxActor _prim;
555
556 public PhysXPrim(NxActor prim)
557 {
558 _velocity = Vector3.Zero;
559 _acceleration = Vector3.Zero;
560 _prim = prim;
561 }
562
563 public override int PhysicsActorType
564 {
565 get { return (int) ActorTypes.Prim; }
566 set { return; }
567 }
568
569 public override bool IsPhysical
570 {
571 get { return false; }
572 set { return; }
573 }
574
575 public override bool SetAlwaysRun
576 {
577 get { return false; }
578 set { return; }
579 }
580
581 public override uint LocalID
582 {
583 set { return; }
584 }
585
586 public override bool Grabbed
587 {
588 set { return; }
589 }
590
591 public override bool Selected
592 {
593 set { return; }
594 }
595
596 public override float Buoyancy
597 {
598 get { return 0f; }
599 set { return; }
600 }
601
602 public override bool FloatOnWater
603 {
604 set { return; }
605 }
606
607 public override bool ThrottleUpdates
608 {
609 get { return false; }
610 set { return; }
611 }
612
613 public override Vector3 RotationalVelocity
614 {
615 get { return m_rotationalVelocity; }
616 set { m_rotationalVelocity = value; }
617 }
618
619 public override bool Flying
620 {
621 get { return false; //no flying prims for you
622 }
623 set { }
624 }
625
626 public override bool IsColliding
627 {
628 get { return false; }
629 set { }
630 }
631
632 public override bool CollidingGround
633 {
634 get { return false; }
635 set { return; }
636 }
637
638 public override bool CollidingObj
639 {
640 get { return false; }
641 set { return; }
642 }
643
644 public override bool Stopped
645 {
646 get { return false; }
647 }
648
649 public override Vector3 Position
650 {
651 get
652 {
653 Vector3 pos = Vector3.Zero;
654 Vec3 vec = _prim.Position;
655 pos.X = vec.X;
656 pos.Y = vec.Y;
657 pos.Z = vec.Z;
658 return pos;
659 }
660 set
661 {
662 Vector3 vec = value;
663 Vec3 pos = new Vec3();
664 pos.X = vec.X;
665 pos.Y = vec.Y;
666 pos.Z = vec.Z;
667 _prim.Position = pos;
668 }
669 }
670
671 public override PrimitiveBaseShape Shape
672 {
673 set { return; }
674 }
675
676 public override Vector3 Velocity
677 {
678 get { return _velocity; }
679 set { _velocity = value; }
680 }
681
682 public override Vector3 Torque
683 {
684 get { return Vector3.Zero; }
685 set { return; }
686 }
687
688 public override float CollisionScore
689 {
690 get { return 0f; }
691 set { }
692 }
693
694 public override bool Kinematic
695 {
696 get { return _prim.Kinematic; }
697 set { _prim.Kinematic = value; }
698 }
699
700 public override Quaternion Orientation
701 {
702 get
703 {
704 Quaternion res;
705 PhysXWrapper.Quaternion quat = _prim.GetOrientation();
706 res.W = quat.W;
707 res.X = quat.X;
708 res.Y = quat.Y;
709 res.Z = quat.Z;
710 return res;
711 }
712 set { }
713 }
714
715 public override Vector3 Acceleration
716 {
717 get { return _acceleration; }
718 }
719
720 public void SetAcceleration(Vector3 accel)
721 {
722 _acceleration = accel;
723 }
724
725 public override void AddForce(Vector3 force, bool pushforce)
726 {
727 }
728
729 public override void AddAngularForce(Vector3 force, bool pushforce)
730 {
731 }
732
733 public override void SetMomentum(Vector3 momentum)
734 {
735 }
736
737 public override Vector3 Size
738 {
739 get { return Vector3.Zero; }
740 set { }
741 }
742
743 public override void link(PhysicsActor obj)
744 {
745 }
746
747 public override void delink()
748 {
749 }
750
751 public override void LockAngularMotion(Vector3 axis)
752 {
753
754 }
755
756 public override float Mass
757 {
758 get { return 0f; }
759 }
760
761 public override Vector3 Force
762 {
763 get { return Vector3.Zero; }
764 set { return; }
765 }
766
767 public override int VehicleType
768 {
769 get { return 0; }
770 set { return; }
771 }
772
773 public override void VehicleFloatParam(int param, float value)
774 {
775
776 }
777
778 public override void VehicleVectorParam(int param, Vector3 value)
779 {
780
781 }
782
783 public override void VehicleRotationParam(int param, Quaternion rotation)
784 {
785
786 }
787
788 public override void VehicleFlagsSet(int flags)
789 {
790
791 }
792
793 public override void VehicleFlagsRemove(int flags)
794 {
795
796 }
797
798 public override void SetVolumeDetect(int param)
799 {
800
801 }
802
803 public override Vector3 CenterOfMass
804 {
805 get { return Vector3.Zero; }
806 }
807
808 public override Vector3 GeometricCenter
809 {
810 get { return Vector3.Zero; }
811 }
812
813 public override void CrossingFailure()
814 {
815 }
816
817 public override Vector3 PIDTarget { set { return; } }
818 public override bool PIDActive { set { return; } }
819 public override float PIDTau { set { return; } }
820
821 public override float PIDHoverHeight { set { return; } }
822 public override bool PIDHoverActive { set { return; } }
823 public override PIDHoverType PIDHoverType { set { return; } }
824 public override float PIDHoverTau { set { return; } }
825
826 public override Quaternion APIDTarget
827 {
828 set { return; }
829 }
830
831 public override bool APIDActive
832 {
833 set { return; }
834 }
835
836 public override float APIDStrength
837 {
838 set { return; }
839 }
840
841 public override float APIDDamping
842 {
843 set { return; }
844 }
845
846
847
848 public override void SubscribeEvents(int ms)
849 {
850
851 }
852 public override void UnSubscribeEvents()
853 {
854
855 }
856 public override bool SubscribedEvents()
857 {
858 return false;
859 }
860 }
861}