29 using System.Collections.Generic;
33 using OpenSim.Framework;
34 using OpenSim.Region.PhysicsModules.SharedBase;
35 using OpenSim.Region.Framework.Scenes;
36 using OpenSim.Region.Framework.Interfaces;
38 namespace OpenSim.
Region.PhysicsModule.POS
40 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"POSPhysicsScene")]
43 private List<POSCharacter> _characters =
new List<POSCharacter>();
44 private List<POSPrim> _prims =
new List<POSPrim>();
45 private float[] _heightMap;
46 private const float gravity = -9.8f;
48 private bool m_Enabled =
false;
51 #region INonSharedRegionModule
57 public Type ReplaceableInterface
65 IConfig config = source.Configs[
"Startup"];
68 string physics = config.GetString(
"physics", string.Empty);
85 PhysicsSceneName = EngineType +
"/" + scene.RegionInfo.RegionName;
88 base.Initialise(scene.PhysicsRequestAsset,
112 string avName, Vector3 position, Vector3 velocity, Vector3 size,
bool isFlying)
115 act.Position = position;
116 act.Flying = isFlying;
117 _characters.Add(act);
124 if (_prims.Contains(p))
133 if (_characters.Contains(act))
135 _characters.Remove(act);
147 Vector3 size, Quaternion
rotation,
bool isPhysical, uint localid)
150 prim.Position = position;
161 Vector3 avatarSize =
new Vector3(c.
Size.X, c.
Size.Y, c.
Size.Z) * Quaternion.Inverse(p.Orientation);
163 return (Math.Abs(rotatedPos.X) < (p.Size.X*0.5 + Math.Abs(avatarSize.X)) &&
164 Math.Abs(rotatedPos.Y) < (p.
Size.Y*0.5 + Math.Abs(avatarSize.Y)) &&
165 Math.Abs(rotatedPos.Z) < (p.Size.Z*0.5 + Math.Abs(avatarSize.Z)));
168 private bool isCollidingWithPrim(POSCharacter c)
170 foreach (POSPrim p
in _prims)
172 if (isColliding(c, p))
188 for (
int i = 0; i < _characters.Count; ++i)
193 float oldposX = character.Position.X;
194 float oldposY = character.Position.Y;
195 float oldposZ = character.Position.Z;
199 character._target_velocity.Z += gravity * timeStep;
202 Vector3 characterPosition = character.Position;
204 characterPosition.X += character._target_velocity.X * timeStep;
205 characterPosition.Y += character._target_velocity.Y * timeStep;
207 characterPosition.X = Util.Clamp(character.Position.X, 0.01f, Constants.RegionSize - 0.01f);
208 characterPosition.Y = Util.Clamp(character.Position.Y, 0.01f, Constants.RegionSize - 0.01f);
210 bool forcedZ =
false;
215 characterPosition.Z = terrainheight + character.Size.Z;
220 characterPosition.Z += character._target_velocity.Z*timeStep;
227 if (isCollidingWithPrim(character))
229 characterPosition.Z = oldposZ;
230 if (isCollidingWithPrim(character))
232 characterPosition.Z = oldposZ + character.Size.Z / 4.4f;
233 if (isCollidingWithPrim(character))
235 characterPosition.Z = oldposZ + character.Size.Z / 2.2f;
236 if (isCollidingWithPrim(character))
238 characterPosition.X = oldposX;
239 characterPosition.Y = oldposY;
240 characterPosition.Z = oldposZ;
242 characterPosition.X += character._target_velocity.X * timeStep;
243 if (isCollidingWithPrim(character))
245 characterPosition.X = oldposX;
248 characterPosition.Y += character._target_velocity.Y * timeStep;
249 if (isCollidingWithPrim(character))
251 characterPosition.Y = oldposY;
270 characterPosition.X = Util.Clamp(character.Position.X, 0.01f, Constants.RegionSize - 0.01f);
271 characterPosition.Y = Util.Clamp(character.Position.Y, 0.01f, Constants.RegionSize - 0.01f);
273 character.Position = characterPosition;
275 character._velocity.X = (character.Position.X - oldposX)/timeStep;
276 character._velocity.Y = (character.Position.Y - oldposY)/timeStep;
280 character._velocity.Z = 0;
281 character._target_velocity.Z = 0;
283 character.RequestPhysicsterseUpdate();
288 character._velocity.Z = (character.Position.Z - oldposZ)/timeStep;
298 public override bool IsThreaded
301 get {
return (
false); }
306 _heightMap = heightMap;
319 Dictionary<uint, float> returncolliders =
new Dictionary<uint, float>();
320 return returncolliders;
override void SetWaterLevel(float baseheight)
override void RemoveAvatar(PhysicsActor character)
Remove an avatar.
void Initialise(IConfigSource source)
This is called to initialize the region module. For shared modules, this is called exactly once...
override void GetResults()
override void SetTerrain(float[] heightMap)
override Dictionary< uint, float > GetTopColliders()
RegionSettings RegionSettings
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion rotation
override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 velocity, Vector3 size, bool isFlying)
Add an avatar
override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position, Vector3 size, Quaternion rotation, bool isPhysical, uint localid)
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
override Vector3 Position
override void DeleteTerrain()
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
virtual RegionInfo RegionInfo
override void RemovePrim(PhysicsActor prim)
Remove a prim.
override void AddPhysicsActorTaint(PhysicsActor prim)
override Vector3 Position
override float Simulate(float timeStep)
Perform a simulation of the current physics scene over the given timestep.