Skip to content

Commit

Permalink
past orbits
Browse files Browse the repository at this point in the history
  • Loading branch information
hannorein committed Jan 30, 2024
1 parent 25104b4 commit 5427f5b
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 32 deletions.
2 changes: 1 addition & 1 deletion examples/shearing_sheet/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export OPENGL=1# Set this to 1 to enable OpenGL
export OPENGL=0# Set this to 1 to enable OpenGL
export SERVER=1# Set this to 1 to enable the visualization web server
include ../../src/Makefile.defs

Expand Down
2 changes: 1 addition & 1 deletion examples/solar_system/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export OPENGL=0# Set this to 1 to enable OpenGL
export OPENGL=1# Set this to 1 to enable OpenGL
export SERVER=1# Set this to 1 to enable the visualization web server
include ../../src/Makefile.defs

Expand Down
102 changes: 72 additions & 30 deletions src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,10 @@ void reb_render_frame(void* p){
glBufferData(GL_ARRAY_BUFFER, data->past_N*N_real*sizeof(struct reb_vec4d_opengl), NULL, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, data->particle_buffer_current);
glBufferData(GL_ARRAY_BUFFER, N_real*sizeof(struct reb_vec4d_opengl), NULL, GL_STATIC_DRAW);

glBindBuffer(GL_ARRAY_BUFFER, data->orbit_buffer);
glBufferData(GL_ARRAY_BUFFER, data->past_N*N_real*sizeof(struct reb_orbit_opengl), NULL, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, data->orbit_buffer_current);
glBufferData(GL_ARRAY_BUFFER, N_real*sizeof(struct reb_orbit_opengl), NULL, GL_STATIC_DRAW);

data->N_allocated = N_real;
Expand Down Expand Up @@ -635,8 +638,11 @@ void reb_render_frame(void* p){
glBindBuffer(GL_ARRAY_BUFFER, data->particle_buffer_current);
glBufferSubData(GL_ARRAY_BUFFER, 0, N_real*sizeof(struct reb_vec4d_opengl), data->particle_data);
}

glBindBuffer(GL_ARRAY_BUFFER, data->orbit_buffer);
glBufferSubData(GL_ARRAY_BUFFER, data->past_current_index*(N_real-1)*sizeof(struct reb_orbit_opengl), (N_real-1)*sizeof(struct reb_orbit_opengl), data->orbit_data);
if (data->wire){
glBindBuffer(GL_ARRAY_BUFFER, data->orbit_buffer);
glBindBuffer(GL_ARRAY_BUFFER, data->orbit_buffer_current);
glBufferSubData(GL_ARRAY_BUFFER, 0, (N_real-1)*sizeof(struct reb_orbit_opengl), data->orbit_data);
}
}
Expand Down Expand Up @@ -700,7 +706,6 @@ void reb_render_frame(void* p){
glUniform1i(data->point_shader_past_N_location, data->past_N_allocated);
int current_vertex = (data->past_current_index-1+data->past_N_allocated)%data->past_N_allocated;
if (data->past==1){
// History
glUniform4f(data->point_shader_color_location, 1.,1.,1.,0.8);
glUniform1i(data->point_shader_N_real_location, N_real);
glUniform1i(data->point_shader_current_vertex_location, current_vertex);
Expand All @@ -715,9 +720,14 @@ void reb_render_frame(void* p){
if (data->wire==1){
// Orbits
glUseProgram(data->orbit_shader_program);
glBindVertexArray(data->orbit_shader_particle_vao);
glUniformMatrix4fv(data->orbit_shader_mvp_location, 1, GL_TRUE, (GLfloat*) tmp2);
reb_glDrawArraysInstanced(GL_LINE_STRIP, 0, data->orbit_shader_vertex_count, N_real-1);
if (data->past==1){
glBindVertexArray(data->orbit_shader_particle_vao);
reb_glDrawArraysInstanced(GL_LINE_STRIP, 0, data->orbit_shader_vertex_count, data->past_N_allocated*(N_real-1));
}else{
glBindVertexArray(data->orbit_shader_particle_vao_current);
reb_glDrawArraysInstanced(GL_LINE_STRIP, 0, data->orbit_shader_vertex_count, N_real-1);
}
glBindVertexArray(0);
}
}
Expand Down Expand Up @@ -1392,19 +1402,7 @@ void reb_display_init(struct reb_simulation * const r){
data->orbit_shader_mvp_location = glGetUniformLocation(data->orbit_shader_program, "mvp");

// Orbit data
glUseProgram(data->orbit_shader_program);
glGenVertexArrays(1, &data->orbit_shader_particle_vao);
glBindVertexArray(data->orbit_shader_particle_vao);
GLuint olintwopip = glGetAttribLocation(data->orbit_shader_program,"lintwopi");
glEnableVertexAttribArray(olintwopip);
GLuint ofocusp = glGetAttribLocation(data->orbit_shader_program,"focus");
glEnableVertexAttribArray(ofocusp);
GLuint oaefp = glGetAttribLocation(data->orbit_shader_program,"aef");
glEnableVertexAttribArray(oaefp);
GLuint oomegaOmegaincp = glGetAttribLocation(data->orbit_shader_program,"omegaOmegainc");
glEnableVertexAttribArray(oomegaOmegaincp);

data->orbit_shader_vertex_count = 500;
data->orbit_shader_vertex_count = 500; // higher number = smoother orbits
float* lin_data = malloc(sizeof(float)*data->orbit_shader_vertex_count);
for(int i=0;i<data->orbit_shader_vertex_count;i++){
lin_data[i] = (float)i/(float)(data->orbit_shader_vertex_count-1)*2.*M_PI;
Expand All @@ -1414,21 +1412,65 @@ void reb_display_init(struct reb_simulation * const r){
glBindBuffer(GL_ARRAY_BUFFER, orbit_vertex_buffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*data->orbit_shader_vertex_count, lin_data, GL_STATIC_DRAW);
free(lin_data);
glVertexAttribPointer(olintwopip, 1, GL_FLOAT, GL_FALSE, 0, NULL);

// Generate two orbit vao
glUseProgram(data->orbit_shader_program);
GLuint olintwopip = glGetAttribLocation(data->orbit_shader_program,"lintwopi");
GLuint ofocusp = glGetAttribLocation(data->orbit_shader_program,"focus");
GLuint oaefp = glGetAttribLocation(data->orbit_shader_program,"aef");
GLuint oomegaOmegaincp = glGetAttribLocation(data->orbit_shader_program,"omegaOmegainc");

glGenBuffers(1, &data->orbit_buffer);
glBindBuffer(GL_ARRAY_BUFFER, data->orbit_buffer);
glVertexAttribPointer(ofocusp, 3, GL_FLOAT, GL_FALSE, sizeof(float)*9, NULL);
glVertexAttribPointer(oaefp, 3, GL_FLOAT, GL_FALSE, sizeof(float)*9, (void*)(sizeof(float)*3));
glVertexAttribPointer(oomegaOmegaincp, 3, GL_FLOAT, GL_FALSE, sizeof(float)*9, (void*)(sizeof(float)*6));

GLuint divisor = 0;
reb_glVertexAttribDivisor(olintwopip, divisor);
reb_glVertexAttribDivisor(data->orbit_shader_mvp_location, 0);
reb_glVertexAttribDivisor(ofocusp, 1);
reb_glVertexAttribDivisor(oaefp, 1);
reb_glVertexAttribDivisor(oomegaOmegaincp, 1);
{ // Current
glGenVertexArrays(1, &data->orbit_shader_particle_vao_current);
glBindVertexArray(data->orbit_shader_particle_vao_current);
glBindBuffer(GL_ARRAY_BUFFER, orbit_vertex_buffer);
glEnableVertexAttribArray(olintwopip);
glEnableVertexAttribArray(ofocusp);
glEnableVertexAttribArray(oaefp);
glEnableVertexAttribArray(oomegaOmegaincp);

glVertexAttribPointer(olintwopip, 1, GL_FLOAT, GL_FALSE, 0, NULL);


glGenBuffers(1, &data->orbit_buffer_current);
glBindBuffer(GL_ARRAY_BUFFER, data->orbit_buffer_current);
glVertexAttribPointer(ofocusp, 3, GL_FLOAT, GL_FALSE, sizeof(float)*9, NULL);
glVertexAttribPointer(oaefp, 3, GL_FLOAT, GL_FALSE, sizeof(float)*9, (void*)(sizeof(float)*3));
glVertexAttribPointer(oomegaOmegaincp, 3, GL_FLOAT, GL_FALSE, sizeof(float)*9, (void*)(sizeof(float)*6));

GLuint divisor = 0;
reb_glVertexAttribDivisor(olintwopip, divisor);
reb_glVertexAttribDivisor(data->orbit_shader_mvp_location, 0);
reb_glVertexAttribDivisor(ofocusp, 1);
reb_glVertexAttribDivisor(oaefp, 1);
reb_glVertexAttribDivisor(oomegaOmegaincp, 1);
}

{ // Past
glGenVertexArrays(1, &data->orbit_shader_particle_vao);
glBindVertexArray(data->orbit_shader_particle_vao);
glBindBuffer(GL_ARRAY_BUFFER, orbit_vertex_buffer);
glEnableVertexAttribArray(olintwopip);
glEnableVertexAttribArray(ofocusp);
glEnableVertexAttribArray(oaefp);
glEnableVertexAttribArray(oomegaOmegaincp);

glVertexAttribPointer(olintwopip, 1, GL_FLOAT, GL_FALSE, 0, NULL);


glGenBuffers(1, &data->orbit_buffer);
glBindBuffer(GL_ARRAY_BUFFER, data->orbit_buffer);
glVertexAttribPointer(ofocusp, 3, GL_FLOAT, GL_FALSE, sizeof(float)*9, NULL);
glVertexAttribPointer(oaefp, 3, GL_FLOAT, GL_FALSE, sizeof(float)*9, (void*)(sizeof(float)*3));
glVertexAttribPointer(oomegaOmegaincp, 3, GL_FLOAT, GL_FALSE, sizeof(float)*9, (void*)(sizeof(float)*6));

GLuint divisor = 0;
reb_glVertexAttribDivisor(olintwopip, divisor);
reb_glVertexAttribDivisor(data->orbit_shader_mvp_location, 0);
reb_glVertexAttribDivisor(ofocusp, 1);
reb_glVertexAttribDivisor(oaefp, 1);
reb_glVertexAttribDivisor(oomegaOmegaincp, 1);
}

glBindVertexArray(0);

Expand Down
2 changes: 2 additions & 0 deletions src/rebound.h
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,7 @@ struct reb_display_data {
unsigned int sphere_shader_particle_vao;
unsigned int orbit_shader_mvp_location;
unsigned int orbit_shader_program;
unsigned int orbit_shader_particle_vao_current;
unsigned int orbit_shader_particle_vao;
unsigned int orbit_shader_vertex_count;
uint64_t past_last_steps_done;
Expand All @@ -1163,6 +1164,7 @@ struct reb_display_data {
unsigned int particle_buffer;
unsigned int particle_buffer_current;
unsigned int orbit_buffer;
unsigned int orbit_buffer_current;
void* window;

};
Expand Down

0 comments on commit 5427f5b

Please sign in to comment.