diff options
author | Jeff Ames | 2008-06-26 02:03:40 +0000 |
---|---|---|
committer | Jeff Ames | 2008-06-26 02:03:40 +0000 |
commit | 76e24d02ad422987f1bff7c2202e6c9955cfedd8 (patch) | |
tree | 5b58435612b0875df2f09717ceefb541445649b1 /OpenSim | |
parent | Add patch from bug #1596 - adds Doxygen documentation in OpenSim.Data.MySQL f... (diff) | |
download | opensim-SC_OLD-76e24d02ad422987f1bff7c2202e6c9955cfedd8.zip opensim-SC_OLD-76e24d02ad422987f1bff7c2202e6c9955cfedd8.tar.gz opensim-SC_OLD-76e24d02ad422987f1bff7c2202e6c9955cfedd8.tar.bz2 opensim-SC_OLD-76e24d02ad422987f1bff7c2202e6c9955cfedd8.tar.xz |
Minor refactoring of POS. Adds a Util.Clamp(x, min, max) function.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/Util.cs | 8 | ||||
-rw-r--r-- | OpenSim/Region/Physics/POSPlugin/POSScene.cs | 71 |
2 files changed, 27 insertions, 52 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index a835cec..5b529da 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs | |||
@@ -130,6 +130,14 @@ namespace OpenSim.Framework | |||
130 | return Helpers.UIntsToLong(X, Y); | 130 | return Helpers.UIntsToLong(X, Y); |
131 | } | 131 | } |
132 | 132 | ||
133 | public static T Clamp<T>(T x, T min, T max) | ||
134 | where T : System.IComparable<T> | ||
135 | { | ||
136 | return x.CompareTo(max) > 0 ? max : | ||
137 | x.CompareTo(min) < 0 ? min : | ||
138 | x; | ||
139 | } | ||
140 | |||
133 | public static uint GetNextXferID() | 141 | public static uint GetNextXferID() |
134 | { | 142 | { |
135 | uint id = 0; | 143 | uint id = 0; |
diff --git a/OpenSim/Region/Physics/POSPlugin/POSScene.cs b/OpenSim/Region/Physics/POSPlugin/POSScene.cs index e9ecaa5..a32021d 100644 --- a/OpenSim/Region/Physics/POSPlugin/POSScene.cs +++ b/OpenSim/Region/Physics/POSPlugin/POSScene.cs | |||
@@ -107,14 +107,8 @@ namespace OpenSim.Region.Physics.POSPlugin | |||
107 | return prim; | 107 | return prim; |
108 | } | 108 | } |
109 | 109 | ||
110 | private bool check_collision(POSCharacter c, POSPrim p) | 110 | private bool isColliding(POSCharacter c, POSPrim p) |
111 | { | 111 | { |
112 | /* | ||
113 | Console.WriteLine("checking whether " + c + " collides with " + p + | ||
114 | " absX: " + Math.Abs(p.Position.X - c.Position.X) + | ||
115 | " sizeX: " + p.Size.X * 0.5 + 0.5); | ||
116 | */ | ||
117 | |||
118 | Vector3 rotatedPos = p.Orientation.Inverse() * | 112 | Vector3 rotatedPos = p.Orientation.Inverse() * |
119 | new Vector3(c.Position.X - p.Position.X, c.Position.Y - p.Position.Y, | 113 | new Vector3(c.Position.X - p.Position.X, c.Position.Y - p.Position.Y, |
120 | c.Position.Z - p.Position.Z); | 114 | c.Position.Z - p.Position.Z); |
@@ -129,11 +123,11 @@ namespace OpenSim.Region.Physics.POSPlugin | |||
129 | return true; | 123 | return true; |
130 | } | 124 | } |
131 | 125 | ||
132 | private bool check_all_prims(POSCharacter c) | 126 | private bool isCollidingWithPrim(POSCharacter c) |
133 | { | 127 | { |
134 | for (int i = 0; i < _prims.Count; ++i) | 128 | for (int i = 0; i < _prims.Count; ++i) |
135 | { | 129 | { |
136 | if (check_collision(c, _prims[i])) | 130 | if (isColliding(c, _prims[i])) |
137 | { | 131 | { |
138 | return true; | 132 | return true; |
139 | } | 133 | } |
@@ -160,33 +154,19 @@ namespace OpenSim.Region.Physics.POSPlugin | |||
160 | 154 | ||
161 | if (!character.Flying) | 155 | if (!character.Flying) |
162 | { | 156 | { |
163 | character._target_velocity.Z += gravity*timeStep; | 157 | character._target_velocity.Z += gravity * timeStep; |
164 | } | 158 | } |
165 | 159 | ||
166 | bool forcedZ = false; | 160 | character.Position.X += character._target_velocity.X * timeStep; |
167 | character.Position.X += character._target_velocity.X*timeStep; | 161 | character.Position.Y += character._target_velocity.Y * timeStep; |
168 | character.Position.Y += character._target_velocity.Y*timeStep; | ||
169 | 162 | ||
170 | if (character.Position.Y < 0) | 163 | character.Position.X = Util.Clamp(character.Position.X, 0.01f, Constants.RegionSize - 0.01f); |
171 | { | 164 | character.Position.Y = Util.Clamp(character.Position.Y, 0.01f, Constants.RegionSize - 0.01f); |
172 | character.Position.Y = 0.1F; | ||
173 | } | ||
174 | else if (character.Position.Y >= Constants.RegionSize) | ||
175 | { | ||
176 | character.Position.Y = Constants.RegionSize - 0.1f; | ||
177 | } | ||
178 | 165 | ||
179 | if (character.Position.X < 0) | 166 | bool forcedZ = false; |
180 | { | ||
181 | character.Position.X = 0.1F; | ||
182 | } | ||
183 | else if (character.Position.X >= Constants.RegionSize) | ||
184 | { | ||
185 | character.Position.X = Constants.RegionSize - 0.1f; | ||
186 | } | ||
187 | 167 | ||
188 | float terrainheight = _heightMap[(int)character.Position.Y * Constants.RegionSize + (int)character.Position.X]; | 168 | float terrainheight = _heightMap[(int)character.Position.Y * Constants.RegionSize + (int)character.Position.X]; |
189 | if (character.Position.Z + (character._target_velocity.Z*timeStep) < terrainheight + 2) | 169 | if (character.Position.Z + (character._target_velocity.Z * timeStep) < terrainheight + 2) |
190 | { | 170 | { |
191 | character.Position.Z = terrainheight + 1.0f; | 171 | character.Position.Z = terrainheight + 1.0f; |
192 | forcedZ = true; | 172 | forcedZ = true; |
@@ -200,24 +180,26 @@ namespace OpenSim.Region.Physics.POSPlugin | |||
200 | /// Completely Bogus Collision Detection!!! | 180 | /// Completely Bogus Collision Detection!!! |
201 | /// better known as the CBCD algorithm | 181 | /// better known as the CBCD algorithm |
202 | 182 | ||
203 | if (check_all_prims(character)) | 183 | if (isCollidingWithPrim(character)) |
204 | { | 184 | { |
205 | character.Position.Z = oldposZ; // first try Z axis | 185 | character.Position.Z = oldposZ; // first try Z axis |
206 | if (check_all_prims(character)) | 186 | if (isCollidingWithPrim(character)) |
207 | { | 187 | { |
208 | character.Position.Z = oldposZ + 0.4f; // try harder | 188 | character.Position.Z = oldposZ + 0.4f; // try harder |
209 | if (check_all_prims(character)) | 189 | if (isCollidingWithPrim(character)) |
210 | { | 190 | { |
211 | character.Position.X = oldposX; | 191 | character.Position.X = oldposX; |
212 | character.Position.Y = oldposY; | 192 | character.Position.Y = oldposY; |
213 | character.Position.Z = oldposZ; | 193 | character.Position.Z = oldposZ; |
194 | |||
214 | character.Position.X += character._target_velocity.X * timeStep; | 195 | character.Position.X += character._target_velocity.X * timeStep; |
215 | if (check_all_prims(character)) | 196 | if (isCollidingWithPrim(character)) |
216 | { | 197 | { |
217 | character.Position.X = oldposX; | 198 | character.Position.X = oldposX; |
218 | } | 199 | } |
200 | |||
219 | character.Position.Y += character._target_velocity.Y * timeStep; | 201 | character.Position.Y += character._target_velocity.Y * timeStep; |
220 | if (check_all_prims(character)) | 202 | if (isCollidingWithPrim(character)) |
221 | { | 203 | { |
222 | character.Position.Y = oldposY; | 204 | character.Position.Y = oldposY; |
223 | } | 205 | } |
@@ -233,23 +215,8 @@ namespace OpenSim.Region.Physics.POSPlugin | |||
233 | } | 215 | } |
234 | } | 216 | } |
235 | 217 | ||
236 | if (character.Position.Y < 0) | 218 | character.Position.X = Util.Clamp(character.Position.X, 0.01f, Constants.RegionSize - 0.01f); |
237 | { | 219 | character.Position.Y = Util.Clamp(character.Position.Y, 0.01f, Constants.RegionSize - 0.01f); |
238 | character.Position.Y = 0.1F; | ||
239 | } | ||
240 | else if (character.Position.Y >= Constants.RegionSize) | ||
241 | { | ||
242 | character.Position.Y = Constants.RegionSize - 0.1f; | ||
243 | } | ||
244 | |||
245 | if (character.Position.X < 0) | ||
246 | { | ||
247 | character.Position.X = 0.1F; | ||
248 | } | ||
249 | else if (character.Position.X >= Constants.RegionSize) | ||
250 | { | ||
251 | character.Position.X = Constants.RegionSize - 0.1f; | ||
252 | } | ||
253 | 220 | ||
254 | character._velocity.X = (character.Position.X - oldposX)/timeStep; | 221 | character._velocity.X = (character.Position.X - oldposX)/timeStep; |
255 | character._velocity.Y = (character.Position.Y - oldposY)/timeStep; | 222 | character._velocity.Y = (character.Position.Y - oldposY)/timeStep; |