ComeHitherNavigationToolFactory::ComeHitherNavigationToolFactory(ToolManager& toolManager) :ToolFactory("ComeHitherNavigationTool",toolManager), linearSnapThreshold(getDisplaySize()*Scalar(0.5)), angularSnapThreshold(Scalar(45)), maxLinearVelocity(getDisplaySize()*Scalar(1.5)), maxAngularVelocity(Scalar(90.0)) { /* Initialize tool layout: */ layout.setNumDevices(1); layout.setNumButtons(0,1); /* Insert class into class hierarchy: */ ToolFactory* navigationToolFactory=toolManager.loadClass("NavigationTool"); navigationToolFactory->addChildClass(this); addParentClass(navigationToolFactory); /* Load class settings: */ Misc::ConfigurationFileSection cfs=toolManager.getToolClassSection(getClassName()); linearSnapThreshold=cfs.retrieveValue<Scalar>("./linearSnapThreshold",linearSnapThreshold); angularSnapThreshold=Math::rad(cfs.retrieveValue<Scalar>("./angularSnapThreshold",angularSnapThreshold)); maxLinearVelocity=cfs.retrieveValue<Scalar>("./maxLinearVelocity",maxLinearVelocity); maxAngularVelocity=Math::rad(cfs.retrieveValue<Scalar>("./maxAngularVelocity",maxAngularVelocity)); /* Set tool class' factory pointer: */ ComeHitherNavigationTool::factory=this; }
ValuatorFlyNavigationToolFactory::ValuatorFlyNavigationToolFactory(ToolManager& toolManager) :ToolFactory("ValuatorFlyNavigationTool",toolManager), valuatorThreshold(0), flyDirection(Vector(0,1,0)), flyFactor(getDisplaySize()*Scalar(0.5)) { /* Initialize tool layout: */ layout.setNumDevices(1); layout.setNumValuators(0,1); /* Insert class into class hierarchy: */ ToolFactory* navigationToolFactory=toolManager.loadClass("NavigationTool"); navigationToolFactory->addChildClass(this); addParentClass(navigationToolFactory); /* Load class settings: */ Misc::ConfigurationFileSection cfs=toolManager.getToolClassSection(getClassName()); valuatorThreshold=cfs.retrieveValue<Scalar>("./valuatorThreshold",valuatorThreshold); flyDirection=cfs.retrieveValue<Vector>("./flyDirection",flyDirection); flyDirection.normalize(); flyFactor=cfs.retrieveValue<Scalar>("./flyFactor",flyFactor); /* Set tool class' factory pointer: */ ValuatorFlyNavigationTool::factory=this; }
Point TrackballNavigationTool::calcTrackballPosition(void) const { /* Get device ray equation: */ Ray ray=getButtonDeviceRay(0); /* Intersect ray with trackball sphere: */ Vector d=getDisplayCenter()-ray.getOrigin(); Scalar dLen2=Geometry::sqr(d); Scalar ph=ray.getDirection()*d; Scalar radius=getDisplaySize(); Scalar det=Math::sqr(ph)+Math::sqr(radius)-dLen2; if(det>=Scalar(0)) { /* Find first intersection of ray with sphere (even if behind start point): */ det=Math::sqrt(det); Scalar lambda=ph-det; return ray(lambda); } else { /* Find closest point on sphere to ray: */ Vector ctop=ray.getDirection()*((d*ray.getDirection())/Geometry::sqr(ray.getDirection()))-d; ctop*=radius/Geometry::mag(ctop); return getDisplayCenter()+ctop; } }
ValuatorTurnNavigationToolFactory::ValuatorTurnNavigationToolFactory(ToolManager& toolManager) :ToolFactory("ValuatorTurnNavigationTool",toolManager), valuatorThreshold(0.25), flyDirection(Vector(0,1,0)), flyFactor(getDisplaySize()*Scalar(0.5)), rotationAxis0(Vector(0,0,1)), rotationAxis1(Vector(1,0,0)), rotationCenter(Point::origin), rotationFactor(Scalar(90)) { /* Initialize tool layout: */ layout.setNumButtons(1); layout.setNumValuators(2); /* Insert class into class hierarchy: */ ToolFactory* navigationToolFactory=toolManager.loadClass("NavigationTool"); navigationToolFactory->addChildClass(this); addParentClass(navigationToolFactory); /* Load class settings: */ Misc::ConfigurationFileSection cfs=toolManager.getToolClassSection(getClassName()); valuatorThreshold=cfs.retrieveValue<Scalar>("./valuatorThreshold",valuatorThreshold); flyDirection=cfs.retrieveValue<Vector>("./flyDirection",flyDirection); flyDirection.normalize(); flyFactor=cfs.retrieveValue<Scalar>("./flyFactor",flyFactor); rotationAxis0=cfs.retrieveValue<Vector>("./rotationAxis0",rotationAxis0); rotationAxis0.normalize(); rotationAxis1=cfs.retrieveValue<Vector>("./rotationAxis1",rotationAxis1); rotationAxis1.normalize(); rotationCenter=cfs.retrieveValue<Point>("./rotationCenter",rotationCenter); rotationFactor=Math::rad(cfs.retrieveValue<Scalar>("./rotationFactor",rotationFactor)); /* Set tool class' factory pointer: */ ValuatorTurnNavigationTool::factory=this; }
SixAxisSurfaceNavigationToolFactory::SixAxisSurfaceNavigationToolFactory(ToolManager& toolManager) :ToolFactory("SixAxisSurfaceNavigationTool",toolManager), canRoll(true), bankTurns(false),levelSpeed(5), canFly(true), probeSize(getDisplaySize()), maxClimb(getDisplaySize()), fixAzimuth(false), drawHud(true),hudColor(0.0f,1.0f,0.0f),hudRadius(float(getFrontplaneDist()*1.25f)),hudFontSize(float(getUiSize())*1.5f) { /* Initialize tool layout: */ layout.setNumValuators(6); /* Load class settings: */ Misc::ConfigurationFileSection cfs=toolManager.getToolClassSection(getClassName()); Vector trans; for(int i=0;i<3;++i) trans[i]=getDisplaySize(); trans=cfs.retrieveValue<Vector>("./translateFactors",trans); for(int i=0;i<3;++i) translateFactors[i]=trans[i]; Vector rot=cfs.retrieveValue<Vector>("./rotateFactors",Vector(180,180,180)); for(int i=0;i<3;++i) rotateFactors[i]=Math::rad(rot[i]); canRoll=cfs.retrieveValue<bool>("./canRoll",canRoll); bankTurns=cfs.retrieveValue<bool>("./bankTurns",bankTurns); levelSpeed=cfs.retrieveValue<Scalar>("./levelSpeed",levelSpeed); if(levelSpeed<Scalar(0)) levelSpeed=Scalar(0); canFly=cfs.retrieveValue<bool>("./canFly",canFly); probeSize=cfs.retrieveValue<Scalar>("./probeSize",probeSize); maxClimb=cfs.retrieveValue<Scalar>("./maxClimb",maxClimb); fixAzimuth=cfs.retrieveValue<bool>("./fixAzimuth",fixAzimuth); drawHud=cfs.retrieveValue<bool>("./drawHud",drawHud); hudColor=cfs.retrieveValue<Color>("./hudColor",hudColor); hudRadius=cfs.retrieveValue<float>("./hudRadius",hudRadius); hudFontSize=cfs.retrieveValue<float>("./hudFontSize",hudFontSize); /* Insert class into class hierarchy: */ ToolFactory* navigationToolFactory=toolManager.loadClass("SurfaceNavigationTool"); navigationToolFactory->addChildClass(this); addParentClass(navigationToolFactory); /* Set tool class' factory pointer: */ SixAxisSurfaceNavigationTool::factory=this; }
bool ViewpointFileNavigationTool::navigate(Scalar parameter) { /* Find the spline segment containing the given parameter: */ int l=0; int r=splines.size(); while(r-l>1) { int m=(l+r)>>1; if(parameter>=splines[m].t[0]) l=m; else r=m; } const SplineSegment& s=splines[l]; if(parameter>=s.t[0]&¶meter<=s.t[1]) { /* Evaluate the spline segment at the current time: */ Scalar t=(parameter-s.t[0])/(s.t[1]-s.t[0]); ControlPoint cp[6]; for(int i=0;i<3;++i) interpolate(s.p[i],s.p[i+1],t,cp[i]); for(int i=0;i<2;++i) interpolate(cp[i],cp[i+1],t,cp[3+i]); interpolate(cp[3],cp[4],t,cp[5]); /* Compute the appropriate navigation transformation from the next viewpoint: */ NavTransform nav=NavTransform::identity; nav*=NavTransform::translateFromOriginTo(getDisplayCenter()); nav*=NavTransform::rotate(Rotation::fromBaseVectors(Geometry::cross(getForwardDirection(),getUpDirection()),getForwardDirection())); nav*=NavTransform::scale(getDisplaySize()/Math::exp(cp[5].size)); // Scales are interpolated logarithmically nav*=NavTransform::rotate(Geometry::invert(Rotation::fromBaseVectors(Geometry::cross(cp[5].forward,cp[5].up),cp[5].forward))); nav*=NavTransform::translateToOriginFrom(cp[5].center); if(isActive()) { /* Set the viewpoint: */ setNavigationTransformation(nav); } else if(activate()) { /* Set the viewpoint: */ setNavigationTransformation(nav); /* Deactivate again: */ deactivate(); } nextViewpointIndex=l+1; return true; } else { /* Stop animating; spline is over: */ nextViewpointIndex=0; return false; } }
WalkNavigationToolFactory::WalkNavigationToolFactory(ToolManager& toolManager) :ToolFactory("WalkNavigationTool",toolManager), floorPlane(getFloorPlane()), centerOnActivation(false), centerPoint(getDisplayCenter()), moveSpeed(getDisplaySize()), innerRadius(getDisplaySize()*Scalar(0.5)),outerRadius(getDisplaySize()*Scalar(0.75)), centerViewDirection(getForwardDirection()), rotateSpeed(Math::rad(Scalar(120))), innerAngle(Math::rad(Scalar(30))),outerAngle(Math::rad(Scalar(120))), drawMovementCircles(true), movementCircleColor(0.0f,1.0f,0.0f) { /* Initialize tool layout: */ layout.setNumDevices(1); layout.setNumButtons(0,1); /* Insert class into class hierarchy: */ ToolFactory* navigationToolFactory=toolManager.loadClass("NavigationTool"); navigationToolFactory->addChildClass(this); addParentClass(navigationToolFactory); /* Load class settings: */ Misc::ConfigurationFileSection cfs=toolManager.getToolClassSection(getClassName()); floorPlane=cfs.retrieveValue<Plane>("./floorPlane",floorPlane); floorPlane.normalize(); centerOnActivation=cfs.retrieveValue<bool>("./centerOnActivation",centerOnActivation); centerPoint=cfs.retrieveValue<Point>("./centerPoint",centerPoint); centerPoint=floorPlane.project(centerPoint); moveSpeed=cfs.retrieveValue<Scalar>("./moveSpeed",moveSpeed); innerRadius=cfs.retrieveValue<Scalar>("./innerRadius",innerRadius); outerRadius=cfs.retrieveValue<Scalar>("./outerRadius",outerRadius); centerViewDirection=cfs.retrieveValue<Vector>("./centerViewDirection",centerViewDirection); centerViewDirection=floorPlane.project(centerViewDirection); centerViewDirection.normalize(); rotateSpeed=Math::rad(cfs.retrieveValue<Scalar>("./rotateSpeed",Math::deg(rotateSpeed))); innerAngle=Math::rad(cfs.retrieveValue<Scalar>("./innerAngle",Math::deg(innerAngle))); outerAngle=Math::rad(cfs.retrieveValue<Scalar>("./outerAngle",Math::deg(outerAngle))); drawMovementCircles=cfs.retrieveValue<bool>("./drawMovementCircles",drawMovementCircles); movementCircleColor=cfs.retrieveValue<Color>("./movementCircleColor",movementCircleColor); /* Set tool class' factory pointer: */ WalkNavigationTool::factory=this; }
void ViewpointFileNavigationTool::buttonCallback(int,InputDevice::ButtonCallbackData* cbData) { if(cbData->newButtonState) // Activation button has just been pressed { #if 0 /* Set the next saved viewpoint if the tool can be activated: */ if(!viewpoints.empty()&&activate()) { /* Compute the appropriate navigation transformation from the next viewpoint: */ const Viewpoint& v=viewpoints[nextViewpointIndex]; NavTransform nav=NavTransform::identity; nav*=NavTransform::translateFromOriginTo(getDisplayCenter()); nav*=NavTransform::rotate(Rotation::fromBaseVectors(Geometry::cross(getForwardDirection(),getUpDirection()),getForwardDirection())); nav*=NavTransform::scale(getDisplaySize()/Math::exp(v.size)); // Scales are interpolated logarithmically nav*=NavTransform::rotate(Geometry::invert(Rotation::fromBaseVectors(Geometry::cross(v.forward,v.up),v.forward))); nav*=NavTransform::translateToOriginFrom(v.center); /* Set the viewpoint: */ setNavigationTransformation(nav); /* Go to the next viewpoint: */ ++nextViewpointIndex; if(nextViewpointIndex==viewpoints.size()) nextViewpointIndex=0U; /* Deactivate the tool: */ deactivate(); } #else /* Start animating the viewpoint if there are spline segments and the tool can be activated: */ if(!splines.empty()) { if(paused&&activate()) { /* Unpause the animation: */ paused=false; parameter-=Scalar(getFrameTime())*speed; } else if(isActive()) { /* Pause the animation: */ paused=true; deactivate(); } else if(activate()) { /* Animate from the beginning: */ paused=false; parameter=splines.front().t[0]-Scalar(getFrameTime())*speed; if(positionSlider!=0) positionSlider->setValue(parameter); } } #endif } }
Vector2 convertTouch(SDL_Event& ev) { //log::messageln("convert %.2f %.2f %.2f", ev.tfinger.x, ev.tfinger.y, ev.tfinger.pressure); Point size = getDisplaySize(); return Vector2(ev.tfinger.x * size.x, ev.tfinger.y * size.y); //SDL_Touch* inTouch = SDL_GetTouch(ev.tfinger.touchId); //return Point( // (int(ev.tfinger.x) * size.x) / inTouch->xres, // (int(ev.tfinger.y) * size.y) / inTouch->yres); }
void init2() { #ifdef OXYGINE_SDL initGLExtensions(SDL_GL_GetProcAddress); #endif Point size = getDisplaySize(); log::messageln("display size: %d %d", size.x, size.y); #if __S3E__ int glversion = s3eGLGetInt(S3E_GL_VERSION); int major_gl = glversion >> 8; if (major_gl == 2) IVideoDriver::instance = new VideoDriverGLES20(); else { OX_ASSERT(!"gl version should be 2"); //IVideoDriver::instance = new VideoDriverGLES11(); } #elif __FLASHPLAYER__ { VideoDriverStage3D *vd = new VideoDriverStage3D(); vd->init(); IVideoDriver::instance = vd; } //IVideoDriver::instance = new VideoDriverNull(); #else IVideoDriver::instance = new VideoDriverGLES20(); #endif checkGLError(); IVideoDriver::instance->setDefaultSettings(); checkGLError(); Renderer::initialize(); Resources::registerResourceType(ResAtlas::create, "atlas"); Resources::registerResourceType(ResBuffer::create, "buffer"); Resources::registerResourceType(ResFontBM::create, "font"); Resources::registerResourceType(ResFontBM::createBM, "bmfc_font"); Resources::registerResourceType(ResFontBM::createSD, "sdfont"); Resources::registerResourceType(ResStarlingAtlas::create, "starling"); checkGLError(); log::messageln("oxygine initialized"); }
static int getCellCount ( Tcl_Interp *interp, BrlapiSession *session, unsigned int *count ) { if (!(session->displayWidth && session->displayHeight)) { TEST_TCL_OK(getDisplaySize(interp, session)); } *count = session->displayWidth * session->displayHeight; return TCL_OK; }
SixAxisTransformToolFactory::Configuration::Configuration(void) :translateFactor(getDisplaySize()/Scalar(3)), translations(Vector::zero), rotateFactor(Scalar(180)), rotations(Vector::zero), deviceGlyphType("Cone"), deviceGlyphMaterial(GLMaterial::Color(0.5f,0.5f,0.5f),GLMaterial::Color(1.0f,1.0f,1.0f),25.0f) { /* Initialize translation vectors and scaled rotation axes: */ for(int i=0; i<3; ++i) translations[i][i]=Scalar(1); for(int i=0; i<3; ++i) rotations[i][i]=Scalar(1); }
void Init(sf::Window& window, sf::RenderTarget& target) { s_window = &window; ImGuiIO& io = ImGui::GetIO(); // init keyboard mapping io.KeyMap[ImGuiKey_Tab] = sf::Keyboard::Tab; io.KeyMap[ImGuiKey_LeftArrow] = sf::Keyboard::Left; io.KeyMap[ImGuiKey_RightArrow] = sf::Keyboard::Right; io.KeyMap[ImGuiKey_UpArrow] = sf::Keyboard::Up; io.KeyMap[ImGuiKey_DownArrow] = sf::Keyboard::Down; io.KeyMap[ImGuiKey_Home] = sf::Keyboard::Home; io.KeyMap[ImGuiKey_End] = sf::Keyboard::End; io.KeyMap[ImGuiKey_Delete] = sf::Keyboard::Delete; io.KeyMap[ImGuiKey_Backspace] = sf::Keyboard::BackSpace; io.KeyMap[ImGuiKey_Enter] = sf::Keyboard::Return; io.KeyMap[ImGuiKey_Escape] = sf::Keyboard::Escape; io.KeyMap[ImGuiKey_A] = sf::Keyboard::A; io.KeyMap[ImGuiKey_C] = sf::Keyboard::C; io.KeyMap[ImGuiKey_V] = sf::Keyboard::V; io.KeyMap[ImGuiKey_X] = sf::Keyboard::X; io.KeyMap[ImGuiKey_Y] = sf::Keyboard::Y; io.KeyMap[ImGuiKey_Z] = sf::Keyboard::Z; s_deltaClock.restart(); // init rendering s_renderTarget = ⌖ io.DisplaySize = getDisplaySize(); io.RenderDrawListsFn = RenderDrawLists; // set render callback // create font texture unsigned char* pixels; int width, height; io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); if (s_fontTexture) { // was already created, delete it delete s_fontTexture; } s_fontTexture = new sf::Texture; s_fontTexture->create(width, height); s_fontTexture->update(pixels); io.Fonts->TexID = (void*)s_fontTexture; io.Fonts->ClearInputData(); io.Fonts->ClearTexData(); }
ScaleBar::ScaleBar(const char* sName,GLMotif::WidgetManager* sManager) :GLMotif::Widget(sName,0,false),manager(sManager), targetLength(getDisplaySize()*Scalar(0.2)), currentMantissa(1),currentExponent(0),currentNavLength(1),currentScale(1), lengthLabel(0),scaleLabel(0), currentPhysLength(0) { /* Set widget parameters: */ setBorderWidth(0.0f); setBorderType(GLMotif::Widget::PLAIN); /* Set default background and foreground colors: */ Color bgColor=Vrui::getBackgroundColor(); bgColor[3]=0.0f; Color fgColor; for(int i=0;i<3;++i) fgColor[i]=1.0f-bgColor[i]; fgColor[3]=1.0f; setBorderColor(bgColor); setBackgroundColor(bgColor); setForegroundColor(fgColor); /* Create the initial scale bar length label: */ if(getCoordinateManager()->getUnit().unit!=Geometry::LinearUnit::UNKNOWN) { char labelText[10]; snprintf(labelText,sizeof(labelText),"1 %s",getCoordinateManager()->getUnit().getAbbreviation()); lengthLabel=new GLLabel(labelText,*getUiFont()); } else lengthLabel=new GLLabel("1",*getUiFont()); lengthLabel->setBackground(bgColor); lengthLabel->setForeground(fgColor); scaleLabel=new GLLabel("1:1",*getUiFont()); scaleLabel->setBackground(bgColor); scaleLabel->setForeground(fgColor); /* Calculate the initial navigation-space scale bar length: */ calcSize(getNavigationTransformation()); /* Resize the widget: */ GLMotif::Vector newSize=calcNaturalSize(); GLMotif::Vector newOrigin=GLMotif::Vector(0.0f,0.0f,0.0f); newOrigin[0]=-newSize[0]*0.5f; resize(GLMotif::Box(newOrigin,newSize)); /* Register a navigation change callback with the Vrui kernel: */ getNavigationTransformationChangedCallbacks().add(this,&ScaleBar::navigationChangedCallback); }
void WIN32Window::internalCreateWindow() { m_defaultCursor = LoadCursor(NULL, IDC_ARROW); WNDCLASSA wc; wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wc.lpfnWndProc = (WNDPROC)WindowProcProxy::call; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = m_instance; wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); wc.hCursor = m_defaultCursor; wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = g_app.getCompactName().c_str(); if(!RegisterClassA(&wc)) g_logger.fatal("Failed to register the window class."); DWORD dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; DWORD dwStyle = WS_OVERLAPPEDWINDOW; // initialize in the center of the screen m_position = ((getDisplaySize() - m_size) / 2).toPoint(); Rect screenRect = adjustWindowRect(Rect(m_position, m_size)); updateUnmaximizedCoords(); m_window = CreateWindowExA(dwExStyle, g_app.getCompactName().c_str(), NULL, dwStyle, screenRect.left(), screenRect.top(), screenRect.width(), screenRect.height(), NULL, NULL, m_instance, NULL); if(!m_window) g_logger.fatal("Unable to create window"); ShowWindow(m_window, SW_HIDE); m_deviceContext = GetDC(m_window); if(!m_deviceContext) g_logger.fatal("GetDC failed"); }
void RayInputDeviceTool::display(GLContextData&) const { if(isActive()) { /* Draw the interaction ray: */ glPushAttrib(GL_ENABLE_BIT|GL_LINE_BIT); glDisable(GL_LIGHTING); glColor3f(1.0f,0.0f,0.0f); glLineWidth(3.0f); glBegin(GL_LINES); glVertex(interactionRay.getOrigin()); glVertex(interactionRay(getDisplaySize())); glEnd(); glPopAttrib(); } }
void RayScreenMenuTool::display(GLContextData&) const { if(insideWidget||widgetActive||isActive()) { /* Draw the menu selection ray: */ glPushAttrib(GL_ENABLE_BIT|GL_LINE_BIT); glDisable(GL_LIGHTING); glColor3f(1.0f,0.0f,0.0f); glLineWidth(3.0f); glBegin(GL_LINES); glVertex(selectionRay.getOrigin()); glVertex(selectionRay(getDisplaySize()*Scalar(5))); glEnd(); glPopAttrib(); } }
void SixAxisNavigationTool::display(GLContextData& contextData) const { if(config.showNavigationCenter&&isActive()) { /* Set up OpenGL state: */ glPushAttrib(GL_DEPTH_BUFFER_BIT|GL_ENABLE_BIT|GL_LINE_BIT); glDisable(GL_LIGHTING); glDepthFunc(GL_LEQUAL); /* Calculate colors to draw the crosshairs: */ Color bgColor=getBackgroundColor(); Color fgColor; for(int i=0;i<3;++i) fgColor[i]=1.0f-bgColor[i]; fgColor[3]=bgColor[3]; /* Go to crosshair space: */ glPushMatrix(); ONTransform trans=calcHUDTransform(config.followDisplayCenter?getDisplayCenter():config.navigationCenter); glMultMatrix(trans); glLineWidth(3.0f); glBegin(GL_LINES); glColor(bgColor); glVertex2d(-getDisplaySize(),0.0); glVertex2d(getDisplaySize(),0.0); glVertex2d(0.0,-getDisplaySize()); glVertex2d(0.0,getDisplaySize()); glEnd(); glLineWidth(1.0f); glBegin(GL_LINES); glColor(fgColor); glVertex2d(-getDisplaySize(),0.0); glVertex2d(getDisplaySize(),0.0); glVertex2d(0.0,-getDisplaySize()); glVertex2d(0.0,getDisplaySize()); glEnd(); glPopMatrix(); /* Restore OpenGL state: */ glPopAttrib(); } }
void Update() { ImGuiIO& io = ImGui::GetIO(); io.DisplaySize = getDisplaySize(); io.DeltaTime = s_deltaClock.restart().asSeconds(); // restart the clock and get delta // update mouse assert(s_window); sf::Vector2f mousePos = static_cast<sf::Vector2f>(sf::Mouse::getPosition(*s_window)); io.MousePos = ImVec2(mousePos.x, mousePos.y); io.MouseDown[0] = s_mousePressed[0] || sf::Mouse::isButtonPressed(sf::Mouse::Left); io.MouseDown[1] = s_mousePressed[1] || sf::Mouse::isButtonPressed(sf::Mouse::Right); io.MouseDown[2] = s_mousePressed[2] || sf::Mouse::isButtonPressed(sf::Mouse::Middle); s_mousePressed[0] = s_mousePressed[1] = s_mousePressed[2] = false; ImGui::NewFrame(); }
SixAxisNavigationToolFactory::Configuration::Configuration(void) :translateFactor(getDisplaySize()/Scalar(3)), translations(Vector::zero), rotateFactor(Scalar(180)), rotations(Vector::zero), zoomFactor(Scalar(1)), followDisplayCenter(false), navigationCenter(getDisplayCenter()), invertNavigation(false), showNavigationCenter(true) { /* Initialize translation vectors and scaled rotation axes: */ for(int i=0;i<3;++i) translations[i][i]=Scalar(1); for(int i=0;i<3;++i) rotations[i][i]=Scalar(1); }
void init2() { #ifdef OXYGINE_QT setlocale(LC_ALL, "POSIX"); #endif #ifdef OXYGINE_SDL int missing = initGLExtensions(SDL_GL_GetProcAddress); #endif Point size = getDisplaySize(); log::messageln("display size: %d %d", size.x, size.y); #if __S3E__ int glversion = s3eGLGetInt(S3E_GL_VERSION); int major_gl = glversion >> 8; OX_ASSERT( major_gl == 2 && "gl version should be 2"); IVideoDriver::instance = new VideoDriverGLES20(); #endif IVideoDriver::instance = new VideoDriverGLES20(); CHECKGL(); IVideoDriver::instance->setDefaultSettings(); CHECKGL(); Renderer::initialize(); Resources::registerResourceType(ResAtlas::create, "atlas"); Resources::registerResourceType(ResBuffer::create, "buffer"); Resources::registerResourceType(ResFontBM::create, "font"); Resources::registerResourceType(ResFontBM::createBM, "bmfc_font"); Resources::registerResourceType(ResFontBM::createSD, "sdfont"); Resources::registerResourceType(ResStarlingAtlas::create, "starling"); CHECKGL(); log::messageln("oxygine initialized"); }
ValuatorFlyTurnNavigationToolFactory::ValuatorFlyTurnNavigationToolFactory(ToolManager& toolManager) :ToolFactory("ValuatorFlyTurnNavigationTool",toolManager), valuatorThreshold(Scalar(0.25)), valuatorExponent(Scalar(1)), superAccelerationFactor(Scalar(1.1)), flyDirectionDeviceCoordinates(true),flyDirection(Vector(0,1,0)), flyFactor(getDisplaySize()*Scalar(2)), rotationAxisDeviceCoordinates(true),rotationAxis(Vector(0,0,1)), rotationCenterDeviceCoordinates(true),rotationCenter(Point::origin), rotationFactor(Scalar(90)) { /* Initialize tool layout: */ layout.setNumDevices(1); layout.setNumValuators(0,2); /* Insert class into class hierarchy: */ ToolFactory* navigationToolFactory=toolManager.loadClass("NavigationTool"); navigationToolFactory->addChildClass(this); addParentClass(navigationToolFactory); /* Load class settings: */ Misc::ConfigurationFileSection cfs=toolManager.getToolClassSection(getClassName()); valuatorThreshold=cfs.retrieveValue<Scalar>("./valuatorThreshold",valuatorThreshold); valuatorExponent=cfs.retrieveValue<Scalar>("./valuatorExponent",valuatorExponent); superAccelerationFactor=cfs.retrieveValue<Scalar>("./superAccelerationFactor",superAccelerationFactor); flyDirectionDeviceCoordinates=cfs.retrieveValue<bool>("./flyDirectionDeviceCoordinates",flyDirectionDeviceCoordinates); flyDirection=cfs.retrieveValue<Vector>("./flyDirection",flyDirection); flyDirection.normalize(); flyFactor=cfs.retrieveValue<Scalar>("./flyFactor",flyFactor); rotationAxisDeviceCoordinates=cfs.retrieveValue<bool>("./rotationAxisDeviceCoordinates",rotationAxisDeviceCoordinates); rotationAxis=cfs.retrieveValue<Vector>("./rotationAxis",rotationAxis); rotationAxis.normalize(); rotationCenterDeviceCoordinates=cfs.retrieveValue<bool>("./rotationCenterDeviceCoordinates",rotationCenterDeviceCoordinates); rotationCenter=cfs.retrieveValue<Point>("./rotationCenter",rotationCenter); rotationFactor=Math::rad(cfs.retrieveValue<Scalar>("./rotationFactor",rotationFactor)); /* Set tool class' factory pointer: */ ValuatorFlyTurnNavigationTool::factory=this; }
void TwoRayTransformTool::display(GLContextData& contextData) const { if(numRays>0) { /* Draw the selection rays: */ glPushAttrib(GL_ENABLE_BIT|GL_LINE_BIT); glDisable(GL_LIGHTING); glColor3f(1.0f,0.0f,0.0f); glLineWidth(3.0f); glBegin(GL_LINES); for(int i=0;i<(active?numRays+1:numRays);++i) { Ray tr=rays[i]; tr.transform(getNavigationTransformation()); glVertex(tr.getOrigin()); glVertex(tr(getDisplaySize()*Scalar(5))); } glEnd(); glPopAttrib(); } }
void WIN32Window::setFullscreen(bool fullscreen) { if(m_fullscreen == fullscreen) return; m_fullscreen = fullscreen; DWORD dwStyle = GetWindowLong(m_window, GWL_STYLE); static WINDOWPLACEMENT wpPrev; wpPrev.length = sizeof(wpPrev); if(fullscreen) { Size size = getDisplaySize(); GetWindowPlacement(m_window, &wpPrev); SetWindowLong(m_window, GWL_STYLE, (dwStyle & ~WS_OVERLAPPEDWINDOW) | WS_POPUP | WS_EX_TOPMOST); SetWindowPos(m_window, HWND_TOPMOST, 0, 0, size.width(), size.height(), SWP_FRAMECHANGED); } else { SetWindowLong(m_window, GWL_STYLE, (dwStyle & ~(WS_POPUP | WS_EX_TOPMOST)) | WS_OVERLAPPEDWINDOW); SetWindowPlacement(m_window, &wpPrev); SetWindowPos(m_window, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED); } }
LaserpointerToolFactory::LaserpointerToolFactory(ToolManager& toolManager) :ToolFactory("LaserpointerTool",toolManager), rayLength(getDisplaySize()*Scalar(5)), rayLineWidth(3.0f), rayColor(1.0f,0.0f,0.0f) { /* Initialize tool layout: */ layout.setNumButtons(1); /* Insert class into class hierarchy: */ ToolFactory* toolFactory=toolManager.loadClass("PointingTool"); toolFactory->addChildClass(this); addParentClass(toolFactory); /* Load class settings: */ Misc::ConfigurationFileSection cfs=toolManager.getToolClassSection(getClassName()); rayLength=cfs.retrieveValue<Scalar>("./rayLength",rayLength); rayLineWidth=cfs.retrieveValue<float>("./rayLineWidth",rayLineWidth); rayColor=cfs.retrieveValue<Color>("./rayColor",rayColor); /* Set tool class' factory pointer: */ LaserpointerTool::factory=this; }
QString Layer::toMainHtml() { QString desc; desc = QString("<big><b>%1</b></big><br/>").arg(p->Name); if (!p->Description.isEmpty()) desc += QString("<b>%1</b><br/>").arg(p->Description); desc += QString("<small>(%1)</small>").arg(id()); QString S = "<html><head/><body>" "<small><i>" + QString(metaObject()->className()) + "</i></small><br/>" + desc; S += "<hr/>"; S += "<i>"+QApplication::translate("Layer", "Size")+": </i>" + QApplication::translate("Layer", "%n features", "", QCoreApplication::CodecForTr, getDisplaySize())+"<br/>"; S += "%1"; S += "</body></html>"; return S; }
void ViewpointFileNavigationTool::readViewpointFile(const char* fileName) { try { /* Open the viewpoint file: */ Misc::File viewpointFile(fileName,"rt"); if(Misc::hasCaseExtension(fileName,".views")) { /* Load all viewpoint keyframes from the file: */ Scalar time(0); while(true) { /* Read the next viewpoint: */ Scalar timeInterval; ControlPoint v; if(fscanf(viewpointFile.getFilePtr(),"%lf (%lf, %lf, %lf) %lf (%lf, %lf, %lf) (%lf, %lf, %lf)\n",&timeInterval,&v.center[0],&v.center[1],&v.center[2],&v.size,&v.forward[0],&v.forward[1],&v.forward[2],&v.up[0],&v.up[1],&v.up[2])!=11) break; /* Store the viewpoint: */ time+=timeInterval; times.push_back(time); v.size=Math::log(v.size); // Sizes are interpolated logarithmically viewpoints.push_back(v); } if(viewpoints.size()>1) { /* Create a big matrix to solve the C^2 spline problem: */ unsigned int n=viewpoints.size()-1; Math::Matrix A(4*n,4*n,0.0); Math::Matrix b(4*n,10,0.0); A(0,0)=1.0; writeControlPoint(viewpoints[0],b,0); double dt1=double(times[1])-double(times[0]); #if 1 /* Zero velocity at start: */ A(1,0)=-3.0/dt1; A(1,1)=3.0/dt1; #else /* Zero acceleration at start: */ A(1,0)=6.0/Math::sqr(dt1); A(1,1)=-12.0/Math::sqr(dt1); A(1,2)=6.0/Math::sqr(dt1); #endif for(unsigned int i=1;i<n;++i) { double dt0=double(times[i])-double(times[i-1]); double dt1=double(times[i+1])-double(times[i]); A(i*4-2,i*4-3)=6.0/Math::sqr(dt0); A(i*4-2,i*4-2)=-12.0/Math::sqr(dt0); A(i*4-2,i*4-1)=6.0/Math::sqr(dt0); A(i*4-2,i*4+0)=-6.0/Math::sqr(dt1); A(i*4-2,i*4+1)=12.0/Math::sqr(dt1); A(i*4-2,i*4+2)=-6.0/Math::sqr(dt1); A(i*4-1,i*4-2)=-3.0/dt0; A(i*4-1,i*4-1)=3.0/dt0; A(i*4-1,i*4+0)=3/dt1; A(i*4-1,i*4+1)=-3/dt1; A(i*4+0,i*4-1)=1.0; writeControlPoint(viewpoints[i],b,i*4+0); A(i*4+1,i*4+0)=1.0; writeControlPoint(viewpoints[i],b,i*4+1); } double dtn=double(times[n])-double(times[n-1]); #if 1 /* Zero velocity at end: */ A(n*4-2,n*4-2)=-3.0/dtn; A(n*4-2,n*4-1)=3.0/dtn; #else /* Zero acceleration at end: */ A(n*4-2,n*4-3)=6.0/Math::sqr(dtn); A(n*4-2,n*4-2)=-12.0/Math::sqr(dtn); A(n*4-2,n*4-1)=6.0/Math::sqr(dtn); #endif A(n*4-1,n*4-1)=1.0; writeControlPoint(viewpoints[n],b,n*4-1); /* Solve the system of equations: */ Math::Matrix x=b/A; /* Create the spline segment list: */ for(unsigned int i=0;i<n;++i) { SplineSegment s; for(int j=0;j<2;++j) s.t[j]=times[i+j]; for(int cp=0;cp<4;++cp) { for(int j=0;j<3;++j) s.p[cp].center[j]=x(i*4+cp,j); s.p[cp].size=x(i*4+cp,3); for(int j=0;j<3;++j) s.p[cp].forward[j]=x(i*4+cp,4+j); for(int j=0;j<3;++j) s.p[cp].up[j]=x(i*4+cp,7+j); } splines.push_back(s); } } } else if(Misc::hasCaseExtension(fileName,".curve")) { /* Load all spline segments from the file: */ while(true) { SplineSegment s; if(splines.empty()) { /* Read the first control point: */ ControlPoint cp; if(fscanf(viewpointFile.getFilePtr(),"(%lf, %lf, %lf) %lf (%lf, %lf, %lf) (%lf, %lf, %lf)\n",&cp.center[0],&cp.center[1],&cp.center[2],&cp.size,&cp.forward[0],&cp.forward[1],&cp.forward[2],&cp.up[0],&cp.up[1],&cp.up[2])!=10) break; cp.size=Math::log(cp.size); // Sizes are interpolated logarithmically viewpoints.push_back(cp); times.push_back(Scalar(0)); s.t[0]=Scalar(0); s.p[0]=cp; } else { /* Copy the last control point from the previous segment: */ s.t[0]=splines.back().t[1]; s.p[0]=splines.back().p[3]; } /* Read the segment's parameter interval: */ double pi; if(fscanf(viewpointFile.getFilePtr(),"%lf\n",&pi)!=1) break; s.t[1]=s.t[0]+Scalar(pi); /* Read the intermediate control points: */ ControlPoint m0; if(fscanf(viewpointFile.getFilePtr(),"(%lf, %lf, %lf) %lf (%lf, %lf, %lf) (%lf, %lf, %lf)\n",&m0.center[0],&m0.center[1],&m0.center[2],&m0.size,&m0.forward[0],&m0.forward[1],&m0.forward[2],&m0.up[0],&m0.up[1],&m0.up[2])!=10) break; m0.size=Math::log(m0.size); // Sizes are interpolated logarithmically s.p[1]=m0; ControlPoint m1; if(fscanf(viewpointFile.getFilePtr(),"(%lf, %lf, %lf) %lf (%lf, %lf, %lf) (%lf, %lf, %lf)\n",&m1.center[0],&m1.center[1],&m1.center[2],&m1.size,&m1.forward[0],&m1.forward[1],&m1.forward[2],&m1.up[0],&m1.up[1],&m1.up[2])!=10) break; m1.size=Math::log(m1.size); // Sizes are interpolated logarithmically s.p[2]=m1; /* Read the last control point: */ ControlPoint cp; if(fscanf(viewpointFile.getFilePtr(),"(%lf, %lf, %lf) %lf (%lf, %lf, %lf) (%lf, %lf, %lf)\n",&cp.center[0],&cp.center[1],&cp.center[2],&cp.size,&cp.forward[0],&cp.forward[1],&cp.forward[2],&cp.up[0],&cp.up[1],&cp.up[2])!=10) break; cp.size=Math::log(cp.size); // Sizes are interpolated logarithmically viewpoints.push_back(cp); times.push_back(s.t[1]); s.p[3]=cp; /* Save the spline segment: */ splines.push_back(s); } } else { /* Display an error message: */ std::string message="Curve file "; message.append(fileName); message.append(" has unrecognized extension \""); message.append(Misc::getExtension(fileName)); message.push_back('"'); showErrorMessage("Curve File Animation",message.c_str()); } } catch(std::runtime_error err) { /* Display an error message: */ std::string message="Could not read curve file "; message.append(fileName); message.append(" due to exception "); message.append(err.what()); showErrorMessage("Curve File Animation",message.c_str()); } if(!splines.empty()) { /* Start animating from the beginning: */ paused=false; parameter=splines.front().t[0]; /* Create playback control dialog if requested: */ if(showGui) createGui(); /* Start animating if requested: */ if(autostart) activate(); } else if(!viewpoints.empty()&&activate()) { /* Go to the first viewpoint: */ const ControlPoint& v=viewpoints[0]; NavTransform nav=NavTransform::identity; nav*=NavTransform::translateFromOriginTo(getDisplayCenter()); nav*=NavTransform::rotate(Rotation::fromBaseVectors(Geometry::cross(getForwardDirection(),getUpDirection()),getForwardDirection())); nav*=NavTransform::scale(getDisplaySize()/Math::exp(v.size)); // Scales are interpolated logarithmically nav*=NavTransform::rotate(Geometry::invert(Rotation::fromBaseVectors(Geometry::cross(v.forward,v.up),v.forward))); nav*=NavTransform::translateToOriginFrom(v.center); setNavigationTransformation(nav); deactivate(); } }
Vector2 convertTouch(SDL_Event& ev) { Point size = getDisplaySize(); return Vector2(ev.tfinger.x * size.x, ev.tfinger.y * size.y); }
void DaisyWheelTool::display(GLContextData&) const { if(active) { /* Save OpenGL state: */ glPushAttrib(GL_ENABLE_BIT|GL_LINE_BIT); /* Draw the daisy wheel: */ glPushMatrix(); glMultMatrix(wheelTransform); /* Set up OpenGL state: */ glDisable(GL_LIGHTING); glBegin(GL_QUADS); Scalar angle0=Scalar(0); Scalar angleDiff=zoomAngle-angle0; if(angleDiff<-Math::Constants<Scalar>::pi) angleDiff+=Scalar(2)*Math::Constants<Scalar>::pi; else if(angleDiff>Math::Constants<Scalar>::pi) angleDiff-=Scalar(2)*Math::Constants<Scalar>::pi; Scalar weight=Math::abs(angleDiff)/Math::Constants<Scalar>::pi; angleDiff*=Math::pow(weight,Scalar(1)-zoomStrength)/weight; Scalar wAngle0=zoomAngle-angleDiff; Scalar c0=Math::cos(wAngle0); Scalar s0=Math::sin(wAngle0); for(int i=0;i<numCharacters;++i) { Scalar angle1=angle0+dynamicWeights[i]*Scalar(2)*Math::Constants<Scalar>::pi/dynamicWeightSum; angleDiff=zoomAngle-angle1; if(angleDiff<-Math::Constants<Scalar>::pi) angleDiff+=Scalar(2)*Math::Constants<Scalar>::pi; else if(angleDiff>Math::Constants<Scalar>::pi) angleDiff-=Scalar(2)*Math::Constants<Scalar>::pi; weight=Math::abs(angleDiff)/Math::Constants<Scalar>::pi; angleDiff*=Math::pow(weight,Scalar(1)-zoomStrength)/weight; Scalar wAngle1=zoomAngle-angleDiff; Scalar c1=Math::cos(wAngle1); Scalar s1=Math::sin(wAngle1); if(i%2==0) glColor3f(1.0f,0.5f,0.5f); else glColor3f(0.0f,0.5f,1.0f); glVertex3f(s0*factory->innerRadius,0.0f,c0*factory->innerRadius); glVertex3f(s1*factory->innerRadius,0.0f,c1*factory->innerRadius); glVertex3f(s1*factory->outerRadius,0.0f,c1*factory->outerRadius); glVertex3f(s0*factory->outerRadius,0.0f,c0*factory->outerRadius); angle0=angle1; wAngle0=wAngle1; c0=c1; s0=s1; } glEnd(); glPopMatrix(); /* Draw the menu selection ray: */ glLineWidth(3.0f); glColor3f(1.0f,0.0f,0.0f); glBegin(GL_LINES); glVertex(selectionRay.getOrigin()); glVertex(selectionRay(getDisplaySize()*Scalar(5))); glEnd(); /* Restore OpenGL state: */ glPopAttrib(); } }