changed to a better make header hack ... added position delta to screen collisions...
[physics.git] / src / Effects / Screen.cpp
CommitLineData
e68f847b
PG
1/*
2 * Copyright (C) 2008 Patrik Gornicz, Gornicz_P (at) hotmail (dot) com.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
2c18685d 18#include "Screen.h"
2c18685d
PG
19
20#include "../Entities/PhysicsEntity.h"
094a13b8 21#include "../Entities/Ball.h"
2c18685d 22
617dcc71
PG
23
24/// ***** Constructors/Destructors *****
25
2c18685d
PG
26Screen::Screen()
27{
28
29}
30Screen::~Screen()
31{
32
33}
34
617dcc71
PG
35/// ***** Public Class Methods *****
36
5d5a6f3f
PG
37Vector2 Screen::positionDelta(const PhysicsEntity* e, float time_step) const
38{
39 const Vector2& pos = e->positionRaw();
40 const Vector2& velo = e->velocityRaw();
41
42 Vector2 acc(0,0);
43
44 float radius = 0;
45 const Ball* b = dynamic_cast<const Ball*>(e);
46 if( b != NULL )
47 radius = b->getRadius();
48
49
50 if(pos.y > 600-radius && velo.y > 0)
51 acc.y += 600-radius - pos.y;
52
53 if(pos.y < 0+radius && velo.y < 0)
54 acc.y += 0+radius - pos.y;
55
56 if(pos.x > 800-radius && velo.x > 0)
57 acc.x += 800-radius - pos.x;
58
59 if(pos.x < 0+radius && velo.x < 0)
60 acc.x += 0+radius - pos.x;
61
62 return acc;
63}
64
2c18685d
PG
65Vector2 Screen::velocityDelta(const PhysicsEntity* e, float time_step) const
66{
67 const Vector2& pos = e->positionRaw();
68 const Vector2& velo = e->velocityRaw();
69
70 Vector2 acc(0,0);
71
d69c6a21 72 float CoR = e->CoR;
094a13b8
PG
73 float radius = 0;
74 const Ball* b = dynamic_cast<const Ball*>(e);
75 if( b != NULL )
76 radius = b->getRadius();
77
78
79 if(pos.y > 600-radius && velo.y > 0)
d69c6a21 80 acc.y += velo.y * -(1 + CoR);
2c18685d 81
094a13b8 82 if(pos.y < 0+radius && velo.y < 0)
d69c6a21 83 acc.y += velo.y * -(1 + CoR);
2c18685d 84
094a13b8 85 if(pos.x > 800-radius && velo.x > 0)
d69c6a21 86 acc.x += velo.x * -(1 + CoR);
2c18685d 87
094a13b8 88 if(pos.x < 0+radius && velo.x < 0)
d69c6a21 89 acc.x += velo.x * -(1 + CoR);
2c18685d
PG
90
91 return acc;
92}