diff options
Diffstat (limited to 'OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs')
-rw-r--r-- | OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs | 294 |
1 files changed, 294 insertions, 0 deletions
diff --git a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs new file mode 100644 index 0000000..dcb8f3b --- /dev/null +++ b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs | |||
@@ -0,0 +1,294 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim.Physics.Manager; | ||
31 | |||
32 | namespace OpenSim.Region.Physics.BasicPhysicsPlugin | ||
33 | { | ||
34 | /// <summary> | ||
35 | /// Will be the PhysX plugin but for now will be a very basic physics engine | ||
36 | /// </summary> | ||
37 | public class BasicPhysicsPlugin : IPhysicsPlugin | ||
38 | { | ||
39 | private BasicScene _mScene; | ||
40 | |||
41 | public BasicPhysicsPlugin() | ||
42 | { | ||
43 | |||
44 | } | ||
45 | |||
46 | public bool Init() | ||
47 | { | ||
48 | return true; | ||
49 | } | ||
50 | |||
51 | public PhysicsScene GetScene() | ||
52 | { | ||
53 | return new BasicScene(); | ||
54 | } | ||
55 | |||
56 | public string GetName() | ||
57 | { | ||
58 | return("basicphysics"); | ||
59 | } | ||
60 | |||
61 | public void Dispose() | ||
62 | { | ||
63 | |||
64 | } | ||
65 | } | ||
66 | |||
67 | public class BasicScene :PhysicsScene | ||
68 | { | ||
69 | private List<BasicActor> _actors = new List<BasicActor>(); | ||
70 | private float[] _heightMap; | ||
71 | |||
72 | public BasicScene() | ||
73 | { | ||
74 | |||
75 | } | ||
76 | |||
77 | public override PhysicsActor AddAvatar(PhysicsVector position) | ||
78 | { | ||
79 | BasicActor act = new BasicActor(); | ||
80 | act.Position = position; | ||
81 | _actors.Add(act); | ||
82 | return act; | ||
83 | } | ||
84 | |||
85 | public override void RemoveAvatar(PhysicsActor actor) | ||
86 | { | ||
87 | BasicActor act = (BasicActor)actor; | ||
88 | if(_actors.Contains(act)) | ||
89 | { | ||
90 | _actors.Remove(act); | ||
91 | } | ||
92 | |||
93 | } | ||
94 | |||
95 | public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size) | ||
96 | { | ||
97 | return null; | ||
98 | } | ||
99 | |||
100 | public override void Simulate(float timeStep) | ||
101 | { | ||
102 | foreach (BasicActor actor in _actors) | ||
103 | { | ||
104 | actor.Position.X = actor.Position.X + (actor.Velocity.X * timeStep); | ||
105 | actor.Position.Y = actor.Position.Y + (actor.Velocity.Y * timeStep); | ||
106 | actor.Position.Z = actor.Position.Z + (actor.Velocity.Z * timeStep); | ||
107 | /*if(actor.Flying) | ||
108 | { | ||
109 | actor.Position.Z = actor.Position.Z + (actor.Velocity.Z * timeStep); | ||
110 | } | ||
111 | else | ||
112 | { | ||
113 | actor.Position.Z = actor.Position.Z + ((-9.8f + actor.Velocity.Z) * timeStep); | ||
114 | } | ||
115 | if(actor.Position.Z < (_heightMap[(int)actor.Position.Y * 256 + (int)actor.Position.X]+1)) | ||
116 | {*/ | ||
117 | if ((actor.Position.Y > 0 && actor.Position.Y < 256) && (actor.Position.X > 0 && actor.Position.X < 256)) | ||
118 | { | ||
119 | actor.Position.Z = _heightMap[(int)actor.Position.Y * 256 + (int)actor.Position.X] + 1; | ||
120 | } | ||
121 | else | ||
122 | { | ||
123 | if (actor.Position.Y < 0) | ||
124 | { | ||
125 | actor.Position.Y = 0; | ||
126 | } | ||
127 | else if (actor.Position.Y > 256) | ||
128 | { | ||
129 | actor.Position.Y = 256; | ||
130 | } | ||
131 | |||
132 | if (actor.Position.X < 0) | ||
133 | { | ||
134 | actor.Position.X = 0; | ||
135 | } | ||
136 | if (actor.Position.X > 256) | ||
137 | { | ||
138 | actor.Position.X = 256; | ||
139 | } | ||
140 | } | ||
141 | //} | ||
142 | |||
143 | |||
144 | |||
145 | // This code needs sorting out - border crossings etc | ||
146 | /* if(actor.Position.X<0) | ||
147 | { | ||
148 | ControllingClient.CrossSimBorder(new LLVector3(this.Position.X,this.Position.Y,this.Position.Z)); | ||
149 | actor.Position.X = 0; | ||
150 | actor.Velocity.X = 0; | ||
151 | } | ||
152 | if(actor.Position.Y < 0) | ||
153 | { | ||
154 | ControllingClient.CrossSimBorder(new LLVector3(this.Position.X,this.Position.Y,this.Position.Z)); | ||
155 | actor.Position.Y = 0; | ||
156 | actor.Velocity.Y = 0; | ||
157 | } | ||
158 | if(actor.Position.X > 255) | ||
159 | { | ||
160 | ControllingClient.CrossSimBorder(new LLVector3(this.Position.X,this.Position.Y,this.Position.Z)); | ||
161 | actor.Position.X = 255; | ||
162 | actor.Velocity.X = 0; | ||
163 | } | ||
164 | if(actor.Position.Y > 255) | ||
165 | { | ||
166 | ControllingClient.CrossSimBorder(new LLVector3(this.Position.X,this.Position.Y,this.Position.Z)); | ||
167 | actor.Position.Y = 255; | ||
168 | actor.Velocity.X = 0; | ||
169 | }*/ | ||
170 | } | ||
171 | } | ||
172 | |||
173 | public override void GetResults() | ||
174 | { | ||
175 | |||
176 | } | ||
177 | |||
178 | public override bool IsThreaded | ||
179 | { | ||
180 | get | ||
181 | { | ||
182 | return(false); // for now we won't be multithreaded | ||
183 | } | ||
184 | } | ||
185 | |||
186 | public override void SetTerrain(float[] heightMap) | ||
187 | { | ||
188 | this._heightMap = heightMap; | ||
189 | } | ||
190 | |||
191 | public override void DeleteTerrain() | ||
192 | { | ||
193 | |||
194 | } | ||
195 | } | ||
196 | |||
197 | public class BasicActor : PhysicsActor | ||
198 | { | ||
199 | private PhysicsVector _position; | ||
200 | private PhysicsVector _velocity; | ||
201 | private PhysicsVector _acceleration; | ||
202 | private bool flying; | ||
203 | public BasicActor() | ||
204 | { | ||
205 | _velocity = new PhysicsVector(); | ||
206 | _position = new PhysicsVector(); | ||
207 | _acceleration = new PhysicsVector(); | ||
208 | } | ||
209 | |||
210 | public override bool Flying | ||
211 | { | ||
212 | get | ||
213 | { | ||
214 | return false; | ||
215 | } | ||
216 | set | ||
217 | { | ||
218 | flying= value; | ||
219 | } | ||
220 | } | ||
221 | |||
222 | public override PhysicsVector Position | ||
223 | { | ||
224 | get | ||
225 | { | ||
226 | return _position; | ||
227 | } | ||
228 | set | ||
229 | { | ||
230 | _position = value; | ||
231 | } | ||
232 | } | ||
233 | |||
234 | public override PhysicsVector Velocity | ||
235 | { | ||
236 | get | ||
237 | { | ||
238 | return _velocity; | ||
239 | } | ||
240 | set | ||
241 | { | ||
242 | _velocity = value; | ||
243 | } | ||
244 | } | ||
245 | |||
246 | public override Axiom.MathLib.Quaternion Orientation | ||
247 | { | ||
248 | get | ||
249 | { | ||
250 | return Axiom.MathLib.Quaternion.Identity; | ||
251 | } | ||
252 | set | ||
253 | { | ||
254 | |||
255 | } | ||
256 | } | ||
257 | |||
258 | public override PhysicsVector Acceleration | ||
259 | { | ||
260 | get | ||
261 | { | ||
262 | return _acceleration; | ||
263 | } | ||
264 | |||
265 | } | ||
266 | |||
267 | public override bool Kinematic | ||
268 | { | ||
269 | get | ||
270 | { | ||
271 | return true; | ||
272 | } | ||
273 | set | ||
274 | { | ||
275 | |||
276 | } | ||
277 | } | ||
278 | public void SetAcceleration (PhysicsVector accel) | ||
279 | { | ||
280 | this._acceleration = accel; | ||
281 | } | ||
282 | |||
283 | public override void AddForce(PhysicsVector force) | ||
284 | { | ||
285 | |||
286 | } | ||
287 | |||
288 | public override void SetMomentum(PhysicsVector momentum) | ||
289 | { | ||
290 | |||
291 | } | ||
292 | } | ||
293 | |||
294 | } | ||