EntityBase.cs 8.4 KB

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