BasicPhysicsScene.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 OpenSimulator 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 Nini.Config;
  30. using OpenMetaverse;
  31. using OpenSim.Framework;
  32. using OpenSim.Region.Physics.Manager;
  33. namespace OpenSim.Region.Physics.BasicPhysicsPlugin
  34. {
  35. public class BasicScene : PhysicsScene
  36. {
  37. private List<BasicActor> _actors = new List<BasicActor>();
  38. private float[] _heightMap;
  39. //protected internal string sceneIdentifier;
  40. public BasicScene(string _sceneIdentifier)
  41. {
  42. //sceneIdentifier = _sceneIdentifier;
  43. }
  44. public override void Initialise(IMesher meshmerizer, IConfigSource config)
  45. {
  46. }
  47. public override void Dispose()
  48. {
  49. }
  50. public override PhysicsActor AddAvatar(string avName, PhysicsVector position, PhysicsVector size, bool isFlying)
  51. {
  52. BasicActor act = new BasicActor();
  53. act.Position = position;
  54. act.Flying = isFlying;
  55. _actors.Add(act);
  56. return act;
  57. }
  58. public override void RemovePrim(PhysicsActor prim)
  59. {
  60. }
  61. public override void RemoveAvatar(PhysicsActor actor)
  62. {
  63. BasicActor act = (BasicActor) actor;
  64. if (_actors.Contains(act))
  65. {
  66. _actors.Remove(act);
  67. }
  68. }
  69. /*
  70. public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size, Quaternion rotation)
  71. {
  72. return null;
  73. }
  74. */
  75. public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position,
  76. PhysicsVector size, Quaternion rotation)
  77. {
  78. return AddPrimShape(primName, pbs, position, size, rotation, false);
  79. }
  80. public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position,
  81. PhysicsVector size, Quaternion rotation, bool isPhysical)
  82. {
  83. return null;
  84. }
  85. public override void AddPhysicsActorTaint(PhysicsActor prim)
  86. {
  87. }
  88. public override float Simulate(float timeStep)
  89. {
  90. float fps = 0;
  91. for (int i = 0; i < _actors.Count; ++i)
  92. {
  93. BasicActor actor = _actors[i];
  94. actor.Position.X += actor.Velocity.X*timeStep;
  95. actor.Position.Y += actor.Velocity.Y*timeStep;
  96. if (actor.Position.Y < 0)
  97. {
  98. actor.Position.Y = 0.1F;
  99. }
  100. else if (actor.Position.Y >= Constants.RegionSize)
  101. {
  102. actor.Position.Y = ((int)Constants.RegionSize - 0.1f);
  103. }
  104. if (actor.Position.X < 0)
  105. {
  106. actor.Position.X = 0.1F;
  107. }
  108. else if (actor.Position.X >= Constants.RegionSize)
  109. {
  110. actor.Position.X = ((int)Constants.RegionSize - 0.1f);
  111. }
  112. float height = _heightMap[(int)actor.Position.Y * Constants.RegionSize + (int)actor.Position.X] + actor.Size.Z;
  113. if (actor.Flying)
  114. {
  115. if (actor.Position.Z + (actor.Velocity.Z*timeStep) <
  116. _heightMap[(int)actor.Position.Y * Constants.RegionSize + (int)actor.Position.X] + 2)
  117. {
  118. actor.Position.Z = height;
  119. actor.Velocity.Z = 0;
  120. actor.IsColliding = true;
  121. }
  122. else
  123. {
  124. actor.Position.Z += actor.Velocity.Z*timeStep;
  125. actor.IsColliding = false;
  126. }
  127. }
  128. else
  129. {
  130. actor.Position.Z = height;
  131. actor.Velocity.Z = 0;
  132. actor.IsColliding = true;
  133. }
  134. }
  135. return fps;
  136. }
  137. public override void GetResults()
  138. {
  139. }
  140. public override bool IsThreaded
  141. {
  142. get { return (false); // for now we won't be multithreaded
  143. }
  144. }
  145. public override void SetTerrain(float[] heightMap)
  146. {
  147. _heightMap = heightMap;
  148. }
  149. public override void DeleteTerrain()
  150. {
  151. }
  152. public override void SetWaterLevel(float baseheight)
  153. {
  154. }
  155. public override Dictionary<uint, float> GetTopColliders()
  156. {
  157. Dictionary<uint, float> returncolliders = new Dictionary<uint, float>();
  158. return returncolliders;
  159. }
  160. }
  161. }