bool MapControl::isGeometryVisible( Geometry * geometry) { if ( !geometry || getViewport() == QRectF() ) return false; return getViewport().contains( geometry->boundingBox() ); }
void Controller::OnKeyDown(int keycode) { Vec3 center = getViewport().getScene()->getBounding().getCenter(); Float f = (getViewport().m_pCamera->m_pos - center).getLen()/100; Matrix r = m_Rotation2 * Matrix::Scale(Vec3(f,f,f)); switch(keycode) { case 38: case 315: //forward this->m_Translation += transform(Vec3(0,0,-1),r); break; case 40: case 317: //back this->m_Translation -= transform(Vec3(0,0,-1),r); break; case 37: case 314: //left this->m_Translation -= transform(Vec3(1,0,0),r); break; case 39: case 316: //right this->m_Translation += transform(Vec3(1,0,0),r); break; case 33: case 366: //up this->m_Translation += transform(Vec3(0,1,0),r); break; case 34: case 367: //down this->m_Translation -= transform(Vec3(0,1,0),r); break; } }
void CameraPan::_onDrag(const Point& pt) { getCamera()->moveRelative( Ogre::Vector3(+mDragDelta.x * getSceneManipulator()->_getMoveFactor() / getViewport()->getActualWidth(), -mDragDelta.y * getSceneManipulator()->_getMoveFactor() / getViewport()->getActualHeight(), 0)); getSceneManipulator()->_fireCameraPosChanged(); }
void Controller::reset() { m_zoom = 1.f; m_Rotation = getViewport().m_pCamera->getRotation(); m_Rotation2 = Matrix::Identity(); Vec3 center = getViewport().getScene()->getBounding().getCenter(); m_Translation = transform( getViewport().m_pCamera->getPosition() - center, m_Rotation) + center; }
const osg::Matrix SceneView::computeMVPW() const { osg::Matrix matrix( getViewMatrix() * getProjectionMatrix()); if (getViewport()) matrix.postMult(getViewport()->computeWindowMatrix()); else osg::notify(osg::WARN)<<"osg::Matrix SceneView::computeMVPW() - error no viewport attached to SceneView, coords will be computed inccorectly."<<std::endl; return matrix; }
SystemPainter::SystemPainter(CCoordinateSystem *system) : m_system(*system) { m_origin = CPoint(0,0); m_oldFont = NULL; getViewport().setScale(getScale(m_system.m_xAxisType), X_AXIS); getViewport().setScale(getScale(m_system.m_yAxisType), Y_AXIS); if(m_font) { m_oldFont = getViewport().getDC()->SelectObject(m_font); } m_xAxisPainter = createAxisPainter(true , m_system.m_xAxisType); m_yAxisPainter = createAxisPainter(false, m_system.m_yAxisType); makeSpaceForText(); }
void Controller::OnMouseMove(Flags nFlags, int x, int y) { Point point(x,y); if (nFlags == LBUTTON) { Vec3 r; r.x = -(Float)(point.x - mouse.x)/3; r.y = (Float)(point.y - mouse.y)/3; r = cross(r, Vec3(0,0,1)); Matrix rot = Matrix::Rotation( r.normalized(), r.getLen()); m_Rotation = m_Rotation * rot; } if (nFlags == (LBUTTON|RBUTTON) ) { Vec3 r; r.x = -(Float)(point.x - mouse.x)/3; r.y = (Float)(point.y - mouse.y)/3; r = cross(r, Vec3(0,0,1)); Matrix rot = Matrix::Rotation( r.normalized(), r.getLen()); m_Rotation2 = m_Rotation2 * rot; } if (nFlags == RBUTTON ) { Vec3 n = transform(Vec3(0,0,-1), m_Rotation.getInverted() ); n = n.normalized(); Plane ebene = Plane(n.x, n.y, n.z, 0); Ray a = getViewport().DPtoRay(mouse.x, mouse.y); Ray b = getViewport().DPtoRay(point.x, point.y); Float ta = 0, tb = 0; ebene.getIntersectionWithLine(a.getOrigin(), a.getPointAt(1), ta); ebene.getIntersectionWithLine(b.getOrigin(), b.getPointAt(1), tb); Vec3 d = a.getPointAt(ta) - b.getPointAt(tb); m_Translation = m_Translation + transform(d, m_Rotation ); } mouse = point; }
void Controller::OnMouseDown(Flags nFlags, int x, int y) { down = mouse = Point(x,y); Ptr<SceneNode> pSelected = doHitTest( getViewport().DPtoRay(x, y), *getViewport().getScene(), NULL ); if(pSelected) { if(pSelected->Flags() & SceneNode::FLAG_SELECTED) pSelected->Flags() &= ~SceneNode::FLAG_SELECTED; else pSelected->Flags() |= SceneNode::FLAG_SELECTED; } }
Matrix Controller::getViewMatrix() const { Ptr<Camera> c = getViewport().m_pCamera; Vec3 center = getViewport().getScene()->getBounding().getCenter(); Matrix r = m_Rotation.getInverted(); Matrix k = c->getRotation(); Vec3 pos = transform( m_Translation - center, r) + center; Vec3 dir = transform( Vec3(0,0,-1), m_Rotation2 * r); Vec3 up = transform( Vec3(0,1,0), m_Rotation2 * r); return Matrix::Lookat(pos, dir, up ); }
void SystemPainter::makeSpaceForText() { const int leftMargin = m_yAxisPainter->getMaxTextOffset() + 2; const int rightMargin = AbstractAxisPainter::ARROW_SIZE / 2; const int topMargin = AbstractAxisPainter::ARROW_SIZE / 2; const int bottomMargin = m_xAxisPainter->getMaxTextOffset() + getTextExtent(m_yAxisPainter->getMaxText()).cy + 1; Rectangle2D fr = getViewport().getFromRectangle(); const IntervalTransformation &xtr = getViewport().getXTransformation(); const IntervalTransformation &ytr = getViewport().getYTransformation(); bool adjustRectangle = false; if(xtr.isLinear() && fr.getMinX() == 0) { const double dx = -xtr.backwardTransform(getToRectangle().left + leftMargin); fr.m_x += dx; fr.m_w -= dx; adjustRectangle = true; } if(ytr.isLinear() && fr.getMinY() == 0) { const double dy = -ytr.backwardTransform(getToRectangle().top - bottomMargin); fr.m_y += dy; fr.m_h -= dy; adjustRectangle = true; } if(adjustRectangle) { getViewport().setFromRectangle(fr); } Rectangle2DR innerRectangle = getToRectangle(); innerRectangle.m_x += leftMargin; innerRectangle.m_w -= leftMargin + rightMargin; innerRectangle.m_y -= bottomMargin; innerRectangle.m_h += bottomMargin + topMargin; Point2D orig = innerRectangle.getProjection(Point2D(m_xAxisPainter->getAxisPoint(),m_yAxisPainter->getAxisPoint())); const double dx = min(orig.x - innerRectangle.m_x, leftMargin - getTextExtent(m_xAxisPainter->getMinText()).cx/2 - 1); const double dy = min(innerRectangle.m_y - orig.y, bottomMargin - getTextExtent(m_yAxisPainter->getMinText()).cy/2 - 1); if(dx > 0) { innerRectangle.m_x -= dx; innerRectangle.m_w += dx; } if(dy > 0) { innerRectangle.m_y += dy; innerRectangle.m_h -= dy; } m_origin = innerRectangle.getProjection(orig); }
// High-level void Camera::gethViewport( ViewportValueType& viewport, const int drawingSurfaceWidth, const EyeUsagePolicyValueType eyeUsagePolicy ) const { // Retrieves viewport field viewport = getViewport(); const float drawingSurfaceWidthf = static_cast< float >( drawingSurfaceWidth ); const float halfImageShift = (drawingSurfaceWidthf/16.f) * getImageShift()/100.f; switch ( eyeUsagePolicy.value() ) { case EYE_LEFT: viewport[0] -= static_cast< int >( halfImageShift ); break; case EYE_RIGHT: viewport[0] += static_cast< int >( halfImageShift ); break; case EYE_BOTH: // Nothing to do break; default: vgAssertN( false, "Unexpected value for eye usage policy %i", eyeUsagePolicy.value() ); } }
void ofEasyCam::updateMouse(const ofMouseEventArgs & mouse){ ofRectangle viewport = getViewport(this->viewport); int vFlip; if(isVFlipped()){ vFlip = -1; }else{ vFlip = 1; } if (bDoTranslate) { moveX = 0; moveY = 0; moveZ = 0; if (mouse.button == OF_MOUSE_BUTTON_RIGHT) { moveZ = mouseVel.y * sensitivityZ * (getDistance() + FLT_EPSILON)/ viewport.height; }else { moveX = -mouseVel.x * sensitivityXY * (getDistance() + FLT_EPSILON)/viewport.width; moveY = vFlip * mouseVel.y * sensitivityXY * (getDistance() + FLT_EPSILON)/viewport.height; } }else { xRot = 0; yRot = 0; zRot = 0; if (bInsideArcball) { xRot = vFlip * -mouseVel.y * rotationFactor; yRot = -mouseVel.x * rotationFactor; }else { ofVec2f center(viewport.width/2, viewport.height/2); zRot = - vFlip * ofVec2f(mouse.x - viewport.x - center.x, mouse.y - viewport.y - center.y).angle(lastMouse - ofVec2f(viewport.x, viewport.y) - center); } } }
void ofEasyCam::mouseScrolled(ofMouseEventArgs & mouse){ ofRectangle viewport = getViewport(this->viewport); prevPosition = ofCamera::getGlobalPosition(); prevAxisZ = getZAxis(); moveZ = mouse.y * 30 * sensitivityZ * (getDistance() + FLT_EPSILON)/ viewport.height; bDoScrollZoom = true; }
void ofEasyCam::mousePressed(ofMouseEventArgs & mouse){ ofRectangle viewport = getViewport(this->viewport); if(viewport.inside(mouse.x, mouse.y)){ lastMouse = mouse; prevMouse = mouse; prevAxisX = getXAxis(); prevAxisY = getYAxis(); prevAxisZ = getZAxis(); prevPosition = ofCamera::getGlobalPosition(); prevOrientation = ofCamera::getGlobalOrientation(); if ((bEnableMouseMiddleButton && mouse.button == OF_MOUSE_BUTTON_MIDDLE) || events->getKeyPressed(doTranslationKey) || mouse.button == OF_MOUSE_BUTTON_RIGHT){ bDoTranslate = true; bDoRotate = false; }else if (mouse.button == OF_MOUSE_BUTTON_LEFT) { bDoTranslate = false; bDoRotate = true; if(ofVec2f(mouse.x - viewport.x - (viewport.width/2), mouse.y - viewport.y - (viewport.height/2)).length() < min(viewport.width/2, viewport.height/2)){ bInsideArcball = true; }else { bInsideArcball = false; } } bApplyInertia = false; } }
// Executed on the UI IFrameLayerAndroid* FixedPositioning::updatePosition(SkRect aViewport, IFrameLayerAndroid* parentIframeLayer) { SkRect viewport = getViewport(aViewport, parentIframeLayer); float w = viewport.width(); float h = viewport.height(); float dx = viewport.fLeft; float dy = viewport.fTop; float x = dx; float y = dy; // It turns out that when it is 'auto', we should use the webkit value // from the original render layer's X,Y, that will take care of alignment // with the parent's layer and fix Margin etc. if (!(m_fixedLeft.defined() || m_fixedRight.defined())) x += m_renderLayerPos.x(); else if (m_fixedLeft.defined() || !m_fixedRight.defined()) x += m_fixedMarginLeft.calcFloatValue(w) + m_fixedLeft.calcFloatValue(w) - m_fixedRect.fLeft; else x += w - m_fixedMarginRight.calcFloatValue(w) - m_fixedRight.calcFloatValue(w) - m_fixedRect.fRight; if (!(m_fixedTop.defined() || m_fixedBottom.defined())) y += m_renderLayerPos.y(); else if (m_fixedTop.defined() || !m_fixedBottom.defined()) y += m_fixedMarginTop.calcFloatValue(h) + m_fixedTop.calcFloatValue(h) - m_fixedRect.fTop; else y += h - m_fixedMarginBottom.calcFloatValue(h) - m_fixedBottom.calcFloatValue(h) - m_fixedRect.fBottom; m_layer->setPosition(x, y); return parentIframeLayer; }
//----------------------------------------------------------------------------- // createWindow() -- create the main window //----------------------------------------------------------------------------- int GlutDisplay::createWindow() { winId = -1; #ifdef __FREEGLUT_EXT_H__ /* freeglut only */ glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS); #endif unsigned int wmode = GLUT_DOUBLE | GLUT_RGB | GLUT_ALPHA; if (getClearDepth() >= 0.0f) { wmode = wmode | GLUT_DEPTH; } if (accumBuff) { wmode = wmode | GLUT_ACCUM; } if (stencilBuff) { wmode = wmode | GLUT_STENCIL; } glutInitDisplayMode( wmode ); GLint vpX(0), vpY(0); // our initial viewport position GLsizei vpWidth(0), vpHeight(0); // our initial viewport size getViewport(&vpX, &vpY, &vpWidth, &vpHeight); glutInitWindowPosition(vpX, vpY); glutInitWindowSize(vpWidth, vpHeight); winId = glutCreateWindow(getName()); if (winId > 0) { if (isMessageEnabled(MSG_INFO)) { std::cout << "GlutDisplay::createWindow() name = " << getName() << ", winId = " << winId << std::endl; } // Configure the new window if (fullScreenFlg) glutFullScreen(); glutDisplayFunc(drawFuncCB); glutReshapeFunc(reshapeItCB); glutIdleFunc(idleCB); glutPassiveMotionFunc(passiveMotionFuncCB); glutMotionFunc(motionFuncCB); glutKeyboardFunc(keyboardFuncCB); glutSpecialFunc(specialFuncCB); glutMouseFunc(mouseFuncCB); glutEntryFunc(entryFuncCB); registerGlutDisplay(winId, this); glutSetWindow(winId); configure(); loadTextures(); // Create sub windows (if any) if (subDisplays() != nullptr) { Basic::List::Item* item = subDisplays()->getFirstItem(); while (item != nullptr) { Basic::Pair* pair = dynamic_cast<Basic::Pair*>(item->getValue()); if (pair != nullptr) { GlutDisplay* dobj = dynamic_cast<GlutDisplay*>( pair->object() ); if (dobj != nullptr) dobj->createSubWindow(winId); } item = item->getNext(); } } // Select this window select(); } return winId; }
void GLView::changeViewport(int t) { float rx,ry,rz,x,z,d; getViewport(rx,ry,rz,x,z,d); switch(t) { case Top: setViewport(90,0,0,x,z,d); break; case Bottom: setViewport(-90,0,0,x,z,d); break; case Left: setViewport(0,0,90,x,z,d); break; case Right: setViewport(0,0,-90,x,z,d); break; case Front: setViewport(0,0,0,x,z,d); break; case Back: setViewport(0,0,-180,x,z,d); break; } }
//---------------------------------------- void ofEasyCam::begin(ofRectangle _viewport){ if(!bEventsSet){ setEvents(ofEvents()); } viewport = getViewport(_viewport); ofCamera::begin(viewport); }
/**Call when viewport size or zoom has changed. * Recompute camera zoom and reps requiring vpMs. */ void ViewWrapper2D::viewportChanged() { if (!mView->getRenderer()->IsActiveCameraCreated()) return; mView->setZoomFactor(mZoom2D->getFactor()); double viewHeight = mView->getViewport_s().range()[1]; mView->getRenderer()->GetActiveCamera()->SetParallelScale(viewHeight / 2); // Heuristic guess for a good clip depth. The point is to show 3D data clipped in 2D // with a suitable thickness projected onto the plane. double clipDepth = 2.0; // i.e. all 3D props rendered outside this range is not shown. double length = clipDepth*10; clipDepth = viewHeight/120 + 1.5; mView->getRenderer()->GetActiveCamera()->SetPosition(0,0,length); mView->getRenderer()->GetActiveCamera()->SetClippingRange(length-clipDepth, length+0.1); mSliceProxy->setToolViewportHeight(viewHeight); double anyplaneViewOffset = settings()->value("Navigation/anyplaneViewOffset").toDouble(); mSliceProxy->initializeFromPlane(mSliceProxy->getComputer().getPlaneType(), false, Vector3D(0, 0, 1), true, viewHeight, anyplaneViewOffset, true); DoubleBoundingBox3D BB_vp = getViewport(); Transform3D vpMs = mView->get_vpMs(); DoubleBoundingBox3D BB_s = transform(vpMs.inv(), BB_vp); PLANE_TYPE plane = mSliceProxy->getComputer().getPlaneType(); mToolRep2D->setViewportData(vpMs, BB_vp); if (mSlicePlanes3DMarker) { mSlicePlanes3DMarker->getProxy()->setViewportData(plane, mSliceProxy, BB_s); } mViewFollower->setView(BB_s); }
// Executed on the UI IFrameLayerAndroid* BackgroundImagePositioning::updatePosition(SkRect aViewport, IFrameLayerAndroid* parentIframeLayer) { SkRect viewport = getViewport(aViewport, parentIframeLayer); float w = viewport.width() - m_layer->getWidth(); float h = viewport.height() - m_layer->getHeight(); float x = 0; float y = 0; if (m_fixedLeft.defined()) x += m_fixedLeft.calcFloatValue(w); if (m_fixedTop.defined()) y += m_fixedTop.calcFloatValue(h); m_nbRepeatX = ceilf((viewport.width() / m_layer->getWidth()) + 1); m_offsetX = ceilf(x / m_layer->getWidth()); m_nbRepeatY = ceilf((viewport.height() / m_layer->getHeight()) + 1); m_offsetY = ceilf(y / m_layer->getHeight()); x += viewport.fLeft; y += viewport.fTop; m_layer->setPosition(x, y); return parentIframeLayer; }
void Channel::_drawHelp() { const FrameData& frameData = _getFrameData(); std::string message = frameData.getMessage(); if( !frameData.showHelp() && message.empty( )) return; applyOverlayState(); const eq::PixelViewport& pvp = getPixelViewport(); const eq::Viewport& vp = getViewport(); const float height = pvp.h / vp.h; if( !message.empty( )) { const eq::util::BitmapFont* font = getWindow()->getMediumFont(); const float width = pvp.w / vp.w; const float xOffset = vp.x * width; const float yOffset = vp.y * height; const float yPos = 0.618f * height; float y = yPos - yOffset; for( size_t pos = message.find( '\n' ); pos != std::string::npos; pos = message.find( '\n' )) { glRasterPos3f( 10.f - xOffset, y, 0.99f ); font->draw( message.substr( 0, pos )); message = message.substr( pos + 1 ); y -= 22.f; } // last line glRasterPos3f( 10.f - xOffset, y, 0.99f ); font->draw( message ); } if( frameData.showHelp( )) { const eq::util::BitmapFont* font = getWindow()->getSmallFont(); std::string help = EqPly::getHelp(); float y = height - 16.f; for( size_t pos = help.find( '\n' ); pos != std::string::npos; pos = help.find( '\n' )) { glRasterPos3f( 10.f, y, 0.99f ); font->draw( help.substr( 0, pos )); help = help.substr( pos + 1 ); y -= 16.f; } // last line glRasterPos3f( 10.f, y, 0.99f ); font->draw( help ); } resetOverlayState(); }
SystemPainter::~SystemPainter() { SAFEDELETE(m_xAxisPainter); SAFEDELETE(m_yAxisPainter); if(m_oldFont) { CDC *dc = getViewport().getDC(); dc->SelectObject(m_oldFont); } }
void LayerManager::updateRequest(QRectF rect) { const QPoint topleft = mapmiddle_px - screenmiddle; QPointF c = rect.topLeft(); if (getViewport().contains(c) || getViewport().contains(rect.bottomRight())) { // QPoint point = getLayer()->getMapAdapter()->coordinateToDisplay(c); // QPoint finalpoint = point-topleft; // QRect rect_px = QRect(int(finalpoint.x()-(rect.width()-1)/2), int(finalpoint.y()-(rect.height()-1)/2), // int(rect.width()+1), int(rect.height()+1)); // // mapcontrol->updateRequest(rect_px); mapcontrol->update(); // newOffscreenImage(); } }
void CIntuitiveEditorView::OnMouseLeave() { m_bMouseTracking = false; IViewport* pViewport = getViewport(); pViewport->onMouseLeave(); CView::OnMouseLeave(); }
BOOL CIntuitiveEditorView::OnDrop(COleDataObject* pDataObject, DROPEFFECT dropEffect, CPoint point) { bool ret = false; CUIManager::getInstance()->eventDrop(getViewport(), CIWEPoint<int>(point.x, point.y), [&ret](bool b) { if (b) ret = true; }); return (!ret) ? CView::OnDrop(pDataObject, dropEffect, point) : true; }
DROPEFFECT CIntuitiveEditorView::OnDragOver(COleDataObject* pDataObject, DWORD dwKeyState, CPoint point) { e_dropEffect ret = UI_DROPEFFECT_NONE; CUIManager::getInstance()->eventDragOver(getViewport(), CIWEPoint<int>(point.x, point.y), [&ret](e_dropEffect e) { if (e != UI_DROPEFFECT_NONE) ret = e; }); return (ret == UI_DROPEFFECT_NONE) ? CView::OnDragOver(pDataObject, dwKeyState, point) : getDropEffect(ret); }
LRESULT CIntuitiveEditorView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { if (message == WM_MOUSELEAVE) { IViewport* pViewport = getViewport(); pViewport->onMouseLeave(); } return CView::WindowProc(message, wParam, lParam); }
void CIntuitiveEditorView::OnShowWindow(BOOL bShow, UINT nStatus) { CView::OnShowWindow(bShow, nStatus); IViewport* pViewport = getViewport(); if (!pViewport) return; pViewport->showWindow(bShow); }
/// Convert a point from target coordinates to the view coordinates Vec2f Window::convertCoords(const Vec2i &point, const View &view){ // First, convert from viewport coordinates to homogeneous coordinates Vec2f coords; IntRect viewport = getViewport(view); coords.x = -1.f + 2.f * (point.x - viewport.left) / viewport.width; coords.y = 1.f - 2.f * (point.y - viewport.top) / viewport.height; // Then transform by the inverse of the view matrix return view.getInverseTransform().transformPoint(coords); };
void CRenderSystem::GetPickRay(Vec3D& vRayPos, Vec3D& vRayDir,int x, int y) { Matrix mProj; getProjectionMatrix(mProj); CRect<int> rc; getViewport(rc); Matrix mView; getViewMatrix(mView); ::GetPickRay(vRayPos,vRayDir,x,y,mView,mProj,rc.getRECT()); }