-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbullet.cpp
60 lines (52 loc) · 1.29 KB
/
bullet.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
#include <GL/freeglut.h>
#include "bullet.h"
#include <cmath>
#include <iostream>
using namespace std;
Bullet::Bullet(GLfloat bulletRadius, GLfloat posX, GLfloat posY, GLfloat bulletTheta, GLfloat gunPosX, GLfloat gunPosY, GLfloat velTiro)
{
this->radius = bulletRadius;
this->gX = posX;
this->gY = posY;
this->gTheta = bulletTheta;
this->gunPosX = gunPosX;
this->gunPosY = gunPosY;
this->velTiro = velTiro;
}
void Bullet::drawBullet()
{
glPushMatrix();
glTranslatef(gX, gY, 0);
glRotatef(gTheta, 0, 0, 1);
glTranslatef(gunPosX, gunPosY, 0);
drawCircle(.75, 0, 0);
glPopMatrix();
}
void Bullet::drawCircle(GLfloat R, GLfloat G, GLfloat B)
{
glColor3f(R, G, B);
glBegin(GL_TRIANGLE_FAN);
for (int i = 0; i < 360; i++)
{
float rad = i*(M_PI/180.0);
glVertex2f(cos(rad)*(this->radius), sin(rad)*(this->radius));
}
glEnd();
}
void Bullet::updateBullet()
{
gX += velTiro*sin(gTheta*(M_PI/180.0));
gY -= velTiro*cos(gTheta*(M_PI/180.0));
}
GLfloat Bullet::getgX()
{
return (this->gX + this->gunPosX*sin(gTheta*(M_PI/180.0)));
}
GLfloat Bullet::getgY()
{
return (this->gY + this->gunPosY*cos(gTheta*(M_PI/180.0)));
}
GLfloat Bullet::getRadius()
{
return this->radius;
}