Skip to content

Commit

Permalink
orbits past
Browse files Browse the repository at this point in the history
  • Loading branch information
hannorein committed Jan 30, 2024
1 parent 5427f5b commit ffc9885
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
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=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
32 changes: 29 additions & 3 deletions src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,22 @@ static void reb_display_clear_particle_data(struct reb_display_data* data){
data->particle_data[i].z = n;
data->particle_data[i].r = n;
}
glBindBuffer(GL_ARRAY_BUFFER, data->particle_buffer);
for (int i=0; i<N_hist; i++){
glBufferSubData(GL_ARRAY_BUFFER, i*N_real*sizeof(struct reb_vec4d_opengl), N_real*sizeof(struct reb_vec4d_opengl), data->particle_data);
}
}
glBindBuffer(GL_ARRAY_BUFFER, data->particle_buffer);
for (int i=0; i<N_hist; i++){
glBufferSubData(GL_ARRAY_BUFFER, i*N_real*sizeof(struct reb_vec4d_opengl), N_real*sizeof(struct reb_vec4d_opengl), data->particle_data);
if (data->orbit_data){
float n = NAN;
for (int i=0; i<N_real; i++){
data->orbit_data[i].x = n; // enought to not render
data->orbit_data[i].y = n;
data->orbit_data[i].z = n;
}
glBindBuffer(GL_ARRAY_BUFFER, data->orbit_buffer);
for (int i=0; i<N_hist; i++){
glBufferSubData(GL_ARRAY_BUFFER, i*(N_real-1)*sizeof(struct reb_orbit_opengl), (N_real-1)*sizeof(struct reb_orbit_opengl), data->orbit_data);
}
}
}

Expand Down Expand Up @@ -721,11 +733,16 @@ void reb_render_frame(void* p){
// Orbits
glUseProgram(data->orbit_shader_program);
glUniformMatrix4fv(data->orbit_shader_mvp_location, 1, GL_TRUE, (GLfloat*) tmp2);
glUniform1i(data->orbit_shader_past_N_location, data->past_N_allocated);
if (data->past==1){
glBindVertexArray(data->orbit_shader_particle_vao);
glUniform1i(data->orbit_shader_N_real_location, N_real-1);
int current_vertex = (data->past_current_index-1+data->past_N_allocated)%data->past_N_allocated;
glUniform1i(data->orbit_shader_current_vertex_location, current_vertex);
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);
glUniform1i(data->orbit_shader_N_real_location, 0);
reb_glDrawArraysInstanced(GL_LINE_STRIP, 0, data->orbit_shader_vertex_count, N_real-1);
}
glBindVertexArray(0);
Expand Down Expand Up @@ -1357,6 +1374,9 @@ void reb_display_init(struct reb_simulation * const r){
"in vec3 aef;\n"
"in vec3 omegaOmegainc;\n"
"in float lintwopi;\n"
"uniform int current_vertex;\n"
"uniform int N_real;\n"
"uniform int past_N;\n"
"out float lin;\n"
"uniform mat4 mvp;\n"
"const float M_PI = 3.14159265359;\n"
Expand All @@ -1370,6 +1390,9 @@ void reb_display_init(struct reb_simulation * const r){
" f = 0.0001-theta_max+1.9998*lin*theta_max;\n"
" lin = sqrt(min(0.5,lin));\n"
" }\n"
" if (N_real != 0) {\n"
" lin = float( (gl_InstanceID/N_real -1 - current_vertex + 2*past_N)%past_N )/float(past_N);\n"
" }\n"
" float omega = omegaOmegainc.x;\n"
" float Omega = omegaOmegainc.y;\n"
" float inc = omegaOmegainc.z;\n"
Expand Down Expand Up @@ -1400,6 +1423,9 @@ void reb_display_init(struct reb_simulation * const r){

data->orbit_shader_program = loadShader(vertex_shader, fragment_shader);
data->orbit_shader_mvp_location = glGetUniformLocation(data->orbit_shader_program, "mvp");
data->orbit_shader_current_vertex_location = glGetUniformLocation(data->orbit_shader_program, "current_vertex");
data->orbit_shader_past_N_location = glGetUniformLocation(data->orbit_shader_program, "past_N");
data->orbit_shader_N_real_location = glGetUniformLocation(data->orbit_shader_program, "N_real");

// Orbit data
data->orbit_shader_vertex_count = 500; // higher number = smoother orbits
Expand Down
3 changes: 3 additions & 0 deletions src/rebound.h
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,9 @@ struct reb_display_data {
unsigned int sphere_shader_particle_vao_current;
unsigned int sphere_shader_particle_vao;
unsigned int orbit_shader_mvp_location;
unsigned int orbit_shader_current_vertex_location;
unsigned int orbit_shader_past_N_location;
unsigned int orbit_shader_N_real_location;
unsigned int orbit_shader_program;
unsigned int orbit_shader_particle_vao_current;
unsigned int orbit_shader_particle_vao;
Expand Down

0 comments on commit ffc9885

Please sign in to comment.