// Create the prism for Servo int Servo2D::createInitialPrism() { prism_ = requestNewPrism(getInitialPrismExtents()); if (!prism_) { ML_LOG(Error, "Servo2D Error creating default prism."); return 1; } return 0; }
lumin::Node* Servo2D::instanceScene(const SceneDescriptor& scene) { // Load resources. if (!prism_->loadResourceModel(scene.getResourceModelPath())) { ML_LOG(Info, "No resource model loaded"); } // Load a scene file. std::string editorObjectModelName; if (!prism_->loadObjectModel(scene.getSceneGraphPath(), editorObjectModelName)) { ML_LOG(Error, "Servo2D Failed to load object model"); abort(); return nullptr; } // Add scene to this prism. lumin::Node* newTree = prism_->createAll(editorObjectModelName); if (!prism_->getRootNode()->addChild(newTree)) { ML_LOG(Error, "Servo2D Failed to add newTree to the prism root node"); abort(); return nullptr; } return newTree; }
int main(int argc, char** argv) { const double x0 = 2.0, y0 = 0.0; const size_t nsteps = 1000; const double dt = 50.0/( (double) nsteps); const size_t nnodes = 3; const size_t niters = 1; const double nu = 5.0; const pfasst::quadrature::QuadratureType nodetype = pfasst::quadrature::QuadratureType::GaussLegendre; pfasst::init(argc, argv); ML_LOG(INFO, "Used timestep:" << dt); pfasst::examples::vdp::run_vdp_sdc(nsteps, dt, nnodes, niters, nu, x0, y0, nodetype); }
// Initialize a Servo instance int Servo2D::init() { ML_LOG(Debug, "Servo2D Initializing."); // Set up the prism createInitialPrism(); lumin::ui::Cursor::SetScale(prism_, 0.03f); instanceInitialScenes(); // Get the planar resource that holds the EGL context lumin::RootNode* root_node = prism_->getRootNode(); if (!root_node) { ML_LOG(Error, "Servo2D Failed to get root node"); abort(); return 1; } std::string content_node_id = Servo2D_exportedNodes::content; content_node_ = lumin::QuadNode::CastFrom(prism_->findNode(content_node_id, root_node)); if (!content_node_) { ML_LOG(Error, "Servo2D Failed to get content node"); abort(); return 1; } content_node_->setTriggerable(true); content_panel_ = lumin::ui::UiPanel::CastFrom(prism_->findNode(Servo2D_exportedNodes::contentPanel, root_node)); if (!content_panel_) { ML_LOG(Error, "Servo2D Failed to get content panel"); abort(); return 1; } lumin::ui::UiPanel::RequestFocus(content_panel_); lumin::ResourceIDType plane_id = prism_->createPlanarEGLResourceId(); if (!plane_id) { ML_LOG(Error, "Servo2D Failed to create EGL resource"); abort(); return 1; } plane_ = static_cast<lumin::PlanarResource*>(prism_->getResource(plane_id)); if (!plane_) { ML_LOG(Error, "Servo2D Failed to create plane"); abort(); return 1; } content_node_->setRenderResource(plane_id); // Get the EGL context, surface and display. EGLContext ctx = plane_->getEGLContext(); EGLSurface surf = plane_->getEGLSurface(); EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); // Hook into servo servo_ = init_servo(ctx, surf, dpy, this, logger, history, HOME_PAGE, VIEWPORT_W, VIEWPORT_H, HIDPI); if (!servo_) { ML_LOG(Error, "Servo2D Failed to init servo instance"); abort(); return 1; } // Add a callback to the back button std::string back_button_id = Servo2D_exportedNodes::backButton; back_button_ = lumin::ui::UiButton::CastFrom(prism_->findNode(back_button_id, root_node)); if (!back_button_) { ML_LOG(Error, "Servo2D Failed to get back button"); abort(); return 1; } back_button_->onActivateSub(std::bind(traverse_servo, servo_, -1)); // Add a callback to the forward button std::string fwd_button_id = Servo2D_exportedNodes::fwdButton; fwd_button_ = lumin::ui::UiButton::CastFrom(prism_->findNode(fwd_button_id, root_node)); if (!fwd_button_) { ML_LOG(Error, "Servo2D Failed to get forward button"); abort(); return 1; } fwd_button_->onActivateSub(std::bind(traverse_servo, servo_, +1)); // Add a callback to the URL bar std::string url_bar_id = Servo2D_exportedNodes::urlBar; url_bar_ = lumin::ui::UiTextEdit::CastFrom(prism_->findNode(url_bar_id, root_node)); if (!url_bar_) { ML_LOG(Error, "Servo2D Failed to get URL bar"); abort(); return 1; } lumin::ui::KeyboardProperties keyboard_properties; keyboard_properties.keyboardZPosition = lumin::ui::KeyboardProperties::KeyboardZPosition::kVolumeCursorPlane; keyboard_properties.width = KEYBOARD_W; url_bar_->setKeyboardProperties(keyboard_properties); url_bar_->onFocusLostSub(std::bind(&Servo2D::urlBarEventListener, this)); // Add the laser pointer laser_ = lumin::LineNode::CastFrom(prism_->findNode(Servo2D_exportedNodes::laser, root_node)); if (!laser_) { ML_LOG(Error, "Servo2D Failed to get laser"); abort(); return 1; } return 0; }
// Destroy a Servo 2D instance Servo2D::~Servo2D() { ML_LOG(Debug, "Servo2D Destructor."); }
// Create a Servo2D instance Servo2D::Servo2D() { ML_LOG(Debug, "Servo2D Constructor."); }
int Servo2D::deInit() { ML_LOG(Debug, "Servo2D Deinitializing."); discard_servo(servo_); servo_ = nullptr; return 0; }