Newer
Older
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "ComponentForModulation.h"
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode)
{
std::cout << key << std::endl;
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
glfwSetWindowShouldClose(window, GL_TRUE);
}
void coord_axis(GLuint &VAO, axis draw_axis){
std::vector<GLfloat> m_axis; //{x, y, z, color_x, color, y, color_z}
switch (draw_axis)
{
case _OX: m_axis = { -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0 }; break;
case _OY: m_axis = { 0.0, -1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0 }; break;
case _OZ: m_axis = { 0.0, 0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0 }; break;
}
GLuint VBO;
glGenBuffers(1, &VBO);
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, m_axis.size() * sizeof(m_axis), &m_axis.front(), GL_STREAM_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
glEnableVertexAttribArray(1);
glDrawArrays(GL_LINE_STRIP, 0, m_axis.size() / 6);
glBindVertexArray(0);
glDeleteBuffers(1, &VBO);
}
void draw_coord_axis(GLuint &i_VAO)
{
coord_axis(i_VAO, _OX);
coord_axis(i_VAO, _OY);
coord_axis(i_VAO, _OZ);
}
int j = 0;
void modulation(Satellite& sat, double step_time, double end, std::vector<GLfloat>& DCS, std::vector<GLfloat>& DVS) {
if (step_time <= end) {
//
sat.integration_step(step_time);
std::cout << " j = " << j++;
GLfloat R = sat.getRadius();
GLfloat omega = sat.getOmega();
std::cout << " R = " << R << " u = " << omega << std::endl;
std::vector<GLfloat> buff; //
// ,
//buff = { float(sat.getDCS().at(0, 0)), float(sat.getDCS().at(1, 0)), float(sat.getDCS().at(2, 0)), 0.0f, 0.0f, 1.0f };
buff = {0.9f*omega/abs(omega), sin(omega), 0.0, 0.0, 0.0, 1.0};
//
DCS.insert(DCS.end(), buff.begin(), buff.end());
//// ,
//buff = { float(sat.getDVS().at(0, 0)), float(sat.getDVS().at(1, 0)), float(sat.getDVS().at(2, 0)), 0.0f, 0.0f, 1.0f };
////
//DVS.insert(DVS.end(), buff.begin(), buff.end());
}
}
void scaling(std::vector<GLfloat>& DS, float& main_max)
{
float max = main_max;
std::vector<GLfloat> buff = DS;
if (DS.size() == 6) {
if ((abs(DS.at(0)) > abs(DS.at(1))) && abs((DS.at(0)) > abs(DS.at(2)))) max = abs(DS.at(0));
else if ((abs(DS.at(1)) > abs(DS.at(2)))) max = abs(DS.at(1));
else max = abs(DS.at(2));
}
else {
int pos = DS.size() - 6;
if ((abs(DS.at(pos)) > max) && (abs(DS.at(pos)) > abs(DS.at(pos+1))) && abs((DS.at(pos)) > abs(DS.at(pos+2)))) max = abs(DS.at(pos));
else if ((abs(DS.at(pos+1)) > max) && (abs(DS.at(pos+1)) > abs(DS.at(pos+2)))) max = abs(DS.at(pos+1));
else if(abs(DS.at(pos + 2) > max)) max = abs(DS.at(pos+2));
}
if (max > main_max) main_max = max;
/*for (int i = 0; i < DS.size(); i = i + 3) {
buff.at(i) = DS.at(i) / max;
i++;
buff.at(i) = DS.at(i) / max;
i++;
buff.at(i) = DS.at(i) / max;
i++;
}*/
//return buff;
}
unsigned int i = 0;
void draw_modulation(std::vector<GLfloat>& DCS, std::vector<GLfloat>& DVS, GLfloat& max, Shader& _Shader) {
GLuint VBO, VAO;
glm::mat4 scale;
//scale = glm::scale(scale, glm::vec3(1E+15, 1E+15, 1));
GLuint scaleLoc = glGetUniformLocation(_Shader.Id, "scale");
glGenBuffers(1, &VBO);
glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
// glUniformMatrix4fv(scaleLoc, 1, GL_FALSE, glm::value_ptr(scale));
glBufferData(GL_ARRAY_BUFFER, DCS.size() * sizeof(DCS), &DCS.front(), GL_STREAM_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(DCS), (GLvoid*)0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(DCS), (GLvoid*)(3 * sizeof(GLfloat)));
glEnableVertexAttribArray(1);
glDrawArrays(GL_LINE_STRIP, 0, DCS.size() / 6);
i++;
glBindVertexArray(0);
glDeleteBuffers(1, &VBO);
}