diff options
author | Jeff Ames | 2007-11-16 10:25:27 +0000 |
---|---|---|
committer | Jeff Ames | 2007-11-16 10:25:27 +0000 |
commit | e3998230cc8e4283b013add367abdf91420b4b1f (patch) | |
tree | f6206557e95e41a07a86a0d8658f632632593383 /OpenSim/Region/Physics/POSPlugin/POSPlugin.cs | |
parent | * ODE step two on the way to separate dynamic space allocation ( One more to ... (diff) | |
download | opensim-SC_OLD-e3998230cc8e4283b013add367abdf91420b4b1f.zip opensim-SC_OLD-e3998230cc8e4283b013add367abdf91420b4b1f.tar.gz opensim-SC_OLD-e3998230cc8e4283b013add367abdf91420b4b1f.tar.bz2 opensim-SC_OLD-e3998230cc8e4283b013add367abdf91420b4b1f.tar.xz |
added dummy POS physics plugin
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Physics/POSPlugin/POSPlugin.cs | 301 |
1 files changed, 301 insertions, 0 deletions
diff --git a/OpenSim/Region/Physics/POSPlugin/POSPlugin.cs b/OpenSim/Region/Physics/POSPlugin/POSPlugin.cs new file mode 100644 index 0000000..ef7b1f0 --- /dev/null +++ b/OpenSim/Region/Physics/POSPlugin/POSPlugin.cs | |||
@@ -0,0 +1,301 @@ | |||
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.Collections.Generic; | ||
29 | using Axiom.Math; | ||
30 | using OpenSim.Framework; | ||
31 | using OpenSim.Region.Physics.Manager; | ||
32 | |||
33 | namespace OpenSim.Region.Physics.POSPlugin | ||
34 | { | ||
35 | /// <summary> | ||
36 | /// for now will be a very POS physics engine | ||
37 | /// </summary> | ||
38 | public class POSPlugin : IPhysicsPlugin | ||
39 | { | ||
40 | public POSPlugin() | ||
41 | { | ||
42 | } | ||
43 | |||
44 | public bool Init() | ||
45 | { | ||
46 | return true; | ||
47 | } | ||
48 | |||
49 | public PhysicsScene GetScene() | ||
50 | { | ||
51 | return new POSScene(); | ||
52 | } | ||
53 | |||
54 | public string GetName() | ||
55 | { | ||
56 | return ("POS"); | ||
57 | } | ||
58 | |||
59 | public void Dispose() | ||
60 | { | ||
61 | } | ||
62 | } | ||
63 | |||
64 | public class POSScene : PhysicsScene | ||
65 | { | ||
66 | private List<POSActor> _actors = new List<POSActor>(); | ||
67 | private float[] _heightMap; | ||
68 | |||
69 | public POSScene() | ||
70 | { | ||
71 | } | ||
72 | |||
73 | public override void Initialise(IMesher meshmerizer) | ||
74 | { | ||
75 | // Does nothing right now | ||
76 | } | ||
77 | |||
78 | public override PhysicsActor AddAvatar(string avName, PhysicsVector position) | ||
79 | { | ||
80 | POSActor act = new POSActor(); | ||
81 | act.Position = position; | ||
82 | _actors.Add(act); | ||
83 | return act; | ||
84 | } | ||
85 | |||
86 | public override void RemovePrim(PhysicsActor prim) | ||
87 | { | ||
88 | } | ||
89 | |||
90 | public override void RemoveAvatar(PhysicsActor actor) | ||
91 | { | ||
92 | POSActor act = (POSActor) actor; | ||
93 | if (_actors.Contains(act)) | ||
94 | { | ||
95 | _actors.Remove(act); | ||
96 | } | ||
97 | } | ||
98 | |||
99 | /* | ||
100 | public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size, Quaternion rotation) | ||
101 | { | ||
102 | return null; | ||
103 | } | ||
104 | */ | ||
105 | |||
106 | public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, | ||
107 | PhysicsVector size, Quaternion rotation) | ||
108 | { | ||
109 | return this.AddPrimShape(primName, pbs, position, size, rotation, false); | ||
110 | } | ||
111 | |||
112 | public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, | ||
113 | PhysicsVector size, Quaternion rotation, bool isPhysical) | ||
114 | { | ||
115 | return null; | ||
116 | } | ||
117 | |||
118 | public override void Simulate(float timeStep) | ||
119 | { | ||
120 | foreach (POSActor actor in _actors) | ||
121 | { | ||
122 | actor.Position.X = actor.Position.X + (actor.Velocity.X*timeStep); | ||
123 | actor.Position.Y = actor.Position.Y + (actor.Velocity.Y*timeStep); | ||
124 | if (actor.Position.Y < 0) | ||
125 | { | ||
126 | actor.Position.Y = 0.1F; | ||
127 | } | ||
128 | else if (actor.Position.Y >= 256) | ||
129 | { | ||
130 | actor.Position.Y = 255.9F; | ||
131 | } | ||
132 | |||
133 | if (actor.Position.X < 0) | ||
134 | { | ||
135 | actor.Position.X = 0.1F; | ||
136 | } | ||
137 | else if (actor.Position.X > 256) | ||
138 | { | ||
139 | actor.Position.X = 255.9F; | ||
140 | } | ||
141 | |||
142 | float height = _heightMap[(int) actor.Position.Y*256 + (int) actor.Position.X] + 1.0f; | ||
143 | if (actor.Flying) | ||
144 | { | ||
145 | if (actor.Position.Z + (actor.Velocity.Z*timeStep) < | ||
146 | _heightMap[(int) actor.Position.Y*256 + (int) actor.Position.X] + 2) | ||
147 | { | ||
148 | actor.Position.Z = height; | ||
149 | actor.Velocity.Z = 0; | ||
150 | } | ||
151 | else | ||
152 | { | ||
153 | actor.Position.Z = actor.Position.Z + (actor.Velocity.Z*timeStep); | ||
154 | } | ||
155 | } | ||
156 | else | ||
157 | { | ||
158 | actor.Position.Z = height; | ||
159 | actor.Velocity.Z = 0; | ||
160 | } | ||
161 | } | ||
162 | } | ||
163 | |||
164 | public override void GetResults() | ||
165 | { | ||
166 | } | ||
167 | |||
168 | public override bool IsThreaded | ||
169 | { | ||
170 | get { return (false); // for now we won't be multithreaded | ||
171 | } | ||
172 | } | ||
173 | |||
174 | public override void SetTerrain(float[] heightMap) | ||
175 | { | ||
176 | _heightMap = heightMap; | ||
177 | } | ||
178 | |||
179 | public override void DeleteTerrain() | ||
180 | { | ||
181 | } | ||
182 | } | ||
183 | |||
184 | public class POSActor : PhysicsActor | ||
185 | { | ||
186 | private PhysicsVector _position; | ||
187 | private PhysicsVector _velocity; | ||
188 | private PhysicsVector _acceleration; | ||
189 | private PhysicsVector m_rotationalVelocity = PhysicsVector.Zero; | ||
190 | private bool flying; | ||
191 | private bool iscolliding; | ||
192 | |||
193 | public POSActor() | ||
194 | { | ||
195 | _velocity = new PhysicsVector(); | ||
196 | _position = new PhysicsVector(); | ||
197 | _acceleration = new PhysicsVector(); | ||
198 | } | ||
199 | public override int PhysicsActorType | ||
200 | { | ||
201 | get { return (int)ActorTypes.Agent; } | ||
202 | set { return; } | ||
203 | } | ||
204 | public override PhysicsVector RotationalVelocity | ||
205 | { | ||
206 | get { return m_rotationalVelocity; } | ||
207 | set { m_rotationalVelocity = value; } | ||
208 | } | ||
209 | public override bool SetAlwaysRun | ||
210 | { | ||
211 | get { return false; } | ||
212 | set { return; } | ||
213 | } | ||
214 | public override bool IsPhysical | ||
215 | { | ||
216 | get { return false; } | ||
217 | set { return; } | ||
218 | } | ||
219 | public override bool ThrottleUpdates | ||
220 | { | ||
221 | get { return false; } | ||
222 | set { return; } | ||
223 | } | ||
224 | public override bool Flying | ||
225 | { | ||
226 | get { return flying; } | ||
227 | set { flying = value; } | ||
228 | } | ||
229 | |||
230 | public override bool IsColliding | ||
231 | { | ||
232 | get { return iscolliding; } | ||
233 | set { iscolliding = value; } | ||
234 | } | ||
235 | public override bool CollidingGround | ||
236 | { | ||
237 | get { return false; } | ||
238 | set { return; } | ||
239 | } | ||
240 | public override bool CollidingObj | ||
241 | { | ||
242 | get { return false; } | ||
243 | set { return; } | ||
244 | } | ||
245 | public override PhysicsVector Position | ||
246 | { | ||
247 | get { return _position; } | ||
248 | set { _position = value; } | ||
249 | } | ||
250 | |||
251 | public override PhysicsVector Size | ||
252 | { | ||
253 | get { return new PhysicsVector(0, 0, 0); } | ||
254 | set { } | ||
255 | } | ||
256 | |||
257 | public override PrimitiveBaseShape Shape | ||
258 | { | ||
259 | set | ||
260 | { | ||
261 | return; | ||
262 | } | ||
263 | } | ||
264 | |||
265 | public override PhysicsVector Velocity | ||
266 | { | ||
267 | get { return _velocity; } | ||
268 | set { _velocity = value; } | ||
269 | } | ||
270 | |||
271 | public override Quaternion Orientation | ||
272 | { | ||
273 | get { return Quaternion.Identity; } | ||
274 | set { } | ||
275 | } | ||
276 | |||
277 | public override PhysicsVector Acceleration | ||
278 | { | ||
279 | get { return _acceleration; } | ||
280 | } | ||
281 | |||
282 | public override bool Kinematic | ||
283 | { | ||
284 | get { return true; } | ||
285 | set { } | ||
286 | } | ||
287 | |||
288 | public void SetAcceleration(PhysicsVector accel) | ||
289 | { | ||
290 | _acceleration = accel; | ||
291 | } | ||
292 | |||
293 | public override void AddForce(PhysicsVector force) | ||
294 | { | ||
295 | } | ||
296 | |||
297 | public override void SetMomentum(PhysicsVector momentum) | ||
298 | { | ||
299 | } | ||
300 | } | ||
301 | } | ||