EMI: use X-Z in Vector3d::intersectLine2d

This commit is contained in:
Dries Harnie 2012-02-01 01:20:59 +01:00
parent ef8239f8cf
commit c3237e129e
3 changed files with 19 additions and 8 deletions

View File

@ -335,16 +335,18 @@ Common::List<Math::Line3d> Sector::getBridgesTo(Sector *sector) const {
bool b1_out = edge.x() * delta_b1.y() < edge.y() * delta_b1.x();
bool b2_out = edge.x() * delta_b2.y() < edge.y() * delta_b2.x();
bool useXZ = (g_grim->getGameType() == GType_MONKEY4);
if (b1_out && b2_out) {
// Both points are outside.
it = bridges.erase(it);
continue;
} else if (b1_out) {
if (bridge.intersectLine2d(line, &pos)) {
if (bridge.intersectLine2d(line, &pos), useXZ) {
bridge = Math::Line3d(pos, bridge.end());
}
} else if (b2_out) {
if (bridge.intersectLine2d(line, &pos)) {
if (bridge.intersectLine2d(line, &pos, useXZ)) {
bridge = Math::Line3d(bridge.begin(), pos);
}
}

View File

@ -49,13 +49,22 @@ Math::Vector3d Line3d::middle() const {
return (_begin + _end) / 2.f;
}
bool Line3d::intersectLine2d(const Line3d &other, Math::Vector3d *pos) {
bool Line3d::intersectLine2d(const Line3d &other, Math::Vector3d *pos, bool useXZ) {
float denom = ((other._end.y() - other._begin.y()) * (_end.x() - _begin.x())) -
((other._end.x() - other._begin.x()) * (_end.y() - _begin.y()));
float denom, nume_a;
if (useXZ) {
denom = ((other._end.z() - other._begin.z()) * (_end.x() - _begin.x())) -
((other._end.x() - other._begin.x()) * (_end.z() - _begin.z()));
float nume_a = ((other._end.x() - other._begin.x()) * (_begin.y() - other._begin.y())) -
((other._end.y() - other._begin.y()) * (_begin.x() - other._begin.x()));
nume_a = ((other._end.x() - other._begin.x()) * (_begin.z() - other._begin.z())) -
((other._end.z() - other._begin.z()) * (_begin.x() - other._begin.x()));
} else {
denom = ((other._end.y() - other._begin.y()) * (_end.x() - _begin.x())) -
((other._end.x() - other._begin.x()) * (_end.y() - _begin.y()));
nume_a = ((other._end.x() - other._begin.x()) * (_begin.y() - other._begin.y())) -
((other._end.y() - other._begin.y()) * (_begin.x() - other._begin.x()));
}
if (denom == 0.0f) {
return false;

View File

@ -40,7 +40,7 @@ public:
Math::Vector3d end() const;
Math::Vector3d middle() const;
bool intersectLine2d(const Line3d &other, Math::Vector3d *pos);
bool intersectLine2d(const Line3d &other, Math::Vector3d *pos, bool useXZ = false);
void operator=(const Line3d &other);