Skip to content
Snippets Groups Projects
ComponentForModulation.cpp 4.03 KiB
Newer Older
#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);

}