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/POSPlugin/POSPlugin.cs | |
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 '')
-rw-r--r-- | OpenSim/Region/Physics/POSPlugin/POSPlugin.cs | 715 |
1 files changed, 0 insertions, 715 deletions
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 | } |