static void DetatchComplete(void *data) { log_info("detatch complete"); sim_spacecraft_t *sc = (sim_spacecraft_t*)data; sc->detatchPossible = false; // Do not reenable, must be false after last stage detatched sc->detatchComplete = true; sim_stage_t *stage = sc->stages.elems[MERC_CAPSULE]; sim_engine_disable(ARRAY_ELEM(stage->engines, THR_POSI)); sim_stage_arm_engines(stage); sim_engine_disarm(ARRAY_ELEM(stage->engines, THR_POSI)); }
void sim_init(void) { pl_init(); sim_spacecraft_control_init(); // Set log level, need to do that here const char *levStr = NULL; config_get_str_def("openorbit/sys/log-level", &levStr, "info"); log_set_level(log_get_lev_from_str(levStr)); // Load and run initialisation script scripting_init(); if (!scripting_run_file("script/init.py")) { log_fatal("script/init.py missing"); } sim_init_graphics(); float freq; config_get_float_def("openorbit/sim/freq", &freq, 20.0); // Read in Hz gSIM_state.stepSize = 1.0 / freq; // Period in s // Setup IO-tables, must be done after joystick system has been initialised io_init(); gSIM_state.world = sim_load_world(sim_get_scene(), "data/solsystem.hrml"); pl_time_set(sim_time_get_jd()); sim_spacecraft_t *sc = sim_new_spacecraft("Mercury", "Mercury I"); sim_spacecraft_set_sys_and_coords(sc, "Earth", 0.0 /*longitude*/, 0.0 /*latitude*/, 250.0e3 /*altitude*/); sim_set_spacecraft(sc); sg_camera_t *cam = sg_scene_get_cam(sc->scene); sim_stage_t *stage = ARRAY_ELEM(sc->stages, 1); sg_camera_track_object(cam, stage->sgobj); sg_camera_follow_object(cam, stage->sgobj); sg_camera_set_follow_offset(cam, vd3_set(0.0, 0.0, -150.0e9)); simMfdInitAll(sim_get_main_viewport()); sim_init_plugins(); if (!scripting_run_file("script/postinit.py")) { log_fatal("script/postinit.py missing"); } sim_setup_menus(&gSIM_state); }
static void MainEngineToggle(sim_spacecraft_t *sc) { switch (sc->detatchSequence) { case MERC_REDSTONE: { sim_stage_t *redstone = sc->stages.elems[MERC_REDSTONE]; sim_engine_t *eng = ARRAY_ELEM(redstone->engines, THR_ROCKETDYNE); if (eng->state == SIM_ARMED) sim_engine_fire(eng); else if (eng->state == SIM_BURNING) sim_engine_disable(eng); break; } case MERC_CAPSULE: { sim_stage_t *capsule = sc->stages.elems[MERC_CAPSULE]; sim_engine_t *eng = ARRAY_ELEM(capsule->engines, THR_RETRO_0); (void)eng; break; } default: assert(0 && "invalid case"); } }
static void DetatchStage(sim_spacecraft_t *sc) { log_info("detatch commanded"); sc->detatchPossible = false; if (sc->detatchSequence == MERC_REDSTONE) { log_info("detatching redstone"); sim_stage_t *redstone = sc->stages.elems[MERC_REDSTONE]; sim_stage_t *capsule = sc->stages.elems[MERC_CAPSULE]; sim_stage_disable_engines(redstone); sim_stage_lock_engines(redstone); sim_spaccraft_detatch_stage(sc, redstone); sim_engine_arm(ARRAY_ELEM(capsule->engines, THR_POSI)); sim_engine_fire(ARRAY_ELEM(capsule->engines, THR_POSI)); sc->detatchComplete = false; sim_event_enqueue_relative_s(1.0, DetatchComplete, sc); } }
void sgDrawOverlays(SGscenegraph *sg) { SG_CHECK_ERROR; glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho(0.0, sgRenderInfo.w, 0.0, sgRenderInfo.h, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glPushAttrib(GL_ENABLE_BIT); glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glDisable(GL_CULL_FACE); for (size_t i = 0 ; i < sg->overlays.length ; i ++) { SGoverlay *overlay = ARRAY_ELEM(sg->overlays, i); if (overlay->enabled) { glUseProgram(0); // No shader for now // Bind the fbo texture so that the mfd rendering ends up in the texture glBindFramebuffer(GL_FRAMEBUFFER, overlay->fbo); glPushAttrib(GL_VIEWPORT_BIT); glViewport(0,0, overlay->w, overlay->h); ooLogTrace("draw overlay %d", i); // Here we draw the overlay into a texture overlay->draw(overlay); glPopAttrib(); // Re-attach the real framebuffer as rendering target, and draw the // texture using a quad. glUseProgram(sg->overlay_shader); glBindFramebuffer(GL_FRAMEBUFFER, 0); SG_CHECK_ERROR; // Set shader arguments GLfloat modelview[16], projection[16]; glGetFloatv(GL_MODELVIEW_MATRIX , modelview); glGetFloatv(GL_PROJECTION_MATRIX , projection); glUniformMatrix4fv(sg->modelview_id, 1, GL_FALSE, modelview); glUniformMatrix4fv(sg->projection_id, 1, GL_FALSE, projection); glEnable(GL_TEXTURE_2D); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, overlay->tex); glUniform1i(sg->tex_id, 0); GLint shaderIsValid; glValidateProgram(sg->overlay_shader); glGetProgramiv(sg->overlay_shader, GL_VALIDATE_STATUS, &shaderIsValid); assert(shaderIsValid); SG_CHECK_ERROR; glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBegin(GL_QUADS); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f (overlay->x, overlay->y, 0.0); glTexCoord2f(0.0f, 1.0f); glVertex3f(overlay->x, overlay->y + overlay->h, 0.0); glTexCoord2f(1.0, 1.0); glVertex3f(overlay->x + overlay->w, overlay->y + overlay->h, 0.0); glTexCoord2f(1.0f, 0.0f); glVertex3f(overlay->x + overlay->w, overlay->y, 0.0); glEnd(); SG_CHECK_ERROR; glUseProgram(0); } } glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glPopAttrib(); SG_CHECK_ERROR; }
static void AxisUpdate(sim_spacecraft_t *sc) { // TODO: Replace IO-system queries with sim variable lookups. // This is important in order to allow for multiplexed axis commands, // in turn enabling autopilots and network control. sim_axises_t axises; sim_get_axises(&axises); switch (sc->detatchSequence) { case MERC_REDSTONE: { sim_stage_t *redstone = sc->stages.elems[MERC_REDSTONE]; sim_engine_t *eng = ARRAY_ELEM(redstone->engines, THR_ROCKETDYNE); sim_engine_set_throttle(eng, SIM_VAL(axises.orbital)); break; } case MERC_CAPSULE: { if (!sc->detatchComplete) break; sim_stage_t *capsule = sc->stages.elems[MERC_CAPSULE]; sim_engine_set_throttle(ARRAY_ELEM(capsule->engines, THR_ROLL_0), SIM_VAL(axises.roll)); sim_engine_fire(ARRAY_ELEM(capsule->engines, THR_ROLL_0)); sim_engine_set_throttle(ARRAY_ELEM(capsule->engines, THR_ROLL_1), -SIM_VAL(axises.roll)); sim_engine_fire(ARRAY_ELEM(capsule->engines, THR_ROLL_1)); sim_engine_set_throttle(ARRAY_ELEM(capsule->engines, THR_PITCH_0), SIM_VAL(axises.pitch)); sim_engine_fire(ARRAY_ELEM(capsule->engines, THR_PITCH_0)); sim_engine_set_throttle(ARRAY_ELEM(capsule->engines, THR_PITCH_1), -SIM_VAL(axises.pitch)); sim_engine_fire(ARRAY_ELEM(capsule->engines, THR_PITCH_1)); sim_engine_set_throttle(ARRAY_ELEM(capsule->engines, THR_YAW_0), SIM_VAL(axises.yaw)); sim_engine_fire(ARRAY_ELEM(capsule->engines, THR_YAW_0)); sim_engine_set_throttle(ARRAY_ELEM(capsule->engines, THR_YAW_1), -SIM_VAL(axises.yaw)); sim_engine_fire(ARRAY_ELEM(capsule->engines, THR_YAW_1)); break; } default: assert(0 && "invalid case"); } }