-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasteroid.cpp
More file actions
52 lines (42 loc) · 1.15 KB
/
asteroid.cpp
File metadata and controls
52 lines (42 loc) · 1.15 KB
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
#include "asteroid.h"
#include <iostream>
Asteroid::Asteroid(Radius r)
{
active = GL_FALSE;
radius = r;
}
void Asteroid::generate_asteroid_vertices(int num_vertices, Radius radius)
{
GLfloat angle, x, y;
for(int i=0; i != num_vertices; i++)
{
angle = 2*M_PI/num_vertices * i;
x = static_cast<GLfloat>(radius)/1000 * cos(angle);
y = static_cast<GLfloat>(radius)/1000 * sin(angle);
if(radius == Radius::large)
{
large_asteroid_vertices.push_back(x);
large_asteroid_vertices.push_back(y);
}
else if(radius == Radius::medium)
{
medium_asteroid_vertices.push_back(x);
medium_asteroid_vertices.push_back(y);
}
else if(radius == Radius::small)
{
small_asteroid_vertices.push_back(x);
small_asteroid_vertices.push_back(y);
}
}
}
void Asteroid::move(GLfloat delta)
{
position.x += delta*cos(angle);
position.y += delta*sin(angle);
}
bool Asteroid::check_collision(glm::vec3 ship_position)
{
if(std::abs(position.x - ship_position.x) < static_cast<GLfloat>(radius)/1000 && std::abs(position.y - ship_position.y) < static_cast<GLfloat>(radius)/1000)
return true;
}