aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/POSPlugin/POSScene.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Physics/POSPlugin/POSScene.cs')
-rw-r--r--OpenSim/Region/Physics/POSPlugin/POSScene.cs270
1 files changed, 0 insertions, 270 deletions
diff --git a/OpenSim/Region/Physics/POSPlugin/POSScene.cs b/OpenSim/Region/Physics/POSPlugin/POSScene.cs
deleted file mode 100644
index 2f24a50..0000000
--- a/OpenSim/Region/Physics/POSPlugin/POSScene.cs
+++ /dev/null
@@ -1,270 +0,0 @@
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
28using System;
29using System.Collections.Generic;
30using Nini.Config;
31using OpenMetaverse;
32using OpenSim.Framework;
33using OpenSim.Region.Physics.Manager;
34
35namespace OpenSim.Region.Physics.POSPlugin
36{
37 public class POSScene : PhysicsScene
38 {
39 private List<POSCharacter> _characters = new List<POSCharacter>();
40 private List<POSPrim> _prims = new List<POSPrim>();
41 private float[] _heightMap;
42 private const float gravity = -9.8f;
43
44 //protected internal string sceneIdentifier;
45
46 public POSScene(String _sceneIdentifier)
47 {
48 //sceneIdentifier = _sceneIdentifier;
49 }
50
51 public override void Initialise(IMesher meshmerizer, IConfigSource config)
52 {
53 }
54
55 public override void Dispose()
56 {
57 }
58
59 public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 size, bool isFlying)
60 {
61 POSCharacter act = new POSCharacter();
62 act.Position = position;
63 act.Flying = isFlying;
64 _characters.Add(act);
65 return act;
66 }
67
68 public override void RemovePrim(PhysicsActor prim)
69 {
70 POSPrim p = (POSPrim) prim;
71 if (_prims.Contains(p))
72 {
73 _prims.Remove(p);
74 }
75 }
76
77 public override void RemoveAvatar(PhysicsActor character)
78 {
79 POSCharacter act = (POSCharacter) character;
80 if (_characters.Contains(act))
81 {
82 _characters.Remove(act);
83 }
84 }
85
86/*
87 public override PhysicsActor AddPrim(Vector3 position, Vector3 size, Quaternion rotation)
88 {
89 return null;
90 }
91*/
92
93 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
94 Vector3 size, Quaternion rotation, bool isPhysical, uint localid)
95 {
96 POSPrim prim = new POSPrim();
97 prim.Position = position;
98 prim.Orientation = rotation;
99 prim.Size = size;
100 _prims.Add(prim);
101 return prim;
102 }
103
104 private bool isColliding(POSCharacter c, POSPrim p)
105 {
106 Vector3 rotatedPos = new Vector3(c.Position.X - p.Position.X, c.Position.Y - p.Position.Y,
107 c.Position.Z - p.Position.Z) * Quaternion.Inverse(p.Orientation);
108 Vector3 avatarSize = new Vector3(c.Size.X, c.Size.Y, c.Size.Z) * Quaternion.Inverse(p.Orientation);
109
110 return (Math.Abs(rotatedPos.X) < (p.Size.X*0.5 + Math.Abs(avatarSize.X)) &&
111 Math.Abs(rotatedPos.Y) < (p.Size.Y*0.5 + Math.Abs(avatarSize.Y)) &&
112 Math.Abs(rotatedPos.Z) < (p.Size.Z*0.5 + Math.Abs(avatarSize.Z)));
113 }
114
115 private bool isCollidingWithPrim(POSCharacter c)
116 {
117 foreach (POSPrim p in _prims)
118 {
119 if (isColliding(c, p))
120 {
121 return true;
122 }
123 }
124
125 return false;
126 }
127
128 public override void AddPhysicsActorTaint(PhysicsActor prim)
129 {
130 }
131
132 public override float Simulate(float timeStep)
133 {
134 float fps = 0;
135 for (int i = 0; i < _characters.Count; ++i)
136 {
137 fps++;
138 POSCharacter character = _characters[i];
139
140 float oldposX = character.Position.X;
141 float oldposY = character.Position.Y;
142 float oldposZ = character.Position.Z;
143
144 if (!character.Flying)
145 {
146 character._target_velocity.Z += gravity * timeStep;
147 }
148
149 Vector3 characterPosition = character.Position;
150
151 characterPosition.X += character._target_velocity.X * timeStep;
152 characterPosition.Y += character._target_velocity.Y * timeStep;
153
154 characterPosition.X = Util.Clamp(character.Position.X, 0.01f, Constants.RegionSize - 0.01f);
155 characterPosition.Y = Util.Clamp(character.Position.Y, 0.01f, Constants.RegionSize - 0.01f);
156
157 bool forcedZ = false;
158
159 float terrainheight = _heightMap[(int)character.Position.Y * Constants.RegionSize + (int)character.Position.X];
160 if (character.Position.Z + (character._target_velocity.Z * timeStep) < terrainheight + 2)
161 {
162 characterPosition.Z = terrainheight + character.Size.Z;
163 forcedZ = true;
164 }
165 else
166 {
167 characterPosition.Z += character._target_velocity.Z*timeStep;
168 }
169
170 /// this is it -- the magic you've all been waiting for! Ladies and gentlemen --
171 /// Completely Bogus Collision Detection!!!
172 /// better known as the CBCD algorithm
173
174 if (isCollidingWithPrim(character))
175 {
176 characterPosition.Z = oldposZ; // first try Z axis
177 if (isCollidingWithPrim(character))
178 {
179 characterPosition.Z = oldposZ + character.Size.Z / 4.4f; // try harder
180 if (isCollidingWithPrim(character))
181 {
182 characterPosition.Z = oldposZ + character.Size.Z / 2.2f; // try very hard
183 if (isCollidingWithPrim(character))
184 {
185 characterPosition.X = oldposX;
186 characterPosition.Y = oldposY;
187 characterPosition.Z = oldposZ;
188
189 characterPosition.X += character._target_velocity.X * timeStep;
190 if (isCollidingWithPrim(character))
191 {
192 characterPosition.X = oldposX;
193 }
194
195 characterPosition.Y += character._target_velocity.Y * timeStep;
196 if (isCollidingWithPrim(character))
197 {
198 characterPosition.Y = oldposY;
199 }
200 }
201 else
202 {
203 forcedZ = true;
204 }
205 }
206 else
207 {
208 forcedZ = true;
209 }
210 }
211 else
212 {
213 forcedZ = true;
214 }
215 }
216
217 characterPosition.X = Util.Clamp(character.Position.X, 0.01f, Constants.RegionSize - 0.01f);
218 characterPosition.Y = Util.Clamp(character.Position.Y, 0.01f, Constants.RegionSize - 0.01f);
219
220 character.Position = characterPosition;
221
222 character._velocity.X = (character.Position.X - oldposX)/timeStep;
223 character._velocity.Y = (character.Position.Y - oldposY)/timeStep;
224
225 if (forcedZ)
226 {
227 character._velocity.Z = 0;
228 character._target_velocity.Z = 0;
229 ((PhysicsActor)character).IsColliding = true;
230 character.RequestPhysicsterseUpdate();
231 }
232 else
233 {
234 ((PhysicsActor)character).IsColliding = false;
235 character._velocity.Z = (character.Position.Z - oldposZ)/timeStep;
236 }
237 }
238 return fps;
239 }
240
241 public override void GetResults()
242 {
243 }
244
245 public override bool IsThreaded
246 {
247 // for now we won't be multithreaded
248 get { return (false); }
249 }
250
251 public override void SetTerrain(float[] heightMap)
252 {
253 _heightMap = heightMap;
254 }
255
256 public override void DeleteTerrain()
257 {
258 }
259
260 public override void SetWaterLevel(float baseheight)
261 {
262 }
263
264 public override Dictionary<uint, float> GetTopColliders()
265 {
266 Dictionary<uint, float> returncolliders = new Dictionary<uint, float>();
267 return returncolliders;
268 }
269 }
270}