aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/World/Land
diff options
context:
space:
mode:
authorUbitUmarov2015-12-15 17:13:32 +0000
committerUbitUmarov2015-12-15 17:13:32 +0000
commitc7b963df8f531f112c235c748c27ca2d36d770b8 (patch)
treefd55e8bec9103362fc4ae6a57f2128f485beaa1b /OpenSim/Region/CoreModules/World/Land
parentsome changes parcels AABB math etc (diff)
downloadopensim-SC_OLD-c7b963df8f531f112c235c748c27ca2d36d770b8.zip
opensim-SC_OLD-c7b963df8f531f112c235c748c27ca2d36d770b8.tar.gz
opensim-SC_OLD-c7b963df8f531f112c235c748c27ca2d36d770b8.tar.bz2
opensim-SC_OLD-c7b963df8f531f112c235c748c27ca2d36d770b8.tar.xz
replace GetNearestPoint... funtions
Diffstat (limited to 'OpenSim/Region/CoreModules/World/Land')
-rw-r--r--OpenSim/Region/CoreModules/World/Land/LandObject.cs147
1 files changed, 144 insertions, 3 deletions
diff --git a/OpenSim/Region/CoreModules/World/Land/LandObject.cs b/OpenSim/Region/CoreModules/World/Land/LandObject.cs
index ed509fe..378e996 100644
--- a/OpenSim/Region/CoreModules/World/Land/LandObject.cs
+++ b/OpenSim/Region/CoreModules/World/Land/LandObject.cs
@@ -121,6 +121,147 @@ namespace OpenSim.Region.CoreModules.World.Land
121 } 121 }
122 } 122 }
123 123
124 public Vector2? GetNearestPoint(Vector3 pos)
125 {
126 Vector3 direction = new Vector3(m_centerPoint.X - pos.X, m_centerPoint.Y - pos.Y, 0f );
127 return GetNearestPointAlongDirection(pos, direction);
128 }
129
130 public Vector2? GetNearestPointAlongDirection(Vector3 pos, Vector3 pdirection)
131 {
132 Vector2 testpos;
133 Vector2 direction;
134
135 testpos.X = pos.X / landUnit;
136 testpos.Y = pos.Y / landUnit;
137
138 if(LandBitmap[(int)testpos.X, (int)testpos.Y])
139 return new Vector2(pos.X, pos.Y); // we are already here
140
141 direction.X = pdirection.X;
142 direction.Y = pdirection.Y;
143
144 if(direction.X == 0f && direction.Y == 0f)
145 return null; // we can't look anywhere
146
147 direction.Normalize();
148
149 int minx = (int)(m_AABBmin.X / landUnit);
150 int maxx = (int)(m_AABBmax.X / landUnit);
151
152 // check against AABB
153 if(direction.X > 0f)
154 {
155 if(testpos.X >= maxx)
156 return null; // will never get there
157 if(testpos.X < minx)
158 testpos.X = minx;
159 }
160 else if(direction.X < 0f)
161 {
162 if(testpos.X < minx)
163 return null; // will never get there
164 if(testpos.X >= maxx)
165 testpos.X = maxx - 1;
166 }
167 else
168 {
169 if(testpos.X < minx)
170 return null; // will never get there
171 else if(testpos.X >= maxx)
172 return null; // will never get there
173 }
174
175 int miny = (int)(m_AABBmin.Y / landUnit);
176 int maxy = (int)(m_AABBmax.Y / landUnit);
177
178 if(direction.Y > 0f)
179 {
180 if(testpos.Y >= maxy)
181 return null; // will never get there
182 if(testpos.Y < miny)
183 testpos.Y = miny;
184 }
185 else if(direction.Y < 0f)
186 {
187 if(testpos.Y < miny)
188 return null; // will never get there
189 if(testpos.Y >= maxy)
190 testpos.Y = maxy - 1;
191 }
192 else
193 {
194 if(testpos.Y < miny)
195 return null; // will never get there
196 else if(testpos.Y >= maxy)
197 return null; // will never get there
198 }
199
200 while(!LandBitmap[(int)testpos.X, (int)testpos.Y])
201 {
202 testpos += direction;
203
204 if(testpos.X < minx)
205 return null;
206 if (testpos.X >= maxx)
207 return null;
208 if(testpos.Y < miny)
209 return null;
210 if (testpos.Y >= maxy)
211 return null;
212 }
213
214 testpos *= landUnit;
215 float ftmp;
216
217 if(Math.Abs(direction.X) > Math.Abs(direction.Y))
218 {
219 if(direction.X < 0)
220 testpos.X += landUnit - 0.5f;
221 else
222 testpos.X += 0.5f;
223 ftmp = testpos.X - pos.X;
224 ftmp /= direction.X;
225 ftmp = Math.Abs(ftmp);
226 ftmp *= direction.Y;
227 ftmp += pos.Y;
228
229 if(ftmp < testpos.Y + .5f)
230 ftmp = testpos.Y + .5f;
231 else
232 {
233 testpos.Y += landUnit - 0.5f;
234 if(ftmp > testpos.Y)
235 ftmp = testpos.Y;
236 }
237 testpos.Y = ftmp;
238 }
239 else
240 {
241 if(direction.Y < 0)
242 testpos.Y += landUnit - 0.5f;
243 else
244 testpos.Y += 0.5f;
245 ftmp = testpos.Y - pos.Y;
246 ftmp /= direction.Y;
247 ftmp = Math.Abs(ftmp);
248 ftmp *= direction.X;
249 ftmp += pos.X;
250
251 if(ftmp < testpos.X + .5f)
252 ftmp = testpos.X + .5f;
253 else
254 {
255 testpos.X += landUnit - 0.5f;
256 if(ftmp > testpos.X)
257 ftmp = testpos.X;
258 }
259 testpos.X = ftmp;
260 }
261 return testpos;
262 }
263
264
124 #region Constructors 265 #region Constructors
125 266
126 public LandObject(LandData landData, Scene scene) 267 public LandObject(LandData landData, Scene scene)
@@ -791,7 +932,7 @@ namespace OpenSim.Region.CoreModules.World.Land
791 { 932 {
792 for (y = 0; y < LandBitmap.GetLength(1); y++) 933 for (y = 0; y < LandBitmap.GetLength(1); y++)
793 { 934 {
794 if (LandBitmap[x, y] == true) 935 if (LandBitmap[x, y])
795 { 936 {
796 if (min_x > x) 937 if (min_x > x)
797 min_x = x; 938 min_x = x;
@@ -856,7 +997,7 @@ namespace OpenSim.Region.CoreModules.World.Land
856 m_AABBmin.X = tx; 997 m_AABBmin.X = tx;
857 m_AABBmin.Y = ty; 998 m_AABBmin.Y = ty;
858 999
859 if(m_scene == null) 1000 if(m_scene == null || m_scene.Heightmap == null)
860 LandData.AABBMin = new Vector3(tx, ty, 0f); 1001 LandData.AABBMin = new Vector3(tx, ty, 0f);
861 else 1002 else
862 LandData.AABBMin = new Vector3(tx, ty, (float)m_scene.Heightmap[tx, ty]); 1003 LandData.AABBMin = new Vector3(tx, ty, (float)m_scene.Heightmap[tx, ty]);
@@ -874,7 +1015,7 @@ namespace OpenSim.Region.CoreModules.World.Land
874 m_AABBmax.X = tx; 1015 m_AABBmax.X = tx;
875 m_AABBmax.Y = ty; 1016 m_AABBmax.Y = ty;
876 1017
877 if(m_scene == null) 1018 if(m_scene == null || m_scene.Heightmap == null)
878 LandData.AABBMax = new Vector3(tx, ty, 0f); 1019 LandData.AABBMax = new Vector3(tx, ty, 0f);
879 else 1020 else
880 LandData.AABBMax = new Vector3(tx, ty, (float)m_scene.Heightmap[tx - 1, ty - 1]); 1021 LandData.AABBMax = new Vector3(tx, ty, (float)m_scene.Heightmap[tx - 1, ty - 1]);