Newer
Older
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);
}
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;
}
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, m_axis.size() * sizeof(GLfloat), &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);
coord_axis(_OX);
coord_axis(_OY);
coord_axis(_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) {
//
buff = { float(sat.getDCS().at(0, 0))*0.00003f, float(sat.getDCS().at(1, 0)) * 0.00003f, float(sat.getDCS().at(2, 0)) * 0.00003f,0.0f, 0.0f, 1.0f };
//
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());
//std::cout << "angle = " << cos(omega) << " sin = " << sin(omega) << std::endl;
}
}
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;
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(GLfloat), &DCS.front(), GL_STREAM_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
glEnableVertexAttribArray(1);
glDrawArrays(GL_LINE_STRIP, 0, DCS.size() / 6);
i++;
glBindVertexArray(0);
glDeleteBuffers(1, &VBO);
glDeleteVertexArrays(1, &VAO);
std::cout << i << std::endl;