|
|
|
|
@ -13,11 +13,15 @@
|
|
|
|
|
#include "orbits.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const double SCALING = 0.001; |
|
|
|
|
static bool g_running = false; |
|
|
|
|
static system_2body g_sys = {0}; |
|
|
|
|
static MemoryArena* g_arena = nullptr; |
|
|
|
|
|
|
|
|
|
const double SCALING = 0.001; |
|
|
|
|
const vec4 g_light_direction = vec4(-2, 1, 3, 1); |
|
|
|
|
const vec4 g_light_color = vec4(0.5, 0.5, 0.5, 1); |
|
|
|
|
const uvec4 g_light_intensities = uvec4(1, 0, 0, 0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
|
initCamera(RenderState* rs, vec3 cam_pos, vec3 cam_focus, vec3 cam_up) |
|
|
|
|
@ -28,6 +32,22 @@ initCamera(RenderState* rs, vec3 cam_pos, vec3 cam_focus, vec3 cam_up)
|
|
|
|
|
assert(xform_ubo != nullptr); |
|
|
|
|
updateGLBuffer(xform_ubo, &rs->camera->xforms); |
|
|
|
|
} |
|
|
|
|
void |
|
|
|
|
initLights(RenderState* rs) |
|
|
|
|
{ |
|
|
|
|
LightsBuffer* lb = rs->lights_buf; |
|
|
|
|
u32 idx = 0; |
|
|
|
|
|
|
|
|
|
// NOTE: add a directional light
|
|
|
|
|
idx = (*lb->active_d_lights)++; |
|
|
|
|
lb->dl_directions[idx] = g_light_direction; |
|
|
|
|
lb->dl_colors[idx] = g_light_color; |
|
|
|
|
lb->dl_intensities[idx] = g_light_intensities; |
|
|
|
|
|
|
|
|
|
GLBuffer* lights_ubo = getUBOByName(rs->gl_ctx, "lights"); |
|
|
|
|
assert(lights_ubo != nullptr); |
|
|
|
|
updateGLBuffer(lights_ubo, lb->buffer); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Entity* |
|
|
|
|
initEllipseEntity(RenderState* rs, |
|
|
|
|
@ -59,32 +79,22 @@ initEllipseEntity(RenderState* rs,
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Entity* |
|
|
|
|
initPlanetEntity(RenderState* rs) |
|
|
|
|
initPlanetEntity(RenderState* rs, double r) |
|
|
|
|
{ |
|
|
|
|
u32 num_vertices = 24; |
|
|
|
|
vec3 vertex_color = vec3(255, 255, 0); |
|
|
|
|
float radius = 3; |
|
|
|
|
|
|
|
|
|
Mesh* m = meshInit(rs->rg_arena, num_vertices, num_vertices, false, true); |
|
|
|
|
float angle = (float) M_PI * 2 / num_vertices; |
|
|
|
|
float r = radius / SCALING; |
|
|
|
|
|
|
|
|
|
for (uint i = 0; i < num_vertices; i++) { |
|
|
|
|
m->vertices[i] = glm::vec3(cos(i * angle) * r, sin(i * angle) * r, 0); |
|
|
|
|
m->colors[i] = vertex_color; |
|
|
|
|
m->indices[i] = i; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Model* mdl = modelInitManual(rs->rg_arena, 1, m); |
|
|
|
|
RenderGroup* rg = getRenderGroupByName(rs, "manual mesh group"); |
|
|
|
|
Entity* e = getFreeEntity(rg); |
|
|
|
|
initEntity(e, rs->gl_ctx, |
|
|
|
|
ShaderProgram* shader_lit = getShaderByName("full_lighting", rs->gl_ctx); |
|
|
|
|
RenderGroup* rg_full = getFreeRenderGroup(rs); |
|
|
|
|
initRenderGroup(rg_full, rs->rg_arena, shader_lit, 256, "lit group"); |
|
|
|
|
Model* icosphere = getModelByPath(&rs->assets, "../data/icosphere.gltf"); |
|
|
|
|
Entity* e = getFreeEntity(rg_full); |
|
|
|
|
assert(icosphere && e); |
|
|
|
|
initEntity(e, |
|
|
|
|
rs->gl_ctx, |
|
|
|
|
rs->rg_arena, |
|
|
|
|
mdl, |
|
|
|
|
rg->shader->num_vertex_attribs, |
|
|
|
|
rg->shader->attrib_mappings, |
|
|
|
|
"planet 01", |
|
|
|
|
GL_LINE_LOOP); |
|
|
|
|
icosphere, |
|
|
|
|
shader_lit->num_vertex_attribs, |
|
|
|
|
shader_lit->attrib_mappings, |
|
|
|
|
"grav body 01"); |
|
|
|
|
scaleEntity(e, r); |
|
|
|
|
|
|
|
|
|
return e; |
|
|
|
|
} |
|
|
|
|
@ -123,6 +133,7 @@ void
|
|
|
|
|
loadScene(RenderState* rs) |
|
|
|
|
{ |
|
|
|
|
initCamera(rs, vec3(0, -75 / SCALING, 0), vec3(0, 0, 0), vec3(0,0,1)); |
|
|
|
|
initLights(rs); |
|
|
|
|
|
|
|
|
|
double a = 26564.5; // NOTE: semi-major axis in km
|
|
|
|
|
double e = 0.7411; // NOTE: eccentricity
|
|
|
|
|
@ -141,8 +152,7 @@ loadScene(RenderState* rs)
|
|
|
|
|
setEntityPosition(ellipse_entity, vec3(0, 0, 0)); |
|
|
|
|
rotateEntity(ellipse_entity, vec3(1, 0, 0), (float) M_PI / 2); |
|
|
|
|
|
|
|
|
|
Entity* planet_entity = initPlanetEntity(rs); |
|
|
|
|
rotateEntity(planet_entity, vec3(1, 0, 0), (float) M_PI / 2); |
|
|
|
|
initPlanetEntity(rs, r); |
|
|
|
|
|
|
|
|
|
Entity* satellite_entity = initSatelliteEntity(rs); |
|
|
|
|
scaleEntity(satellite_entity, 1 / SCALING); |
|
|
|
|
|