Entity.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Axiom.MathLib;
  5. using OpenSim.Physics.Manager;
  6. using OpenSim.types;
  7. using libsecondlife;
  8. using OpenSim.RegionServer.world.scripting;
  9. namespace OpenSim.world
  10. {
  11. public abstract class Entity : IScriptReadonlyEntity
  12. {
  13. public libsecondlife.LLUUID uuid;
  14. public uint localid;
  15. public LLVector3 velocity;
  16. public Quaternion rotation;
  17. protected List<Entity> children;
  18. protected string m_name;
  19. public virtual string Name
  20. {
  21. get { return m_name; }
  22. }
  23. protected LLVector3 m_pos;
  24. protected PhysicsActor _physActor;
  25. protected World m_world;
  26. public virtual LLVector3 Pos
  27. {
  28. get
  29. {
  30. if (this._physActor != null)
  31. {
  32. m_pos.X = _physActor.Position.X;
  33. m_pos.Y = _physActor.Position.Y;
  34. m_pos.Z = _physActor.Position.Z;
  35. }
  36. return m_pos;
  37. }
  38. set
  39. {
  40. if (this._physActor != null)
  41. {
  42. try
  43. {
  44. lock (this.m_world.LockPhysicsEngine)
  45. {
  46. this._physActor.Position = new PhysicsVector(value.X, value.Y, value.Z);
  47. }
  48. }
  49. catch (Exception e)
  50. {
  51. Console.WriteLine(e.Message);
  52. }
  53. }
  54. m_pos = value;
  55. }
  56. }
  57. /// <summary>
  58. /// Creates a new Entity (should not occur on it's own)
  59. /// </summary>
  60. public Entity()
  61. {
  62. uuid = new libsecondlife.LLUUID();
  63. localid = 0;
  64. m_pos = new LLVector3();
  65. velocity = new LLVector3();
  66. rotation = new Quaternion();
  67. m_name = "(basic entity)";
  68. children = new List<Entity>();
  69. }
  70. public virtual void addForces()
  71. {
  72. foreach (Entity child in children)
  73. {
  74. child.addForces();
  75. }
  76. }
  77. /// <summary>
  78. /// Performs any updates that need to be done at each frame. This function is overridable from it's children.
  79. /// </summary>
  80. public virtual void update() {
  81. // Do any per-frame updates needed that are applicable to every type of entity
  82. foreach (Entity child in children)
  83. {
  84. child.update();
  85. }
  86. }
  87. /// <summary>
  88. /// Returns a mesh for this object and any dependents
  89. /// </summary>
  90. /// <returns>The mesh of this entity tree</returns>
  91. public virtual Mesh getMesh()
  92. {
  93. Mesh mesh = new Mesh();
  94. foreach (Entity child in children)
  95. {
  96. mesh += child.getMesh();
  97. }
  98. return mesh;
  99. }
  100. public virtual void BackUp()
  101. {
  102. }
  103. public virtual void LandRenegerated()
  104. {
  105. }
  106. }
  107. }