diff options
Diffstat (limited to 'OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsScene.cs')
-rw-r--r-- | OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsScene.cs | 185 |
1 files changed, 185 insertions, 0 deletions
diff --git a/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsScene.cs b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsScene.cs new file mode 100644 index 0000000..66bd099 --- /dev/null +++ b/OpenSim/Region/Physics/BasicPhysicsPlugin/BasicPhysicsScene.cs | |||
@@ -0,0 +1,185 @@ | |||
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 | public class BasicScene : PhysicsScene | ||
38 | { | ||
39 | private List<BasicActor> _actors = new List<BasicActor>(); | ||
40 | private float[] _heightMap; | ||
41 | |||
42 | //protected internal string sceneIdentifier; | ||
43 | |||
44 | public BasicScene(string _sceneIdentifier) | ||
45 | { | ||
46 | //sceneIdentifier = _sceneIdentifier; | ||
47 | } | ||
48 | |||
49 | public override void Initialise(IMesher meshmerizer, IConfigSource config) | ||
50 | { | ||
51 | } | ||
52 | |||
53 | public override void Dispose() | ||
54 | { | ||
55 | |||
56 | } | ||
57 | public override PhysicsActor AddAvatar(string avName, PhysicsVector position, PhysicsVector size, bool isFlying) | ||
58 | { | ||
59 | BasicActor act = new BasicActor(); | ||
60 | act.Position = position; | ||
61 | act.Flying = isFlying; | ||
62 | _actors.Add(act); | ||
63 | return act; | ||
64 | } | ||
65 | |||
66 | public override void RemovePrim(PhysicsActor prim) | ||
67 | { | ||
68 | } | ||
69 | |||
70 | public override void RemoveAvatar(PhysicsActor actor) | ||
71 | { | ||
72 | BasicActor act = (BasicActor) actor; | ||
73 | if (_actors.Contains(act)) | ||
74 | { | ||
75 | _actors.Remove(act); | ||
76 | } | ||
77 | } | ||
78 | |||
79 | /* | ||
80 | public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size, Quaternion rotation) | ||
81 | { | ||
82 | return null; | ||
83 | } | ||
84 | */ | ||
85 | |||
86 | public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, | ||
87 | PhysicsVector size, Quaternion rotation) | ||
88 | { | ||
89 | return AddPrimShape(primName, pbs, position, size, rotation, false); | ||
90 | } | ||
91 | |||
92 | public override PhysicsActor AddPrimShape(string primName, PrimitiveBaseShape pbs, PhysicsVector position, | ||
93 | PhysicsVector size, Quaternion rotation, bool isPhysical) | ||
94 | { | ||
95 | return null; | ||
96 | } | ||
97 | |||
98 | public override void AddPhysicsActorTaint(PhysicsActor prim) | ||
99 | { | ||
100 | } | ||
101 | |||
102 | public override float Simulate(float timeStep) | ||
103 | { | ||
104 | float fps = 0; | ||
105 | for (int i = 0; i < _actors.Count; ++i) | ||
106 | { | ||
107 | BasicActor actor = _actors[i]; | ||
108 | |||
109 | actor.Position.X += actor.Velocity.X*timeStep; | ||
110 | actor.Position.Y += actor.Velocity.Y*timeStep; | ||
111 | |||
112 | if (actor.Position.Y < 0) | ||
113 | { | ||
114 | actor.Position.Y = 0.1F; | ||
115 | } | ||
116 | else if (actor.Position.Y >= Constants.RegionSize) | ||
117 | { | ||
118 | actor.Position.Y = ((int)Constants.RegionSize - 0.1f); | ||
119 | } | ||
120 | |||
121 | if (actor.Position.X < 0) | ||
122 | { | ||
123 | actor.Position.X = 0.1F; | ||
124 | } | ||
125 | else if (actor.Position.X >= Constants.RegionSize) | ||
126 | { | ||
127 | actor.Position.X = ((int)Constants.RegionSize - 0.1f); | ||
128 | } | ||
129 | |||
130 | float height = _heightMap[(int)actor.Position.Y * Constants.RegionSize + (int)actor.Position.X] + actor.Size.Z; | ||
131 | if (actor.Flying) | ||
132 | { | ||
133 | if (actor.Position.Z + (actor.Velocity.Z*timeStep) < | ||
134 | _heightMap[(int)actor.Position.Y * Constants.RegionSize + (int)actor.Position.X] + 2) | ||
135 | { | ||
136 | actor.Position.Z = height; | ||
137 | actor.Velocity.Z = 0; | ||
138 | actor.IsColliding = true; | ||
139 | } | ||
140 | else | ||
141 | { | ||
142 | actor.Position.Z += actor.Velocity.Z*timeStep; | ||
143 | actor.IsColliding = false; | ||
144 | } | ||
145 | } | ||
146 | else | ||
147 | { | ||
148 | actor.Position.Z = height; | ||
149 | actor.Velocity.Z = 0; | ||
150 | actor.IsColliding = true; | ||
151 | } | ||
152 | } | ||
153 | return fps; | ||
154 | } | ||
155 | |||
156 | public override void GetResults() | ||
157 | { | ||
158 | } | ||
159 | |||
160 | public override bool IsThreaded | ||
161 | { | ||
162 | get { return (false); // for now we won't be multithreaded | ||
163 | } | ||
164 | } | ||
165 | |||
166 | public override void SetTerrain(float[] heightMap) | ||
167 | { | ||
168 | _heightMap = heightMap; | ||
169 | } | ||
170 | |||
171 | public override void DeleteTerrain() | ||
172 | { | ||
173 | } | ||
174 | |||
175 | public override void SetWaterLevel(float baseheight) | ||
176 | { | ||
177 | } | ||
178 | |||
179 | public override Dictionary<uint, float> GetTopColliders() | ||
180 | { | ||
181 | Dictionary<uint, float> returncolliders = new Dictionary<uint, float>(); | ||
182 | return returncolliders; | ||
183 | } | ||
184 | } | ||
185 | } | ||