1
0

PhysicsActor.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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 OpenSim 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. */
  28. using System;
  29. using System.Collections.Generic;
  30. using Axiom.Math;
  31. using OpenSim.Framework;
  32. namespace OpenSim.Region.Physics.Manager
  33. {
  34. public delegate void PositionUpdate(PhysicsVector position);
  35. public delegate void VelocityUpdate(PhysicsVector velocity);
  36. public delegate void OrientationUpdate(Quaternion orientation);
  37. public enum ActorTypes : int
  38. {
  39. Unknown = 0,
  40. Agent = 1,
  41. Prim = 2,
  42. Ground = 3,
  43. PrimVolume = 4 // rex
  44. }
  45. public class CollisionEventUpdate : EventArgs
  46. {
  47. // Raising the event on the object, so don't need to provide location.. further up the tree knows that info.
  48. public int m_colliderType;
  49. public bool m_startOrEnd;
  50. public uint m_LocalID; // rex
  51. public List<uint> m_objCollisionList;
  52. public CollisionEventUpdate(uint localID, int colliderType, bool startOrEnd, List<uint> objCollisionList)
  53. {
  54. m_LocalID = localID; // rex
  55. m_colliderType = colliderType;
  56. m_startOrEnd = startOrEnd;
  57. m_objCollisionList = objCollisionList;
  58. }
  59. public CollisionEventUpdate(bool startOrEnd)
  60. {
  61. m_colliderType = (int) ActorTypes.Unknown;
  62. m_startOrEnd = startOrEnd;
  63. m_objCollisionList = null;
  64. }
  65. public CollisionEventUpdate()
  66. {
  67. m_colliderType = (int) ActorTypes.Unknown;
  68. m_startOrEnd = false;
  69. m_objCollisionList = null;
  70. }
  71. public int collidertype
  72. {
  73. get { return m_colliderType; }
  74. set { m_colliderType = value; }
  75. }
  76. public bool startOrEnd
  77. {
  78. get { return m_startOrEnd; }
  79. set { m_startOrEnd = value; }
  80. }
  81. public void addCollider(uint localID)
  82. {
  83. m_objCollisionList.Add(localID);
  84. }
  85. }
  86. public abstract class PhysicsActor
  87. {
  88. public delegate void RequestTerseUpdate();
  89. public delegate void CollisionUpdate(EventArgs e);
  90. public delegate void OutOfBounds(PhysicsVector pos);
  91. #pragma warning disable 67
  92. public event PositionUpdate OnPositionUpdate;
  93. public event VelocityUpdate OnVelocityUpdate;
  94. public event OrientationUpdate OnOrientationUpdate;
  95. public event RequestTerseUpdate OnRequestTerseUpdate;
  96. public event CollisionUpdate OnCollisionUpdate;
  97. public event OutOfBounds OnOutOfBounds;
  98. #pragma warning restore 67
  99. public static PhysicsActor Null
  100. {
  101. get { return new NullPhysicsActor(); }
  102. }
  103. public abstract PhysicsVector Size { get; set; }
  104. public abstract PrimitiveBaseShape Shape { set; }
  105. public virtual void RequestPhysicsterseUpdate()
  106. {
  107. // Make a temporary copy of the event to avoid possibility of
  108. // a race condition if the last subscriber unsubscribes
  109. // immediately after the null check and before the event is raised.
  110. RequestTerseUpdate handler = OnRequestTerseUpdate;
  111. if (handler != null)
  112. {
  113. OnRequestTerseUpdate();
  114. }
  115. }
  116. public virtual void RaiseOutOfBounds(PhysicsVector pos)
  117. {
  118. // Make a temporary copy of the event to avoid possibility of
  119. // a race condition if the last subscriber unsubscribes
  120. // immediately after the null check and before the event is raised.
  121. OutOfBounds handler = OnOutOfBounds;
  122. if (handler != null)
  123. {
  124. OnOutOfBounds(pos);
  125. }
  126. }
  127. public virtual void SendCollisionUpdate(EventArgs e)
  128. {
  129. // CollisionUpdate handler = OnCollisionUpdate;
  130. if (OnCollisionUpdate != null)
  131. OnCollisionUpdate(e);
  132. }
  133. public abstract PhysicsVector Position { get; set; }
  134. public abstract float Mass { get; }
  135. public abstract PhysicsVector Force { get; }
  136. public abstract PhysicsVector GeometricCenter { get; }
  137. public abstract PhysicsVector CenterOfMass { get; }
  138. public abstract PhysicsVector Velocity { get; set; }
  139. public abstract PhysicsVector Acceleration { get; }
  140. public abstract Quaternion Orientation { get; set; }
  141. public abstract int PhysicsActorType { get; set; }
  142. public abstract bool IsPhysical { get; set; }
  143. public abstract bool Flying { get; set; }
  144. public abstract bool SetAlwaysRun { get; set; }
  145. public abstract bool ThrottleUpdates { get; set; }
  146. public abstract bool IsColliding { get; set; }
  147. public abstract bool CollidingGround { get; set; }
  148. public abstract bool CollidingObj { get; set; }
  149. public abstract PhysicsVector RotationalVelocity { get; set; }
  150. public abstract bool Kinematic { get; set; }
  151. public abstract void AddForce(PhysicsVector force);
  152. public abstract void SetMomentum(PhysicsVector momentum);
  153. public virtual void SetCollisionMesh(byte[] vData, string MeshName, bool vbScaleMesh) { } // rex
  154. public virtual void SetBoundsScaling(bool vbScaleMesh) { } // rex
  155. public int NextPrimVolumeTime = 0; // rex
  156. public uint m_localID; // rex
  157. }
  158. public class NullPhysicsActor : PhysicsActor
  159. {
  160. public override PhysicsVector Position
  161. {
  162. get { return PhysicsVector.Zero; }
  163. set { return; }
  164. }
  165. public override bool SetAlwaysRun
  166. {
  167. get { return false; }
  168. set { return; }
  169. }
  170. public override bool CollidingGround
  171. {
  172. get { return false; }
  173. set { return; }
  174. }
  175. public override bool CollidingObj
  176. {
  177. get { return false; }
  178. set { return; }
  179. }
  180. public override PhysicsVector Size
  181. {
  182. get { return PhysicsVector.Zero; }
  183. set { return; }
  184. }
  185. public override float Mass
  186. {
  187. get { return 0f; }
  188. }
  189. public override PhysicsVector Force
  190. {
  191. get { return PhysicsVector.Zero; }
  192. }
  193. public override PhysicsVector CenterOfMass
  194. {
  195. get { return PhysicsVector.Zero; }
  196. }
  197. public override PhysicsVector GeometricCenter
  198. {
  199. get { return PhysicsVector.Zero; }
  200. }
  201. public override PrimitiveBaseShape Shape
  202. {
  203. set { return; }
  204. }
  205. public override PhysicsVector Velocity
  206. {
  207. get { return PhysicsVector.Zero; }
  208. set { return; }
  209. }
  210. public override Quaternion Orientation
  211. {
  212. get { return Quaternion.Identity; }
  213. set { }
  214. }
  215. public override PhysicsVector Acceleration
  216. {
  217. get { return PhysicsVector.Zero; }
  218. }
  219. public override bool IsPhysical
  220. {
  221. get { return false; }
  222. set { return; }
  223. }
  224. public override bool Flying
  225. {
  226. get { return false; }
  227. set { return; }
  228. }
  229. public override bool ThrottleUpdates
  230. {
  231. get { return false; }
  232. set { return; }
  233. }
  234. public override bool IsColliding
  235. {
  236. get { return false; }
  237. set { return; }
  238. }
  239. public override int PhysicsActorType
  240. {
  241. get { return (int) ActorTypes.Unknown; }
  242. set { return; }
  243. }
  244. public override bool Kinematic
  245. {
  246. get { return true; }
  247. set { return; }
  248. }
  249. public override void AddForce(PhysicsVector force)
  250. {
  251. return;
  252. }
  253. public override PhysicsVector RotationalVelocity
  254. {
  255. get { return PhysicsVector.Zero; }
  256. set { return; }
  257. }
  258. public override void SetMomentum(PhysicsVector momentum)
  259. {
  260. return;
  261. }
  262. }
  263. }