-
Notifications
You must be signed in to change notification settings - Fork 0
/
CannonBall.cpp
61 lines (51 loc) · 1.19 KB
/
CannonBall.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "CannonBall.h"
CannonBall::CannonBall(float startX, float startY, float velocity, float angle, float radius)
: curX(startX), curY(startY), angle(angle), radius(radius)
{
velocityX = (velocity * cos(angle));
velocityY = (velocity * sin(angle));
}
CannonBall::~CannonBall()
{
}
void CannonBall::draw(float resolution)
{
glPushMatrix();
glTranslatef(curX, curY, 0);
glColor4ub(0, 0, 0, 255);
glBegin(GL_POLYGON);
//draws a circle
for (int i = 0; i < 360; i++)
{
float x = DEG2RAD * i;
glVertex3f(cos(x) * radius, sin(x) * radius, 0);
}
glEnd();
glPopMatrix();
glPushMatrix();
//Refactor
//Remove Magic numbers
float stepSize = 0.005;
float xStep = 0;
float dist = 1;
int i = 0;
glColor3f(0, 0, 0);
glBegin(GL_LINE_STRIP);
while (dist > 0)
{
i++;
xStep += stepSize;
dist = (velocityY)*xStep + 0.5*GRAVITY*xStep*xStep + curY;
//Z value to hide behind water
glVertex3f(velocityX*xStep + curX, dist, -9);
}
glEnd();
glPopMatrix();
}
void CannonBall::idle(float changeTime)
{
//Update X and Y
curX += (velocityX * changeTime);
curY += (velocityY * changeTime);
velocityY += GRAVITY * changeTime;
}