PhysXplugin.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * Copyright (c) OpenSim project, http://sim.opensecondlife.org/
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. * * Redistributions of source code must retain the above copyright
  7. * notice, this list of conditions and the following disclaimer.
  8. * * Redistributions in binary form must reproduce the above copyright
  9. * notice, this list of conditions and the following disclaimer in the
  10. * documentation and/or other materials provided with the distribution.
  11. * * Neither the name of the <organization> nor the
  12. * names of its contributors may be used to endorse or promote products
  13. * derived from this software without specific prior written permission.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
  16. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
  19. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  22. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. *
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using PhysicsSystem;
  30. namespace PhysXplugin
  31. {
  32. /// <summary>
  33. /// Will be the PhysX plugin but for now will be a very basic physics engine
  34. /// </summary>
  35. public class PhysXPlugin : IPhysicsPlugin
  36. {
  37. private PhysXScene _mScene;
  38. public PhysXPlugin()
  39. {
  40. }
  41. public bool Init()
  42. {
  43. return true;
  44. }
  45. public PhysicsScene GetScene()
  46. {
  47. if(_mScene == null)
  48. {
  49. _mScene = new PhysXScene();
  50. }
  51. return(_mScene);
  52. }
  53. public string GetName()
  54. {
  55. return("PhysX");
  56. }
  57. public void Dispose()
  58. {
  59. }
  60. }
  61. public class PhysXScene :PhysicsScene
  62. {
  63. private List<PhysXActor> _actors = new List<PhysXActor>();
  64. public PhysXScene()
  65. {
  66. }
  67. public override PhysicsActor AddAvatar(PhysicsVector position)
  68. {
  69. PhysXActor act = new PhysXActor();
  70. act.Position = position;
  71. _actors.Add(act);
  72. return act;
  73. }
  74. public override void Simulate(float timeStep)
  75. {
  76. foreach (PhysXActor actor in _actors)
  77. {
  78. actor.Position.X = actor.Position.X + actor.Velocity.X * timeStep;
  79. actor.Position.Y = actor.Position.Y + actor.Velocity.Y * timeStep;
  80. actor.Position.Z = actor.Position.Z + actor.Velocity.Z * timeStep;
  81. if(actor.Position.X<0)
  82. {
  83. actor.Position.X = 0;
  84. actor.Velocity.X = 0;
  85. }
  86. if(actor.Position.Y < 0)
  87. {
  88. actor.Position.Y = 0;
  89. actor.Velocity.Y = 0;
  90. }
  91. if(actor.Position.X > 255)
  92. {
  93. actor.Position.X = 255;
  94. actor.Velocity.X = 0;
  95. }
  96. if(actor.Position.Y > 255)
  97. {
  98. actor.Position.Y = 255;
  99. actor.Velocity.X = 0;
  100. }
  101. }
  102. }
  103. public override void GetResults()
  104. {
  105. }
  106. public override bool IsThreaded
  107. {
  108. get
  109. {
  110. return(false); // for now we won't be multithreaded
  111. }
  112. }
  113. public override void SetTerrain(float[] heightMap)
  114. {
  115. }
  116. }
  117. public class PhysXActor : PhysicsActor
  118. {
  119. private PhysicsVector _position;
  120. private PhysicsVector _velocity;
  121. private PhysicsVector _acceleration;
  122. public PhysXActor()
  123. {
  124. }
  125. public override PhysicsVector Position
  126. {
  127. get
  128. {
  129. return _position;
  130. }
  131. set
  132. {
  133. _position = value;
  134. }
  135. }
  136. public override PhysicsVector Velocity
  137. {
  138. get
  139. {
  140. return _velocity;
  141. }
  142. set
  143. {
  144. _velocity = value;
  145. }
  146. }
  147. public override PhysicsVector Acceleration
  148. {
  149. get
  150. {
  151. return _acceleration;
  152. }
  153. }
  154. public void SetAcceleration (PhysicsVector accel)
  155. {
  156. this._acceleration = accel;
  157. }
  158. public override void AddForce(PhysicsVector force)
  159. {
  160. }
  161. public override void SetMomentum(PhysicsVector momentum)
  162. {
  163. }
  164. }
  165. }