diff options
author | gareth | 2007-03-22 10:11:15 +0000 |
---|---|---|
committer | gareth | 2007-03-22 10:11:15 +0000 |
commit | 7daa3955bc3a1918e40962851f9e8d38597a245e (patch) | |
tree | bee3e1372a7eed0c1b220a8a49f7bee7d29a6b91 /OpenSim.Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs | |
parent | Load XML for neighbourinfo from grid (diff) | |
download | opensim-SC-7daa3955bc3a1918e40962851f9e8d38597a245e.zip opensim-SC-7daa3955bc3a1918e40962851f9e8d38597a245e.tar.gz opensim-SC-7daa3955bc3a1918e40962851f9e8d38597a245e.tar.bz2 opensim-SC-7daa3955bc3a1918e40962851f9e8d38597a245e.tar.xz |
brought zircon branch into trunk
Diffstat (limited to 'OpenSim.Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs')
-rw-r--r-- | OpenSim.Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs | 251 |
1 files changed, 251 insertions, 0 deletions
diff --git a/OpenSim.Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs b/OpenSim.Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs new file mode 100644 index 0000000..deff803 --- /dev/null +++ b/OpenSim.Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs | |||
@@ -0,0 +1,251 @@ | |||
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 | */ | ||
27 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using OpenSim.Physics.Manager; | ||
30 | |||
31 | namespace 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 PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size) | ||
89 | { | ||
90 | return null; | ||
91 | } | ||
92 | |||
93 | public override void Simulate(float timeStep) | ||
94 | { | ||
95 | foreach (BasicActor actor in _actors) | ||
96 | { | ||
97 | actor.Position.X = actor.Position.X + (actor.Velocity.X * timeStep); | ||
98 | actor.Position.Y = actor.Position.Y + (actor.Velocity.Y * timeStep); | ||
99 | actor.Position.Z = actor.Position.Z + (actor.Velocity.Z * timeStep); | ||
100 | /*if(actor.Flying) | ||
101 | { | ||
102 | actor.Position.Z = actor.Position.Z + (actor.Velocity.Z * timeStep); | ||
103 | } | ||
104 | else | ||
105 | { | ||
106 | actor.Position.Z = actor.Position.Z + ((-9.8f + actor.Velocity.Z) * timeStep); | ||
107 | } | ||
108 | if(actor.Position.Z < (_heightMap[(int)actor.Position.Y * 256 + (int)actor.Position.X]+1)) | ||
109 | {*/ | ||
110 | actor.Position.Z = _heightMap[(int)actor.Position.Y * 256 + (int)actor.Position.X]+1; | ||
111 | //} | ||
112 | if(actor.Position.X<0) | ||
113 | { | ||
114 | actor.Position.X = 0; | ||
115 | actor.Velocity.X = 0; | ||
116 | } | ||
117 | if(actor.Position.Y < 0) | ||
118 | { | ||
119 | actor.Position.Y = 0; | ||
120 | actor.Velocity.Y = 0; | ||
121 | } | ||
122 | if(actor.Position.X > 255) | ||
123 | { | ||
124 | actor.Position.X = 255; | ||
125 | actor.Velocity.X = 0; | ||
126 | } | ||
127 | if(actor.Position.Y > 255) | ||
128 | { | ||
129 | actor.Position.Y = 255; | ||
130 | actor.Velocity.X = 0; | ||
131 | } | ||
132 | } | ||
133 | } | ||
134 | |||
135 | public override void GetResults() | ||
136 | { | ||
137 | |||
138 | } | ||
139 | |||
140 | public override bool IsThreaded | ||
141 | { | ||
142 | get | ||
143 | { | ||
144 | return(false); // for now we won't be multithreaded | ||
145 | } | ||
146 | } | ||
147 | |||
148 | public override void SetTerrain(float[] heightMap) | ||
149 | { | ||
150 | this._heightMap = heightMap; | ||
151 | } | ||
152 | } | ||
153 | |||
154 | public class BasicActor : PhysicsActor | ||
155 | { | ||
156 | private PhysicsVector _position; | ||
157 | private PhysicsVector _velocity; | ||
158 | private PhysicsVector _acceleration; | ||
159 | private bool flying; | ||
160 | public BasicActor() | ||
161 | { | ||
162 | _velocity = new PhysicsVector(); | ||
163 | _position = new PhysicsVector(); | ||
164 | _acceleration = new PhysicsVector(); | ||
165 | } | ||
166 | |||
167 | public override bool Flying | ||
168 | { | ||
169 | get | ||
170 | { | ||
171 | return false; | ||
172 | } | ||
173 | set | ||
174 | { | ||
175 | flying= value; | ||
176 | } | ||
177 | } | ||
178 | |||
179 | public override PhysicsVector Position | ||
180 | { | ||
181 | get | ||
182 | { | ||
183 | return _position; | ||
184 | } | ||
185 | set | ||
186 | { | ||
187 | _position = value; | ||
188 | } | ||
189 | } | ||
190 | |||
191 | public override PhysicsVector Velocity | ||
192 | { | ||
193 | get | ||
194 | { | ||
195 | return _velocity; | ||
196 | } | ||
197 | set | ||
198 | { | ||
199 | _velocity = value; | ||
200 | } | ||
201 | } | ||
202 | |||
203 | public override Axiom.MathLib.Quaternion Orientation | ||
204 | { | ||
205 | get | ||
206 | { | ||
207 | return Axiom.MathLib.Quaternion.Identity; | ||
208 | } | ||
209 | set | ||
210 | { | ||
211 | |||
212 | } | ||
213 | } | ||
214 | |||
215 | public override PhysicsVector Acceleration | ||
216 | { | ||
217 | get | ||
218 | { | ||
219 | return _acceleration; | ||
220 | } | ||
221 | |||
222 | } | ||
223 | |||
224 | public override bool Kinematic | ||
225 | { | ||
226 | get | ||
227 | { | ||
228 | return true; | ||
229 | } | ||
230 | set | ||
231 | { | ||
232 | |||
233 | } | ||
234 | } | ||
235 | public void SetAcceleration (PhysicsVector accel) | ||
236 | { | ||
237 | this._acceleration = accel; | ||
238 | } | ||
239 | |||
240 | public override void AddForce(PhysicsVector force) | ||
241 | { | ||
242 | |||
243 | } | ||
244 | |||
245 | public override void SetMomentum(PhysicsVector momentum) | ||
246 | { | ||
247 | |||
248 | } | ||
249 | } | ||
250 | |||
251 | } | ||