PhysicsActor.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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 abstract void LockAngularMotion(PhysicsVector axis);
  104. public virtual void RequestPhysicsterseUpdate()
  105. {
  106. // Make a temporary copy of the event to avoid possibility of
  107. // a race condition if the last subscriber unsubscribes
  108. // immediately after the null check and before the event is raised.
  109. RequestTerseUpdate handler = OnRequestTerseUpdate;
  110. if (handler != null)
  111. {
  112. handler();
  113. }
  114. }
  115. public virtual void RaiseOutOfBounds(PhysicsVector pos)
  116. {
  117. // Make a temporary copy of the event to avoid possibility of
  118. // a race condition if the last subscriber unsubscribes
  119. // immediately after the null check and before the event is raised.
  120. OutOfBounds handler = OnOutOfBounds;
  121. if (handler != null)
  122. {
  123. handler(pos);
  124. }
  125. }
  126. public virtual void SendCollisionUpdate(EventArgs e)
  127. {
  128. CollisionUpdate handler = OnCollisionUpdate;
  129. if (handler != null)
  130. {
  131. handler(e);
  132. }
  133. }
  134. public abstract PhysicsVector Position { get; set; }
  135. public abstract float Mass { get; }
  136. public abstract PhysicsVector Force { get; }
  137. public abstract PhysicsVector GeometricCenter { get; }
  138. public abstract PhysicsVector CenterOfMass { get; }
  139. public abstract PhysicsVector Velocity { get; set; }
  140. public abstract float CollisionScore { get;}
  141. public abstract PhysicsVector Acceleration { get; }
  142. public abstract Quaternion Orientation { get; set; }
  143. public abstract int PhysicsActorType { get; set; }
  144. public abstract bool IsPhysical { get; set; }
  145. public abstract bool Flying { get; set; }
  146. public abstract bool SetAlwaysRun { get; set; }
  147. public abstract bool ThrottleUpdates { get; set; }
  148. public abstract bool IsColliding { get; set; }
  149. public abstract bool CollidingGround { get; set; }
  150. public abstract bool CollidingObj { get; set; }
  151. public abstract bool FloatOnWater { set; }
  152. public abstract PhysicsVector RotationalVelocity { get; set; }
  153. public abstract bool Kinematic { get; set; }
  154. public abstract float Buoyancy { get; set; }
  155. public abstract PhysicsVector PIDTarget { set;}
  156. public abstract bool PIDActive { set;}
  157. public abstract float PIDTau { set; }
  158. public abstract void AddForce(PhysicsVector force);
  159. public abstract void SetMomentum(PhysicsVector momentum);
  160. }
  161. public class NullPhysicsActor : PhysicsActor
  162. {
  163. public override bool Stopped
  164. {
  165. get{ return false; }
  166. }
  167. public override PhysicsVector Position
  168. {
  169. get { return PhysicsVector.Zero; }
  170. set { return; }
  171. }
  172. public override bool SetAlwaysRun
  173. {
  174. get { return false; }
  175. set { return; }
  176. }
  177. public override uint LocalID
  178. {
  179. set { return; }
  180. }
  181. public override bool Grabbed
  182. {
  183. set { return; }
  184. }
  185. public override bool Selected
  186. {
  187. set { return; }
  188. }
  189. public override float Buoyancy
  190. {
  191. get { return 0f; }
  192. set { return; }
  193. }
  194. public override bool FloatOnWater
  195. {
  196. set { return; }
  197. }
  198. public override bool CollidingGround
  199. {
  200. get { return false; }
  201. set { return; }
  202. }
  203. public override bool CollidingObj
  204. {
  205. get { return false; }
  206. set { return; }
  207. }
  208. public override PhysicsVector Size
  209. {
  210. get { return PhysicsVector.Zero; }
  211. set { return; }
  212. }
  213. public override float Mass
  214. {
  215. get { return 0f; }
  216. }
  217. public override PhysicsVector Force
  218. {
  219. get { return PhysicsVector.Zero; }
  220. }
  221. public override PhysicsVector CenterOfMass
  222. {
  223. get { return PhysicsVector.Zero; }
  224. }
  225. public override PhysicsVector GeometricCenter
  226. {
  227. get { return PhysicsVector.Zero; }
  228. }
  229. public override PrimitiveBaseShape Shape
  230. {
  231. set { return; }
  232. }
  233. public override PhysicsVector Velocity
  234. {
  235. get { return PhysicsVector.Zero; }
  236. set { return; }
  237. }
  238. public override float CollisionScore
  239. {
  240. get { return 0f; }
  241. }
  242. public override void CrossingFailure()
  243. {
  244. }
  245. public override Quaternion Orientation
  246. {
  247. get { return Quaternion.Identity; }
  248. set { }
  249. }
  250. public override PhysicsVector Acceleration
  251. {
  252. get { return PhysicsVector.Zero; }
  253. }
  254. public override bool IsPhysical
  255. {
  256. get { return false; }
  257. set { return; }
  258. }
  259. public override bool Flying
  260. {
  261. get { return false; }
  262. set { return; }
  263. }
  264. public override bool ThrottleUpdates
  265. {
  266. get { return false; }
  267. set { return; }
  268. }
  269. public override bool IsColliding
  270. {
  271. get { return false; }
  272. set { return; }
  273. }
  274. public override int PhysicsActorType
  275. {
  276. get { return (int) ActorTypes.Unknown; }
  277. set { return; }
  278. }
  279. public override bool Kinematic
  280. {
  281. get { return true; }
  282. set { return; }
  283. }
  284. public override void link(PhysicsActor obj)
  285. {
  286. }
  287. public override void delink()
  288. {
  289. }
  290. public override void LockAngularMotion(PhysicsVector axis)
  291. {
  292. }
  293. public override void AddForce(PhysicsVector force)
  294. {
  295. }
  296. public override PhysicsVector RotationalVelocity
  297. {
  298. get { return PhysicsVector.Zero; }
  299. set { return; }
  300. }
  301. public override PhysicsVector PIDTarget { set { return; } }
  302. public override bool PIDActive { set { return; } }
  303. public override float PIDTau { set { return; } }
  304. public override void SetMomentum(PhysicsVector momentum)
  305. {
  306. }
  307. }
  308. }