aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/PhysicsModules/POS
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/PhysicsModules/POS')
-rw-r--r--OpenSim/Region/PhysicsModules/POS/AssemblyInfo.cs58
-rw-r--r--OpenSim/Region/PhysicsModules/POS/POSCharacter.cs341
-rw-r--r--OpenSim/Region/PhysicsModules/POS/POSPlugin.cs64
-rw-r--r--OpenSim/Region/PhysicsModules/POS/POSPrim.cs336
-rw-r--r--OpenSim/Region/PhysicsModules/POS/POSScene.cs273
5 files changed, 1072 insertions, 0 deletions
diff --git a/OpenSim/Region/PhysicsModules/POS/AssemblyInfo.cs b/OpenSim/Region/PhysicsModules/POS/AssemblyInfo.cs
new file mode 100644
index 0000000..fc1ffba
--- /dev/null
+++ b/OpenSim/Region/PhysicsModules/POS/AssemblyInfo.cs
@@ -0,0 +1,58 @@
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.Reflection;
29using System.Runtime.InteropServices;
30
31// Information about this assembly is defined by the following
32// attributes.
33//
34// change them to the information which is associated with the assembly
35// you compile.
36
37[assembly : AssemblyTitle("POSPlugin")]
38[assembly : AssemblyDescription("")]
39[assembly : AssemblyConfiguration("")]
40[assembly : AssemblyCompany("http://opensimulator.org")]
41[assembly : AssemblyProduct("POSPlugin")]
42[assembly : AssemblyCopyright("Copyright (c) OpenSimulator.org Developers")]
43[assembly : AssemblyTrademark("")]
44[assembly : AssemblyCulture("")]
45
46// This sets the default COM visibility of types in the assembly to invisible.
47// If you need to expose a type to COM, use [ComVisible(true)] on that type.
48
49[assembly : ComVisible(false)]
50
51// The assembly version has following format :
52//
53// Major.Minor.Build.Revision
54//
55// You can specify all values by your own or you can build default build and revision
56// numbers with the '*' character (the default):
57
58[assembly : AssemblyVersion("0.8.2.*")]
diff --git a/OpenSim/Region/PhysicsModules/POS/POSCharacter.cs b/OpenSim/Region/PhysicsModules/POS/POSCharacter.cs
new file mode 100644
index 0000000..40ab984
--- /dev/null
+++ b/OpenSim/Region/PhysicsModules/POS/POSCharacter.cs
@@ -0,0 +1,341 @@
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 POSCharacter : PhysicsActor
38 {
39 private Vector3 _position;
40 public Vector3 _velocity;
41 public Vector3 _target_velocity = Vector3.Zero;
42 public Vector3 _size = Vector3.Zero;
43 private Vector3 _acceleration;
44 private Vector3 m_rotationalVelocity = Vector3.Zero;
45 private bool flying;
46 private bool isColliding;
47
48 public POSCharacter()
49 {
50 }
51
52 public override int PhysicsActorType
53 {
54 get { return (int) ActorTypes.Agent; }
55 set { return; }
56 }
57
58 public override Vector3 RotationalVelocity
59 {
60 get { return m_rotationalVelocity; }
61 set { m_rotationalVelocity = value; }
62 }
63
64 public override bool SetAlwaysRun
65 {
66 get { return false; }
67 set { return; }
68 }
69
70 public override uint LocalID
71 {
72 set { return; }
73 }
74
75 public override bool Grabbed
76 {
77 set { return; }
78 }
79
80 public override bool Selected
81 {
82 set { return; }
83 }
84
85 public override float Buoyancy
86 {
87 get { return 0f; }
88 set { return; }
89 }
90
91 public override bool FloatOnWater
92 {
93 set { return; }
94 }
95
96 public override bool IsPhysical
97 {
98 get { return false; }
99 set { return; }
100 }
101
102 public override bool ThrottleUpdates
103 {
104 get { return false; }
105 set { return; }
106 }
107
108 public override bool Flying
109 {
110 get { return flying; }
111 set { flying = value; }
112 }
113
114 public override bool IsColliding
115 {
116 get { return isColliding; }
117 set { isColliding = value; }
118 }
119
120 public override bool CollidingGround
121 {
122 get { return false; }
123 set { return; }
124 }
125
126 public override bool CollidingObj
127 {
128 get { return false; }
129 set { return; }
130 }
131
132 public override bool Stopped
133 {
134 get { return false; }
135 }
136
137 public override Vector3 Position
138 {
139 get { return _position; }
140 set { _position = value; }
141 }
142
143 public override Vector3 Size
144 {
145 get { return _size; }
146 set
147 {
148 _size = value;
149 _size.Z = _size.Z / 2.0f;
150 }
151 }
152
153 public override float Mass
154 {
155 get { return 0f; }
156 }
157
158 public override Vector3 Force
159 {
160 get { return Vector3.Zero; }
161 set { return; }
162 }
163
164 public override int VehicleType
165 {
166 get { return 0; }
167 set { return; }
168 }
169
170 public override void VehicleFloatParam(int param, float value)
171 {
172
173 }
174
175 public override void VehicleVectorParam(int param, Vector3 value)
176 {
177
178 }
179
180 public override void VehicleRotationParam(int param, Quaternion rotation)
181 {
182
183 }
184
185 public override void VehicleFlags(int param, bool remove) { }
186
187 public override void SetVolumeDetect(int param)
188 {
189
190 }
191
192 public override Vector3 CenterOfMass
193 {
194 get { return Vector3.Zero; }
195 }
196
197 public override Vector3 GeometricCenter
198 {
199 get { return Vector3.Zero; }
200 }
201
202 public override PrimitiveBaseShape Shape
203 {
204 set { return; }
205 }
206
207 public override Vector3 Velocity
208 {
209 get { return _velocity; }
210 set { _target_velocity = value; }
211 }
212
213 public override Vector3 Torque
214 {
215 get { return Vector3.Zero; }
216 set { return; }
217 }
218
219 public override float CollisionScore
220 {
221 get { return 0f; }
222 set { }
223 }
224
225 public override Quaternion Orientation
226 {
227 get { return Quaternion.Identity; }
228 set { }
229 }
230
231 public override Vector3 Acceleration
232 {
233 get { return _acceleration; }
234 set { _acceleration = value; }
235 }
236
237 public override bool Kinematic
238 {
239 get { return true; }
240 set { }
241 }
242
243 public override void link(PhysicsActor obj)
244 {
245 }
246
247 public override void delink()
248 {
249 }
250
251 public override void LockAngularMotion(Vector3 axis)
252 {
253 }
254
255 public override void AddForce(Vector3 force, bool pushforce)
256 {
257 }
258
259 public override void AddAngularForce(Vector3 force, bool pushforce)
260 {
261 }
262
263 public override void SetMomentum(Vector3 momentum)
264 {
265 }
266
267 public override void CrossingFailure()
268 {
269 }
270
271 public override Vector3 PIDTarget
272 {
273 set { return; }
274 }
275
276 public override bool PIDActive
277 {
278 get { return false; }
279 set { return; }
280 }
281
282 public override float PIDTau
283 {
284 set { return; }
285 }
286
287 public override float PIDHoverHeight
288 {
289 set { return; }
290 }
291
292 public override bool PIDHoverActive
293 {
294 set { return; }
295 }
296
297 public override PIDHoverType PIDHoverType
298 {
299 set { return; }
300 }
301
302 public override float PIDHoverTau
303 {
304 set { return; }
305 }
306
307 public override Quaternion APIDTarget
308 {
309 set { return; }
310 }
311
312 public override bool APIDActive
313 {
314 set { return; }
315 }
316
317 public override float APIDStrength
318 {
319 set { return; }
320 }
321
322 public override float APIDDamping
323 {
324 set { return; }
325 }
326
327
328 public override void SubscribeEvents(int ms)
329 {
330 }
331
332 public override void UnSubscribeEvents()
333 {
334 }
335
336 public override bool SubscribedEvents()
337 {
338 return false;
339 }
340 }
341}
diff --git a/OpenSim/Region/PhysicsModules/POS/POSPlugin.cs b/OpenSim/Region/PhysicsModules/POS/POSPlugin.cs
new file mode 100644
index 0000000..ed086dd
--- /dev/null
+++ b/OpenSim/Region/PhysicsModules/POS/POSPlugin.cs
@@ -0,0 +1,64 @@
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 OpenSim.Framework;
32using OpenSim.Region.Physics.Manager;
33
34namespace OpenSim.Region.Physics.POSPlugin
35{
36 /// <summary>
37 /// for now will be a very POS physics engine
38 /// </summary>
39 public class POSPlugin : IPhysicsPlugin
40 {
41 public POSPlugin()
42 {
43 }
44
45 public bool Init()
46 {
47 return true;
48 }
49
50 public PhysicsScene GetScene(string sceneIdentifier)
51 {
52 return new POSScene(GetName(), sceneIdentifier);
53 }
54
55 public string GetName()
56 {
57 return ("POS");
58 }
59
60 public void Dispose()
61 {
62 }
63 }
64}
diff --git a/OpenSim/Region/PhysicsModules/POS/POSPrim.cs b/OpenSim/Region/PhysicsModules/POS/POSPrim.cs
new file mode 100644
index 0000000..7c1e915
--- /dev/null
+++ b/OpenSim/Region/PhysicsModules/POS/POSPrim.cs
@@ -0,0 +1,336 @@
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 POSPrim : PhysicsActor
38 {
39 private Vector3 _position;
40 private Vector3 _velocity;
41 private Vector3 _acceleration;
42 private Vector3 _size;
43 private Vector3 m_rotationalVelocity = Vector3.Zero;
44 private Quaternion _orientation;
45 private bool iscolliding;
46
47 public POSPrim()
48 {
49 }
50
51 public override int PhysicsActorType
52 {
53 get { return (int) ActorTypes.Prim; }
54 set { return; }
55 }
56
57 public override Vector3 RotationalVelocity
58 {
59 get { return m_rotationalVelocity; }
60 set { m_rotationalVelocity = value; }
61 }
62
63 public override bool IsPhysical
64 {
65 get { return false; }
66 set { return; }
67 }
68
69 public override bool ThrottleUpdates
70 {
71 get { return false; }
72 set { return; }
73 }
74
75 public override bool IsColliding
76 {
77 get { return iscolliding; }
78 set { iscolliding = value; }
79 }
80
81 public override bool CollidingGround
82 {
83 get { return false; }
84 set { return; }
85 }
86
87 public override bool CollidingObj
88 {
89 get { return false; }
90 set { return; }
91 }
92
93 public override bool Stopped
94 {
95 get { return false; }
96 }
97
98 public override Vector3 Position
99 {
100 get { return _position; }
101 set { _position = value; }
102 }
103
104 public override Vector3 Size
105 {
106 get { return _size; }
107 set { _size = value; }
108 }
109
110 public override float Mass
111 {
112 get { return 0f; }
113 }
114
115 public override Vector3 Force
116 {
117 get { return Vector3.Zero; }
118 set { return; }
119 }
120
121 public override int VehicleType
122 {
123 get { return 0; }
124 set { return; }
125 }
126
127 public override void VehicleFloatParam(int param, float value)
128 {
129
130 }
131
132 public override void VehicleVectorParam(int param, Vector3 value)
133 {
134
135 }
136
137 public override void VehicleRotationParam(int param, Quaternion rotation)
138 {
139
140 }
141
142 public override void VehicleFlags(int param, bool remove) { }
143
144 public override void SetVolumeDetect(int param)
145 {
146
147 }
148
149 public override Vector3 CenterOfMass
150 {
151 get { return Vector3.Zero; }
152 }
153
154 public override Vector3 GeometricCenter
155 {
156 get { return Vector3.Zero; }
157 }
158
159 public override PrimitiveBaseShape Shape
160 {
161 set { return; }
162 }
163
164 public override float Buoyancy
165 {
166 get { return 0f; }
167 set { return; }
168 }
169
170 public override bool FloatOnWater
171 {
172 set { return; }
173 }
174
175 public override Vector3 Velocity
176 {
177 get { return _velocity; }
178 set { _velocity = value; }
179 }
180
181 public override float CollisionScore
182 {
183 get { return 0f; }
184 set { }
185 }
186
187 public override Quaternion Orientation
188 {
189 get { return _orientation; }
190 set { _orientation = value; }
191 }
192
193 public override Vector3 Acceleration
194 {
195 get { return _acceleration; }
196 set { _acceleration = value; }
197 }
198
199 public override bool Kinematic
200 {
201 get { return true; }
202 set { }
203 }
204
205 public override void AddForce(Vector3 force, bool pushforce)
206 {
207 }
208
209 public override void AddAngularForce(Vector3 force, bool pushforce)
210 {
211 }
212
213 public override Vector3 Torque
214 {
215 get { return Vector3.Zero; }
216 set { return; }
217 }
218
219 public override void SetMomentum(Vector3 momentum)
220 {
221 }
222
223 public override bool Flying
224 {
225 get { return false; }
226 set { }
227 }
228
229 public override bool SetAlwaysRun
230 {
231 get { return false; }
232 set { return; }
233 }
234
235 public override uint LocalID
236 {
237 set { return; }
238 }
239
240 public override bool Grabbed
241 {
242 set { return; }
243 }
244
245 public override void link(PhysicsActor obj)
246 {
247 }
248
249 public override void delink()
250 {
251 }
252
253 public override void LockAngularMotion(Vector3 axis)
254 {
255 }
256
257 public override bool Selected
258 {
259 set { return; }
260 }
261
262 public override void CrossingFailure()
263 {
264 }
265
266 public override Vector3 PIDTarget
267 {
268 set { return; }
269 }
270
271 public override bool PIDActive
272 {
273 get { return false; }
274 set { return; }
275 }
276
277 public override float PIDTau
278 {
279 set { return; }
280 }
281
282 public override float PIDHoverHeight
283 {
284 set { return; }
285 }
286
287 public override bool PIDHoverActive
288 {
289 set { return; }
290 }
291
292 public override PIDHoverType PIDHoverType
293 {
294 set { return; }
295 }
296
297 public override float PIDHoverTau
298 {
299 set { return; }
300 }
301
302 public override Quaternion APIDTarget
303 {
304 set { return; }
305 }
306
307 public override bool APIDActive
308 {
309 set { return; }
310 }
311
312 public override float APIDStrength
313 {
314 set { return; }
315 }
316
317 public override float APIDDamping
318 {
319 set { return; }
320 }
321
322
323 public override void SubscribeEvents(int ms)
324 {
325 }
326
327 public override void UnSubscribeEvents()
328 {
329 }
330
331 public override bool SubscribedEvents()
332 {
333 return false;
334 }
335 }
336}
diff --git a/OpenSim/Region/PhysicsModules/POS/POSScene.cs b/OpenSim/Region/PhysicsModules/POS/POSScene.cs
new file mode 100644
index 0000000..080c6ab
--- /dev/null
+++ b/OpenSim/Region/PhysicsModules/POS/POSScene.cs
@@ -0,0 +1,273 @@
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 engineType, String _sceneIdentifier)
47 {
48 EngineType = engineType;
49 Name = EngineType + "/" + _sceneIdentifier;
50 //sceneIdentifier = _sceneIdentifier;
51 }
52
53 public override void Initialise(IMesher meshmerizer, IConfigSource config)
54 {
55 }
56
57 public override void Dispose()
58 {
59 }
60
61 public override PhysicsActor AddAvatar(
62 string avName, Vector3 position, Vector3 velocity, Vector3 size, bool isFlying)
63 {
64 POSCharacter act = new POSCharacter();
65 act.Position = position;
66 act.Flying = isFlying;
67 _characters.Add(act);
68 return act;
69 }
70
71 public override void RemovePrim(PhysicsActor prim)
72 {
73 POSPrim p = (POSPrim) prim;
74 if (_prims.Contains(p))
75 {
76 _prims.Remove(p);
77 }
78 }
79
80 public override void RemoveAvatar(PhysicsActor character)
81 {
82 POSCharacter act = (POSCharacter) character;
83 if (_characters.Contains(act))
84 {
85 _characters.Remove(act);
86 }
87 }
88
89/*
90 public override PhysicsActor AddPrim(Vector3 position, Vector3 size, Quaternion rotation)
91 {
92 return null;
93 }
94*/
95
96 public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position,
97 Vector3 size, Quaternion rotation, bool isPhysical, uint localid)
98 {
99 POSPrim prim = new POSPrim();
100 prim.Position = position;
101 prim.Orientation = rotation;
102 prim.Size = size;
103 _prims.Add(prim);
104 return prim;
105 }
106
107 private bool isColliding(POSCharacter c, POSPrim p)
108 {
109 Vector3 rotatedPos = new Vector3(c.Position.X - p.Position.X, c.Position.Y - p.Position.Y,
110 c.Position.Z - p.Position.Z) * Quaternion.Inverse(p.Orientation);
111 Vector3 avatarSize = new Vector3(c.Size.X, c.Size.Y, c.Size.Z) * Quaternion.Inverse(p.Orientation);
112
113 return (Math.Abs(rotatedPos.X) < (p.Size.X*0.5 + Math.Abs(avatarSize.X)) &&
114 Math.Abs(rotatedPos.Y) < (p.Size.Y*0.5 + Math.Abs(avatarSize.Y)) &&
115 Math.Abs(rotatedPos.Z) < (p.Size.Z*0.5 + Math.Abs(avatarSize.Z)));
116 }
117
118 private bool isCollidingWithPrim(POSCharacter c)
119 {
120 foreach (POSPrim p in _prims)
121 {
122 if (isColliding(c, p))
123 {
124 return true;
125 }
126 }
127
128 return false;
129 }
130
131 public override void AddPhysicsActorTaint(PhysicsActor prim)
132 {
133 }
134
135 public override float Simulate(float timeStep)
136 {
137 float fps = 0;
138 for (int i = 0; i < _characters.Count; ++i)
139 {
140 fps++;
141 POSCharacter character = _characters[i];
142
143 float oldposX = character.Position.X;
144 float oldposY = character.Position.Y;
145 float oldposZ = character.Position.Z;
146
147 if (!character.Flying)
148 {
149 character._target_velocity.Z += gravity * timeStep;
150 }
151
152 Vector3 characterPosition = character.Position;
153
154 characterPosition.X += character._target_velocity.X * timeStep;
155 characterPosition.Y += character._target_velocity.Y * timeStep;
156
157 characterPosition.X = Util.Clamp(character.Position.X, 0.01f, Constants.RegionSize - 0.01f);
158 characterPosition.Y = Util.Clamp(character.Position.Y, 0.01f, Constants.RegionSize - 0.01f);
159
160 bool forcedZ = false;
161
162 float terrainheight = _heightMap[(int)character.Position.Y * Constants.RegionSize + (int)character.Position.X];
163 if (character.Position.Z + (character._target_velocity.Z * timeStep) < terrainheight + 2)
164 {
165 characterPosition.Z = terrainheight + character.Size.Z;
166 forcedZ = true;
167 }
168 else
169 {
170 characterPosition.Z += character._target_velocity.Z*timeStep;
171 }
172
173 /// this is it -- the magic you've all been waiting for! Ladies and gentlemen --
174 /// Completely Bogus Collision Detection!!!
175 /// better known as the CBCD algorithm
176
177 if (isCollidingWithPrim(character))
178 {
179 characterPosition.Z = oldposZ; // first try Z axis
180 if (isCollidingWithPrim(character))
181 {
182 characterPosition.Z = oldposZ + character.Size.Z / 4.4f; // try harder
183 if (isCollidingWithPrim(character))
184 {
185 characterPosition.Z = oldposZ + character.Size.Z / 2.2f; // try very hard
186 if (isCollidingWithPrim(character))
187 {
188 characterPosition.X = oldposX;
189 characterPosition.Y = oldposY;
190 characterPosition.Z = oldposZ;
191
192 characterPosition.X += character._target_velocity.X * timeStep;
193 if (isCollidingWithPrim(character))
194 {
195 characterPosition.X = oldposX;
196 }
197
198 characterPosition.Y += character._target_velocity.Y * timeStep;
199 if (isCollidingWithPrim(character))
200 {
201 characterPosition.Y = oldposY;
202 }
203 }
204 else
205 {
206 forcedZ = true;
207 }
208 }
209 else
210 {
211 forcedZ = true;
212 }
213 }
214 else
215 {
216 forcedZ = true;
217 }
218 }
219
220 characterPosition.X = Util.Clamp(character.Position.X, 0.01f, Constants.RegionSize - 0.01f);
221 characterPosition.Y = Util.Clamp(character.Position.Y, 0.01f, Constants.RegionSize - 0.01f);
222
223 character.Position = characterPosition;
224
225 character._velocity.X = (character.Position.X - oldposX)/timeStep;
226 character._velocity.Y = (character.Position.Y - oldposY)/timeStep;
227
228 if (forcedZ)
229 {
230 character._velocity.Z = 0;
231 character._target_velocity.Z = 0;
232 ((PhysicsActor)character).IsColliding = true;
233 character.RequestPhysicsterseUpdate();
234 }
235 else
236 {
237 ((PhysicsActor)character).IsColliding = false;
238 character._velocity.Z = (character.Position.Z - oldposZ)/timeStep;
239 }
240 }
241 return fps;
242 }
243
244 public override void GetResults()
245 {
246 }
247
248 public override bool IsThreaded
249 {
250 // for now we won't be multithreaded
251 get { return (false); }
252 }
253
254 public override void SetTerrain(float[] heightMap)
255 {
256 _heightMap = heightMap;
257 }
258
259 public override void DeleteTerrain()
260 {
261 }
262
263 public override void SetWaterLevel(float baseheight)
264 {
265 }
266
267 public override Dictionary<uint, float> GetTopColliders()
268 {
269 Dictionary<uint, float> returncolliders = new Dictionary<uint, float>();
270 return returncolliders;
271 }
272 }
273}