Simplified checkIfWallsBetween calculation.
This commit is contained in:
parent
81be59fcd2
commit
654b5748d3
@ -119,31 +119,23 @@ public class WallData implements IXmlReader
|
|||||||
|
|
||||||
for (WallHolder wall : allWalls)
|
for (WallHolder wall : allWalls)
|
||||||
{
|
{
|
||||||
boolean intersectFace = false;
|
// lower part of the multiplier fraction, if it is 0 we avoid an error and also know that the lines are parallel
|
||||||
for (int i = 0; i < 2; i++)
|
final int denominator = ((ty - y) * (wall.getPoint1X() - wall.getPoint2X())) - ((tx - x) * (wall.getPoint1Y() - wall.getPoint2Y()));
|
||||||
|
if (denominator == 0)
|
||||||
{
|
{
|
||||||
// lower part of the multiplier fraction, if it is 0 we avoid an error and also know that the lines are parallel
|
continue;
|
||||||
final int denominator = ((ty - y) * (wall.getPoint1X() - wall.getPoint2X())) - ((tx - x) * (wall.getPoint1Y() - wall.getPoint2Y()));
|
}
|
||||||
if (denominator == 0)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// multipliers to the equations of the lines. If they are lower than 0 or bigger than 1, we know that segments don't intersect
|
// multipliers to the equations of the lines. If they are lower than 0 or bigger than 1, we know that segments don't intersect
|
||||||
final float multiplier1 = (float) (((wall.getPoint2X() - wall.getPoint1X()) * (y - wall.getPoint1Y())) - ((wall.getPoint2Y() - wall.getPoint1Y()) * (x - wall.getPoint1X()))) / denominator;
|
final float multiplier1 = (float) (((wall.getPoint2X() - wall.getPoint1X()) * (y - wall.getPoint1Y())) - ((wall.getPoint2Y() - wall.getPoint1Y()) * (x - wall.getPoint1X()))) / denominator;
|
||||||
final float multiplier2 = (float) (((tx - x) * (y - wall.getPoint1Y())) - ((ty - y) * (x - wall.getPoint1X()))) / denominator;
|
final float multiplier2 = (float) (((tx - x) * (y - wall.getPoint1Y())) - ((ty - y) * (x - wall.getPoint1X()))) / denominator;
|
||||||
if ((multiplier1 >= 0) && (multiplier1 <= 1) && (multiplier2 >= 0) && (multiplier2 <= 1))
|
if ((multiplier1 >= 0) && (multiplier1 <= 1) && (multiplier2 >= 0) && (multiplier2 <= 1))
|
||||||
|
{
|
||||||
|
final int intersectZ = Math.round(z + (multiplier1 * (tz - z)));
|
||||||
|
// now checking if the resulting point is between door's min and max z
|
||||||
|
if ((intersectZ > wall.getZMin()) && (intersectZ < wall.getZMax()))
|
||||||
{
|
{
|
||||||
final int intersectZ = Math.round(z + (multiplier1 * (tz - z)));
|
return true;
|
||||||
// now checking if the resulting point is between door's min and max z
|
|
||||||
if ((intersectZ > wall.getZMin()) && (intersectZ < wall.getZMax()))
|
|
||||||
{
|
|
||||||
if (intersectFace)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
intersectFace = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user