diff options
Diffstat (limited to 'OpenSim/Region/PhysicsModules/BasicPhysics/BasicPhysicsScene.cs')
-rw-r--r-- | OpenSim/Region/PhysicsModules/BasicPhysics/BasicPhysicsScene.cs | 210 |
1 files changed, 210 insertions, 0 deletions
diff --git a/OpenSim/Region/PhysicsModules/BasicPhysics/BasicPhysicsScene.cs b/OpenSim/Region/PhysicsModules/BasicPhysics/BasicPhysicsScene.cs new file mode 100644 index 0000000..06a205e --- /dev/null +++ b/OpenSim/Region/PhysicsModules/BasicPhysics/BasicPhysicsScene.cs | |||
@@ -0,0 +1,210 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.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 OpenSimulator 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 Nini.Config; | ||
31 | using OpenMetaverse; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Region.Physics.Manager; | ||
34 | |||
35 | namespace OpenSim.Region.Physics.BasicPhysicsPlugin | ||
36 | { | ||
37 | /// <summary> | ||
38 | /// This is an incomplete extremely basic physics implementation | ||
39 | /// </summary> | ||
40 | /// <remarks> | ||
41 | /// Not useful for anything at the moment apart from some regression testing in other components where some form | ||
42 | /// of physics plugin is needed. | ||
43 | /// </remarks> | ||
44 | public class BasicScene : PhysicsScene | ||
45 | { | ||
46 | private List<BasicActor> _actors = new List<BasicActor>(); | ||
47 | private List<BasicPhysicsPrim> _prims = new List<BasicPhysicsPrim>(); | ||
48 | private float[] _heightMap; | ||
49 | private Vector3 m_regionExtent; | ||
50 | |||
51 | //protected internal string sceneIdentifier; | ||
52 | |||
53 | public BasicScene(string engineType, string _sceneIdentifier) | ||
54 | { | ||
55 | EngineType = engineType; | ||
56 | Name = EngineType + "/" + _sceneIdentifier; | ||
57 | //sceneIdentifier = _sceneIdentifier; | ||
58 | } | ||
59 | |||
60 | public override void Initialise(IMesher meshmerizer, IConfigSource config) | ||
61 | { | ||
62 | throw new Exception("Should not be called."); | ||
63 | } | ||
64 | |||
65 | public override void Initialise(IMesher meshmerizer, IConfigSource config, Vector3 regionExtent) | ||
66 | { | ||
67 | m_regionExtent = regionExtent; | ||
68 | } | ||
69 | |||
70 | public override void Dispose() {} | ||
71 | |||
72 | public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, Vector3 position, | ||
73 | Vector3 size, Quaternion rotation, bool isPhysical, uint localid) | ||
74 | { | ||
75 | BasicPhysicsPrim prim = new BasicPhysicsPrim(primName, localid, position, size, rotation, pbs); | ||
76 | prim.IsPhysical = isPhysical; | ||
77 | |||
78 | _prims.Add(prim); | ||
79 | |||
80 | return prim; | ||
81 | } | ||
82 | |||
83 | public override PhysicsActor AddAvatar(string avName, Vector3 position, Vector3 velocity, Vector3 size, bool isFlying) | ||
84 | { | ||
85 | BasicActor act = new BasicActor(size); | ||
86 | act.Position = position; | ||
87 | act.Velocity = velocity; | ||
88 | act.Flying = isFlying; | ||
89 | _actors.Add(act); | ||
90 | return act; | ||
91 | } | ||
92 | |||
93 | public override void RemovePrim(PhysicsActor actor) | ||
94 | { | ||
95 | BasicPhysicsPrim prim = (BasicPhysicsPrim)actor; | ||
96 | if (_prims.Contains(prim)) | ||
97 | _prims.Remove(prim); | ||
98 | } | ||
99 | |||
100 | public override void RemoveAvatar(PhysicsActor actor) | ||
101 | { | ||
102 | BasicActor act = (BasicActor)actor; | ||
103 | if (_actors.Contains(act)) | ||
104 | _actors.Remove(act); | ||
105 | } | ||
106 | |||
107 | public override void AddPhysicsActorTaint(PhysicsActor prim) | ||
108 | { | ||
109 | } | ||
110 | |||
111 | public override float Simulate(float timeStep) | ||
112 | { | ||
113 | // Console.WriteLine("Simulating"); | ||
114 | |||
115 | float fps = 0; | ||
116 | for (int i = 0; i < _actors.Count; ++i) | ||
117 | { | ||
118 | BasicActor actor = _actors[i]; | ||
119 | Vector3 actorPosition = actor.Position; | ||
120 | Vector3 actorVelocity = actor.Velocity; | ||
121 | |||
122 | // Console.WriteLine( | ||
123 | // "Processing actor {0}, starting pos {1}, starting vel {2}", i, actorPosition, actorVelocity); | ||
124 | |||
125 | actorPosition.X += actor.Velocity.X * timeStep; | ||
126 | actorPosition.Y += actor.Velocity.Y * timeStep; | ||
127 | |||
128 | if (actor.Position.Y < 0) | ||
129 | { | ||
130 | actorPosition.Y = 0.1F; | ||
131 | } | ||
132 | else if (actor.Position.Y >= m_regionExtent.Y) | ||
133 | { | ||
134 | actorPosition.Y = (m_regionExtent.Y - 0.1f); | ||
135 | } | ||
136 | |||
137 | if (actor.Position.X < 0) | ||
138 | { | ||
139 | actorPosition.X = 0.1F; | ||
140 | } | ||
141 | else if (actor.Position.X >= m_regionExtent.X) | ||
142 | { | ||
143 | actorPosition.X = (m_regionExtent.X - 0.1f); | ||
144 | } | ||
145 | |||
146 | float terrainHeight = 0; | ||
147 | if (_heightMap != null) | ||
148 | terrainHeight = _heightMap[(int)actor.Position.Y * (int)m_regionExtent.Y + (int)actor.Position.X]; | ||
149 | |||
150 | float height = terrainHeight + actor.Size.Z; | ||
151 | // Console.WriteLine("height {0}, actorPosition {1}", height, actorPosition); | ||
152 | |||
153 | if (actor.Flying) | ||
154 | { | ||
155 | if (actor.Position.Z + (actor.Velocity.Z * timeStep) < terrainHeight + 2) | ||
156 | { | ||
157 | actorPosition.Z = height; | ||
158 | actorVelocity.Z = 0; | ||
159 | actor.IsColliding = true; | ||
160 | } | ||
161 | else | ||
162 | { | ||
163 | actorPosition.Z += actor.Velocity.Z * timeStep; | ||
164 | actor.IsColliding = false; | ||
165 | } | ||
166 | } | ||
167 | else | ||
168 | { | ||
169 | actorPosition.Z = height; | ||
170 | actorVelocity.Z = 0; | ||
171 | actor.IsColliding = true; | ||
172 | } | ||
173 | |||
174 | actor.Position = actorPosition; | ||
175 | actor.Velocity = actorVelocity; | ||
176 | } | ||
177 | |||
178 | return fps; | ||
179 | } | ||
180 | |||
181 | public override void GetResults() | ||
182 | { | ||
183 | } | ||
184 | |||
185 | public override bool IsThreaded | ||
186 | { | ||
187 | get { return (false); // for now we won't be multithreaded | ||
188 | } | ||
189 | } | ||
190 | |||
191 | public override void SetTerrain(float[] heightMap) | ||
192 | { | ||
193 | _heightMap = heightMap; | ||
194 | } | ||
195 | |||
196 | public override void DeleteTerrain() | ||
197 | { | ||
198 | } | ||
199 | |||
200 | public override void SetWaterLevel(float baseheight) | ||
201 | { | ||
202 | } | ||
203 | |||
204 | public override Dictionary<uint, float> GetTopColliders() | ||
205 | { | ||
206 | Dictionary<uint, float> returncolliders = new Dictionary<uint, float>(); | ||
207 | return returncolliders; | ||
208 | } | ||
209 | } | ||
210 | } | ||