aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Physics/POSPlugin/POSPlugin.cs
diff options
context:
space:
mode:
authordan miller2007-11-17 09:59:07 +0000
committerdan miller2007-11-17 09:59:07 +0000
commitd71b28c7312995e1187e81e278b23a4418b64c11 (patch)
tree7b0282ecf948ff33ba22ffd6c8fcd1e29642490c /OpenSim/Region/Physics/POSPlugin/POSPlugin.cs
parentset svn:eol-style (diff)
downloadopensim-SC-d71b28c7312995e1187e81e278b23a4418b64c11.zip
opensim-SC-d71b28c7312995e1187e81e278b23a4418b64c11.tar.gz
opensim-SC-d71b28c7312995e1187e81e278b23a4418b64c11.tar.bz2
opensim-SC-d71b28c7312995e1187e81e278b23a4418b64c11.tar.xz
Out of a fog of alcohol and adenovirus, I present - POS!
EXTREMELY basic collision detection; walk on prims don't rotate anything do not feed or annoy POS YMMV
Diffstat (limited to 'OpenSim/Region/Physics/POSPlugin/POSPlugin.cs')
-rw-r--r--OpenSim/Region/Physics/POSPlugin/POSPlugin.cs249
1 files changed, 218 insertions, 31 deletions
diff --git a/OpenSim/Region/Physics/POSPlugin/POSPlugin.cs b/OpenSim/Region/Physics/POSPlugin/POSPlugin.cs
index 5b4450c..635e430 100644
--- a/OpenSim/Region/Physics/POSPlugin/POSPlugin.cs
+++ b/OpenSim/Region/Physics/POSPlugin/POSPlugin.cs
@@ -26,6 +26,7 @@
26* 26*
27*/ 27*/
28using System.Collections.Generic; 28using System.Collections.Generic;
29using System;
29using Axiom.Math; 30using Axiom.Math;
30using OpenSim.Framework; 31using OpenSim.Framework;
31using OpenSim.Region.Physics.Manager; 32using OpenSim.Region.Physics.Manager;
@@ -63,9 +64,10 @@ namespace OpenSim.Region.Physics.POSPlugin
63 64
64 public class POSScene : PhysicsScene 65 public class POSScene : PhysicsScene
65 { 66 {
66 private List<POSActor> _actors = new List<POSActor>(); 67 private List<POSCharacter> _characters = new List<POSCharacter>();
68 private List<POSPrim> _prims = new List<POSPrim>();
67 private float[] _heightMap; 69 private float[] _heightMap;
68 private const float gravity = -1.0f; 70 private const float gravity = -9.8f;
69 71
70 public POSScene() 72 public POSScene()
71 { 73 {
@@ -78,22 +80,27 @@ namespace OpenSim.Region.Physics.POSPlugin
78 80
79 public override PhysicsActor AddAvatar(string avName, PhysicsVector position) 81 public override PhysicsActor AddAvatar(string avName, PhysicsVector position)
80 { 82 {
81 POSActor act = new POSActor(); 83 POSCharacter act = new POSCharacter();
82 act.Position = position; 84 act.Position = position;
83 _actors.Add(act); 85 _characters.Add(act);
84 return act; 86 return act;
85 } 87 }
86 88
87 public override void RemovePrim(PhysicsActor prim) 89 public override void RemovePrim(PhysicsActor prim)
88 { 90 {
91 POSPrim p = (POSPrim) prim;
92 if (_prims.Contains(p))
93 {
94 _prims.Remove(p);
95 }
89 } 96 }
90 97
91 public override void RemoveAvatar(PhysicsActor actor) 98 public override void RemoveAvatar(PhysicsActor character)
92 { 99 {
93 POSActor act = (POSActor) actor; 100 POSCharacter act = (POSCharacter) character;
94 if (_actors.Contains(act)) 101 if (_characters.Contains(act))
95 { 102 {
96 _actors.Remove(act); 103 _characters.Remove(act);
97 } 104 }
98 } 105 }
99 106
@@ -113,46 +120,105 @@ namespace OpenSim.Region.Physics.POSPlugin
113 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, 120 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position,
114 PhysicsVector size, Quaternion rotation, bool isPhysical) 121 PhysicsVector size, Quaternion rotation, bool isPhysical)
115 { 122 {
116 return null; 123 POSPrim prim = new POSPrim();
124 prim.Position = position;
125 prim.Orientation = rotation;
126 prim.Size = size;
127 _prims.Add(prim);
128 return prim;
129 }
130
131 private bool check_collision(POSCharacter c, POSPrim p)
132 {
133 /*
134 Console.WriteLine("checking whether " + c + " collides with " + p +
135 " absX: " + Math.Abs(p.Position.X - c.Position.X) +
136 " sizeX: " + p.Size.X * 0.5 + 0.5);
137 */
138 bool collides = true;
139 if (Math.Abs(p.Position.X - c.Position.X) >= (p.Size.X * 0.5 + 0.5))
140 {
141 collides = false;
142 }
143 if (Math.Abs(p.Position.Y - c.Position.Y) >= (p.Size.Y * 0.5 + 0.5))
144 {
145 collides = false;
146 }
147 if (Math.Abs(p.Position.Z - c.Position.Z) >= (p.Size.Z * 0.5 + 1.0))
148 {
149 collides = false;
150 }
151 return collides;
117 } 152 }
118 153
119 public override void Simulate(float timeStep) 154 public override void Simulate(float timeStep)
120 { 155 {
121 foreach (POSActor actor in _actors) 156 foreach (POSCharacter character in _characters)
122 { 157 {
123 actor.Position.X += actor.Velocity.X * timeStep; 158 float oldposX = character.Position.X;
124 actor.Position.Y += actor.Velocity.Y * timeStep; 159 float oldposY = character.Position.Y;
125 actor.Position.Z += actor.Velocity.Z * timeStep; 160 float oldposZ = character.Position.Z;
126 161
127 if (!actor.Flying) 162 if (!character.Flying)
128 { 163 {
129 actor.Velocity.Z += gravity; 164 character._target_velocity.Z += gravity * timeStep;
130 } 165 }
131 166
132 if (actor.Position.X < 0) 167 character.Position.X = character.Position.X + (character._target_velocity.X * timeStep);
168 character.Position.Y = character.Position.Y + (character._target_velocity.Y * timeStep);
169 float terrainheight = _heightMap[(int)character.Position.Y * 256 + (int)character.Position.X];
170 if (character.Position.Z + (character._target_velocity.Z * timeStep) < terrainheight + 2)
171 {
172 character.Position.Z = terrainheight + 1.0f;
173 character._target_velocity.Z = 0;
174 character._velocity.Z = 0;
175 }
176 else
133 { 177 {
134 actor.Position.X = 0.1F; 178 character.Position.Z = character.Position.Z + (character._target_velocity.Z * timeStep);
135 } 179 }
136 else if (actor.Position.X > 256) 180
181 /// this is it -- the magic you've all been waiting for! Ladies and gentlemen --
182 /// Completely Bogus Collision Detection!!!
183 /// better known as the CBCD algorithm
184
185 foreach (POSPrim p in _prims)
137 { 186 {
138 actor.Position.X = 255.9F; 187 if (check_collision(character, p))
188 {
189 character.Position.Z = oldposZ; // first try Z axis
190 if (check_collision(character, p))
191 {
192 character.Position.X = oldposX;
193 character.Position.Y = oldposY;
194 }
195 else
196 {
197 character._target_velocity.Z = 0;
198 }
199 }
139 } 200 }
140 201
141 if (actor.Position.Y < 0) 202 if (character.Position.Y < 0)
142 { 203 {
143 actor.Position.Y = 0.1F; 204 character.Position.Y = 0.1F;
144 } 205 }
145 else if (actor.Position.Y >= 256) 206 else if (character.Position.Y >= 256)
146 { 207 {
147 actor.Position.Y = 255.9F; 208 character.Position.Y = 255.9F;
148 } 209 }
149 210
150 float terrainheight = _heightMap[(int) actor.Position.Y * 256 + (int) actor.Position.X]; 211 if (character.Position.X < 0)
151 if (actor.Position.Z + (actor.Velocity.Z * timeStep) < terrainheight + 2)
152 { 212 {
153 actor.Position.Z = terrainheight + 1.0f; 213 character.Position.X = 0.1F;
154 actor.Velocity.Z = 0;
155 } 214 }
215 else if (character.Position.X > 256)
216 {
217 character.Position.X = 255.9F;
218 }
219
220 character._velocity.X = (character.Position.X - oldposX) / timeStep;
221 character._velocity.Y = (character.Position.Y - oldposY) / timeStep;
156 } 222 }
157 } 223 }
158 224
@@ -176,16 +242,17 @@ namespace OpenSim.Region.Physics.POSPlugin
176 } 242 }
177 } 243 }
178 244
179 public class POSActor : PhysicsActor 245 public class POSCharacter : PhysicsActor
180 { 246 {
181 private PhysicsVector _position; 247 private PhysicsVector _position;
182 private PhysicsVector _velocity; 248 public PhysicsVector _velocity;
249 public PhysicsVector _target_velocity = PhysicsVector.Zero;
183 private PhysicsVector _acceleration; 250 private PhysicsVector _acceleration;
184 private PhysicsVector m_rotationalVelocity = PhysicsVector.Zero; 251 private PhysicsVector m_rotationalVelocity = PhysicsVector.Zero;
185 private bool flying; 252 private bool flying;
186 private bool iscolliding; 253 private bool iscolliding;
187 254
188 public POSActor() 255 public POSCharacter()
189 { 256 {
190 _velocity = new PhysicsVector(); 257 _velocity = new PhysicsVector();
191 _position = new PhysicsVector(); 258 _position = new PhysicsVector();
@@ -260,7 +327,7 @@ namespace OpenSim.Region.Physics.POSPlugin
260 public override PhysicsVector Velocity 327 public override PhysicsVector Velocity
261 { 328 {
262 get { return _velocity; } 329 get { return _velocity; }
263 set { _velocity = value; } 330 set { _target_velocity = value; }
264 } 331 }
265 332
266 public override Quaternion Orientation 333 public override Quaternion Orientation
@@ -293,4 +360,124 @@ namespace OpenSim.Region.Physics.POSPlugin
293 { 360 {
294 } 361 }
295 } 362 }
363
364 public class POSPrim : PhysicsActor
365 {
366 private PhysicsVector _position;
367 private PhysicsVector _velocity;
368 private PhysicsVector _acceleration;
369 private PhysicsVector _size;
370 private PhysicsVector m_rotationalVelocity = PhysicsVector.Zero;
371 private Quaternion _orientation;
372 private bool flying;
373 private bool iscolliding;
374
375 public POSPrim()
376 {
377 _velocity = new PhysicsVector();
378 _position = new PhysicsVector();
379 _acceleration = new PhysicsVector();
380 }
381 public override int PhysicsActorType
382 {
383 get { return (int)ActorTypes.Prim; }
384 set { return; }
385 }
386 public override PhysicsVector RotationalVelocity
387 {
388 get { return m_rotationalVelocity; }
389 set { m_rotationalVelocity = value; }
390 }
391 public override bool IsPhysical
392 {
393 get { return false; }
394 set { return; }
395 }
396 public override bool ThrottleUpdates
397 {
398 get { return false; }
399 set { return; }
400 }
401 public override bool IsColliding
402 {
403 get { return iscolliding; }
404 set { iscolliding = value; }
405 }
406 public override bool CollidingGround
407 {
408 get { return false; }
409 set { return; }
410 }
411 public override bool CollidingObj
412 {
413 get { return false; }
414 set { return; }
415 }
416 public override PhysicsVector Position
417 {
418 get { return _position; }
419 set { _position = value; }
420 }
421
422 public override PhysicsVector Size
423 {
424 get { return _size; }
425 set { _size = value; }
426 }
427
428 public override PrimitiveBaseShape Shape
429 {
430 set
431 {
432 return;
433 }
434 }
435
436 public override PhysicsVector Velocity
437 {
438 get { return _velocity; }
439 set { _velocity = value; }
440 }
441
442 public override Quaternion Orientation
443 {
444 get { return _orientation; }
445 set { _orientation = value; }
446 }
447
448 public override PhysicsVector Acceleration
449 {
450 get { return _acceleration; }
451 }
452
453 public override bool Kinematic
454 {
455 get { return true; }
456 set { }
457 }
458
459 public void SetAcceleration(PhysicsVector accel)
460 {
461 _acceleration = accel;
462 }
463
464 public override void AddForce(PhysicsVector force)
465 {
466 }
467
468 public override void SetMomentum(PhysicsVector momentum)
469 {
470 }
471 public override bool Flying
472 {
473 get { return false; }
474 set { }
475 }
476
477 public override bool SetAlwaysRun
478 {
479 get { return false; }
480 set { return; }
481 }
482 }
296} 483}