// This is the entry point called by main(). void run_server() { assert(mongoose == NULL); srand((unsigned int)time(NULL)); init_oculus(); const char *options[] = { "listening_ports", "5578", "document_root", document_root, // Forbid everyone except localhost. "access_control_list", "-0.0.0.0/0,+127.0.0.0/8", // We have a lot of concurrent long-lived requests, so start a lot of // threads to make sure we can handle them all. "num_threads", "32", NULL }; struct mg_callbacks callbacks; memset(&callbacks, 0, sizeof(callbacks)); callbacks.begin_request = mongoose_begin_request_callback; mongoose = mg_start(&callbacks, NULL, options); if (!mongoose) { debug_log("Failed to start server."); exit(1); } usleep(0); if (!open_browser("http://localhost:5578/")) { debug_log("Failed to open browser."); } // Wait for an initial keep-alive connection to be established. while(keep_alives == 0) { usleep(1000 * 1000); } // Wait for all keep-alive connections to be closed. while(keep_alives > 0) { // NOTE: If you are debugging using GDB or XCode, you may encounter signal // SIGPIPE on this line. SIGPIPE is harmless and you should configure your // debugger to ignore it. For instructions see here: // http://stackoverflow.com/questions/10431579/permanently-configuring-lldb-in-xcode-4-3-2-not-to-stop-on-signals // http://ricochen.wordpress.com/2011/07/14/debugging-with-gdb-a-couple-of-notes/ usleep(1000 * 100); } mg_stop(mongoose); mongoose = NULL; }
int main(int argc, char** argv) { // initialize guacamole gua::init(argc, argv); gua::ShadingModelDatabase::load_shading_models_from("data/materials/"); gua::MaterialDatabase::load_materials_from("data/materials/"); // initialize Oculus SDK OVR::SensorFusion* oculus_sensor = init_oculus(); if (!oculus_sensor) return 1; // no oculus sensor found // setup scene gua::SceneGraph graph("main_scenegraph"); gua::TriMeshLoader loader; auto monkey_geometry(loader.create_geometry_from_file( "root_ape", geometry, "data/materials/Stones.gmd" )); auto root_monkey = graph.add_node("/", monkey_geometry); root_monkey->scale(0.5, 0.5, 0.5); // depth monkey cube car // 1 14.084 56 3.619.000 Vertices / 7 draw calls // 2 74.444 296 19.129.000 Vertices / 37 draw calls // 3 436.604 1.736 112.189.000 Vertices / 217 draw calls // 4 2.609.564 10.376 Vertices / 1.297 draw calls // 5 15.647.324 62.216 Vertices / 7.777 draw calls // 6 93.873.884 373.256 Vertices / 46.657 draw calls setup_scene(graph, root_monkey, 4); auto lights = add_lights(graph, 50); auto pos = graph.add_node<gua::node::TransformNode>("/", "pos"); pos->translate(0, 0, 2); auto nav = graph.add_node<gua::node::TransformNode>("/pos", "nav"); auto screen = graph.add_node<gua::node::ScreenNode>("/pos/nav", "screen_l"); screen->data.set_size(gua::math::vec2(0.08, 0.1)); screen->translate(-0.04, 0, -0.05f); screen = graph.add_node<gua::node::ScreenNode>("/pos/nav", "screen_r"); screen->data.set_size(gua::math::vec2(0.08, 0.1)); screen->translate(0.04, 0, -0.05f); auto eye = graph.add_node<gua::node::TransformNode>("/pos/nav", "eye_l"); eye->translate(-0.032, 0, 0); eye = graph.add_node<gua::node::TransformNode>("/pos/nav", "eye_r"); eye->translate(0.032, 0, 0); unsigned width = 1280/2; unsigned height = 800; auto pipe = new gua::Pipeline(); pipe->config.set_camera(gua::Camera("/pos/nav/eye_l", "/pos/nav/eye_r", "/pos/nav/screen_l", "/pos/nav/screen_r", "main_scenegraph")); pipe->config.set_left_resolution(gua::math::vec2ui(width, height)); pipe->config.set_right_resolution(gua::math::vec2ui(width, height)); pipe->config.set_enable_fps_display(true); pipe->config.set_enable_frustum_culling(true); pipe->config.set_enable_stereo(true); pipe->config.set_enable_ssao(true); pipe->config.set_ssao_intensity(2.f); pipe->config.set_enable_fxaa(true); pipe->config.set_enable_hdr(true); pipe->config.set_hdr_key(5.f); pipe->config.set_enable_bloom(true); pipe->config.set_bloom_radius(10.f); pipe->config.set_bloom_threshold(0.8f); pipe->config.set_bloom_intensity(0.8f); #if WIN32 auto oculus_window(new gua::OculusWindow("\\\\.\\DISPLAY1")); #else auto oculus_window(new gua::OculusWindow(":0.0")); #endif pipe->set_window(oculus_window); gua::Renderer renderer({ pipe }); gua::Timer timer; timer.start(); double time(0); float desired_frame_time(1.0 / 60.0); gua::events::MainLoop loop; // application loop gua::events::Ticker ticker(loop, desired_frame_time); ticker.on_tick.connect([&]() { double frame_time(timer.get_elapsed()); time += frame_time; timer.reset(); std::function<void (std::shared_ptr<gua::node::Node>, int)> rotate; rotate = [&](std::shared_ptr<gua::node::Node> node, int depth) { node->rotate(frame_time * (1+depth) * 0.5, 1, 1, 0); for (auto child: node->get_children()) { rotate(child, ++depth); } }; rotate(graph["/root_ape"], 1); for (int i = 0; i < lights.size(); ++i) { lights[i]->rotate( std::sin(time * (i * 0.1 + 0.5)) * frame_time * 2.5, 0, 1, 0); } graph["/root_ape"]->rotate(15 * frame_time, 0, 1, 0); //graph["/screen"]->rotate(20*frame_time, 0, 1, 0); nav->set_transform(get_oculus_transform(oculus_sensor)); renderer.queue_draw({&graph}); }); loop.start(); return 0; }