aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/OpenSim.Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/OpenSim.Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs297
1 files changed, 297 insertions, 0 deletions
diff --git a/OpenSim/OpenSim.Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs b/OpenSim/OpenSim.Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs
new file mode 100644
index 0000000..54be853
--- /dev/null
+++ b/OpenSim/OpenSim.Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs
@@ -0,0 +1,297 @@
1/*
2* Copyright (c) OpenSim project, http://sim.opensecondlife.org/
3*
4* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions are met:
6* * Redistributions of source code must retain the above copyright
7* notice, this list of conditions and the following disclaimer.
8* * Redistributions in binary form must reproduce the above copyright
9* notice, this list of conditions and the following disclaimer in the
10* documentation and/or other materials provided with the distribution.
11* * Neither the name of the <organization> nor the
12* names of its contributors may be used to endorse or promote products
13* derived from this software without specific prior written permission.
14*
15* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
16* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
19* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*
26*/
27using System;
28using System.Collections.Generic;
29using OpenSim.Physics.Manager;
30
31namespace OpenSim.Physics.BasicPhysicsPlugin
32{
33 /// <summary>
34 /// Will be the PhysX plugin but for now will be a very basic physics engine
35 /// </summary>
36 public class BasicPhysicsPlugin : IPhysicsPlugin
37 {
38 private BasicScene _mScene;
39
40 public BasicPhysicsPlugin()
41 {
42
43 }
44
45 public bool Init()
46 {
47 return true;
48 }
49
50 public PhysicsScene GetScene()
51 {
52 if(_mScene == null)
53 {
54 _mScene = new BasicScene();
55 }
56 return(_mScene);
57 }
58
59 public string GetName()
60 {
61 return("basicphysics");
62 }
63
64 public void Dispose()
65 {
66
67 }
68 }
69
70 public class BasicScene :PhysicsScene
71 {
72 private List<BasicActor> _actors = new List<BasicActor>();
73 private float[] _heightMap;
74
75 public BasicScene()
76 {
77
78 }
79
80 public override PhysicsActor AddAvatar(PhysicsVector position)
81 {
82 BasicActor act = new BasicActor();
83 act.Position = position;
84 _actors.Add(act);
85 return act;
86 }
87
88 public override void RemoveAvatar(PhysicsActor actor)
89 {
90 BasicActor act = (BasicActor)actor;
91 if(_actors.Contains(act))
92 {
93 _actors.Remove(act);
94 }
95
96 }
97
98 public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size)
99 {
100 return null;
101 }
102
103 public override void Simulate(float timeStep)
104 {
105 foreach (BasicActor actor in _actors)
106 {
107 actor.Position.X = actor.Position.X + (actor.Velocity.X * timeStep);
108 actor.Position.Y = actor.Position.Y + (actor.Velocity.Y * timeStep);
109 actor.Position.Z = actor.Position.Z + (actor.Velocity.Z * timeStep);
110 /*if(actor.Flying)
111 {
112 actor.Position.Z = actor.Position.Z + (actor.Velocity.Z * timeStep);
113 }
114 else
115 {
116 actor.Position.Z = actor.Position.Z + ((-9.8f + actor.Velocity.Z) * timeStep);
117 }
118 if(actor.Position.Z < (_heightMap[(int)actor.Position.Y * 256 + (int)actor.Position.X]+1))
119 {*/
120 if ((actor.Position.Y > 0 && actor.Position.Y < 256) && (actor.Position.X > 0 && actor.Position.X < 256))
121 {
122 actor.Position.Z = _heightMap[(int)actor.Position.Y * 256 + (int)actor.Position.X] + 1;
123 }
124 else
125 {
126 if (actor.Position.Y < -1)
127 {
128 actor.Position.Y = -1;
129 }
130 else if (actor.Position.Y > 257)
131 {
132 actor.Position.Y = 257;
133 }
134
135 if (actor.Position.X < -1)
136 {
137 actor.Position.X = -1;
138 }
139 if (actor.Position.X > 257)
140 {
141 actor.Position.X = 257;
142 }
143 }
144 //}
145
146
147
148 // This code needs sorting out - border crossings etc
149/* if(actor.Position.X<0)
150 {
151 ControllingClient.CrossSimBorder(new LLVector3(this.Position.X,this.Position.Y,this.Position.Z));
152 actor.Position.X = 0;
153 actor.Velocity.X = 0;
154 }
155 if(actor.Position.Y < 0)
156 {
157 ControllingClient.CrossSimBorder(new LLVector3(this.Position.X,this.Position.Y,this.Position.Z));
158 actor.Position.Y = 0;
159 actor.Velocity.Y = 0;
160 }
161 if(actor.Position.X > 255)
162 {
163 ControllingClient.CrossSimBorder(new LLVector3(this.Position.X,this.Position.Y,this.Position.Z));
164 actor.Position.X = 255;
165 actor.Velocity.X = 0;
166 }
167 if(actor.Position.Y > 255)
168 {
169 ControllingClient.CrossSimBorder(new LLVector3(this.Position.X,this.Position.Y,this.Position.Z));
170 actor.Position.Y = 255;
171 actor.Velocity.X = 0;
172 }*/
173 }
174 }
175
176 public override void GetResults()
177 {
178
179 }
180
181 public override bool IsThreaded
182 {
183 get
184 {
185 return(false); // for now we won't be multithreaded
186 }
187 }
188
189 public override void SetTerrain(float[] heightMap)
190 {
191 this._heightMap = heightMap;
192 }
193
194 public override void DeleteTerrain()
195 {
196
197 }
198 }
199
200 public class BasicActor : PhysicsActor
201 {
202 private PhysicsVector _position;
203 private PhysicsVector _velocity;
204 private PhysicsVector _acceleration;
205 private bool flying;
206 public BasicActor()
207 {
208 _velocity = new PhysicsVector();
209 _position = new PhysicsVector();
210 _acceleration = new PhysicsVector();
211 }
212
213 public override bool Flying
214 {
215 get
216 {
217 return false;
218 }
219 set
220 {
221 flying= value;
222 }
223 }
224
225 public override PhysicsVector Position
226 {
227 get
228 {
229 return _position;
230 }
231 set
232 {
233 _position = value;
234 }
235 }
236
237 public override PhysicsVector Velocity
238 {
239 get
240 {
241 return _velocity;
242 }
243 set
244 {
245 _velocity = value;
246 }
247 }
248
249 public override Axiom.MathLib.Quaternion Orientation
250 {
251 get
252 {
253 return Axiom.MathLib.Quaternion.Identity;
254 }
255 set
256 {
257
258 }
259 }
260
261 public override PhysicsVector Acceleration
262 {
263 get
264 {
265 return _acceleration;
266 }
267
268 }
269
270 public override bool Kinematic
271 {
272 get
273 {
274 return true;
275 }
276 set
277 {
278
279 }
280 }
281 public void SetAcceleration (PhysicsVector accel)
282 {
283 this._acceleration = accel;
284 }
285
286 public override void AddForce(PhysicsVector force)
287 {
288
289 }
290
291 public override void SetMomentum(PhysicsVector momentum)
292 {
293
294 }
295 }
296
297}