diff options
Diffstat (limited to 'OpenSim/Region/Physics/BasicPhysicsPlugin')
-rw-r--r-- | OpenSim/Region/Physics/BasicPhysicsPlugin/AssemblyInfo.cs | 56 | ||||
-rw-r--r-- | OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs | 301 |
2 files changed, 357 insertions, 0 deletions
diff --git a/OpenSim/Region/Physics/BasicPhysicsPlugin/AssemblyInfo.cs b/OpenSim/Region/Physics/BasicPhysicsPlugin/AssemblyInfo.cs new file mode 100644 index 0000000..ce567a9 --- /dev/null +++ b/OpenSim/Region/Physics/BasicPhysicsPlugin/AssemblyInfo.cs | |||
@@ -0,0 +1,56 @@ | |||
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.Reflection; | ||
29 | using System.Runtime.InteropServices; | ||
30 | // Information about this assembly is defined by the following | ||
31 | // attributes. | ||
32 | // | ||
33 | // change them to the information which is associated with the assembly | ||
34 | // you compile. | ||
35 | |||
36 | [assembly: AssemblyTitle("PhysXplugin")] | ||
37 | [assembly: AssemblyDescription("")] | ||
38 | [assembly: AssemblyConfiguration("")] | ||
39 | [assembly: AssemblyCompany("")] | ||
40 | [assembly: AssemblyProduct("PhysXplugin")] | ||
41 | [assembly: AssemblyCopyright("")] | ||
42 | [assembly: AssemblyTrademark("")] | ||
43 | [assembly: AssemblyCulture("")] | ||
44 | |||
45 | // This sets the default COM visibility of types in the assembly to invisible. | ||
46 | // If you need to expose a type to COM, use [ComVisible(true)] on that type. | ||
47 | [assembly: ComVisible(false)] | ||
48 | |||
49 | // The assembly version has following format : | ||
50 | // | ||
51 | // Major.Minor.Build.Revision | ||
52 | // | ||
53 | // You can specify all values by your own or you can build default build and revision | ||
54 | // numbers with the '*' character (the default): | ||
55 | |||
56 | [assembly: AssemblyVersion("1.0.*")] | ||
diff --git a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs new file mode 100644 index 0000000..f133045 --- /dev/null +++ b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs | |||
@@ -0,0 +1,301 @@ | |||
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.Collections.Generic; | ||
29 | using Axiom.Math; | ||
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 | if ((actor.Position.Y > 0 && actor.Position.Y < 256) && (actor.Position.X > 0 && actor.Position.X < 256)) | ||
105 | { | ||
106 | float height = _heightMap[(int)actor.Position.Y * 256 + (int)actor.Position.X] + 1.2f; | ||
107 | actor.Position.X = actor.Position.X + (actor.Velocity.X * timeStep); | ||
108 | actor.Position.Y = actor.Position.Y + (actor.Velocity.Y * timeStep); | ||
109 | if (actor.Flying) | ||
110 | { | ||
111 | if (actor.Position.Z + (actor.Velocity.Z * timeStep) < | ||
112 | _heightMap[(int)actor.Position.Y * 256 + (int)actor.Position.X] + 2) | ||
113 | { | ||
114 | actor.Position.Z = height; | ||
115 | actor.Velocity.Z = 0; | ||
116 | } | ||
117 | else | ||
118 | { | ||
119 | actor.Position.Z = actor.Position.Z + (actor.Velocity.Z * timeStep); | ||
120 | } | ||
121 | } | ||
122 | else | ||
123 | { | ||
124 | actor.Position.Z = height; | ||
125 | actor.Velocity.Z = 0; | ||
126 | } | ||
127 | } | ||
128 | else | ||
129 | { | ||
130 | if (actor.Position.Y < 0) | ||
131 | { | ||
132 | actor.Position.Y = 0; | ||
133 | } | ||
134 | else if (actor.Position.Y > 256) | ||
135 | { | ||
136 | actor.Position.Y = 256; | ||
137 | } | ||
138 | |||
139 | if (actor.Position.X < 0) | ||
140 | { | ||
141 | actor.Position.X = 0; | ||
142 | } | ||
143 | if (actor.Position.X > 256) | ||
144 | { | ||
145 | actor.Position.X = 256; | ||
146 | } | ||
147 | } | ||
148 | //} | ||
149 | |||
150 | |||
151 | |||
152 | // This code needs sorting out - border crossings etc | ||
153 | /* if(actor.Position.X<0) | ||
154 | { | ||
155 | ControllingClient.CrossSimBorder(new LLVector3(this.Position.X,this.Position.Y,this.Position.Z)); | ||
156 | actor.Position.X = 0; | ||
157 | actor.Velocity.X = 0; | ||
158 | } | ||
159 | if(actor.Position.Y < 0) | ||
160 | { | ||
161 | ControllingClient.CrossSimBorder(new LLVector3(this.Position.X,this.Position.Y,this.Position.Z)); | ||
162 | actor.Position.Y = 0; | ||
163 | actor.Velocity.Y = 0; | ||
164 | } | ||
165 | if(actor.Position.X > 255) | ||
166 | { | ||
167 | ControllingClient.CrossSimBorder(new LLVector3(this.Position.X,this.Position.Y,this.Position.Z)); | ||
168 | actor.Position.X = 255; | ||
169 | actor.Velocity.X = 0; | ||
170 | } | ||
171 | if(actor.Position.Y > 255) | ||
172 | { | ||
173 | ControllingClient.CrossSimBorder(new LLVector3(this.Position.X,this.Position.Y,this.Position.Z)); | ||
174 | actor.Position.Y = 255; | ||
175 | actor.Velocity.X = 0; | ||
176 | }*/ | ||
177 | } | ||
178 | } | ||
179 | |||
180 | public override void GetResults() | ||
181 | { | ||
182 | |||
183 | } | ||
184 | |||
185 | public override bool IsThreaded | ||
186 | { | ||
187 | get | ||
188 | { | ||
189 | return(false); // for now we won't be multithreaded | ||
190 | } | ||
191 | } | ||
192 | |||
193 | public override void SetTerrain(float[] heightMap) | ||
194 | { | ||
195 | this._heightMap = heightMap; | ||
196 | } | ||
197 | |||
198 | public override void DeleteTerrain() | ||
199 | { | ||
200 | |||
201 | } | ||
202 | } | ||
203 | |||
204 | public class BasicActor : PhysicsActor | ||
205 | { | ||
206 | private PhysicsVector _position; | ||
207 | private PhysicsVector _velocity; | ||
208 | private PhysicsVector _acceleration; | ||
209 | private bool flying; | ||
210 | public BasicActor() | ||
211 | { | ||
212 | _velocity = new PhysicsVector(); | ||
213 | _position = new PhysicsVector(); | ||
214 | _acceleration = new PhysicsVector(); | ||
215 | } | ||
216 | |||
217 | public override bool Flying | ||
218 | { | ||
219 | get | ||
220 | { | ||
221 | return flying; | ||
222 | } | ||
223 | set | ||
224 | { | ||
225 | flying= value; | ||
226 | } | ||
227 | } | ||
228 | |||
229 | public override PhysicsVector Position | ||
230 | { | ||
231 | get | ||
232 | { | ||
233 | return _position; | ||
234 | } | ||
235 | set | ||
236 | { | ||
237 | _position = value; | ||
238 | } | ||
239 | } | ||
240 | |||
241 | public override PhysicsVector Velocity | ||
242 | { | ||
243 | get | ||
244 | { | ||
245 | return _velocity; | ||
246 | } | ||
247 | set | ||
248 | { | ||
249 | _velocity = value; | ||
250 | } | ||
251 | } | ||
252 | |||
253 | public override Quaternion Orientation | ||
254 | { | ||
255 | get | ||
256 | { | ||
257 | return Quaternion.Identity; | ||
258 | } | ||
259 | set | ||
260 | { | ||
261 | |||
262 | } | ||
263 | } | ||
264 | |||
265 | public override PhysicsVector Acceleration | ||
266 | { | ||
267 | get | ||
268 | { | ||
269 | return _acceleration; | ||
270 | } | ||
271 | |||
272 | } | ||
273 | |||
274 | public override bool Kinematic | ||
275 | { | ||
276 | get | ||
277 | { | ||
278 | return true; | ||
279 | } | ||
280 | set | ||
281 | { | ||
282 | |||
283 | } | ||
284 | } | ||
285 | public void SetAcceleration (PhysicsVector accel) | ||
286 | { | ||
287 | this._acceleration = accel; | ||
288 | } | ||
289 | |||
290 | public override void AddForce(PhysicsVector force) | ||
291 | { | ||
292 | |||
293 | } | ||
294 | |||
295 | public override void SetMomentum(PhysicsVector momentum) | ||
296 | { | ||
297 | |||
298 | } | ||
299 | } | ||
300 | |||
301 | } | ||