diff --git a/engines/grim/actor.cpp b/engines/grim/actor.cpp index f1261c875b4..313de320ca0 100644 --- a/engines/grim/actor.cpp +++ b/engines/grim/actor.cpp @@ -1544,8 +1544,8 @@ bool Actor::collidesWith(Actor *actor, Graphics::Vector3d *vec) const { size = model1->_bboxSize * _collisionScale; yaw = _yaw; - circle._x = p2.x(); - circle._y = p2.y(); + circle.setX(p2.x()); + circle.setY(p2.y()); circlePos = p2; radius = size2; } else { @@ -1554,8 +1554,8 @@ bool Actor::collidesWith(Actor *actor, Graphics::Vector3d *vec) const { size = model2->_bboxSize * actor->_collisionScale; yaw = actor->_yaw; - circle._x = p1.x() + vec->x(); - circle._y = p1.y() + vec->y(); + circle.setX(p1.x() + vec->x()); + circle.setY(p1.y() + vec->y()); circlePos = p1; radius = size1; } diff --git a/graphics/line2d.cpp b/graphics/line2d.cpp index 444df1f4c6d..d30ade0cdb9 100644 --- a/graphics/line2d.cpp +++ b/graphics/line2d.cpp @@ -34,13 +34,13 @@ Line2d::Line2d() : Line2d::Line2d(const Vector2d &direction, const Vector2d &point) { Vector2d d = direction; - _a = d._y / d._x; + _a = d.getY() / d.getX(); _b = -1; if (_b == 0) { - _c = -point._x; + _c = -point.getX(); } else { - _c = point._y - (d._y / d._x) * point._x; + _c = point.getY() - (d.getY() / d.getX()) * point.getX(); } } @@ -90,7 +90,7 @@ bool Line2d::intersectsLine(const Line2d &line, Vector2d *pos) const { } bool Line2d::containsPoint(const Vector2d &point) const { - float n = _a * point._x + _b * point._y + _c; + float n = _a * point.getX() + _b * point.getY() + _c; return (n < 0.0001 && n > -0.0001); } @@ -127,8 +127,8 @@ Vector2d Segment2d::middle() const { } Line2d Segment2d::getLine() const { - float y = _end._y - _begin._y; - float x = _end._x - _begin._x; + float y = _end.getY() - _begin.getY(); + float x = _end.getX() - _begin.getX(); Vector2d v(x, y); return Line2d(v, _begin); @@ -139,18 +139,18 @@ Line2d Segment2d::getPerpendicular(const Vector2d &point) const { } bool Segment2d::intersectsSegment(const Segment2d &other, Vector2d *pos) { - float denom = ((other._end._y - other._begin._y) * (_end._x - _begin._x)) - - ((other._end._x - other._begin._x) * (_end._y - _begin._y)); + float denom = ((other._end.getY() - other._begin.getY()) * (_end.getX() - _begin.getX())) - + ((other._end.getX() - other._begin.getX()) * (_end.getY() - _begin.getY())); - float d = ((_end._y - _begin._y) * (other._end._x - other._begin._x)) - - ((_end._x - _begin._x) * (other._end._y - other._begin._y)); + float d = ((_end.getY() - _begin.getY()) * (other._end.getX() - other._begin.getX())) - + ((_end.getX() - _begin.getX()) * (other._end.getY() - other._begin.getY())); - 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)); + float nume_a = ((other._end.getX() - other._begin.getX()) * (_begin.getY() - other._begin.getY())) - + ((other._end.getY() - other._begin.getY()) * (_begin.getX() - other._begin.getX())); - float nume_b = ((_end._x - _begin._x) * (other._begin._y - _begin._y)) - - ((_end._y - _begin._y) * (other._begin._x - _begin._x)); + float nume_b = ((_end.getX() - _begin.getX()) * (other._begin.getY() - _begin.getY())) - + ((_end.getY() - _begin.getY()) * (other._begin.getX() - _begin.getX())); if (denom == 0.0f) { return false; diff --git a/graphics/rect2d.cpp b/graphics/rect2d.cpp index 7f405021951..a51d68a051d 100644 --- a/graphics/rect2d.cpp +++ b/graphics/rect2d.cpp @@ -33,10 +33,10 @@ Rect2d::Rect2d() { } Rect2d::Rect2d(const Vector2d &topLeft, const Vector2d &bottomRight) { - float left = (topLeft._x <= bottomRight._x ? topLeft._x : bottomRight._x); - float right = (topLeft._x <= bottomRight._x ? bottomRight._x : topLeft._x); - float top = (topLeft._y <= bottomRight._y ? topLeft._y : bottomRight._y); - float bottom = (topLeft._y <= bottomRight._y ? bottomRight._y : topLeft._y); + float left = (topLeft.getX() <= bottomRight.getX() ? topLeft.getX() : bottomRight.getX()); + float right = (topLeft.getX() <= bottomRight.getX() ? bottomRight.getX() : topLeft.getX()); + float top = (topLeft.getY() <= bottomRight.getY() ? topLeft.getY() : bottomRight.getY()); + float bottom = (topLeft.getY() <= bottomRight.getY() ? bottomRight.getY() : topLeft.getY()); _topLeft = Vector2d(left, top); _topRight = Vector2d(right, top); @@ -75,24 +75,24 @@ bool Rect2d::intersectsCircle(const Vector2d ¢er, float radius) const { float angle = (_topRight - _topLeft).getAngle(); if (angle < 0.1 && angle > -0.1) { - Vector2d circleDistance(fabs(center._x - c._x), fabs(center._y - c._y)); + Vector2d circleDistance(fabs(center.getX() - c.getX()), fabs(center.getY() - c.getY())); - if (circleDistance._x > (w / 2.f + radius)) { + if (circleDistance.getX() > (w / 2.f + radius)) { return false; } - if (circleDistance._y > (h / 2.f + radius)) { + if (circleDistance.getY() > (h / 2.f + radius)) { return false; } - if (circleDistance._x <= (w / 2.f)) { + if (circleDistance.getX() <= (w / 2.f)) { return true; } - if (circleDistance._y <= (h / 2.f)) { + if (circleDistance.getY() <= (h / 2.f)) { return true; } - float cornerDistance_sq = pow(circleDistance._x - w / 2.f, 2.f) + - pow(circleDistance._y - h / 2.f, 2.f); + float cornerDistance_sq = pow(circleDistance.getX() - w / 2.f, 2.f) + + pow(circleDistance.getY() - h / 2.f, 2.f); return (cornerDistance_sq <= radius * radius); } else { //The rectangle was rotated @@ -105,16 +105,13 @@ bool Rect2d::intersectsCircle(const Vector2d ¢er, float radius) const { } bool Rect2d::containsPoint(const Vector2d &point) const { - return (point._x >= _topLeft._x && point._x <= _bottomRight._x && - point._y >= _topLeft._y && point._y <= _bottomRight._y); + return (point.getX() >= _topLeft.getX() && point.getX() <= _bottomRight.getX() && + point.getY() >= _topLeft.getY() && point.getY() <= _bottomRight.getY()); } Vector2d Rect2d::getCenter() const { - Vector2d sum; - sum._x = _topLeft._x + _topRight._x + _bottomLeft._x + _bottomRight._x; - sum._x /= 4; - sum._y = _topLeft._y + _topRight._y + _bottomLeft._y + _bottomRight._y; - sum._y /= 4; + Vector2d sum = _topLeft + _topRight + _bottomLeft + _bottomRight; + sum /= 4; return sum; } @@ -136,15 +133,15 @@ Vector2d Rect2d::getBottomRight() const { } float Rect2d::getWidth() const { - float x = _topRight._x - _topLeft._x; - float y = _topRight._y - _topLeft._y; + float x = _topRight.getX() - _topLeft.getX(); + float y = _topRight.getY() - _topLeft.getY(); return sqrt(x * x + y * y); } float Rect2d::getHeight() const { - float x = _bottomLeft._x - _topLeft._x; - float y = _bottomLeft._y - _topLeft._y; + float x = _bottomLeft.getX() - _topLeft.getX(); + float y = _bottomLeft.getY() - _topLeft.getY(); return sqrt(x * x + y * y); } diff --git a/graphics/vector2d.cpp b/graphics/vector2d.cpp index 0f92a458234..9336e894b98 100644 --- a/graphics/vector2d.cpp +++ b/graphics/vector2d.cpp @@ -41,12 +41,26 @@ Vector2d::Vector2d(const Vector2d &vec) : } +void Vector2d::setX(float x) { + _x = x; +} + +void Vector2d::setY(float y) { + _y = y; +} + Vector2d &Vector2d::operator=(const Vector2d &vec) { _x = vec._x; _y = vec._y; return *this; } +Vector2d &Vector2d::operator/=(float s) { + _x /= s; + _y /= s; + return *this; +} + void Vector2d::rotateAround(const Vector2d &point, float angle) { _x -= point._x; _y -= point._y; diff --git a/graphics/vector2d.h b/graphics/vector2d.h index 908c592b2ca..8a48513e88d 100644 --- a/graphics/vector2d.h +++ b/graphics/vector2d.h @@ -35,7 +35,13 @@ public: Vector2d(float x, float y); Vector2d(const Vector2d &vec); + inline float getX() const { return _x; } + inline float getY() const { return _y; } + void setX(float x); + void setY(float y); + Vector2d &operator=(const Vector2d &vec); + Vector2d &operator/=(float s); void normalize(); Vector2d getNormalized() const; @@ -47,33 +53,33 @@ public: Vector3d toVector3d() const; - // private: +private: float _x; float _y; }; inline Vector2d operator-(const Vector2d& v1, const Vector2d& v2) { - Vector2d result(v1._x - v2._x, v1._y - v2._y); + Vector2d result(v1.getX() - v2.getX(), v1.getY() - v2.getY()); return result; } inline Vector2d operator+(const Vector2d &v1, const Vector2d &v2) { - Vector2d result(v1._x + v2._x, v1._y + v2._y); + Vector2d result(v1.getX() + v2.getX(), v1.getY() + v2.getY()); return result; } inline Vector2d operator*(const Vector2d &v1, float factor) { - Vector2d result(v1._x * factor, v1._y * factor); + Vector2d result(v1.getX() * factor, v1.getY() * factor); return result; } inline Vector2d operator/(const Vector2d &v1, float factor) { - Vector2d result(v1._x / factor, v1._y / factor); + Vector2d result(v1.getX() / factor, v1.getY() / factor); return result; } inline Vector2d operator-(const Vector2d &v) { - return Vector2d(-v._x, -v._y); + return Vector2d(-v.getX(), -v.getY()); } }