EntityBase.cs 7.9 KB

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