PhysicsActor.cs 11 KB

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