feat: circular orbit
This commit is contained in:
		
							parent
							
								
									16bc542a69
								
							
						
					
					
						commit
						ad51be518b
					
				@ -7,9 +7,9 @@
 | 
			
		||||
 | 
			
		||||
#include "gfx.hpp"
 | 
			
		||||
 | 
			
		||||
Icosphere::Icosphere(float radius, int subdivisions, GLuint shaderProgram, glm::vec3 position) :
 | 
			
		||||
Icosphere::Icosphere(float radius, int subdivisions, GLuint shaderProgram) :
 | 
			
		||||
    _shaderProgram(shaderProgram),
 | 
			
		||||
    _position(position)
 | 
			
		||||
    _position({})
 | 
			
		||||
{
 | 
			
		||||
    generateVertices(radius, subdivisions);
 | 
			
		||||
 | 
			
		||||
@ -157,6 +157,11 @@ void Icosphere::render()
 | 
			
		||||
	glDrawElements(GL_TRIANGLES, _indices.size(), GL_UNSIGNED_INT, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Icosphere::setPosition(glm::vec3 position)
 | 
			
		||||
{
 | 
			
		||||
    _position = position;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Icosphere::~Icosphere()
 | 
			
		||||
{
 | 
			
		||||
    glDeleteVertexArrays(1, &_vao);
 | 
			
		||||
 | 
			
		||||
@ -10,9 +10,11 @@
 | 
			
		||||
class Icosphere
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    Icosphere(float radius, int subdivisions, GLuint shaderProgram, glm::vec3 position);
 | 
			
		||||
    Icosphere(float radius, int subdivisions, GLuint shaderProgram);
 | 
			
		||||
	void render();
 | 
			
		||||
 | 
			
		||||
    void setPosition(glm::vec3 position);
 | 
			
		||||
 | 
			
		||||
	~Icosphere();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										10
									
								
								src/main.cpp
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								src/main.cpp
									
									
									
									
									
								
							@ -51,8 +51,8 @@ int main()
 | 
			
		||||
    GLuint litProgram = compileShaderProgram("./frag_lit.glsl");
 | 
			
		||||
    GLuint unlitProgram = compileShaderProgram("./frag_unlit.glsl");
 | 
			
		||||
 | 
			
		||||
    Icosphere planet(0.4, 2, litProgram, glm::vec3(0.0, 0.0, 0.0));
 | 
			
		||||
    Icosphere orbiter(0.1, 2, litProgram, glm::vec3(0.6, 0.0, 0.0));
 | 
			
		||||
    Icosphere planet(0.4, 2, litProgram);
 | 
			
		||||
    Icosphere orbiter(0.1, 2, litProgram);
 | 
			
		||||
    Orbit orbit(100);
 | 
			
		||||
 | 
			
		||||
    // Main loop
 | 
			
		||||
@ -62,6 +62,12 @@ int main()
 | 
			
		||||
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 | 
			
		||||
 | 
			
		||||
        float time = glfwGetTime();
 | 
			
		||||
        float r = .7;
 | 
			
		||||
        float x = cos(time);
 | 
			
		||||
        float y = sin(time);
 | 
			
		||||
        glm::vec3 pos(x, 0, y);
 | 
			
		||||
        pos *= r;
 | 
			
		||||
        orbiter.setPosition(pos);
 | 
			
		||||
 | 
			
		||||
        // Render lit objects
 | 
			
		||||
        glUseProgram(litProgram);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user