EntityBase.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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.Runtime.Serialization;
  29. using System.Security.Permissions;
  30. using Axiom.Math;
  31. using libsecondlife;
  32. namespace OpenSim.Region.Environment.Scenes
  33. {
  34. [Serializable]
  35. public abstract class EntityBase : ISerializable
  36. {
  37. /// <summary>
  38. /// The scene to which this entity belongs
  39. /// </summary>
  40. public Scene Scene
  41. {
  42. get { return m_scene; }
  43. }
  44. protected Scene m_scene;
  45. protected LLUUID m_uuid;
  46. public virtual LLUUID UUID
  47. {
  48. get { return m_uuid; }
  49. set { m_uuid = value; }
  50. }
  51. protected string m_name;
  52. /// <summary>
  53. ///
  54. /// </summary>
  55. public virtual string Name
  56. {
  57. get { return m_name; }
  58. set { m_name = value; }
  59. }
  60. protected LLVector3 m_pos;
  61. /// <summary>
  62. ///
  63. /// </summary>
  64. public virtual LLVector3 AbsolutePosition
  65. {
  66. get { return m_pos; }
  67. set { m_pos = value; }
  68. }
  69. protected LLVector3 m_velocity;
  70. protected LLVector3 m_rotationalvelocity;
  71. /// <summary>
  72. ///
  73. /// </summary>
  74. public virtual LLVector3 Velocity
  75. {
  76. get { return m_velocity; }
  77. set { m_velocity = value; }
  78. }
  79. protected Quaternion m_rotation = new Quaternion(0, 0, 1, 0);
  80. public virtual Quaternion Rotation
  81. {
  82. get { return m_rotation; }
  83. set { m_rotation = value; }
  84. }
  85. protected uint m_localId;
  86. public virtual uint LocalId
  87. {
  88. get { return m_localId; }
  89. set { m_localId = value; }
  90. }
  91. /// <summary>
  92. /// Creates a new Entity (should not occur on it's own)
  93. /// </summary>
  94. public EntityBase()
  95. {
  96. m_uuid = LLUUID.Zero;
  97. m_pos = new LLVector3();
  98. m_velocity = new LLVector3();
  99. Rotation = new Quaternion();
  100. m_name = "(basic entity)";
  101. m_rotationalvelocity = new LLVector3(0, 0, 0);
  102. }
  103. /// <summary>
  104. ///
  105. /// </summary>
  106. public abstract void UpdateMovement();
  107. /// <summary>
  108. /// Performs any updates that need to be done at each frame.
  109. /// </summary>
  110. public abstract void Update();
  111. /// <summary>
  112. /// Copies the entity
  113. /// </summary>
  114. /// <returns></returns>
  115. public virtual EntityBase Copy()
  116. {
  117. return (EntityBase) MemberwiseClone();
  118. }
  119. public abstract void SetText(string text, Vector3 color, double alpha);
  120. protected EntityBase(SerializationInfo info, StreamingContext context)
  121. {
  122. //System.Console.WriteLine("EntityBase Deserialize BGN");
  123. if (info == null)
  124. {
  125. throw new ArgumentNullException("info");
  126. }
  127. m_uuid = new LLUUID((Guid)info.GetValue("m_uuid", typeof(Guid)));
  128. m_name = (string)info.GetValue("m_name", typeof(string));
  129. m_pos
  130. = new LLVector3(
  131. (float)info.GetValue("m_pos.X", typeof(float)),
  132. (float)info.GetValue("m_pos.Y", typeof(float)),
  133. (float)info.GetValue("m_pos.Z", typeof(float)));
  134. m_velocity
  135. = new LLVector3(
  136. (float)info.GetValue("m_velocity.X", typeof(float)),
  137. (float)info.GetValue("m_velocity.Y", typeof(float)),
  138. (float)info.GetValue("m_velocity.Z", typeof(float)));
  139. m_rotationalvelocity
  140. = new LLVector3(
  141. (float)info.GetValue("m_rotationalvelocity.X", typeof(float)),
  142. (float)info.GetValue("m_rotationalvelocity.Y", typeof(float)),
  143. (float)info.GetValue("m_rotationalvelocity.Z", typeof(float)));
  144. m_rotation
  145. = new Quaternion(
  146. (float)info.GetValue("m_rotation.w", typeof(float)),
  147. (float)info.GetValue("m_rotation.x", typeof(float)),
  148. (float)info.GetValue("m_rotation.y", typeof(float)),
  149. (float)info.GetValue("m_rotation.z", typeof(float)));
  150. m_localId = (uint)info.GetValue("m_localId", typeof(uint));
  151. //System.Console.WriteLine("EntityBase Deserialize END");
  152. }
  153. [SecurityPermission(SecurityAction.LinkDemand,
  154. Flags = SecurityPermissionFlag.SerializationFormatter)]
  155. public virtual void GetObjectData(
  156. SerializationInfo info, StreamingContext context)
  157. {
  158. if (info == null)
  159. {
  160. throw new ArgumentNullException("info");
  161. }
  162. info.AddValue("m_uuid", m_uuid.UUID);
  163. info.AddValue("m_name", m_name);
  164. // LLVector3
  165. info.AddValue("m_pos.X", m_pos.X);
  166. info.AddValue("m_pos.Y", m_pos.Y);
  167. info.AddValue("m_pos.Z", m_pos.Z);
  168. // LLVector3
  169. info.AddValue("m_velocity.X", m_velocity.X);
  170. info.AddValue("m_velocity.Y", m_velocity.Y);
  171. info.AddValue("m_velocity.Z", m_velocity.Z);
  172. // LLVector3
  173. info.AddValue("m_rotationalvelocity.X", m_rotationalvelocity.X);
  174. info.AddValue("m_rotationalvelocity.Y", m_rotationalvelocity.Y);
  175. info.AddValue("m_rotationalvelocity.Z", m_rotationalvelocity.Z);
  176. // Quaternion
  177. info.AddValue("m_rotation.w", m_rotation.w);
  178. info.AddValue("m_rotation.x", m_rotation.x);
  179. info.AddValue("m_rotation.y", m_rotation.y);
  180. info.AddValue("m_rotation.z", m_rotation.z);
  181. info.AddValue("m_localId", m_localId);
  182. }
  183. }
  184. //Nested Classes
  185. public class EntityIntersection
  186. {
  187. public Vector3 ipoint = new Vector3(0, 0, 0);
  188. public Vector3 normal = new Vector3(0, 0, 0);
  189. public Vector3 AAfaceNormal = new Vector3(0, 0, 0);
  190. public int face = -1;
  191. public bool HitTF = false;
  192. public SceneObjectPart obj;
  193. public float distance = 0;
  194. public EntityIntersection()
  195. {
  196. }
  197. public EntityIntersection(Vector3 _ipoint, Vector3 _normal, bool _HitTF)
  198. {
  199. ipoint = _ipoint;
  200. normal = _normal;
  201. HitTF = _HitTF;
  202. }
  203. }
  204. }