This repository was archived by the owner on Oct 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathufo.cpp
More file actions
74 lines (62 loc) · 1.96 KB
/
ufo.cpp
File metadata and controls
74 lines (62 loc) · 1.96 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
// Created by lepet on 8/1/2018.
//
#include <GL/glut.h>
#include <objects/ufo.h>
#include <system/engine.h>
class ufo_body : public object {
private:
GLfloat spin_angle;
GLfloat spin_velocity;
public:
explicit ufo_body(GLfloat spin_angle);
void update() override;
};
class ufo_cockpit : public object {
public:
ufo_cockpit();
};
ufo_body::ufo_body(GLfloat spin_angle) : spin_angle(spin_angle), spin_velocity(12.0) {
auto& engine = engine::get_instance();
mesh = engine.get_model("ufo.body");
}
void ufo_body::update() {
object::update();
spin_angle += spin_velocity;
while (spin_angle > 360)
spin_angle -= 360;
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(spin_angle, 0.0, 1.0, 0.0);
glGetFloatv(GL_MODELVIEW_MATRIX, reinterpret_cast<GLfloat*>(&transform));
}
ufo_cockpit::ufo_cockpit() {
auto& engine = engine::get_instance();
mesh = engine.get_model("ufo.cockpit");
}
ufo::ufo(const glm::vec3& offset,
GLfloat precession_angle,
GLfloat spin_angle) : offset(offset),
pitch(4.0f),
precession_angle(precession_angle),
precession_velocity(-2.0f) {
add_child(std::make_unique<ufo_body>(spin_angle));
add_child(std::make_unique<ufo_cockpit>());
}
void ufo::update() {
object::update();
precession_angle += precession_velocity;
while (precession_angle < -360)
precession_angle += 360;
// Calculate precession of the ufo.
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(offset[0], offset[1], offset[2]);
glScalef(0.1, 0.1, 0.1);
// First, rotate the axis around the y axis.
glRotatef(precession_angle, 0.0, 1.0, 0.0);
// Next, rotate the axis to an angle of pitch.
glRotatef(pitch, 1.0, 0.0, 0.0);
// Finally, save the matrix to variable.
glGetFloatv(GL_MODELVIEW_MATRIX, reinterpret_cast<GLfloat*>(&transform));
}