[5420] | 1 | /* |
---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | ### File Specific: |
---|
[6616] | 12 | main-programmer: Benjamin Grauer |
---|
[5420] | 13 | co-programmer: ... |
---|
| 14 | */ |
---|
| 15 | |
---|
[4578] | 16 | /*! |
---|
[6616] | 17 | * @file vector2D.h |
---|
| 18 | * A basic 2D Vector math framework |
---|
[5008] | 19 | * |
---|
| 20 | * Contains classes to handle vectors, lines, rotations and planes |
---|
[4578] | 21 | */ |
---|
[2043] | 22 | |
---|
[7914] | 23 | #ifndef __RECT2D_H_ |
---|
| 24 | #define __RECT2D_H_ |
---|
[2043] | 25 | |
---|
[7914] | 26 | #include "vector2D.h" |
---|
[2043] | 27 | |
---|
[7914] | 28 | //! 2D Rectangle 2D |
---|
[2043] | 29 | /** |
---|
[7914] | 30 | * Class to handle 2-Dimensional Rectangles. |
---|
[6615] | 31 | */ |
---|
[7914] | 32 | class Rect2D |
---|
| 33 | { |
---|
| 34 | public: |
---|
[7917] | 35 | Rect2D() { }; |
---|
[7914] | 36 | Rect2D(float x, float y, float width, float height); |
---|
| 37 | Rect2D(const Vector2D& topLeft, const Vector2D& bottomRight ); |
---|
| 38 | Rect2D(const Rect2D& rect); |
---|
[2043] | 39 | |
---|
[7914] | 40 | Rect2D& operator=(const Rect2D& rect); |
---|
| 41 | bool operator==(const Rect2D& rect) const; |
---|
| 42 | bool operator!=(const Rect2D& rect) const; |
---|
[3541] | 43 | |
---|
[7914] | 44 | Rect2D operator+(const Rect2D& rect) const; |
---|
| 45 | Rect2D& operator+=(const Rect2D& rect); |
---|
[4476] | 46 | |
---|
[7914] | 47 | Rect2D operator-(const Rect2D& rect) const; |
---|
| 48 | Rect2D& operator-=(const Rect2D& rect); |
---|
[2043] | 49 | |
---|
[7914] | 50 | Rect2D operator&(const Rect2D& rect) const; |
---|
| 51 | Rect2D& operator&=(const Rect2D& rect); |
---|
[2043] | 52 | |
---|
[7914] | 53 | Rect2D operator*(const Vector2D& scaling) const; |
---|
[4476] | 54 | |
---|
[5008] | 55 | |
---|
[5052] | 56 | |
---|
[7914] | 57 | /** @returns the top of the Rectangle */ |
---|
| 58 | inline float top() const { return _topLeft.y; }; |
---|
| 59 | /** @returns the bottom of the Rectangle */ |
---|
| 60 | inline float bottom() const { return _bottomRight.y; }; |
---|
| 61 | /** @returns the left border of the Rectangle */ |
---|
| 62 | inline float left() const { return _topLeft.x; }; |
---|
| 63 | /** @returns the right border of the rectangle */ |
---|
| 64 | inline float right() const { return _bottomRight.x; }; |
---|
| 65 | /** @returns the Center of the Rectangle */ |
---|
| 66 | inline Vector2D center() const { return (_topLeft+_bottomRight)/ 2.0; } |
---|
| 67 | /** @returns the width of the Rectangle */ |
---|
| 68 | inline float width() const { return (right() - left()); }; |
---|
| 69 | /** @returns the height of the rectangle */ |
---|
| 70 | inline float height() const { return (bottom() - top()); }; |
---|
| 71 | /** @returns the Size of the Rectangle */ |
---|
| 72 | inline Vector2D size() const { return Vector2D(width(), height()); } |
---|
| 73 | /** @returns the area of the Rectangle */ |
---|
| 74 | float area() const { return width()*height(); } |
---|
| 75 | |
---|
| 76 | /** @param top sets the top border of the Rectangle */ |
---|
| 77 | inline void setTop(float top) { _topLeft.y = top; }; |
---|
| 78 | /** @param bottom the bottom border of the Rectangle */ |
---|
| 79 | inline void setBottom(float bottom) { _bottomRight.y = bottom; }; |
---|
| 80 | /** @param left the left border of the Rectangle */ |
---|
| 81 | inline void setLeft(float left) { _topLeft.x = left; }; |
---|
| 82 | /** @param right the right border of the Rectangle */ |
---|
| 83 | inline void setRight(float right) { _bottomRight.x = right; }; |
---|
| 84 | /** @param topLeft the top left corner of the Rectangle */ |
---|
[8035] | 85 | inline void setTopLeft(const Vector2D& topLeft) { _topLeft = topLeft; }; |
---|
| 86 | /** @param x the left border of the Rectangle @param y the top border */ |
---|
| 87 | inline void setTopLeft(float x, float y) { this->setTopLeft(Vector2D(x,y)); }; |
---|
[7914] | 88 | /** @param bottomRight the lower right corner of the Rectangle */ |
---|
[8035] | 89 | inline void setBottomRight(const Vector2D& bottomRight) { _bottomRight = bottomRight; }; |
---|
| 90 | /** @param x the right border of the Rectangle @param y the bottom border */ |
---|
| 91 | inline void setBottomRight(float x, float y) { this->setBottomRight(Vector2D(x,y)); }; |
---|
[7914] | 92 | |
---|
| 93 | void setWidth(float width); |
---|
| 94 | void setHeight(float height); |
---|
| 95 | void setSize(float width, float height); |
---|
| 96 | void setSize(const Vector2D& size); |
---|
| 97 | void setCenter(const Vector2D& center); |
---|
[8448] | 98 | void setCenter(float x, float y); |
---|
| 99 | void setCenterX(float x); |
---|
| 100 | void setCenterY(float y); |
---|
[7914] | 101 | |
---|
[8448] | 102 | |
---|
[7914] | 103 | void scaleX(float x); |
---|
| 104 | void scaleY(float y); |
---|
| 105 | void scale(float x, float y); |
---|
| 106 | void scale(const Vector2D& v); |
---|
| 107 | void scaleCentered(float x, float y); |
---|
| 108 | void scaleCentered(const Vector2D& v); |
---|
| 109 | |
---|
| 110 | void moveX(float x); |
---|
| 111 | void moveY(float y); |
---|
[7915] | 112 | void move(float x, float y); |
---|
[7914] | 113 | void move(const Vector2D& v); |
---|
| 114 | |
---|
| 115 | void swapTopBottom(); |
---|
| 116 | void swapLeftRight(); |
---|
| 117 | void normalize(); |
---|
| 118 | Rect2D normalized() const; |
---|
| 119 | |
---|
| 120 | |
---|
| 121 | Rect2D intersection(const Rect2D& intersector) const; |
---|
| 122 | bool intersects(const Rect2D& intersector) const; |
---|
| 123 | Rect2D unite(const Rect2D& rect); |
---|
| 124 | bool contains(const Rect2D& rect) const; |
---|
| 125 | bool contains(const Vector2D& point) const; |
---|
| 126 | |
---|
| 127 | const Rect2D& slerp(const Rect2D& rect, float value); |
---|
| 128 | |
---|
[8619] | 129 | void debug() const; |
---|
| 130 | |
---|
[7914] | 131 | private: |
---|
| 132 | Vector2D _topLeft; |
---|
| 133 | Vector2D _bottomRight; |
---|
| 134 | }; |
---|
| 135 | |
---|
| 136 | |
---|
| 137 | #endif /* __RECT2D_H_ */ |
---|
| 138 | |
---|