Changeset View
Changeset View
Standalone View
Standalone View
gameobject.cpp
Show All 15 Lines | |||||
16 | * You should have received a copy of the GNU Library General Public | 16 | * You should have received a copy of the GNU Library General Public | ||
17 | * License along with KBounce; if not, write to the Free | 17 | * License along with KBounce; if not, write to the Free | ||
18 | * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 18 | * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
19 | * Boston, MA 02110-1301, USA. | 19 | * Boston, MA 02110-1301, USA. | ||
20 | */ | 20 | */ | ||
21 | 21 | | |||
22 | #include "gameobject.h" | 22 | #include "gameobject.h" | ||
23 | 23 | | |||
24 | /** | ||||
25 | * GameObject class | ||||
26 | * | ||||
27 | * Constructor to calculate game object normal | ||||
28 | * @see gameobject.h | ||||
29 | */ | ||||
24 | KBounceVector KBounceVector::normal( const QRectF& rect1, const QRectF& rect2 ) | 30 | KBounceVector KBounceVector::normal(const QRectF& rect1,const QRectF& rect2) | ||
25 | { | 31 | { | ||
26 | KBounceVector normal( 0, 0 ); | 32 | KBounceVector normal(0, 0); | ||
27 | 33 | | |||
28 | if ( rect1.bottom() > rect2.top() && rect1.bottom() < rect2.bottom() ) | 34 | if (rect1.bottom() > rect2.top() && rect1.bottom() < rect2.bottom()) | ||
29 | normal += KBounceVector( 0, -1 ); | 35 | normal += KBounceVector(0, -1); | ||
30 | if ( rect1.top() < rect2.bottom() && rect1.top() > rect2.top() ) | 36 | if (rect1.top() < rect2.bottom() && rect1.top() > rect2.top()) | ||
31 | normal += KBounceVector( 0, 1 ); | 37 | normal += KBounceVector(0, 1); | ||
32 | if ( rect1.right() < rect2.right() && rect1.right() > rect2.left() ) | 38 | if (rect1.right() < rect2.right() && rect1.right() > rect2.left()) | ||
33 | normal += KBounceVector( 1, 0 ); | 39 | normal += KBounceVector(1, 0); | ||
34 | if ( rect1.left() > rect2.left() && rect1.left() < rect2.right() ) | 40 | if (rect1.left() > rect2.left() && rect1.left() < rect2.right()) | ||
35 | normal += KBounceVector( -1, 0 ); | 41 | normal += KBounceVector(-1, 0); | ||
36 | 42 | | |||
37 | return normal; | 43 | return normal; | ||
38 | } | 44 | } | ||
39 | 45 | |