diff options
author | Jeff Ames | 2008-06-26 00:30:33 +0000 |
---|---|---|
committer | Jeff Ames | 2008-06-26 00:30:33 +0000 |
commit | e75dc1bd230700c4b5f17caea49879517d065251 (patch) | |
tree | 1c9db8aa919ce2a623cf7657e2cd4f83ff358d5a /OpenSim/Region/Physics | |
parent | added the flag param to IClientAPI.SendMapBlock (diff) | |
download | opensim-SC_OLD-e75dc1bd230700c4b5f17caea49879517d065251.zip opensim-SC_OLD-e75dc1bd230700c4b5f17caea49879517d065251.tar.gz opensim-SC_OLD-e75dc1bd230700c4b5f17caea49879517d065251.tar.bz2 opensim-SC_OLD-e75dc1bd230700c4b5f17caea49879517d065251.tar.xz |
Separate POS classes into mutiple files.
Diffstat (limited to 'OpenSim/Region/Physics')
-rw-r--r-- | OpenSim/Region/Physics/POSPlugin/POSCharacter.cs | 262 | ||||
-rw-r--r-- | OpenSim/Region/Physics/POSPlugin/POSPlugin.cs | 715 | ||||
-rw-r--r-- | OpenSim/Region/Physics/POSPlugin/POSPrim.cs | 262 | ||||
-rw-r--r-- | OpenSim/Region/Physics/POSPlugin/POSScene.cs | 298 |
4 files changed, 822 insertions, 715 deletions
diff --git a/OpenSim/Region/Physics/POSPlugin/POSCharacter.cs b/OpenSim/Region/Physics/POSPlugin/POSCharacter.cs new file mode 100644 index 0000000..d146b60 --- /dev/null +++ b/OpenSim/Region/Physics/POSPlugin/POSCharacter.cs | |||
@@ -0,0 +1,262 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using Axiom.Math; | ||
31 | using Nini.Config; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Region.Physics.Manager; | ||
34 | |||
35 | namespace OpenSim.Region.Physics.POSPlugin | ||
36 | { | ||
37 | public class POSCharacter : PhysicsActor | ||
38 | { | ||
39 | private PhysicsVector _position; | ||
40 | public PhysicsVector _velocity; | ||
41 | public PhysicsVector _target_velocity = PhysicsVector.Zero; | ||
42 | private PhysicsVector _acceleration; | ||
43 | private PhysicsVector m_rotationalVelocity = PhysicsVector.Zero; | ||
44 | private bool flying; | ||
45 | private bool iscolliding; | ||
46 | |||
47 | public POSCharacter() | ||
48 | { | ||
49 | _velocity = new PhysicsVector(); | ||
50 | _position = new PhysicsVector(); | ||
51 | _acceleration = new PhysicsVector(); | ||
52 | } | ||
53 | |||
54 | public override int PhysicsActorType | ||
55 | { | ||
56 | get { return (int) ActorTypes.Agent; } | ||
57 | set { return; } | ||
58 | } | ||
59 | |||
60 | public override PhysicsVector RotationalVelocity | ||
61 | { | ||
62 | get { return m_rotationalVelocity; } | ||
63 | set { m_rotationalVelocity = value; } | ||
64 | } | ||
65 | |||
66 | public override bool SetAlwaysRun | ||
67 | { | ||
68 | get { return false; } | ||
69 | set { return; } | ||
70 | } | ||
71 | |||
72 | public override uint LocalID | ||
73 | { | ||
74 | set { return; } | ||
75 | } | ||
76 | |||
77 | public override bool Grabbed | ||
78 | { | ||
79 | set { return; } | ||
80 | } | ||
81 | |||
82 | public override bool Selected | ||
83 | { | ||
84 | set { return; } | ||
85 | } | ||
86 | |||
87 | public override float Buoyancy | ||
88 | { | ||
89 | get { return 0f; } | ||
90 | set { return; } | ||
91 | } | ||
92 | |||
93 | public override bool FloatOnWater | ||
94 | { | ||
95 | set { return; } | ||
96 | } | ||
97 | |||
98 | public override bool IsPhysical | ||
99 | { | ||
100 | get { return false; } | ||
101 | set { return; } | ||
102 | } | ||
103 | |||
104 | public override bool ThrottleUpdates | ||
105 | { | ||
106 | get { return false; } | ||
107 | set { return; } | ||
108 | } | ||
109 | |||
110 | public override bool Flying | ||
111 | { | ||
112 | get { return flying; } | ||
113 | set { flying = value; } | ||
114 | } | ||
115 | |||
116 | public override bool IsColliding | ||
117 | { | ||
118 | get { return iscolliding; } | ||
119 | set { iscolliding = value; } | ||
120 | } | ||
121 | |||
122 | public override bool CollidingGround | ||
123 | { | ||
124 | get { return false; } | ||
125 | set { return; } | ||
126 | } | ||
127 | |||
128 | public override bool CollidingObj | ||
129 | { | ||
130 | get { return false; } | ||
131 | set { return; } | ||
132 | } | ||
133 | |||
134 | public override bool Stopped | ||
135 | { | ||
136 | get { return false; } | ||
137 | } | ||
138 | |||
139 | public override PhysicsVector Position | ||
140 | { | ||
141 | get { return _position; } | ||
142 | set { _position = value; } | ||
143 | } | ||
144 | |||
145 | public override PhysicsVector Size | ||
146 | { | ||
147 | get { return new PhysicsVector(0.5f, 0.5f, 1.0f); } | ||
148 | set { } | ||
149 | } | ||
150 | |||
151 | public override float Mass | ||
152 | { | ||
153 | get { return 0f; } | ||
154 | } | ||
155 | |||
156 | public override PhysicsVector Force | ||
157 | { | ||
158 | get { return PhysicsVector.Zero; } | ||
159 | } | ||
160 | |||
161 | public override PhysicsVector CenterOfMass | ||
162 | { | ||
163 | get { return PhysicsVector.Zero; } | ||
164 | } | ||
165 | |||
166 | public override PhysicsVector GeometricCenter | ||
167 | { | ||
168 | get { return PhysicsVector.Zero; } | ||
169 | } | ||
170 | |||
171 | public override PrimitiveBaseShape Shape | ||
172 | { | ||
173 | set { return; } | ||
174 | } | ||
175 | |||
176 | public override PhysicsVector Velocity | ||
177 | { | ||
178 | get { return _velocity; } | ||
179 | set { _target_velocity = value; } | ||
180 | } | ||
181 | |||
182 | public override float CollisionScore | ||
183 | { | ||
184 | get { return 0f; } | ||
185 | set { } | ||
186 | } | ||
187 | |||
188 | public override Quaternion Orientation | ||
189 | { | ||
190 | get { return Quaternion.Identity; } | ||
191 | set { } | ||
192 | } | ||
193 | |||
194 | public override PhysicsVector Acceleration | ||
195 | { | ||
196 | get { return _acceleration; } | ||
197 | } | ||
198 | |||
199 | public override bool Kinematic | ||
200 | { | ||
201 | get { return true; } | ||
202 | set { } | ||
203 | } | ||
204 | |||
205 | public override void link(PhysicsActor obj) | ||
206 | { | ||
207 | } | ||
208 | |||
209 | public override void delink() | ||
210 | { | ||
211 | } | ||
212 | |||
213 | public override void LockAngularMotion(PhysicsVector axis) | ||
214 | { | ||
215 | } | ||
216 | |||
217 | public void SetAcceleration(PhysicsVector accel) | ||
218 | { | ||
219 | _acceleration = accel; | ||
220 | } | ||
221 | |||
222 | public override void AddForce(PhysicsVector force, bool pushforce) | ||
223 | { | ||
224 | } | ||
225 | |||
226 | public override void SetMomentum(PhysicsVector momentum) | ||
227 | { | ||
228 | } | ||
229 | |||
230 | public override void CrossingFailure() | ||
231 | { | ||
232 | } | ||
233 | |||
234 | public override PhysicsVector PIDTarget | ||
235 | { | ||
236 | set { return; } | ||
237 | } | ||
238 | |||
239 | public override bool PIDActive | ||
240 | { | ||
241 | set { return; } | ||
242 | } | ||
243 | |||
244 | public override float PIDTau | ||
245 | { | ||
246 | set { return; } | ||
247 | } | ||
248 | |||
249 | public override void SubscribeEvents(int ms) | ||
250 | { | ||
251 | } | ||
252 | |||
253 | public override void UnSubscribeEvents() | ||
254 | { | ||
255 | } | ||
256 | |||
257 | public override bool SubscribedEvents() | ||
258 | { | ||
259 | return false; | ||
260 | } | ||
261 | } | ||
262 | } | ||
diff --git a/OpenSim/Region/Physics/POSPlugin/POSPlugin.cs b/OpenSim/Region/Physics/POSPlugin/POSPlugin.cs index 8d1fb0e..65f10f9 100644 --- a/OpenSim/Region/Physics/POSPlugin/POSPlugin.cs +++ b/OpenSim/Region/Physics/POSPlugin/POSPlugin.cs | |||
@@ -62,719 +62,4 @@ namespace OpenSim.Region.Physics.POSPlugin | |||
62 | { | 62 | { |
63 | } | 63 | } |
64 | } | 64 | } |
65 | |||
66 | public class POSScene : PhysicsScene | ||
67 | { | ||
68 | private List<POSCharacter> _characters = new List<POSCharacter>(); | ||
69 | private List<POSPrim> _prims = new List<POSPrim>(); | ||
70 | private float[] _heightMap; | ||
71 | private const float gravity = -9.8f; | ||
72 | |||
73 | public POSScene() | ||
74 | { | ||
75 | } | ||
76 | |||
77 | public override void Initialise(IMesher meshmerizer, IConfigSource config) | ||
78 | { | ||
79 | } | ||
80 | |||
81 | public override void Dispose() | ||
82 | { | ||
83 | } | ||
84 | |||
85 | public override PhysicsActor AddAvatar(string avName, PhysicsVector position, PhysicsVector size) | ||
86 | { | ||
87 | POSCharacter act = new POSCharacter(); | ||
88 | act.Position = position; | ||
89 | _characters.Add(act); | ||
90 | return act; | ||
91 | } | ||
92 | |||
93 | public override void SetWaterLevel(float baseheight) | ||
94 | { | ||
95 | } | ||
96 | |||
97 | public override void RemovePrim(PhysicsActor prim) | ||
98 | { | ||
99 | POSPrim p = (POSPrim) prim; | ||
100 | if (_prims.Contains(p)) | ||
101 | { | ||
102 | _prims.Remove(p); | ||
103 | } | ||
104 | } | ||
105 | |||
106 | public override void RemoveAvatar(PhysicsActor character) | ||
107 | { | ||
108 | POSCharacter act = (POSCharacter) character; | ||
109 | if (_characters.Contains(act)) | ||
110 | { | ||
111 | _characters.Remove(act); | ||
112 | } | ||
113 | } | ||
114 | |||
115 | /* | ||
116 | public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size, Quaternion rotation) | ||
117 | { | ||
118 | return null; | ||
119 | } | ||
120 | */ | ||
121 | |||
122 | public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, | ||
123 | PhysicsVector size, Quaternion rotation) | ||
124 | { | ||
125 | return AddPrimShape(primName, pbs, position, size, rotation, false); | ||
126 | } | ||
127 | |||
128 | public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, | ||
129 | PhysicsVector size, Quaternion rotation, bool isPhysical) | ||
130 | { | ||
131 | POSPrim prim = new POSPrim(); | ||
132 | prim.Position = position; | ||
133 | prim.Orientation = rotation; | ||
134 | prim.Size = size; | ||
135 | _prims.Add(prim); | ||
136 | return prim; | ||
137 | } | ||
138 | |||
139 | private bool check_collision(POSCharacter c, POSPrim p) | ||
140 | { | ||
141 | /* | ||
142 | Console.WriteLine("checking whether " + c + " collides with " + p + | ||
143 | " absX: " + Math.Abs(p.Position.X - c.Position.X) + | ||
144 | " sizeX: " + p.Size.X * 0.5 + 0.5); | ||
145 | */ | ||
146 | |||
147 | Vector3 rotatedPos = p.Orientation.Inverse() * | ||
148 | new Vector3(c.Position.X - p.Position.X, c.Position.Y - p.Position.Y, | ||
149 | c.Position.Z - p.Position.Z); | ||
150 | Vector3 avatarSize = p.Orientation.Inverse()*new Vector3(c.Size.X, c.Size.Y, c.Size.Z); | ||
151 | |||
152 | if (Math.Abs(rotatedPos.x) >= (p.Size.X*0.5 + Math.Abs(avatarSize.x)) || | ||
153 | Math.Abs(rotatedPos.y) >= (p.Size.Y*0.5 + Math.Abs(avatarSize.y)) || | ||
154 | Math.Abs(rotatedPos.z) >= (p.Size.Z*0.5 + Math.Abs(avatarSize.z))) | ||
155 | { | ||
156 | return false; | ||
157 | } | ||
158 | return true; | ||
159 | } | ||
160 | |||
161 | private bool check_all_prims(POSCharacter c) | ||
162 | { | ||
163 | for (int i = 0; i < _prims.Count; ++i) | ||
164 | { | ||
165 | if (check_collision(c, _prims[i])) | ||
166 | { | ||
167 | return true; | ||
168 | } | ||
169 | } | ||
170 | |||
171 | return false; | ||
172 | } | ||
173 | |||
174 | public override void AddPhysicsActorTaint(PhysicsActor prim) | ||
175 | { | ||
176 | } | ||
177 | |||
178 | public override float Simulate(float timeStep) | ||
179 | { | ||
180 | float fps = 0; | ||
181 | for (int i = 0; i < _characters.Count; ++i) | ||
182 | { | ||
183 | fps++; | ||
184 | POSCharacter character = _characters[i]; | ||
185 | |||
186 | float oldposX = character.Position.X; | ||
187 | float oldposY = character.Position.Y; | ||
188 | float oldposZ = character.Position.Z; | ||
189 | |||
190 | if (!character.Flying) | ||
191 | { | ||
192 | character._target_velocity.Z += gravity*timeStep; | ||
193 | } | ||
194 | |||
195 | bool forcedZ = false; | ||
196 | character.Position.X += character._target_velocity.X*timeStep; | ||
197 | character.Position.Y += character._target_velocity.Y*timeStep; | ||
198 | |||
199 | if (character.Position.Y < 0) | ||
200 | { | ||
201 | character.Position.Y = 0.1F; | ||
202 | } | ||
203 | else if (character.Position.Y >= Constants.RegionSize) | ||
204 | { | ||
205 | character.Position.Y = Constants.RegionSize - 0.1f; | ||
206 | } | ||
207 | |||
208 | if (character.Position.X < 0) | ||
209 | { | ||
210 | character.Position.X = 0.1F; | ||
211 | } | ||
212 | else if (character.Position.X >= Constants.RegionSize) | ||
213 | { | ||
214 | character.Position.X = Constants.RegionSize - 0.1f; | ||
215 | } | ||
216 | |||
217 | float terrainheight = _heightMap[(int)character.Position.Y * Constants.RegionSize + (int)character.Position.X]; | ||
218 | if (character.Position.Z + (character._target_velocity.Z*timeStep) < terrainheight + 2) | ||
219 | { | ||
220 | character.Position.Z = terrainheight + 1.0f; | ||
221 | forcedZ = true; | ||
222 | } | ||
223 | else | ||
224 | { | ||
225 | character.Position.Z += character._target_velocity.Z*timeStep; | ||
226 | } | ||
227 | |||
228 | /// this is it -- the magic you've all been waiting for! Ladies and gentlemen -- | ||
229 | /// Completely Bogus Collision Detection!!! | ||
230 | /// better known as the CBCD algorithm | ||
231 | |||
232 | if (check_all_prims(character)) | ||
233 | { | ||
234 | character.Position.Z = oldposZ; // first try Z axis | ||
235 | if (check_all_prims(character)) | ||
236 | { | ||
237 | character.Position.Z = oldposZ + 0.4f; // try harder | ||
238 | if (check_all_prims(character)) | ||
239 | { | ||
240 | character.Position.X = oldposX; | ||
241 | character.Position.Y = oldposY; | ||
242 | character.Position.Z = oldposZ; | ||
243 | character.Position.X += character._target_velocity.X * timeStep; | ||
244 | if (check_all_prims(character)) | ||
245 | { | ||
246 | character.Position.X = oldposX; | ||
247 | } | ||
248 | character.Position.Y += character._target_velocity.Y * timeStep; | ||
249 | if (check_all_prims(character)) | ||
250 | { | ||
251 | character.Position.Y = oldposY; | ||
252 | } | ||
253 | } | ||
254 | else | ||
255 | { | ||
256 | forcedZ = true; | ||
257 | } | ||
258 | } | ||
259 | else | ||
260 | { | ||
261 | forcedZ = true; | ||
262 | } | ||
263 | } | ||
264 | |||
265 | if (character.Position.Y < 0) | ||
266 | { | ||
267 | character.Position.Y = 0.1F; | ||
268 | } | ||
269 | else if (character.Position.Y >= Constants.RegionSize) | ||
270 | { | ||
271 | character.Position.Y = Constants.RegionSize - 0.1f; | ||
272 | } | ||
273 | |||
274 | if (character.Position.X < 0) | ||
275 | { | ||
276 | character.Position.X = 0.1F; | ||
277 | } | ||
278 | else if (character.Position.X >= Constants.RegionSize) | ||
279 | { | ||
280 | character.Position.X = Constants.RegionSize - 0.1f; | ||
281 | } | ||
282 | |||
283 | character._velocity.X = (character.Position.X - oldposX)/timeStep; | ||
284 | character._velocity.Y = (character.Position.Y - oldposY)/timeStep; | ||
285 | |||
286 | if (forcedZ) | ||
287 | { | ||
288 | character._velocity.Z = 0; | ||
289 | character._target_velocity.Z = 0; | ||
290 | ((PhysicsActor)character).IsColliding = true; | ||
291 | character.RequestPhysicsterseUpdate(); | ||
292 | } | ||
293 | else | ||
294 | { | ||
295 | ((PhysicsActor)character).IsColliding = false; | ||
296 | character._velocity.Z = (character.Position.Z - oldposZ)/timeStep; | ||
297 | } | ||
298 | } | ||
299 | return fps; | ||
300 | } | ||
301 | |||
302 | public override void GetResults() | ||
303 | { | ||
304 | } | ||
305 | |||
306 | public override bool IsThreaded | ||
307 | { | ||
308 | // for now we won't be multithreaded | ||
309 | get { return (false); } | ||
310 | } | ||
311 | |||
312 | public override void SetTerrain(float[] heightMap) | ||
313 | { | ||
314 | _heightMap = heightMap; | ||
315 | } | ||
316 | |||
317 | public override void DeleteTerrain() | ||
318 | { | ||
319 | } | ||
320 | |||
321 | public override Dictionary<uint, float> GetTopColliders() | ||
322 | { | ||
323 | Dictionary<uint, float> returncolliders = new Dictionary<uint, float>(); | ||
324 | return returncolliders; | ||
325 | } | ||
326 | } | ||
327 | |||
328 | public class POSCharacter : PhysicsActor | ||
329 | { | ||
330 | private PhysicsVector _position; | ||
331 | public PhysicsVector _velocity; | ||
332 | public PhysicsVector _target_velocity = PhysicsVector.Zero; | ||
333 | private PhysicsVector _acceleration; | ||
334 | private PhysicsVector m_rotationalVelocity = PhysicsVector.Zero; | ||
335 | private bool flying; | ||
336 | private bool iscolliding; | ||
337 | |||
338 | public POSCharacter() | ||
339 | { | ||
340 | _velocity = new PhysicsVector(); | ||
341 | _position = new PhysicsVector(); | ||
342 | _acceleration = new PhysicsVector(); | ||
343 | } | ||
344 | |||
345 | public override int PhysicsActorType | ||
346 | { | ||
347 | get { return (int) ActorTypes.Agent; } | ||
348 | set { return; } | ||
349 | } | ||
350 | |||
351 | public override PhysicsVector RotationalVelocity | ||
352 | { | ||
353 | get { return m_rotationalVelocity; } | ||
354 | set { m_rotationalVelocity = value; } | ||
355 | } | ||
356 | |||
357 | public override bool SetAlwaysRun | ||
358 | { | ||
359 | get { return false; } | ||
360 | set { return; } | ||
361 | } | ||
362 | |||
363 | public override uint LocalID | ||
364 | { | ||
365 | set { return; } | ||
366 | } | ||
367 | |||
368 | public override bool Grabbed | ||
369 | { | ||
370 | set { return; } | ||
371 | } | ||
372 | |||
373 | public override bool Selected | ||
374 | { | ||
375 | set { return; } | ||
376 | } | ||
377 | |||
378 | public override float Buoyancy | ||
379 | { | ||
380 | get { return 0f; } | ||
381 | set { return; } | ||
382 | } | ||
383 | |||
384 | public override bool FloatOnWater | ||
385 | { | ||
386 | set { return; } | ||
387 | } | ||
388 | |||
389 | public override bool IsPhysical | ||
390 | { | ||
391 | get { return false; } | ||
392 | set { return; } | ||
393 | } | ||
394 | |||
395 | public override bool ThrottleUpdates | ||
396 | { | ||
397 | get { return false; } | ||
398 | set { return; } | ||
399 | } | ||
400 | |||
401 | public override bool Flying | ||
402 | { | ||
403 | get { return flying; } | ||
404 | set { flying = value; } | ||
405 | } | ||
406 | |||
407 | public override bool IsColliding | ||
408 | { | ||
409 | get { return iscolliding; } | ||
410 | set { iscolliding = value; } | ||
411 | } | ||
412 | |||
413 | public override bool CollidingGround | ||
414 | { | ||
415 | get { return false; } | ||
416 | set { return; } | ||
417 | } | ||
418 | |||
419 | public override bool CollidingObj | ||
420 | { | ||
421 | get { return false; } | ||
422 | set { return; } | ||
423 | } | ||
424 | |||
425 | public override bool Stopped | ||
426 | { | ||
427 | get { return false; } | ||
428 | } | ||
429 | |||
430 | public override PhysicsVector Position | ||
431 | { | ||
432 | get { return _position; } | ||
433 | set { _position = value; } | ||
434 | } | ||
435 | |||
436 | public override PhysicsVector Size | ||
437 | { | ||
438 | get { return new PhysicsVector(0.5f, 0.5f, 1.0f); } | ||
439 | set { } | ||
440 | } | ||
441 | |||
442 | public override float Mass | ||
443 | { | ||
444 | get { return 0f; } | ||
445 | } | ||
446 | |||
447 | public override PhysicsVector Force | ||
448 | { | ||
449 | get { return PhysicsVector.Zero; } | ||
450 | } | ||
451 | |||
452 | public override PhysicsVector CenterOfMass | ||
453 | { | ||
454 | get { return PhysicsVector.Zero; } | ||
455 | } | ||
456 | |||
457 | public override PhysicsVector GeometricCenter | ||
458 | { | ||
459 | get { return PhysicsVector.Zero; } | ||
460 | } | ||
461 | |||
462 | public override PrimitiveBaseShape Shape | ||
463 | { | ||
464 | set { return; } | ||
465 | } | ||
466 | |||
467 | public override PhysicsVector Velocity | ||
468 | { | ||
469 | get { return _velocity; } | ||
470 | set { _target_velocity = value; } | ||
471 | } | ||
472 | |||
473 | public override float CollisionScore | ||
474 | { | ||
475 | get { return 0f; } | ||
476 | set { } | ||
477 | } | ||
478 | |||
479 | public override Quaternion Orientation | ||
480 | { | ||
481 | get { return Quaternion.Identity; } | ||
482 | set { } | ||
483 | } | ||
484 | |||
485 | public override PhysicsVector Acceleration | ||
486 | { | ||
487 | get { return _acceleration; } | ||
488 | } | ||
489 | |||
490 | public override bool Kinematic | ||
491 | { | ||
492 | get { return true; } | ||
493 | set { } | ||
494 | } | ||
495 | |||
496 | public override void link(PhysicsActor obj) | ||
497 | { | ||
498 | } | ||
499 | |||
500 | public override void delink() | ||
501 | { | ||
502 | } | ||
503 | |||
504 | public override void LockAngularMotion(PhysicsVector axis) | ||
505 | { | ||
506 | } | ||
507 | |||
508 | public void SetAcceleration(PhysicsVector accel) | ||
509 | { | ||
510 | _acceleration = accel; | ||
511 | } | ||
512 | |||
513 | public override void AddForce(PhysicsVector force, bool pushforce) | ||
514 | { | ||
515 | } | ||
516 | |||
517 | public override void SetMomentum(PhysicsVector momentum) | ||
518 | { | ||
519 | } | ||
520 | |||
521 | public override void CrossingFailure() | ||
522 | { | ||
523 | } | ||
524 | |||
525 | public override PhysicsVector PIDTarget | ||
526 | { | ||
527 | set { return; } | ||
528 | } | ||
529 | |||
530 | public override bool PIDActive | ||
531 | { | ||
532 | set { return; } | ||
533 | } | ||
534 | |||
535 | public override float PIDTau | ||
536 | { | ||
537 | set { return; } | ||
538 | } | ||
539 | |||
540 | public override void SubscribeEvents(int ms) | ||
541 | { | ||
542 | } | ||
543 | |||
544 | public override void UnSubscribeEvents() | ||
545 | { | ||
546 | } | ||
547 | |||
548 | public override bool SubscribedEvents() | ||
549 | { | ||
550 | return false; | ||
551 | } | ||
552 | } | ||
553 | |||
554 | public class POSPrim : PhysicsActor | ||
555 | { | ||
556 | private PhysicsVector _position; | ||
557 | private PhysicsVector _velocity; | ||
558 | private PhysicsVector _acceleration; | ||
559 | private PhysicsVector _size; | ||
560 | private PhysicsVector m_rotationalVelocity = PhysicsVector.Zero; | ||
561 | private Quaternion _orientation; | ||
562 | private bool iscolliding; | ||
563 | |||
564 | public POSPrim() | ||
565 | { | ||
566 | _velocity = new PhysicsVector(); | ||
567 | _position = new PhysicsVector(); | ||
568 | _acceleration = new PhysicsVector(); | ||
569 | } | ||
570 | |||
571 | public override int PhysicsActorType | ||
572 | { | ||
573 | get { return (int) ActorTypes.Prim; } | ||
574 | set { return; } | ||
575 | } | ||
576 | |||
577 | public override PhysicsVector RotationalVelocity | ||
578 | { | ||
579 | get { return m_rotationalVelocity; } | ||
580 | set { m_rotationalVelocity = value; } | ||
581 | } | ||
582 | |||
583 | public override bool IsPhysical | ||
584 | { | ||
585 | get { return false; } | ||
586 | set { return; } | ||
587 | } | ||
588 | |||
589 | public override bool ThrottleUpdates | ||
590 | { | ||
591 | get { return false; } | ||
592 | set { return; } | ||
593 | } | ||
594 | |||
595 | public override bool IsColliding | ||
596 | { | ||
597 | get { return iscolliding; } | ||
598 | set { iscolliding = value; } | ||
599 | } | ||
600 | |||
601 | public override bool CollidingGround | ||
602 | { | ||
603 | get { return false; } | ||
604 | set { return; } | ||
605 | } | ||
606 | |||
607 | public override bool CollidingObj | ||
608 | { | ||
609 | get { return false; } | ||
610 | set { return; } | ||
611 | } | ||
612 | |||
613 | public override bool Stopped | ||
614 | { | ||
615 | get { return false; } | ||
616 | } | ||
617 | |||
618 | public override PhysicsVector Position | ||
619 | { | ||
620 | get { return _position; } | ||
621 | set { _position = value; } | ||
622 | } | ||
623 | |||
624 | public override PhysicsVector Size | ||
625 | { | ||
626 | get { return _size; } | ||
627 | set { _size = value; } | ||
628 | } | ||
629 | |||
630 | public override float Mass | ||
631 | { | ||
632 | get { return 0f; } | ||
633 | } | ||
634 | |||
635 | public override PhysicsVector Force | ||
636 | { | ||
637 | get { return PhysicsVector.Zero; } | ||
638 | } | ||
639 | |||
640 | public override PhysicsVector CenterOfMass | ||
641 | { | ||
642 | get { return PhysicsVector.Zero; } | ||
643 | } | ||
644 | |||
645 | public override PhysicsVector GeometricCenter | ||
646 | { | ||
647 | get { return PhysicsVector.Zero; } | ||
648 | } | ||
649 | |||
650 | public override PrimitiveBaseShape Shape | ||
651 | { | ||
652 | set { return; } | ||
653 | } | ||
654 | |||
655 | public override float Buoyancy | ||
656 | { | ||
657 | get { return 0f; } | ||
658 | set { return; } | ||
659 | } | ||
660 | |||
661 | public override bool FloatOnWater | ||
662 | { | ||
663 | set { return; } | ||
664 | } | ||
665 | |||
666 | public override PhysicsVector Velocity | ||
667 | { | ||
668 | get { return _velocity; } | ||
669 | set { _velocity = value; } | ||
670 | } | ||
671 | |||
672 | public override float CollisionScore | ||
673 | { | ||
674 | get { return 0f; } | ||
675 | set { } | ||
676 | } | ||
677 | |||
678 | public override Quaternion Orientation | ||
679 | { | ||
680 | get { return _orientation; } | ||
681 | set { _orientation = value; } | ||
682 | } | ||
683 | |||
684 | public override PhysicsVector Acceleration | ||
685 | { | ||
686 | get { return _acceleration; } | ||
687 | } | ||
688 | |||
689 | public override bool Kinematic | ||
690 | { | ||
691 | get { return true; } | ||
692 | set { } | ||
693 | } | ||
694 | |||
695 | public void SetAcceleration(PhysicsVector accel) | ||
696 | { | ||
697 | _acceleration = accel; | ||
698 | } | ||
699 | |||
700 | public override void AddForce(PhysicsVector force, bool pushforce) | ||
701 | { | ||
702 | } | ||
703 | |||
704 | public override void SetMomentum(PhysicsVector momentum) | ||
705 | { | ||
706 | } | ||
707 | |||
708 | public override bool Flying | ||
709 | { | ||
710 | get { return false; } | ||
711 | set { } | ||
712 | } | ||
713 | |||
714 | public override bool SetAlwaysRun | ||
715 | { | ||
716 | get { return false; } | ||
717 | set { return; } | ||
718 | } | ||
719 | |||
720 | public override uint LocalID | ||
721 | { | ||
722 | set { return; } | ||
723 | } | ||
724 | |||
725 | public override bool Grabbed | ||
726 | { | ||
727 | set { return; } | ||
728 | } | ||
729 | |||
730 | public override void link(PhysicsActor obj) | ||
731 | { | ||
732 | } | ||
733 | |||
734 | public override void delink() | ||
735 | { | ||
736 | } | ||
737 | |||
738 | public override void LockAngularMotion(PhysicsVector axis) | ||
739 | { | ||
740 | |||
741 | } | ||
742 | |||
743 | public override bool Selected | ||
744 | { | ||
745 | set { return; } | ||
746 | } | ||
747 | |||
748 | public override void CrossingFailure() | ||
749 | { | ||
750 | } | ||
751 | |||
752 | public override PhysicsVector PIDTarget | ||
753 | { | ||
754 | set { return; } | ||
755 | } | ||
756 | |||
757 | public override bool PIDActive | ||
758 | { | ||
759 | set { return; } | ||
760 | } | ||
761 | |||
762 | public override float PIDTau | ||
763 | { | ||
764 | set { return; } | ||
765 | } | ||
766 | |||
767 | public override void SubscribeEvents(int ms) | ||
768 | { | ||
769 | } | ||
770 | |||
771 | public override void UnSubscribeEvents() | ||
772 | { | ||
773 | } | ||
774 | |||
775 | public override bool SubscribedEvents() | ||
776 | { | ||
777 | return false; | ||
778 | } | ||
779 | } | ||
780 | } | 65 | } |
diff --git a/OpenSim/Region/Physics/POSPlugin/POSPrim.cs b/OpenSim/Region/Physics/POSPlugin/POSPrim.cs new file mode 100644 index 0000000..c767917 --- /dev/null +++ b/OpenSim/Region/Physics/POSPlugin/POSPrim.cs | |||
@@ -0,0 +1,262 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using Axiom.Math; | ||
31 | using Nini.Config; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Region.Physics.Manager; | ||
34 | |||
35 | namespace OpenSim.Region.Physics.POSPlugin | ||
36 | { | ||
37 | public class POSPrim : PhysicsActor | ||
38 | { | ||
39 | private PhysicsVector _position; | ||
40 | private PhysicsVector _velocity; | ||
41 | private PhysicsVector _acceleration; | ||
42 | private PhysicsVector _size; | ||
43 | private PhysicsVector m_rotationalVelocity = PhysicsVector.Zero; | ||
44 | private Quaternion _orientation; | ||
45 | private bool iscolliding; | ||
46 | |||
47 | public POSPrim() | ||
48 | { | ||
49 | _velocity = new PhysicsVector(); | ||
50 | _position = new PhysicsVector(); | ||
51 | _acceleration = new PhysicsVector(); | ||
52 | } | ||
53 | |||
54 | public override int PhysicsActorType | ||
55 | { | ||
56 | get { return (int) ActorTypes.Prim; } | ||
57 | set { return; } | ||
58 | } | ||
59 | |||
60 | public override PhysicsVector RotationalVelocity | ||
61 | { | ||
62 | get { return m_rotationalVelocity; } | ||
63 | set { m_rotationalVelocity = value; } | ||
64 | } | ||
65 | |||
66 | public override bool IsPhysical | ||
67 | { | ||
68 | get { return false; } | ||
69 | set { return; } | ||
70 | } | ||
71 | |||
72 | public override bool ThrottleUpdates | ||
73 | { | ||
74 | get { return false; } | ||
75 | set { return; } | ||
76 | } | ||
77 | |||
78 | public override bool IsColliding | ||
79 | { | ||
80 | get { return iscolliding; } | ||
81 | set { iscolliding = value; } | ||
82 | } | ||
83 | |||
84 | public override bool CollidingGround | ||
85 | { | ||
86 | get { return false; } | ||
87 | set { return; } | ||
88 | } | ||
89 | |||
90 | public override bool CollidingObj | ||
91 | { | ||
92 | get { return false; } | ||
93 | set { return; } | ||
94 | } | ||
95 | |||
96 | public override bool Stopped | ||
97 | { | ||
98 | get { return false; } | ||
99 | } | ||
100 | |||
101 | public override PhysicsVector Position | ||
102 | { | ||
103 | get { return _position; } | ||
104 | set { _position = value; } | ||
105 | } | ||
106 | |||
107 | public override PhysicsVector Size | ||
108 | { | ||
109 | get { return _size; } | ||
110 | set { _size = value; } | ||
111 | } | ||
112 | |||
113 | public override float Mass | ||
114 | { | ||
115 | get { return 0f; } | ||
116 | } | ||
117 | |||
118 | public override PhysicsVector Force | ||
119 | { | ||
120 | get { return PhysicsVector.Zero; } | ||
121 | } | ||
122 | |||
123 | public override PhysicsVector CenterOfMass | ||
124 | { | ||
125 | get { return PhysicsVector.Zero; } | ||
126 | } | ||
127 | |||
128 | public override PhysicsVector GeometricCenter | ||
129 | { | ||
130 | get { return PhysicsVector.Zero; } | ||
131 | } | ||
132 | |||
133 | public override PrimitiveBaseShape Shape | ||
134 | { | ||
135 | set { return; } | ||
136 | } | ||
137 | |||
138 | public override float Buoyancy | ||
139 | { | ||
140 | get { return 0f; } | ||
141 | set { return; } | ||
142 | } | ||
143 | |||
144 | public override bool FloatOnWater | ||
145 | { | ||
146 | set { return; } | ||
147 | } | ||
148 | |||
149 | public override PhysicsVector Velocity | ||
150 | { | ||
151 | get { return _velocity; } | ||
152 | set { _velocity = value; } | ||
153 | } | ||
154 | |||
155 | public override float CollisionScore | ||
156 | { | ||
157 | get { return 0f; } | ||
158 | set { } | ||
159 | } | ||
160 | |||
161 | public override Quaternion Orientation | ||
162 | { | ||
163 | get { return _orientation; } | ||
164 | set { _orientation = value; } | ||
165 | } | ||
166 | |||
167 | public override PhysicsVector Acceleration | ||
168 | { | ||
169 | get { return _acceleration; } | ||
170 | } | ||
171 | |||
172 | public override bool Kinematic | ||
173 | { | ||
174 | get { return true; } | ||
175 | set { } | ||
176 | } | ||
177 | |||
178 | public void SetAcceleration(PhysicsVector accel) | ||
179 | { | ||
180 | _acceleration = accel; | ||
181 | } | ||
182 | |||
183 | public override void AddForce(PhysicsVector force, bool pushforce) | ||
184 | { | ||
185 | } | ||
186 | |||
187 | public override void SetMomentum(PhysicsVector momentum) | ||
188 | { | ||
189 | } | ||
190 | |||
191 | public override bool Flying | ||
192 | { | ||
193 | get { return false; } | ||
194 | set { } | ||
195 | } | ||
196 | |||
197 | public override bool SetAlwaysRun | ||
198 | { | ||
199 | get { return false; } | ||
200 | set { return; } | ||
201 | } | ||
202 | |||
203 | public override uint LocalID | ||
204 | { | ||
205 | set { return; } | ||
206 | } | ||
207 | |||
208 | public override bool Grabbed | ||
209 | { | ||
210 | set { return; } | ||
211 | } | ||
212 | |||
213 | public override void link(PhysicsActor obj) | ||
214 | { | ||
215 | } | ||
216 | |||
217 | public override void delink() | ||
218 | { | ||
219 | } | ||
220 | |||
221 | public override void LockAngularMotion(PhysicsVector axis) | ||
222 | { | ||
223 | } | ||
224 | |||
225 | public override bool Selected | ||
226 | { | ||
227 | set { return; } | ||
228 | } | ||
229 | |||
230 | public override void CrossingFailure() | ||
231 | { | ||
232 | } | ||
233 | |||
234 | public override PhysicsVector PIDTarget | ||
235 | { | ||
236 | set { return; } | ||
237 | } | ||
238 | |||
239 | public override bool PIDActive | ||
240 | { | ||
241 | set { return; } | ||
242 | } | ||
243 | |||
244 | public override float PIDTau | ||
245 | { | ||
246 | set { return; } | ||
247 | } | ||
248 | |||
249 | public override void SubscribeEvents(int ms) | ||
250 | { | ||
251 | } | ||
252 | |||
253 | public override void UnSubscribeEvents() | ||
254 | { | ||
255 | } | ||
256 | |||
257 | public override bool SubscribedEvents() | ||
258 | { | ||
259 | return false; | ||
260 | } | ||
261 | } | ||
262 | } | ||
diff --git a/OpenSim/Region/Physics/POSPlugin/POSScene.cs b/OpenSim/Region/Physics/POSPlugin/POSScene.cs new file mode 100644 index 0000000..e9ecaa5 --- /dev/null +++ b/OpenSim/Region/Physics/POSPlugin/POSScene.cs | |||
@@ -0,0 +1,298 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using Axiom.Math; | ||
31 | using Nini.Config; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Region.Physics.Manager; | ||
34 | |||
35 | namespace 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 | public POSScene() | ||
45 | { | ||
46 | } | ||
47 | |||
48 | public override void Initialise(IMesher meshmerizer, IConfigSource config) | ||
49 | { | ||
50 | } | ||
51 | |||
52 | public override void Dispose() | ||
53 | { | ||
54 | } | ||
55 | |||
56 | public override PhysicsActor AddAvatar(string avName, PhysicsVector position, PhysicsVector size) | ||
57 | { | ||
58 | POSCharacter act = new POSCharacter(); | ||
59 | act.Position = position; | ||
60 | _characters.Add(act); | ||
61 | return act; | ||
62 | } | ||
63 | |||
64 | public override void SetWaterLevel(float baseheight) | ||
65 | { | ||
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(PhysicsVector position, PhysicsVector size, Quaternion rotation) | ||
88 | { | ||
89 | return null; | ||
90 | } | ||
91 | */ | ||
92 | |||
93 | public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, | ||
94 | PhysicsVector size, Quaternion rotation) | ||
95 | { | ||
96 | return AddPrimShape(primName, pbs, position, size, rotation, false); | ||
97 | } | ||
98 | |||
99 | public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, | ||
100 | PhysicsVector size, Quaternion rotation, bool isPhysical) | ||
101 | { | ||
102 | POSPrim prim = new POSPrim(); | ||
103 | prim.Position = position; | ||
104 | prim.Orientation = rotation; | ||
105 | prim.Size = size; | ||
106 | _prims.Add(prim); | ||
107 | return prim; | ||
108 | } | ||
109 | |||
110 | private bool check_collision(POSCharacter c, POSPrim p) | ||
111 | { | ||
112 | /* | ||
113 | Console.WriteLine("checking whether " + c + " collides with " + p + | ||
114 | " absX: " + Math.Abs(p.Position.X - c.Position.X) + | ||
115 | " sizeX: " + p.Size.X * 0.5 + 0.5); | ||
116 | */ | ||
117 | |||
118 | Vector3 rotatedPos = p.Orientation.Inverse() * | ||
119 | new Vector3(c.Position.X - p.Position.X, c.Position.Y - p.Position.Y, | ||
120 | c.Position.Z - p.Position.Z); | ||
121 | Vector3 avatarSize = p.Orientation.Inverse()*new Vector3(c.Size.X, c.Size.Y, c.Size.Z); | ||
122 | |||
123 | if (Math.Abs(rotatedPos.x) >= (p.Size.X*0.5 + Math.Abs(avatarSize.x)) || | ||
124 | Math.Abs(rotatedPos.y) >= (p.Size.Y*0.5 + Math.Abs(avatarSize.y)) || | ||
125 | Math.Abs(rotatedPos.z) >= (p.Size.Z*0.5 + Math.Abs(avatarSize.z))) | ||
126 | { | ||
127 | return false; | ||
128 | } | ||
129 | return true; | ||
130 | } | ||
131 | |||
132 | private bool check_all_prims(POSCharacter c) | ||
133 | { | ||
134 | for (int i = 0; i < _prims.Count; ++i) | ||
135 | { | ||
136 | if (check_collision(c, _prims[i])) | ||
137 | { | ||
138 | return true; | ||
139 | } | ||
140 | } | ||
141 | |||
142 | return false; | ||
143 | } | ||
144 | |||
145 | public override void AddPhysicsActorTaint(PhysicsActor prim) | ||
146 | { | ||
147 | } | ||
148 | |||
149 | public override float Simulate(float timeStep) | ||
150 | { | ||
151 | float fps = 0; | ||
152 | for (int i = 0; i < _characters.Count; ++i) | ||
153 | { | ||
154 | fps++; | ||
155 | POSCharacter character = _characters[i]; | ||
156 | |||
157 | float oldposX = character.Position.X; | ||
158 | float oldposY = character.Position.Y; | ||
159 | float oldposZ = character.Position.Z; | ||
160 | |||
161 | if (!character.Flying) | ||
162 | { | ||
163 | character._target_velocity.Z += gravity*timeStep; | ||
164 | } | ||
165 | |||
166 | bool forcedZ = false; | ||
167 | character.Position.X += character._target_velocity.X*timeStep; | ||
168 | character.Position.Y += character._target_velocity.Y*timeStep; | ||
169 | |||
170 | if (character.Position.Y < 0) | ||
171 | { | ||
172 | character.Position.Y = 0.1F; | ||
173 | } | ||
174 | else if (character.Position.Y >= Constants.RegionSize) | ||
175 | { | ||
176 | character.Position.Y = Constants.RegionSize - 0.1f; | ||
177 | } | ||
178 | |||
179 | if (character.Position.X < 0) | ||
180 | { | ||
181 | character.Position.X = 0.1F; | ||
182 | } | ||
183 | else if (character.Position.X >= Constants.RegionSize) | ||
184 | { | ||
185 | character.Position.X = Constants.RegionSize - 0.1f; | ||
186 | } | ||
187 | |||
188 | float terrainheight = _heightMap[(int)character.Position.Y * Constants.RegionSize + (int)character.Position.X]; | ||
189 | if (character.Position.Z + (character._target_velocity.Z*timeStep) < terrainheight + 2) | ||
190 | { | ||
191 | character.Position.Z = terrainheight + 1.0f; | ||
192 | forcedZ = true; | ||
193 | } | ||
194 | else | ||
195 | { | ||
196 | character.Position.Z += character._target_velocity.Z*timeStep; | ||
197 | } | ||
198 | |||
199 | /// this is it -- the magic you've all been waiting for! Ladies and gentlemen -- | ||
200 | /// Completely Bogus Collision Detection!!! | ||
201 | /// better known as the CBCD algorithm | ||
202 | |||
203 | if (check_all_prims(character)) | ||
204 | { | ||
205 | character.Position.Z = oldposZ; // first try Z axis | ||
206 | if (check_all_prims(character)) | ||
207 | { | ||
208 | character.Position.Z = oldposZ + 0.4f; // try harder | ||
209 | if (check_all_prims(character)) | ||
210 | { | ||
211 | character.Position.X = oldposX; | ||
212 | character.Position.Y = oldposY; | ||
213 | character.Position.Z = oldposZ; | ||
214 | character.Position.X += character._target_velocity.X * timeStep; | ||
215 | if (check_all_prims(character)) | ||
216 | { | ||
217 | character.Position.X = oldposX; | ||
218 | } | ||
219 | character.Position.Y += character._target_velocity.Y * timeStep; | ||
220 | if (check_all_prims(character)) | ||
221 | { | ||
222 | character.Position.Y = oldposY; | ||
223 | } | ||
224 | } | ||
225 | else | ||
226 | { | ||
227 | forcedZ = true; | ||
228 | } | ||
229 | } | ||
230 | else | ||
231 | { | ||
232 | forcedZ = true; | ||
233 | } | ||
234 | } | ||
235 | |||
236 | if (character.Position.Y < 0) | ||
237 | { | ||
238 | character.Position.Y = 0.1F; | ||
239 | } | ||
240 | else if (character.Position.Y >= Constants.RegionSize) | ||
241 | { | ||
242 | character.Position.Y = Constants.RegionSize - 0.1f; | ||
243 | } | ||
244 | |||
245 | if (character.Position.X < 0) | ||
246 | { | ||
247 | character.Position.X = 0.1F; | ||
248 | } | ||
249 | else if (character.Position.X >= Constants.RegionSize) | ||
250 | { | ||
251 | character.Position.X = Constants.RegionSize - 0.1f; | ||
252 | } | ||
253 | |||
254 | character._velocity.X = (character.Position.X - oldposX)/timeStep; | ||
255 | character._velocity.Y = (character.Position.Y - oldposY)/timeStep; | ||
256 | |||
257 | if (forcedZ) | ||
258 | { | ||
259 | character._velocity.Z = 0; | ||
260 | character._target_velocity.Z = 0; | ||
261 | ((PhysicsActor)character).IsColliding = true; | ||
262 | character.RequestPhysicsterseUpdate(); | ||
263 | } | ||
264 | else | ||
265 | { | ||
266 | ((PhysicsActor)character).IsColliding = false; | ||
267 | character._velocity.Z = (character.Position.Z - oldposZ)/timeStep; | ||
268 | } | ||
269 | } | ||
270 | return fps; | ||
271 | } | ||
272 | |||
273 | public override void GetResults() | ||
274 | { | ||
275 | } | ||
276 | |||
277 | public override bool IsThreaded | ||
278 | { | ||
279 | // for now we won't be multithreaded | ||
280 | get { return (false); } | ||
281 | } | ||
282 | |||
283 | public override void SetTerrain(float[] heightMap) | ||
284 | { | ||
285 | _heightMap = heightMap; | ||
286 | } | ||
287 | |||
288 | public override void DeleteTerrain() | ||
289 | { | ||
290 | } | ||
291 | |||
292 | public override Dictionary<uint, float> GetTopColliders() | ||
293 | { | ||
294 | Dictionary<uint, float> returncolliders = new Dictionary<uint, float>(); | ||
295 | return returncolliders; | ||
296 | } | ||
297 | } | ||
298 | } | ||