diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Physics/BasicPhysicsPlugin/AssemblyInfo.cs | 56 | ||||
-rw-r--r-- | OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsPlugin.cs | 301 | ||||
-rw-r--r-- | OpenSim/Region/Physics/Manager/AssemblyInfo.cs | 56 | ||||
-rw-r--r-- | OpenSim/Region/Physics/Manager/PhysicsActor.cs | 167 | ||||
-rw-r--r-- | OpenSim/Region/Physics/Manager/PhysicsManager.cs | 115 | ||||
-rw-r--r-- | OpenSim/Region/Physics/Manager/PhysicsScene.cs | 110 | ||||
-rw-r--r-- | OpenSim/Region/Physics/Manager/PhysicsVector.cs | 55 | ||||
-rw-r--r-- | OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs | 56 | ||||
-rw-r--r-- | OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | 457 | ||||
-rw-r--r-- | OpenSim/Region/Physics/PhysXPlugin/AssemblyInfo.cs | 56 | ||||
-rw-r--r-- | OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs | 425 |
11 files changed, 1854 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 | } | ||
diff --git a/OpenSim/Region/Physics/Manager/AssemblyInfo.cs b/OpenSim/Region/Physics/Manager/AssemblyInfo.cs new file mode 100644 index 0000000..9415db9 --- /dev/null +++ b/OpenSim/Region/Physics/Manager/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("PhysicsManager")] | ||
37 | [assembly: AssemblyDescription("")] | ||
38 | [assembly: AssemblyConfiguration("")] | ||
39 | [assembly: AssemblyCompany("")] | ||
40 | [assembly: AssemblyProduct("PhysicsManager")] | ||
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/Manager/PhysicsActor.cs b/OpenSim/Region/Physics/Manager/PhysicsActor.cs new file mode 100644 index 0000000..da3b560 --- /dev/null +++ b/OpenSim/Region/Physics/Manager/PhysicsActor.cs | |||
@@ -0,0 +1,167 @@ | |||
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 Axiom.Math; | ||
29 | |||
30 | namespace OpenSim.Physics.Manager | ||
31 | { | ||
32 | public delegate void PositionUpdate(PhysicsVector position); | ||
33 | public delegate void VelocityUpdate(PhysicsVector velocity); | ||
34 | public delegate void OrientationUpdate(Quaternion orientation); | ||
35 | |||
36 | public abstract class PhysicsActor | ||
37 | { | ||
38 | public event PositionUpdate OnPositionUpdate; | ||
39 | public event VelocityUpdate OnVelocityUpdate; | ||
40 | public event OrientationUpdate OnOrientationUpdate; | ||
41 | |||
42 | public static PhysicsActor Null | ||
43 | { | ||
44 | get | ||
45 | { | ||
46 | return new NullPhysicsActor(); | ||
47 | } | ||
48 | } | ||
49 | |||
50 | public abstract PhysicsVector Position | ||
51 | { | ||
52 | get; | ||
53 | set; | ||
54 | } | ||
55 | |||
56 | public abstract PhysicsVector Velocity | ||
57 | { | ||
58 | get; | ||
59 | set; | ||
60 | } | ||
61 | |||
62 | public abstract PhysicsVector Acceleration | ||
63 | { | ||
64 | get; | ||
65 | } | ||
66 | |||
67 | public abstract Quaternion Orientation | ||
68 | { | ||
69 | get; | ||
70 | set; | ||
71 | } | ||
72 | |||
73 | public abstract bool Flying | ||
74 | { | ||
75 | get; | ||
76 | set; | ||
77 | } | ||
78 | |||
79 | public abstract bool Kinematic | ||
80 | { | ||
81 | get; | ||
82 | set; | ||
83 | } | ||
84 | |||
85 | public abstract void AddForce(PhysicsVector force); | ||
86 | |||
87 | public abstract void SetMomentum(PhysicsVector momentum); | ||
88 | } | ||
89 | |||
90 | public class NullPhysicsActor : PhysicsActor | ||
91 | { | ||
92 | public override PhysicsVector Position | ||
93 | { | ||
94 | get | ||
95 | { | ||
96 | return PhysicsVector.Zero; | ||
97 | } | ||
98 | set | ||
99 | { | ||
100 | return; | ||
101 | } | ||
102 | } | ||
103 | |||
104 | public override PhysicsVector Velocity | ||
105 | { | ||
106 | get | ||
107 | { | ||
108 | return PhysicsVector.Zero; | ||
109 | } | ||
110 | set | ||
111 | { | ||
112 | return; | ||
113 | } | ||
114 | } | ||
115 | |||
116 | public override Quaternion Orientation | ||
117 | { | ||
118 | get | ||
119 | { | ||
120 | return Quaternion.Identity; | ||
121 | } | ||
122 | set | ||
123 | { | ||
124 | |||
125 | } | ||
126 | } | ||
127 | |||
128 | public override PhysicsVector Acceleration | ||
129 | { | ||
130 | get { return PhysicsVector.Zero; } | ||
131 | } | ||
132 | |||
133 | public override bool Flying | ||
134 | { | ||
135 | get | ||
136 | { | ||
137 | return false; | ||
138 | } | ||
139 | set | ||
140 | { | ||
141 | return; | ||
142 | } | ||
143 | } | ||
144 | |||
145 | public override bool Kinematic | ||
146 | { | ||
147 | get | ||
148 | { | ||
149 | return true; | ||
150 | } | ||
151 | set | ||
152 | { | ||
153 | return; | ||
154 | } | ||
155 | } | ||
156 | |||
157 | public override void AddForce(PhysicsVector force) | ||
158 | { | ||
159 | return; | ||
160 | } | ||
161 | |||
162 | public override void SetMomentum(PhysicsVector momentum) | ||
163 | { | ||
164 | return; | ||
165 | } | ||
166 | } | ||
167 | } | ||
diff --git a/OpenSim/Region/Physics/Manager/PhysicsManager.cs b/OpenSim/Region/Physics/Manager/PhysicsManager.cs new file mode 100644 index 0000000..265bce6 --- /dev/null +++ b/OpenSim/Region/Physics/Manager/PhysicsManager.cs | |||
@@ -0,0 +1,115 @@ | |||
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 System.IO; | ||
31 | using System.Reflection; | ||
32 | using OpenSim.Framework.Console; | ||
33 | |||
34 | namespace OpenSim.Physics.Manager | ||
35 | { | ||
36 | /// <summary> | ||
37 | /// Description of MyClass. | ||
38 | /// </summary> | ||
39 | public class PhysicsManager | ||
40 | { | ||
41 | private Dictionary<string, IPhysicsPlugin> _plugins=new Dictionary<string, IPhysicsPlugin>(); | ||
42 | |||
43 | public PhysicsManager() | ||
44 | { | ||
45 | |||
46 | } | ||
47 | |||
48 | public PhysicsScene GetPhysicsScene(string engineName) | ||
49 | { | ||
50 | if (String.IsNullOrEmpty(engineName)) | ||
51 | { | ||
52 | return PhysicsScene.Null; | ||
53 | } | ||
54 | |||
55 | if(_plugins.ContainsKey(engineName)) | ||
56 | { | ||
57 | MainLog.Instance.WriteLine(LogPriority.LOW,"creating "+engineName); | ||
58 | return _plugins[engineName].GetScene(); | ||
59 | } | ||
60 | else | ||
61 | { | ||
62 | MainLog.Instance.WriteLine(LogPriority.MEDIUM,"couldn't find physicsEngine: {0}",engineName); | ||
63 | throw new ArgumentException(String.Format("couldn't find physicsEngine: {0}",engineName)); | ||
64 | } | ||
65 | } | ||
66 | |||
67 | public void LoadPlugins() | ||
68 | { | ||
69 | string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory ,"Physics"); | ||
70 | string[] pluginFiles = Directory.GetFiles(path, "*.dll"); | ||
71 | |||
72 | |||
73 | for(int i= 0; i<pluginFiles.Length; i++) | ||
74 | { | ||
75 | this.AddPlugin(pluginFiles[i]); | ||
76 | } | ||
77 | } | ||
78 | |||
79 | private void AddPlugin(string FileName) | ||
80 | { | ||
81 | Assembly pluginAssembly = Assembly.LoadFrom(FileName); | ||
82 | |||
83 | foreach (Type pluginType in pluginAssembly.GetTypes()) | ||
84 | { | ||
85 | if (pluginType.IsPublic) | ||
86 | { | ||
87 | if (!pluginType.IsAbstract) | ||
88 | { | ||
89 | Type typeInterface = pluginType.GetInterface("IPhysicsPlugin", true); | ||
90 | |||
91 | if (typeInterface != null) | ||
92 | { | ||
93 | IPhysicsPlugin plug = (IPhysicsPlugin)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); | ||
94 | plug.Init(); | ||
95 | this._plugins.Add(plug.GetName(),plug); | ||
96 | |||
97 | } | ||
98 | |||
99 | typeInterface = null; | ||
100 | } | ||
101 | } | ||
102 | } | ||
103 | |||
104 | pluginAssembly = null; | ||
105 | } | ||
106 | } | ||
107 | |||
108 | public interface IPhysicsPlugin | ||
109 | { | ||
110 | bool Init(); | ||
111 | PhysicsScene GetScene(); | ||
112 | string GetName(); | ||
113 | void Dispose(); | ||
114 | } | ||
115 | } | ||
diff --git a/OpenSim/Region/Physics/Manager/PhysicsScene.cs b/OpenSim/Region/Physics/Manager/PhysicsScene.cs new file mode 100644 index 0000000..d44da00 --- /dev/null +++ b/OpenSim/Region/Physics/Manager/PhysicsScene.cs | |||
@@ -0,0 +1,110 @@ | |||
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 OpenSim.Framework.Console; | ||
29 | |||
30 | namespace OpenSim.Physics.Manager | ||
31 | { | ||
32 | public abstract class PhysicsScene | ||
33 | { | ||
34 | public static PhysicsScene Null | ||
35 | { | ||
36 | get | ||
37 | { | ||
38 | return new NullPhysicsScene(); | ||
39 | } | ||
40 | } | ||
41 | |||
42 | public abstract PhysicsActor AddAvatar(PhysicsVector position); | ||
43 | |||
44 | public abstract void RemoveAvatar(PhysicsActor actor); | ||
45 | |||
46 | public abstract PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size); | ||
47 | |||
48 | public abstract void Simulate(float timeStep); | ||
49 | |||
50 | public abstract void GetResults(); | ||
51 | |||
52 | public abstract void SetTerrain(float[] heightMap); | ||
53 | |||
54 | public abstract void DeleteTerrain(); | ||
55 | |||
56 | public abstract bool IsThreaded | ||
57 | { | ||
58 | get; | ||
59 | } | ||
60 | |||
61 | private class NullPhysicsScene : PhysicsScene | ||
62 | { | ||
63 | private static int m_workIndicator; | ||
64 | |||
65 | public override PhysicsActor AddAvatar(PhysicsVector position) | ||
66 | { | ||
67 | MainLog.Instance.Verbose("NullPhysicsScene : AddAvatar({0})", position); | ||
68 | return PhysicsActor.Null; | ||
69 | } | ||
70 | |||
71 | public override void RemoveAvatar(PhysicsActor actor) | ||
72 | { | ||
73 | |||
74 | } | ||
75 | |||
76 | public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size) | ||
77 | { | ||
78 | MainLog.Instance.Verbose("NullPhysicsScene : AddPrim({0},{1})", position, size); | ||
79 | return PhysicsActor.Null; | ||
80 | } | ||
81 | |||
82 | public override void Simulate(float timeStep) | ||
83 | { | ||
84 | m_workIndicator = (m_workIndicator + 1) % 10; | ||
85 | |||
86 | //OpenSim.Framework.Console.MainLog.Instance.SetStatus(m_workIndicator.ToString()); | ||
87 | } | ||
88 | |||
89 | public override void GetResults() | ||
90 | { | ||
91 | MainLog.Instance.Verbose("NullPhysicsScene : GetResults()"); | ||
92 | } | ||
93 | |||
94 | public override void SetTerrain(float[] heightMap) | ||
95 | { | ||
96 | MainLog.Instance.Verbose("NullPhysicsScene : SetTerrain({0} items)", heightMap.Length); | ||
97 | } | ||
98 | |||
99 | public override void DeleteTerrain() | ||
100 | { | ||
101 | |||
102 | } | ||
103 | |||
104 | public override bool IsThreaded | ||
105 | { | ||
106 | get { return false; } | ||
107 | } | ||
108 | } | ||
109 | } | ||
110 | } | ||
diff --git a/OpenSim/Region/Physics/Manager/PhysicsVector.cs b/OpenSim/Region/Physics/Manager/PhysicsVector.cs new file mode 100644 index 0000000..e75f29b --- /dev/null +++ b/OpenSim/Region/Physics/Manager/PhysicsVector.cs | |||
@@ -0,0 +1,55 @@ | |||
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 | namespace OpenSim.Physics.Manager | ||
29 | { | ||
30 | public class PhysicsVector | ||
31 | { | ||
32 | public float X; | ||
33 | public float Y; | ||
34 | public float Z; | ||
35 | |||
36 | public PhysicsVector() | ||
37 | { | ||
38 | |||
39 | } | ||
40 | |||
41 | public PhysicsVector(float x, float y, float z) | ||
42 | { | ||
43 | X = x; | ||
44 | Y = y; | ||
45 | Z = z; | ||
46 | } | ||
47 | |||
48 | public static readonly PhysicsVector Zero = new PhysicsVector(0f, 0f, 0f); | ||
49 | |||
50 | public override string ToString() | ||
51 | { | ||
52 | return "<" + this.X + "," + this.Y + "," + this.Z + ">"; | ||
53 | } | ||
54 | } | ||
55 | } | ||
diff --git a/OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs b/OpenSim/Region/Physics/OdePlugin/AssemblyInfo.cs new file mode 100644 index 0000000..ee10430 --- /dev/null +++ b/OpenSim/Region/Physics/OdePlugin/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("RealPhysXplugin")] | ||
37 | [assembly: AssemblyDescription("")] | ||
38 | [assembly: AssemblyConfiguration("")] | ||
39 | [assembly: AssemblyCompany("")] | ||
40 | [assembly: AssemblyProduct("RealPhysXplugin")] | ||
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/OdePlugin/OdePlugin.cs b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs new file mode 100644 index 0000000..2780188 --- /dev/null +++ b/OpenSim/Region/Physics/OdePlugin/OdePlugin.cs | |||
@@ -0,0 +1,457 @@ | |||
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 Axiom.Math; | ||
31 | using Ode.NET; | ||
32 | using OpenSim.Physics.Manager; | ||
33 | |||
34 | namespace OpenSim.Region.Physics.OdePlugin | ||
35 | { | ||
36 | /// <summary> | ||
37 | /// ODE plugin | ||
38 | /// </summary> | ||
39 | public class OdePlugin : IPhysicsPlugin | ||
40 | { | ||
41 | private OdeScene _mScene; | ||
42 | |||
43 | public OdePlugin() | ||
44 | { | ||
45 | |||
46 | } | ||
47 | |||
48 | public bool Init() | ||
49 | { | ||
50 | return true; | ||
51 | } | ||
52 | |||
53 | public PhysicsScene GetScene() | ||
54 | { | ||
55 | if (_mScene == null) | ||
56 | { | ||
57 | _mScene = new OdeScene(); | ||
58 | } | ||
59 | return (_mScene); | ||
60 | } | ||
61 | |||
62 | public string GetName() | ||
63 | { | ||
64 | return ("OpenDynamicsEngine"); | ||
65 | } | ||
66 | |||
67 | public void Dispose() | ||
68 | { | ||
69 | |||
70 | } | ||
71 | } | ||
72 | |||
73 | public class OdeScene : PhysicsScene | ||
74 | { | ||
75 | static public IntPtr world; | ||
76 | static public IntPtr space; | ||
77 | static private IntPtr contactgroup; | ||
78 | static private IntPtr LandGeom; | ||
79 | //static private IntPtr Land; | ||
80 | private double[] _heightmap; | ||
81 | static private d.NearCallback nearCallback = near; | ||
82 | private List<OdeCharacter> _characters = new List<OdeCharacter>(); | ||
83 | private static d.ContactGeom[] contacts = new d.ContactGeom[30]; | ||
84 | private static d.Contact contact; | ||
85 | |||
86 | public OdeScene() | ||
87 | { | ||
88 | contact.surface.mode = d.ContactFlags.Bounce | d.ContactFlags.SoftCFM; | ||
89 | contact.surface.mu = d.Infinity; | ||
90 | contact.surface.mu2 = 0.0f; | ||
91 | contact.surface.bounce = 0.1f; | ||
92 | contact.surface.bounce_vel = 0.1f; | ||
93 | contact.surface.soft_cfm = 0.01f; | ||
94 | |||
95 | world = d.WorldCreate(); | ||
96 | space = d.HashSpaceCreate(IntPtr.Zero); | ||
97 | contactgroup = d.JointGroupCreate(0); | ||
98 | d.WorldSetGravity(world, 0.0f, 0.0f, -0.5f); | ||
99 | //d.WorldSetCFM(world, 1e-5f); | ||
100 | d.WorldSetAutoDisableFlag(world, false); | ||
101 | d.WorldSetContactSurfaceLayer(world, 0.001f); | ||
102 | // d.CreatePlane(space, 0, 0, 1, 0); | ||
103 | this._heightmap = new double[65536]; | ||
104 | } | ||
105 | |||
106 | // This function blatantly ripped off from BoxStack.cs | ||
107 | static private void near(IntPtr space, IntPtr g1, IntPtr g2) | ||
108 | { | ||
109 | IntPtr b1 = d.GeomGetBody(g1); | ||
110 | IntPtr b2 = d.GeomGetBody(g2); | ||
111 | if (b1 != IntPtr.Zero && b2 != IntPtr.Zero && d.AreConnectedExcluding(b1, b2, d.JointType.Contact)) | ||
112 | return; | ||
113 | |||
114 | int count = d.Collide(g1, g2, 500, contacts, d.ContactGeom.SizeOf); | ||
115 | for (int i = 0; i < count; ++i) | ||
116 | { | ||
117 | contact.geom = contacts[i]; | ||
118 | IntPtr joint = d.JointCreateContact(world, contactgroup, ref contact); | ||
119 | d.JointAttach(joint, b1, b2); | ||
120 | } | ||
121 | |||
122 | } | ||
123 | |||
124 | public override PhysicsActor AddAvatar(PhysicsVector position) | ||
125 | { | ||
126 | PhysicsVector pos = new PhysicsVector(); | ||
127 | pos.X = position.X; | ||
128 | pos.Y = position.Y; | ||
129 | pos.Z = position.Z + 20; | ||
130 | OdeCharacter newAv = new OdeCharacter(this, pos); | ||
131 | this._characters.Add(newAv); | ||
132 | return newAv; | ||
133 | } | ||
134 | |||
135 | public override void RemoveAvatar(PhysicsActor actor) | ||
136 | { | ||
137 | |||
138 | } | ||
139 | |||
140 | public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size) | ||
141 | { | ||
142 | PhysicsVector pos = new PhysicsVector(); | ||
143 | pos.X = position.X; | ||
144 | pos.Y = position.Y; | ||
145 | pos.Z = position.Z; | ||
146 | PhysicsVector siz = new PhysicsVector(); | ||
147 | siz.X = size.X; | ||
148 | siz.Y = size.Y; | ||
149 | siz.Z = size.Z; | ||
150 | return new OdePrim(); | ||
151 | } | ||
152 | |||
153 | public override void Simulate(float timeStep) | ||
154 | { | ||
155 | foreach (OdeCharacter actor in _characters) | ||
156 | { | ||
157 | actor.Move(timeStep * 5f); | ||
158 | } | ||
159 | d.SpaceCollide(space, IntPtr.Zero, nearCallback); | ||
160 | d.WorldQuickStep(world, timeStep * 5f); | ||
161 | d.JointGroupEmpty(contactgroup); | ||
162 | foreach (OdeCharacter actor in _characters) | ||
163 | { | ||
164 | actor.UpdatePosition(); | ||
165 | } | ||
166 | |||
167 | } | ||
168 | |||
169 | public override void GetResults() | ||
170 | { | ||
171 | |||
172 | } | ||
173 | |||
174 | public override bool IsThreaded | ||
175 | { | ||
176 | get | ||
177 | { | ||
178 | return (false); // for now we won't be multithreaded | ||
179 | } | ||
180 | } | ||
181 | |||
182 | public override void SetTerrain(float[] heightMap) | ||
183 | { | ||
184 | for (int i = 0; i < 65536; i++) | ||
185 | { | ||
186 | // this._heightmap[i] = (double)heightMap[i]; | ||
187 | // dbm (danx0r) -- heightmap x,y must be swapped for Ode (should fix ODE, but for now...) | ||
188 | int x = i & 0xff; | ||
189 | int y = i >> 8; | ||
190 | this._heightmap[i] = (double)heightMap[x * 256 + y]; | ||
191 | } | ||
192 | IntPtr HeightmapData = d.GeomHeightfieldDataCreate(); | ||
193 | d.GeomHeightfieldDataBuildDouble(HeightmapData, _heightmap, 0, 256, 256, 256, 256, 1.0f, 0.0f, 2.0f, 0); | ||
194 | d.GeomHeightfieldDataSetBounds(HeightmapData, 256, 256); | ||
195 | LandGeom = d.CreateHeightfield(space, HeightmapData, 1); | ||
196 | d.Matrix3 R = new d.Matrix3(); | ||
197 | |||
198 | Quaternion q1 =Quaternion.FromAngleAxis(1.5707f, new Vector3(1,0,0)); | ||
199 | Quaternion q2 =Quaternion.FromAngleAxis(1.5707f, new Vector3(0,1,0)); | ||
200 | //Axiom.Math.Quaternion q3 = Axiom.Math.Quaternion.FromAngleAxis(3.14f, new Axiom.Math.Vector3(0, 0, 1)); | ||
201 | |||
202 | q1 = q1 * q2; | ||
203 | //q1 = q1 * q3; | ||
204 | Vector3 v3 = new Vector3(); | ||
205 | float angle = 0; | ||
206 | q1.ToAngleAxis(ref angle, ref v3); | ||
207 | |||
208 | d.RFromAxisAndAngle(out R, v3.x, v3.y, v3.z, angle); | ||
209 | d.GeomSetRotation(LandGeom, ref R); | ||
210 | d.GeomSetPosition(LandGeom, 128, 128, 0); | ||
211 | } | ||
212 | |||
213 | public override void DeleteTerrain() | ||
214 | { | ||
215 | |||
216 | } | ||
217 | } | ||
218 | |||
219 | public class OdeCharacter : PhysicsActor | ||
220 | { | ||
221 | private PhysicsVector _position; | ||
222 | private PhysicsVector _velocity; | ||
223 | private PhysicsVector _acceleration; | ||
224 | private bool flying; | ||
225 | //private float gravityAccel; | ||
226 | private IntPtr BoundingCapsule; | ||
227 | IntPtr capsule_geom; | ||
228 | d.Mass capsule_mass; | ||
229 | |||
230 | public OdeCharacter(OdeScene parent_scene, PhysicsVector pos) | ||
231 | { | ||
232 | _velocity = new PhysicsVector(); | ||
233 | _position = pos; | ||
234 | _acceleration = new PhysicsVector(); | ||
235 | d.MassSetCapsule(out capsule_mass, 5.0f, 3, 0.5f, 2f); | ||
236 | capsule_geom = d.CreateCapsule(OdeScene.space, 0.5f, 2f); | ||
237 | this.BoundingCapsule = d.BodyCreate(OdeScene.world); | ||
238 | d.BodySetMass(BoundingCapsule, ref capsule_mass); | ||
239 | d.BodySetPosition(BoundingCapsule, pos.X, pos.Y, pos.Z); | ||
240 | d.GeomSetBody(capsule_geom, BoundingCapsule); | ||
241 | } | ||
242 | |||
243 | public override bool Flying | ||
244 | { | ||
245 | get | ||
246 | { | ||
247 | return flying; | ||
248 | } | ||
249 | set | ||
250 | { | ||
251 | flying = value; | ||
252 | } | ||
253 | } | ||
254 | |||
255 | public override PhysicsVector Position | ||
256 | { | ||
257 | get | ||
258 | { | ||
259 | return _position; | ||
260 | } | ||
261 | set | ||
262 | { | ||
263 | _position = value; | ||
264 | } | ||
265 | } | ||
266 | |||
267 | public override PhysicsVector Velocity | ||
268 | { | ||
269 | get | ||
270 | { | ||
271 | return _velocity; | ||
272 | } | ||
273 | set | ||
274 | { | ||
275 | _velocity = value; | ||
276 | } | ||
277 | } | ||
278 | |||
279 | public override bool Kinematic | ||
280 | { | ||
281 | get | ||
282 | { | ||
283 | return false; | ||
284 | } | ||
285 | set | ||
286 | { | ||
287 | |||
288 | } | ||
289 | } | ||
290 | |||
291 | public override Quaternion Orientation | ||
292 | { | ||
293 | get | ||
294 | { | ||
295 | return Quaternion.Identity; | ||
296 | } | ||
297 | set | ||
298 | { | ||
299 | |||
300 | } | ||
301 | } | ||
302 | |||
303 | public override PhysicsVector Acceleration | ||
304 | { | ||
305 | get | ||
306 | { | ||
307 | return _acceleration; | ||
308 | } | ||
309 | |||
310 | } | ||
311 | public void SetAcceleration(PhysicsVector accel) | ||
312 | { | ||
313 | this._acceleration = accel; | ||
314 | } | ||
315 | |||
316 | public override void AddForce(PhysicsVector force) | ||
317 | { | ||
318 | |||
319 | } | ||
320 | |||
321 | public override void SetMomentum(PhysicsVector momentum) | ||
322 | { | ||
323 | |||
324 | } | ||
325 | |||
326 | public void Move(float timeStep) | ||
327 | { | ||
328 | PhysicsVector vec = new PhysicsVector(); | ||
329 | vec.X = this._velocity.X * timeStep; | ||
330 | vec.Y = this._velocity.Y * timeStep; | ||
331 | if (flying) | ||
332 | { | ||
333 | vec.Z = (this._velocity.Z + 0.5f) * timeStep; | ||
334 | } | ||
335 | d.BodySetLinearVel(this.BoundingCapsule, vec.X, vec.Y, vec.Z); | ||
336 | } | ||
337 | |||
338 | public void UpdatePosition() | ||
339 | { | ||
340 | d.Vector3 vec = d.BodyGetPosition(BoundingCapsule); | ||
341 | this._position.X = vec.X; | ||
342 | this._position.Y = vec.Y; | ||
343 | this._position.Z = vec.Z+1.0f; | ||
344 | } | ||
345 | } | ||
346 | |||
347 | public class OdePrim : PhysicsActor | ||
348 | { | ||
349 | private PhysicsVector _position; | ||
350 | private PhysicsVector _velocity; | ||
351 | private PhysicsVector _acceleration; | ||
352 | |||
353 | public OdePrim() | ||
354 | { | ||
355 | _velocity = new PhysicsVector(); | ||
356 | _position = new PhysicsVector(); | ||
357 | _acceleration = new PhysicsVector(); | ||
358 | } | ||
359 | public override bool Flying | ||
360 | { | ||
361 | get | ||
362 | { | ||
363 | return false; //no flying prims for you | ||
364 | } | ||
365 | set | ||
366 | { | ||
367 | |||
368 | } | ||
369 | } | ||
370 | public override PhysicsVector Position | ||
371 | { | ||
372 | get | ||
373 | { | ||
374 | PhysicsVector pos = new PhysicsVector(); | ||
375 | // PhysicsVector vec = this._prim.Position; | ||
376 | //pos.X = vec.X; | ||
377 | //pos.Y = vec.Y; | ||
378 | //pos.Z = vec.Z; | ||
379 | return pos; | ||
380 | |||
381 | } | ||
382 | set | ||
383 | { | ||
384 | /*PhysicsVector vec = value; | ||
385 | PhysicsVector pos = new PhysicsVector(); | ||
386 | pos.X = vec.X; | ||
387 | pos.Y = vec.Y; | ||
388 | pos.Z = vec.Z; | ||
389 | this._prim.Position = pos;*/ | ||
390 | } | ||
391 | } | ||
392 | |||
393 | public override PhysicsVector Velocity | ||
394 | { | ||
395 | get | ||
396 | { | ||
397 | return _velocity; | ||
398 | } | ||
399 | set | ||
400 | { | ||
401 | _velocity = value; | ||
402 | } | ||
403 | } | ||
404 | |||
405 | public override bool Kinematic | ||
406 | { | ||
407 | get | ||
408 | { | ||
409 | return false; | ||
410 | //return this._prim.Kinematic; | ||
411 | } | ||
412 | set | ||
413 | { | ||
414 | //this._prim.Kinematic = value; | ||
415 | } | ||
416 | } | ||
417 | |||
418 | public override Quaternion Orientation | ||
419 | { | ||
420 | get | ||
421 | { | ||
422 | Quaternion res = new Quaternion(); | ||
423 | return res; | ||
424 | } | ||
425 | set | ||
426 | { | ||
427 | |||
428 | } | ||
429 | } | ||
430 | |||
431 | public override PhysicsVector Acceleration | ||
432 | { | ||
433 | get | ||
434 | { | ||
435 | return _acceleration; | ||
436 | } | ||
437 | |||
438 | } | ||
439 | public void SetAcceleration(PhysicsVector accel) | ||
440 | { | ||
441 | this._acceleration = accel; | ||
442 | } | ||
443 | |||
444 | public override void AddForce(PhysicsVector force) | ||
445 | { | ||
446 | |||
447 | } | ||
448 | |||
449 | public override void SetMomentum(PhysicsVector momentum) | ||
450 | { | ||
451 | |||
452 | } | ||
453 | |||
454 | |||
455 | } | ||
456 | |||
457 | } | ||
diff --git a/OpenSim/Region/Physics/PhysXPlugin/AssemblyInfo.cs b/OpenSim/Region/Physics/PhysXPlugin/AssemblyInfo.cs new file mode 100644 index 0000000..ee10430 --- /dev/null +++ b/OpenSim/Region/Physics/PhysXPlugin/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("RealPhysXplugin")] | ||
37 | [assembly: AssemblyDescription("")] | ||
38 | [assembly: AssemblyConfiguration("")] | ||
39 | [assembly: AssemblyCompany("")] | ||
40 | [assembly: AssemblyProduct("RealPhysXplugin")] | ||
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/PhysXPlugin/PhysXPlugin.cs b/OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs new file mode 100644 index 0000000..4c82549 --- /dev/null +++ b/OpenSim/Region/Physics/PhysXPlugin/PhysXPlugin.cs | |||
@@ -0,0 +1,425 @@ | |||
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 | using PhysXWrapper; | ||
32 | using Quaternion=Axiom.Math.Quaternion; | ||
33 | |||
34 | namespace OpenSim.Region.Physics.PhysXPlugin | ||
35 | { | ||
36 | /// <summary> | ||
37 | /// Will be the PhysX plugin but for now will be a very basic physics engine | ||
38 | /// </summary> | ||
39 | public class PhysXPlugin : IPhysicsPlugin | ||
40 | { | ||
41 | private PhysXScene _mScene; | ||
42 | |||
43 | public PhysXPlugin() | ||
44 | { | ||
45 | |||
46 | } | ||
47 | |||
48 | public bool Init() | ||
49 | { | ||
50 | return true; | ||
51 | } | ||
52 | |||
53 | public PhysicsScene GetScene() | ||
54 | { | ||
55 | if(_mScene == null) | ||
56 | { | ||
57 | _mScene = new PhysXScene(); | ||
58 | } | ||
59 | return(_mScene); | ||
60 | } | ||
61 | |||
62 | public string GetName() | ||
63 | { | ||
64 | return("RealPhysX"); | ||
65 | } | ||
66 | |||
67 | public void Dispose() | ||
68 | { | ||
69 | |||
70 | } | ||
71 | } | ||
72 | |||
73 | public class PhysXScene :PhysicsScene | ||
74 | { | ||
75 | private List<PhysXCharacter> _characters = new List<PhysXCharacter>(); | ||
76 | private List<PhysXPrim> _prims = new List<PhysXPrim>(); | ||
77 | private float[] _heightMap = null; | ||
78 | private NxPhysicsSDK mySdk; | ||
79 | private NxScene scene; | ||
80 | |||
81 | public PhysXScene() | ||
82 | { | ||
83 | mySdk = NxPhysicsSDK.CreateSDK(); | ||
84 | Console.WriteLine("Sdk created - now creating scene"); | ||
85 | scene = mySdk.CreateScene(); | ||
86 | |||
87 | } | ||
88 | |||
89 | public override PhysicsActor AddAvatar(PhysicsVector position) | ||
90 | { | ||
91 | Vec3 pos = new Vec3(); | ||
92 | pos.X = position.X; | ||
93 | pos.Y = position.Y; | ||
94 | pos.Z = position.Z; | ||
95 | PhysXCharacter act = new PhysXCharacter( scene.AddCharacter(pos)); | ||
96 | act.Position = position; | ||
97 | _characters.Add(act); | ||
98 | return act; | ||
99 | } | ||
100 | |||
101 | public override void RemoveAvatar(PhysicsActor actor) | ||
102 | { | ||
103 | |||
104 | } | ||
105 | |||
106 | public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size) | ||
107 | { | ||
108 | Vec3 pos = new Vec3(); | ||
109 | pos.X = position.X; | ||
110 | pos.Y = position.Y; | ||
111 | pos.Z = position.Z; | ||
112 | Vec3 siz = new Vec3(); | ||
113 | siz.X = size.X; | ||
114 | siz.Y = size.Y; | ||
115 | siz.Z = size.Z; | ||
116 | PhysXPrim act = new PhysXPrim( scene.AddNewBox(pos, siz)); | ||
117 | _prims.Add(act); | ||
118 | return act; | ||
119 | } | ||
120 | public override void Simulate(float timeStep) | ||
121 | { | ||
122 | try | ||
123 | { | ||
124 | foreach (PhysXCharacter actor in _characters) | ||
125 | { | ||
126 | actor.Move(timeStep); | ||
127 | } | ||
128 | scene.Simulate(timeStep); | ||
129 | scene.FetchResults(); | ||
130 | scene.UpdateControllers(); | ||
131 | |||
132 | foreach (PhysXCharacter actor in _characters) | ||
133 | { | ||
134 | actor.UpdatePosition(); | ||
135 | } | ||
136 | } | ||
137 | catch (Exception e) | ||
138 | { | ||
139 | Console.WriteLine(e.Message); | ||
140 | } | ||
141 | |||
142 | } | ||
143 | |||
144 | public override void GetResults() | ||
145 | { | ||
146 | |||
147 | } | ||
148 | |||
149 | public override bool IsThreaded | ||
150 | { | ||
151 | get | ||
152 | { | ||
153 | return(false); // for now we won't be multithreaded | ||
154 | } | ||
155 | } | ||
156 | |||
157 | public override void SetTerrain(float[] heightMap) | ||
158 | { | ||
159 | if (this._heightMap != null) | ||
160 | { | ||
161 | Console.WriteLine("PhysX - deleting old terrain"); | ||
162 | this.scene.DeleteTerrain(); | ||
163 | } | ||
164 | this._heightMap = heightMap; | ||
165 | this.scene.AddTerrain(heightMap); | ||
166 | } | ||
167 | |||
168 | public override void DeleteTerrain() | ||
169 | { | ||
170 | this.scene.DeleteTerrain(); | ||
171 | } | ||
172 | } | ||
173 | |||
174 | public class PhysXCharacter : PhysicsActor | ||
175 | { | ||
176 | private PhysicsVector _position; | ||
177 | private PhysicsVector _velocity; | ||
178 | private PhysicsVector _acceleration; | ||
179 | private NxCharacter _character; | ||
180 | private bool flying; | ||
181 | private float gravityAccel; | ||
182 | |||
183 | public PhysXCharacter(NxCharacter character) | ||
184 | { | ||
185 | _velocity = new PhysicsVector(); | ||
186 | _position = new PhysicsVector(); | ||
187 | _acceleration = new PhysicsVector(); | ||
188 | _character = character; | ||
189 | } | ||
190 | |||
191 | public override bool Flying | ||
192 | { | ||
193 | get | ||
194 | { | ||
195 | return flying; | ||
196 | } | ||
197 | set | ||
198 | { | ||
199 | flying = value; | ||
200 | } | ||
201 | } | ||
202 | |||
203 | public override PhysicsVector Position | ||
204 | { | ||
205 | get | ||
206 | { | ||
207 | return _position; | ||
208 | } | ||
209 | set | ||
210 | { | ||
211 | _position = value; | ||
212 | Vec3 ps = new Vec3(); | ||
213 | ps.X = value.X; | ||
214 | ps.Y = value.Y; | ||
215 | ps.Z = value.Z; | ||
216 | this._character.Position = ps; | ||
217 | } | ||
218 | } | ||
219 | |||
220 | public override PhysicsVector Velocity | ||
221 | { | ||
222 | get | ||
223 | { | ||
224 | return _velocity; | ||
225 | } | ||
226 | set | ||
227 | { | ||
228 | _velocity = value; | ||
229 | } | ||
230 | } | ||
231 | |||
232 | public override bool Kinematic | ||
233 | { | ||
234 | get | ||
235 | { | ||
236 | return false; | ||
237 | } | ||
238 | set | ||
239 | { | ||
240 | |||
241 | } | ||
242 | } | ||
243 | |||
244 | public override Quaternion Orientation | ||
245 | { | ||
246 | get | ||
247 | { | ||
248 | return Quaternion.Identity; | ||
249 | } | ||
250 | set | ||
251 | { | ||
252 | |||
253 | } | ||
254 | } | ||
255 | |||
256 | public override PhysicsVector Acceleration | ||
257 | { | ||
258 | get | ||
259 | { | ||
260 | return _acceleration; | ||
261 | } | ||
262 | |||
263 | } | ||
264 | public void SetAcceleration (PhysicsVector accel) | ||
265 | { | ||
266 | this._acceleration = accel; | ||
267 | } | ||
268 | |||
269 | public override void AddForce(PhysicsVector force) | ||
270 | { | ||
271 | |||
272 | } | ||
273 | |||
274 | public override void SetMomentum(PhysicsVector momentum) | ||
275 | { | ||
276 | |||
277 | } | ||
278 | |||
279 | public void Move(float timeStep) | ||
280 | { | ||
281 | Vec3 vec = new Vec3(); | ||
282 | vec.X = this._velocity.X * timeStep; | ||
283 | vec.Y = this._velocity.Y * timeStep; | ||
284 | if(flying) | ||
285 | { | ||
286 | vec.Z = ( this._velocity.Z) * timeStep; | ||
287 | } | ||
288 | else | ||
289 | { | ||
290 | gravityAccel+= -9.8f; | ||
291 | vec.Z = (gravityAccel + this._velocity.Z) * timeStep; | ||
292 | } | ||
293 | int res = this._character.Move(vec); | ||
294 | if(res == 1) | ||
295 | { | ||
296 | gravityAccel = 0; | ||
297 | } | ||
298 | } | ||
299 | |||
300 | public void UpdatePosition() | ||
301 | { | ||
302 | Vec3 vec = this._character.Position; | ||
303 | this._position.X = vec.X; | ||
304 | this._position.Y = vec.Y; | ||
305 | this._position.Z = vec.Z; | ||
306 | } | ||
307 | } | ||
308 | |||
309 | public class PhysXPrim : PhysicsActor | ||
310 | { | ||
311 | private PhysicsVector _position; | ||
312 | private PhysicsVector _velocity; | ||
313 | private PhysicsVector _acceleration; | ||
314 | private NxActor _prim; | ||
315 | |||
316 | public PhysXPrim(NxActor prim) | ||
317 | { | ||
318 | _velocity = new PhysicsVector(); | ||
319 | _position = new PhysicsVector(); | ||
320 | _acceleration = new PhysicsVector(); | ||
321 | _prim = prim; | ||
322 | } | ||
323 | public override bool Flying | ||
324 | { | ||
325 | get | ||
326 | { | ||
327 | return false; //no flying prims for you | ||
328 | } | ||
329 | set | ||
330 | { | ||
331 | |||
332 | } | ||
333 | } | ||
334 | public override PhysicsVector Position | ||
335 | { | ||
336 | get | ||
337 | { | ||
338 | PhysicsVector pos = new PhysicsVector(); | ||
339 | Vec3 vec = this._prim.Position; | ||
340 | pos.X = vec.X; | ||
341 | pos.Y = vec.Y; | ||
342 | pos.Z = vec.Z; | ||
343 | return pos; | ||
344 | |||
345 | } | ||
346 | set | ||
347 | { | ||
348 | PhysicsVector vec = value; | ||
349 | Vec3 pos = new Vec3(); | ||
350 | pos.X = vec.X; | ||
351 | pos.Y = vec.Y; | ||
352 | pos.Z = vec.Z; | ||
353 | this._prim.Position = pos; | ||
354 | } | ||
355 | } | ||
356 | |||
357 | public override PhysicsVector Velocity | ||
358 | { | ||
359 | get | ||
360 | { | ||
361 | return _velocity; | ||
362 | } | ||
363 | set | ||
364 | { | ||
365 | _velocity = value; | ||
366 | } | ||
367 | } | ||
368 | |||
369 | public override bool Kinematic | ||
370 | { | ||
371 | get | ||
372 | { | ||
373 | return this._prim.Kinematic; | ||
374 | } | ||
375 | set | ||
376 | { | ||
377 | this._prim.Kinematic = value; | ||
378 | } | ||
379 | } | ||
380 | |||
381 | public override Quaternion Orientation | ||
382 | { | ||
383 | get | ||
384 | { | ||
385 | Quaternion res = new Quaternion(); | ||
386 | PhysXWrapper.Quaternion quat = this._prim.GetOrientation(); | ||
387 | res.w = quat.W; | ||
388 | res.x = quat.X; | ||
389 | res.y = quat.Y; | ||
390 | res.z = quat.Z; | ||
391 | return res; | ||
392 | } | ||
393 | set | ||
394 | { | ||
395 | |||
396 | } | ||
397 | } | ||
398 | |||
399 | public override PhysicsVector Acceleration | ||
400 | { | ||
401 | get | ||
402 | { | ||
403 | return _acceleration; | ||
404 | } | ||
405 | |||
406 | } | ||
407 | public void SetAcceleration (PhysicsVector accel) | ||
408 | { | ||
409 | this._acceleration = accel; | ||
410 | } | ||
411 | |||
412 | public override void AddForce(PhysicsVector force) | ||
413 | { | ||
414 | |||
415 | } | ||
416 | |||
417 | public override void SetMomentum(PhysicsVector momentum) | ||
418 | { | ||
419 | |||
420 | } | ||
421 | |||
422 | |||
423 | } | ||
424 | |||
425 | } | ||