Ticket #3541: 3451.2.diff
File 3451.2.diff, 2.6 KB (added by , 9 years ago) |
---|
-
source/simulation2/helpers/Geometry.cpp
236 236 return false; 237 237 } 238 238 239 /** 240 * This function does the same as Geometry::TestRaySquare except it ignores rotations. This saves some computation time 241 * for units which have a round obstruction. 242 * @return true if the vector cross the square, false otherwise. 243 */ 239 244 bool Geometry::TestRayAASquare(CFixedVector2D a, CFixedVector2D b, CFixedVector2D halfSize) 240 245 { 241 // Exactly like TestRaySquare with u=(1,0), v=(0,1)242 243 // Assume the compiler is clever enough to inline and simplify all this244 // (TODO: stop assuming that)245 246 CFixedVector2D u (fixed::FromInt(1), fixed::Zero()); 246 247 CFixedVector2D v (fixed::Zero(), fixed::FromInt(1)); 247 248 248 fixed h w= halfSize.X;249 fixed h h= halfSize.Y;249 fixed halfWidth = halfSize.X; 250 fixed halfHeight = halfSize.Y; 250 251 251 fixed au = a. Dot(u);252 fixed av = a. Dot(v);252 fixed au = a.X; 253 fixed av = a.Y; 253 254 254 if (-h w <= au && au <= hw && -hh <= av && av <= hh)255 if (-halfWidth <= au && au <= halfWidth && -halfHeight <= av && av <= halfHeight) 255 256 return false; // a is inside 256 257 257 fixed bu = b. Dot(u);258 fixed bv = b. Dot(v);258 fixed bu = b.X; 259 fixed bv = b.Y; 259 260 260 if (-h w <= bu && bu <= hw && -hh <= bv && bv <= hh) // TODO: isn't this subsumed by the next checks?261 if (-halfWidth <= bu && bu <= halfWidth && -halfHeight <= bv && bv <= halfHeight) // TODO: isn't this subsumed by the next checks? 261 262 return true; // a is outside, b is inside 262 263 263 if ((au < -h w && bu < -hw) || (au > hw && bu > hw) || (av < -hh && bv < -hh) || (av > hh && bv > hh))264 if ((au < -halfWidth && bu < -halfWidth) || (au > halfWidth && bu > halfWidth) || (av < -halfHeight && bv < -halfHeight) || (av > halfHeight && bv > halfHeight)) 264 265 return false; // ab is entirely above/below/side the square 265 266 266 267 CFixedVector2D abp = (b - a).Perpendicular(); 267 fixed s0 = abp.Dot((u.Multiply(h w) + v.Multiply(hh)) - a);268 fixed s1 = abp.Dot((u.Multiply(h w) - v.Multiply(hh)) - a);269 fixed s2 = abp.Dot((-u.Multiply(h w) - v.Multiply(hh)) - a);270 fixed s3 = abp.Dot((-u.Multiply(h w) + v.Multiply(hh)) - a);268 fixed s0 = abp.Dot((u.Multiply(halfWidth) + v.Multiply(halfHeight)) - a); 269 fixed s1 = abp.Dot((u.Multiply(halfWidth) - v.Multiply(halfHeight)) - a); 270 fixed s2 = abp.Dot((-u.Multiply(halfWidth) - v.Multiply(halfHeight)) - a); 271 fixed s3 = abp.Dot((-u.Multiply(halfWidth) + v.Multiply(halfHeight)) - a); 271 272 if (s0.IsZero() || s1.IsZero() || s2.IsZero() || s3.IsZero()) 272 273 return true; // ray intersects the corner 273 274