Ejemplo n.º 1
0
BOOL CArcView::IntersectsWithRect(const Rect& rectangle)
{
	Point topLeft(rectangle.GetLeft(), rectangle.GetTop());
	Point topRight(rectangle.GetRight(), rectangle.GetTop());
	Point bottomLeft(rectangle.GetLeft(), rectangle.GetBottom());
	Point bottomRight(rectangle.GetRight(), rectangle.GetBottom());

	Point currentPoint(*pathPoints.begin());
	for(auto it=pathPoints.begin() + 1; it != pathPoints.end(); ++it)
	{
		if(rectangle.Contains(currentPoint))
			return TRUE;
		if(Geometry::LinesIntersect(topLeft, topRight, currentPoint, *it))
			return TRUE;
		if(Geometry::LinesIntersect(topLeft, bottomLeft, currentPoint, *it))
			return TRUE;
		if(Geometry::LinesIntersect(bottomLeft, bottomRight, currentPoint, *it))
			return TRUE;
		if(Geometry::LinesIntersect(topRight, bottomRight, currentPoint, *it))
			return TRUE;

		currentPoint = *it;
	}

	return FALSE;
}
void tst_QOpenGL::textureblitterPartTargetRectTransform()
{
    QVector4D topLeft(-1.f, 1.f, 0.f, 1.f);
    QVector4D bottomLeft(-1.f, -1.f, 0.f, 1.f);
    QVector4D topRight(1.f, 1.f, 0.f, 1.f);
    QVector4D bottomRight(1.f, -1.f, 0.f, 1.f);

    QRectF targetRect(50,50,200,200);
    QRect viewport(0,0,400,400);

    //multiply by 2 since coordinate system goes from -1 -> 1;
    qreal x_point_ratio = (50. / 400.) * 2;
    qreal y_point_ratio = (50. / 400.) * 2;
    qreal width_ratio = (200. / 400.) * 2;
    qreal height_ratio = (200. / 400.) * 2;

    QMatrix4x4 targetMatrix = QOpenGLTextureBlitter::targetTransform(targetRect, viewport);

    QVector4D targetTopLeft = targetMatrix * topLeft;
    QVector4D expectedTopLeft(-1 + x_point_ratio, 1 - y_point_ratio, .0, 1.0);
    QCOMPARE(targetTopLeft, expectedTopLeft);

    QVector4D targetBottomLeft = targetMatrix * bottomLeft;
    QVector4D expectedBottomLeft(-1 + x_point_ratio, 1 - y_point_ratio  - height_ratio, 0.0, 1.0);
    QCOMPARE(targetBottomLeft, expectedBottomLeft);

    QVector4D targetTopRight = targetMatrix * topRight;
    QVector4D expectedTopRight(-1 + x_point_ratio + width_ratio, 1 - y_point_ratio, 0.0, 1.0);
    QCOMPARE(targetTopRight, expectedTopRight);

    QVector4D targetBottomRight = targetMatrix * bottomRight;
    QVector4D expectedBottomRight(-1 + x_point_ratio + width_ratio, 1 - y_point_ratio - height_ratio, 0.0, 1.0);
    QCOMPARE(targetBottomRight, expectedBottomRight);
}
Ejemplo n.º 3
0
void BoundingBoxDoorVisual::generateWireframe() {
    delete m_wireframe;
    m_wireframe = new rviz::BillboardLine(m_sceneManager, m_sceneNode);

    m_wireframe->setLineWidth(m_lineWidth);
    m_wireframe->setMaxPointsPerLine(2);
    m_wireframe->setNumLines(12);

    double w = m_width, h = m_height;
    Ogre::Vector3 bottomLeft(0, -w, 0), bottomRight(0, 0, 0), topLeft(0, -w, h), topRight(0, 0, h);
    Ogre::Vector3 rear(m_thickness, 0, 0);

    // Front quad
                                m_wireframe->addPoint(bottomLeft);          m_wireframe->addPoint(bottomRight);
    m_wireframe->newLine();     m_wireframe->addPoint(bottomRight);         m_wireframe->addPoint(topRight);
    m_wireframe->newLine();     m_wireframe->addPoint(topRight);            m_wireframe->addPoint(topLeft);
    m_wireframe->newLine();     m_wireframe->addPoint(topLeft);             m_wireframe->addPoint(bottomLeft);

    // Rear quad
    m_wireframe->newLine();     m_wireframe->addPoint(bottomLeft + rear);   m_wireframe->addPoint(bottomRight + rear);
    m_wireframe->newLine();     m_wireframe->addPoint(bottomRight + rear);  m_wireframe->addPoint(topRight + rear);
    m_wireframe->newLine();     m_wireframe->addPoint(topRight + rear);     m_wireframe->addPoint(topLeft + rear);
    m_wireframe->newLine();     m_wireframe->addPoint(topLeft + rear);      m_wireframe->addPoint(bottomLeft + rear);

    // Four connecting lines between front and rear
    m_wireframe->newLine();     m_wireframe->addPoint(bottomLeft);          m_wireframe->addPoint(bottomLeft + rear);
    m_wireframe->newLine();     m_wireframe->addPoint(bottomRight);         m_wireframe->addPoint(bottomRight + rear);
    m_wireframe->newLine();     m_wireframe->addPoint(topRight);            m_wireframe->addPoint(topRight + rear);
    m_wireframe->newLine();     m_wireframe->addPoint(topLeft);             m_wireframe->addPoint(topLeft + rear);

    m_wireframe->setPosition(Ogre::Vector3(0, 0, 0));
//    Ogre::Quaternion orientation;
//    orientation.FromRotationMatrix(R_do);
//    m_wireframe->setOrientation(orientation);
}
Ejemplo n.º 4
0
// draw window shadow
void Widget::paintEvent(QPaintEvent *e)
{
    QPainter painter(this);

    QRect bottom(5, 136, 200, 7);
    QRect top(5, 0, 200, 3);
    QRect left(0, 3, 5, 133);
    QRect right(205, 3, 5, 133);
    QRect topRight(205, 0, 5, 3);
    QRect topLeft(0, 0, 5, 3);
    QRect bottomLeft(0, 136, 5, 7);
    QRect bottomRight(205, 136, 5, 7);

    QRect tBottom(5, this->height() - 7, this->width() - 10, 7);
    QRect tTop(5, 0, this->width() - 10, 3);
    QRect tLeft(0, 3, 5, this->height() - 10);
    QRect tRight(this->width() - 5, 3, 5, this->height() - 10);
    QRect tTopLeft(0, 0, 5, 3);
    QRect tTopRight(this->width() - 5, 0, 5, 3);
    QRect tBottomLeft(0, this->height() - 7, 5, 7);
    QRect tBottomRight(this->width() - 5, this->height() - 7, 5, 7);

    painter.drawPixmap(tBottom, m_shadow, bottom);
    painter.drawPixmap(tTop, m_shadow, top);
    painter.drawPixmap(tLeft, m_shadow, left);
    painter.drawPixmap(tRight, m_shadow, right);
    painter.drawPixmap(tTopRight, m_shadow, topRight);
    painter.drawPixmap(tTopLeft, m_shadow, topLeft);
    painter.drawPixmap(tBottomLeft, m_shadow, bottomLeft);
    painter.drawPixmap(tBottomRight, m_shadow, bottomRight);
}
Ejemplo n.º 5
0
IRect ScaleManager::GetScaledRect() {
	FPoint topRigth(Core::screen.GLWidth(), Core::screen.GLHeight());
	FPoint bottomLeft(0, 0);
	topRigth = GetPointScaled(topRigth);
	bottomLeft = GetPointScaled(bottomLeft);
	return IRect(bottomLeft.x, bottomLeft.y, topRigth.x, topRigth.y);
}
Ejemplo n.º 6
0
QPainterPath DArrowRectangle::getBottomCornerPath()
{
    qreal delta = shadowBlurRadius() + shadowDistance();

    QRect rect = this->rect().marginsRemoved(QMargins(delta, delta, delta, delta));

    QPoint cornerPoint(rect.x() + (m_arrowX > 0 ? m_arrowX : rect.width() / 2), rect.y()  + rect.height());
    QPoint topLeft(rect.x(), rect.y());
    QPoint topRight(rect.x() + rect.width(), rect.y());
    QPoint bottomRight(rect.x() + rect.width(), rect.y() + rect.height() - m_arrowHeight);
    QPoint bottomLeft(rect.x(), rect.y() + rect.height() - m_arrowHeight);
    int radius = this->m_radius > (rect.height() / 2 - m_arrowHeight) ? rect.height() / 2 -m_arrowHeight : this->m_radius;

    QPainterPath border;
    border.moveTo(topLeft.x() + radius, topLeft.y());
    border.lineTo(topRight.x() - radius, topRight.y());
    border.arcTo(topRight.x() - 2 * radius, topRight.y(), 2 * radius, 2 * radius, 90, -90);
    border.lineTo(bottomRight.x(), bottomRight.y() - radius);
    border.arcTo(bottomRight.x() - 2 * radius, bottomRight.y() - 2 * radius, 2 * radius, 2 * radius, 0, -90);
    border.lineTo(cornerPoint.x() + m_arrowWidth / 2, cornerPoint.y() - m_arrowHeight);
    border.lineTo(cornerPoint);
    border.lineTo(cornerPoint.x() - m_arrowWidth / 2, cornerPoint.y() - m_arrowHeight);
    border.lineTo(bottomLeft.x() + radius, bottomLeft.y());
    border.arcTo(bottomLeft.x(), bottomLeft.y() - 2 * radius, 2 * radius, 2 * radius, -90, -90);
    border.lineTo(topLeft.x(), topLeft.y() + radius);
    border.arcTo(topLeft.x(), topLeft.y(), 2 * radius, 2 * radius, 180, -90);

    return border;
}
Ejemplo n.º 7
0
//--------------------------------------------------------------
void testApp::draw(){
	
	ofBackgroundGradient(ofColor(50), ofColor(0));
	//------
	//draw the scene
	//
	if (usePreview){
		previewCamera.begin();
	}
	else{
		headTrackedCamera.begin();
	}
	
	drawScene(usePreview);
	
	if (usePreview){
		previewCamera.end();
	}
	else{
		headTrackedCamera.end();
	}
	//
	//------
	
	
	//------
	//draw some overlays
	//
	video.draw(0, 0);
	ofPushStyle();
	ofNoFill();
	for(int i = 0; i < finder.blobs.size(); i++) {
		ofRectangle cur = finder.blobs[i].boundingRect;
		ofRect(cur.x, cur.y, cur.width, cur.height);
	}
	ofPopStyle();
	
	stringstream message;
	message << "[SPACE] = User preview camera [" << (usePreview ? 'x' : ' ') << "]";
	
	ofDrawBitmapString(message.str(), video.getWidth() + 10, 20);
	
	if (usePreview){
		ofRectangle bottomLeft(0, ofGetHeight() - 200.0f, 300.0f, 200.0f);
		
		ofPushStyle();
		ofSetColor(0);
		ofRect(bottomLeft);
		ofPopStyle();
		
		headTrackedCamera.begin(bottomLeft);
		drawScene(false);
		headTrackedCamera.end();
	}
	//
	//------
}
Ejemplo n.º 8
0
QRectF GraphConnection::getBoundingRect(void) const
{
    QVector<QPointF> points = _impl->points;
    const auto arrowRect = _impl->arrowHead.boundingRect();
    points.push_back(arrowRect.topLeft());
    points.push_back(arrowRect.topRight());
    points.push_back(arrowRect.bottomRight());
    points.push_back(arrowRect.bottomLeft());
    return QPolygonF(points).boundingRect();
}
Ejemplo n.º 9
0
	Rect GeomUtils::outside(const Rect& rect1, const Rect& rect2) {
		Point bottomLeft(MIN(rect1.getMinX(), rect2.getMinX()),
										 MIN(rect1.getMinY(), rect2.getMinY()));
		Point topRight(MAX(rect1.getMaxX(), rect2.getMaxX()),
									 MAX(rect1.getMaxY(), rect2.getMaxY()));
		return Rect(bottomLeft.x,
								bottomLeft.y,
								topRight.x - bottomLeft.x,
								topRight.y - bottomLeft.y);
	}
Ejemplo n.º 10
0
void TableSideSelector::paintEvent(QPaintEvent* event)
{
	double edgeWidth = 5;
	double inset = edgeWidth/2 + frameWidth()*2;

	QPointF topLeft(inset, inset);
	QPointF topRight(width() - inset, inset);
	QPointF bottomLeft(inset, height() - inset);
	QPointF bottomRight(width() - inset, height() - inset);

	m_left = QLineF(topLeft, bottomLeft);
	m_right = QLineF(topRight, bottomRight);
	m_top = QLineF(topRight, topLeft);
	m_bottom = QLineF(bottomRight, bottomLeft);

	QPainter painter(this);

	// Paint selection.
	painter.setPen(QPen(Qt::black, edgeWidth, Qt::SolidLine, Qt::RoundCap));
	if (m_selection & Left) painter.drawLine(m_left);
	if (m_selection & Right) painter.drawLine(m_right);
	if (m_selection & Top) painter.drawLine(m_top);
	if (m_selection & Bottom) painter.drawLine(m_bottom);

	// Paint the dotted grid.
	painter.setPen(QPen(Qt::gray, edgeWidth/4, Qt::DotLine));
	painter.drawRect(QRectF(topLeft, bottomRight));
	painter.drawLine(m_left.pointAt(0.5), m_right.pointAt(0.5));
	painter.drawLine(m_top.pointAt(0.5), m_bottom.pointAt(0.5));

	// Paint highlighting.
	painter.setPen(QPen(QColor(255, 255, 255, 60), edgeWidth, Qt::SolidLine, Qt::RoundCap));
	switch (m_highlighted)
	{
	case Left:
		painter.drawLine(m_left);
		break;
	case Right:
		painter.drawLine(m_right);
		break;
	case Top:
		painter.drawLine(m_top);
		break;
	case Bottom:
		painter.drawLine(m_bottom);
		break;
	default:
		break;
	}
}
Ejemplo n.º 11
0
// 获取矩形范围内,所有四叉树的所有物体
// 如果这个矩形是完全处于一个四叉树中的,那么跟Retrieve返回的结果一样
// 如果这个矩形处于多个四叉树中,那么需要获取它所在的四叉树,以及它四个点所在四叉树的物体
void FixedQuadTree::RetrieveArea(const plane_shooting::Rectangle& rect, list<Object*>& objList) {
	Retrieve(rect, objList);

	// 左上顶点
	Rectangle topLeft(rect.x - rect.fWidth / 2, rect.y + rect.fHeight / 2, 0, 1);
	// 右上顶点
	Rectangle topRight(rect.x + rect.fWidth / 2, rect.y + rect.fHeight / 2, 0, 1);
	// 左下顶点
	Rectangle bottomLeft(rect.x - rect.fWidth / 2, rect.y - rect.fHeight / 2, 0, 1);
	// 右下顶点
	Rectangle bottomRight(rect.x + rect.fWidth / 2, rect.y - rect.fHeight / 2, 0, 1);

	// TODO , 改成直接返回list<Object*>列表指针
}
Ejemplo n.º 12
0
QPoint HintsWidgetPositioner::positionForSize(QSize size)
{
	auto availableGeometry = QApplication::desktop()->availableGeometry(m_hintsWidget);
	switch (m_hintsConfiguration->corner())
	{
		case HintsConfiguration::Corner::TopLeft:
			return availableGeometry.topLeft() + QPoint{8, 8};
		case HintsConfiguration::Corner::TopRight:
			return availableGeometry.topRight() + QPoint{-8 - size.width(), 8};
		case HintsConfiguration::Corner::BottomLeft:
			return availableGeometry.bottomLeft() + QPoint{8, -8 - size.height()};
		case HintsConfiguration::Corner::BottomRight:
		default:
			return availableGeometry.bottomRight() + QPoint{-8 - size.width(), -8 - size.height()};
	}
}
Ejemplo n.º 13
0
void ScriptEditorCloseButton::paint(QPainter* p,
                                    const QStyleOptionGraphicsItem* o,
                                    QWidget* w)
{
    Q_UNUSED(o);
    Q_UNUSED(w);

    auto br = boundingRect();
    p->setPen(QPen(Colors::base06, 3));

    int offset = 6;
    p->drawLine(br.bottomLeft() + QPointF(offset, -offset),
                br.topRight() - QPointF(offset, -offset));
    p->drawLine(br.topLeft() + QPointF(offset, offset),
                br.bottomRight() - QPointF(offset, offset));
}
Ejemplo n.º 14
0
Prism::DebugFont::CharacterData Prism::DebugFont::GetCharData(char aChar)
{
	int x = aChar % 16;
	int y = aChar / 16;

	
	CU::Vector2<float> topLeft(x * myCharSize.x, y * myCharSize.y);
	CU::Vector2<float> bottomLeft(topLeft.x + myCharSize.x, topLeft.y + myCharSize.y);


	CharacterData data;
	data.myTopLeftUV = topLeft / 512.f;
	data.myBottomRightUV = bottomLeft / 512.f;

	return data;
}
Ejemplo n.º 15
0
bool TagsEditor::IsWindowRectValid(const wxRect *windowRect) const
{
   wxDisplay display;
   wxPoint topLeft(windowRect->GetTopLeft().x, windowRect->GetTopLeft().y);
   wxPoint topRight(windowRect->GetTopRight().x, windowRect->GetTopRight().y);
   wxPoint bottomLeft(windowRect->GetBottomLeft().x, windowRect->GetBottomLeft().y);
   wxPoint bottomRight(windowRect->GetBottomRight().x, windowRect->GetBottomRight().y);
   display.GetFromPoint(topLeft);
   if (display.GetFromPoint(topLeft) == -1 &&
       display.GetFromPoint(topRight) == -1 &&
       display.GetFromPoint(bottomLeft) == -1 &&
       display.GetFromPoint(bottomRight) == -1) {
      return false;
   }

   return true;
}
Ejemplo n.º 16
0
TEST_F(BoxTests, InitialiseWithTwoOppositeCorners)
{
	Point topLeft(2, 2), bottomRight(4, 0);

	expect(Box(topLeft, 2, 2));
	Box b(topLeft, bottomRight);
	compareBoxes(b);
	
	b = Box(bottomRight, topLeft);
	compareBoxes(b);

	Point topRight(4, 2), bottomLeft(2, 0);
	b = Box(topRight, bottomLeft);
	compareBoxes(b);

	b = Box(bottomLeft, topRight);
	compareBoxes(b);
}
Ejemplo n.º 17
0
void dftshift(ImgT& img) {
  const int cx = img.cols/2;
  const int cy = img.rows/2;
  
  ImgT tmp;
  ImgT topLeft(img, cv::Rect(0, 0, cx, cy));
  ImgT topRight(img, cv::Rect(cx, 0, cx, cy));
  ImgT bottomLeft(img, cv::Rect(0, cy, cx, cy));
  ImgT bottomRight(img, cv::Rect(cx, cy, cx, cy));
  
  topLeft.copyTo(tmp);
  bottomRight.copyTo(topLeft);
  tmp.copyTo(bottomRight);
  
  topRight.copyTo(tmp);
  bottomLeft.copyTo(topRight);
  tmp.copyTo(bottomLeft);
}
Ejemplo n.º 18
0
void TennisFieldCalibrator::renderCalibrationWindow(Mat calibrationFrame, double h, double basis_min, double basis_maj, double h_displacement)
{
	Point center = Point(calibrationFrame.cols/2, calibrationFrame.rows/2);

	Point bottomLeft(center.x-(basis_maj/2), center.y+(h/2)+h_displacement);
	Point bottomRight(center.x+(basis_maj/2), center.y+(h/2)+h_displacement);
	Point topLeft(center.x-(basis_min/2), center.y-(h/2)+h_displacement);
	Point topRight(center.x+(basis_min/2), center.y-(h/2)+h_displacement);

	line(calibrationFrame, bottomLeft, bottomRight, Scalar(0, 255, 0), 2);
	line(calibrationFrame, bottomRight, topRight, Scalar(0, 255, 0), 2);
	line(calibrationFrame, topRight, topLeft, Scalar(0, 255, 0), 2);
	line(calibrationFrame, topLeft, bottomLeft, Scalar(0, 255, 0), 2);

	char buffer[300];
	sprintf(buffer, "PARAM: h=%g m=%g M=%g h_displacement=%g", h, basis_min, basis_maj, h_displacement);
	putText(calibrationFrame, buffer, cvPoint(10,30), FONT_HERSHEY_SIMPLEX, 1.0, cvScalar(50, 205, 50), 1, CV_AA);
}
Ejemplo n.º 19
0
void dftshift(cv::Mat_<float>& magnitude) {
  const int cx = magnitude.cols/2;
  const int cy = magnitude.rows/2;
  
  cv::Mat_<float> tmp;
  cv::Mat_<float> topLeft(magnitude, cv::Rect(0, 0, cx, cy));
  cv::Mat_<float> topRight(magnitude, cv::Rect(cx, 0, cx, cy));
  cv::Mat_<float> bottomLeft(magnitude, cv::Rect(0, cy, cx, cy));
  cv::Mat_<float> bottomRight(magnitude, cv::Rect(cx, cy, cx, cy));
  
  topLeft.copyTo(tmp);
  bottomRight.copyTo(topLeft);
  tmp.copyTo(bottomRight);
  
  topRight.copyTo(tmp);
  bottomLeft.copyTo(topRight);
  tmp.copyTo(bottomLeft);
}
Ejemplo n.º 20
0
void StGeometryTest::resizeBrightness() {
    static const size_t BR_QUADS = 11;
    static const size_t VERT_PER_QUAD = 6;
    StGLContext& aCtx = getContext();
    StGLVec2 rectSize(myCellSize.x(), 2.0f * myCellSize.y());

    // move to the center
    StGLVec2 bottomLeft(-1.0f + 0.5f * (2.0f - GLfloat(BR_QUADS) * rectSize.x()),
                        -1.0f + rectSize.y());

    GLfloat anYBottom = bottomLeft.y()                + 4.0f * myPixelSize.x();
    GLfloat anYTop    = bottomLeft.y() + rectSize.y() - 4.0f * myPixelSize.x();

    // setup vertices
    StArray<StGLVec4> aVertArray(BR_QUADS * VERT_PER_QUAD);
    for(size_t quadId = 0; quadId < BR_QUADS; ++quadId) {
        GLfloat anXLeft  = bottomLeft.x() + GLfloat(quadId + 0) * rectSize.x() + 4.0f * myPixelSize.x();
        GLfloat anXRight = bottomLeft.x() + GLfloat(quadId + 1) * rectSize.x() - 4.0f * myPixelSize.x();
        aVertArray[quadId * VERT_PER_QUAD + 0] = StGLVec4(anXLeft,  anYBottom, 0.0f, 1.0f);
        aVertArray[quadId * VERT_PER_QUAD + 1] = StGLVec4(anXRight, anYBottom, 0.0f, 1.0f);
        aVertArray[quadId * VERT_PER_QUAD + 2] = StGLVec4(anXRight, anYTop,    0.0f, 1.0f);
        aVertArray[quadId * VERT_PER_QUAD + 3] = StGLVec4(anXRight, anYTop,    0.0f, 1.0f);
        aVertArray[quadId * VERT_PER_QUAD + 4] = StGLVec4(anXLeft,  anYBottom, 0.0f, 1.0f);
        aVertArray[quadId * VERT_PER_QUAD + 5] = StGLVec4(anXLeft,  anYTop,    0.0f, 1.0f);
    }
    myBrightness.changeVBO(ST_VBO_VERTEX)->init(aCtx, aVertArray);

    // setup color (increased brightness): 3% 10% 20% 30% ... 100%
    StArray<StGLVec4> aColorsArray(BR_QUADS * VERT_PER_QUAD);
    StGLVec4 aColor(0.03f, 0.03f, 0.03f, 1.0f);
    StGLVec4 aColorDelta(0.1f, 0.1f, 0.1f, 1.0f);
    for(size_t quadId = 0; quadId < BR_QUADS; ++quadId) {
        setValues(aColorsArray, aColor, quadId * VERT_PER_QUAD, VERT_PER_QUAD);
        if(quadId == 0) {
            aColor  = aColorDelta;
        } else {
            aColor += aColorDelta;
        }
    }
    myBrightness.changeVBO(ST_VBO_COLORS)->init(aCtx, aColorsArray);
}
Ejemplo n.º 21
0
void Sprite::changeTexturePosition()
{
	vector2f topLeft(sourceRectPosition.x, sourceRectPosition.y);
	vector2f bottomLeft(sourceRectPosition.x, sourceRectPosition.y + sourceRectSize.y);
	vector2f topRight(sourceRectPosition.x + sourceRectSize.x, sourceRectPosition.y);
	vector2f bottomRight(sourceRectPosition.x + sourceRectSize.x, sourceRectPosition.y + sourceRectSize.y);

	VERTEX_DATA[5] = topLeft.x;
	VERTEX_DATA[6] = topLeft.y;

	VERTEX_DATA[5 + 7] = bottomLeft.x;
	VERTEX_DATA[6 + 7] = bottomLeft.y;

	VERTEX_DATA[5 + 14] =  topRight.x;
	VERTEX_DATA[6 + 14] = topRight.y;

	VERTEX_DATA[5 + 21] =  bottomRight.x;
	VERTEX_DATA[6 + 21] =  bottomRight.y;

	texturePositionChanged = false;
}
Ejemplo n.º 22
0
QPainterPath CornersInWipeStrategy::clipPath(int step, const QRect &area)
{
    int width_2 = area.width() >> 1;
    int height_2 = area.height() >> 1;

    qreal percent = static_cast<qreal>(step) / static_cast<qreal>(StepCount);
    int stepx = static_cast<int>(width_2 * percent);
    int stepy = static_cast<int>(height_2 * percent);

    QPainterPath path;

    if(! reverse())
    {
        QSize rectSize(stepx, stepy);

        QRect topLeft(area.topLeft(), rectSize);
        QRect topRight(area.topRight() - QPoint(stepx, 0), rectSize);
        QRect bottomRight(area.bottomRight() - QPoint(stepx, stepy), rectSize);
        QRect bottomLeft(area.bottomLeft() - QPoint(0, stepy), rectSize);

        path.addRect(topLeft);
        path.addRect(topRight);
        path.addRect(bottomRight);
        path.addRect(bottomLeft);
    }
    else
    {
        QRect horzRect(QPoint(0, 0), QSize(2 * stepx, area.height()));
        horzRect.moveCenter(area.center());
        QRect vertRect(QPoint(0, 0), QSize(area.width(), 2 * stepy));
        vertRect.moveCenter(area.center());

        path.addRect(horzRect);
        path.addRect(vertRect);
        path.setFillRule(Qt::WindingFill);
    }

    return path;
}
void tst_QOpenGL::textureblitterFullTargetRectTransform()
{
    QVector4D topLeft(-1.f, 1.f, 0.f, 1.f);
    QVector4D bottomLeft(-1.f, -1.f, 0.f, 1.f);
    QVector4D topRight(1.f, 1.f, 0.f, 1.f);
    QVector4D bottomRight(1.f, -1.f, 0.f, 1.f);

    QRectF rect(0,0,200,200);
    QMatrix4x4 targetMatrix = QOpenGLTextureBlitter::targetTransform(rect,rect.toRect());

    QVector4D translatedTopLeft = targetMatrix * topLeft;
    QCOMPARE(translatedTopLeft, topLeft);

    QVector4D translatedBottomLeft = targetMatrix * bottomLeft;
    QCOMPARE(translatedBottomLeft, bottomLeft);

    QVector4D translatedTopRight = targetMatrix * topRight;
    QCOMPARE(translatedTopRight, topRight);

    QVector4D translatedBottomRight = targetMatrix * bottomRight;
    QCOMPARE(translatedBottomRight, bottomRight);
}
Ejemplo n.º 24
0
BOOL CCircleView::IntersectsWithRect(const Rect& rectangle)
{
	Point center(position);

	double edgeCenterDistance = INT_MAX;
	std::vector<Point> rectCorners;
	Point topLeft(rectangle.GetLeft(), rectangle.GetTop());
	Point topRight(rectangle.GetRight(), rectangle.GetTop());
	Point bottomLeft(rectangle.GetLeft(), rectangle.GetBottom());
	Point bottomRight(rectangle.GetRight(), rectangle.GetBottom());

	rectCorners.push_back(topLeft);
	rectCorners.push_back(topRight);
	rectCorners.push_back(bottomLeft);
	rectCorners.push_back(bottomRight);

	//Le centre du cercle est-il dans le rectangle ?
	if(rectangle.Contains(center)) return TRUE;

	//Un coin du rectangle est-il dans le cercle ?
	for(auto it=rectCorners.begin(); it!=rectCorners.end(); ++it)
		if(Geometry::Distance(*it, center) < radius) return TRUE;

	//Un côté du rectangle coupe-t-il dans le cercle ?
	if(topLeft.X < center.X && center.X < topRight.X
		&& Geometry::LinePointDistance(topLeft, topRight, center) < radius)
		return TRUE;
	if(topLeft.Y < center.Y && center.Y < bottomLeft.Y
		&& Geometry::LinePointDistance(topLeft, bottomLeft, center) < radius)
		return TRUE;
	if(bottomLeft.X < center.X && center.X < bottomRight.X
		&& Geometry::LinePointDistance(bottomLeft, bottomRight, center) < radius)
		return TRUE;
	if(topRight.Y < center.Y && center.Y < bottomRight.Y
		&& Geometry::LinePointDistance(topRight, bottomRight, center) < radius)
		return TRUE;

	return FALSE;
}
Ejemplo n.º 25
0
void StGeometryTest::resizeColor() {
    static const size_t COLOR_QUADS   = 8;
    static const size_t VERT_PER_QUAD = 6;
    StGLContext& aCtx = getContext();
    StGLVec2 rectSize(myCellSize.x(), 2.0f * myCellSize.y());

    // move to the center
    StGLVec2 bottomLeft(-1.0f + 0.5f * (2.0f - GLfloat(COLOR_QUADS) * rectSize.x()),
                        -1.0f + 2.0f * rectSize.y());

    GLfloat anYBottom = bottomLeft.y()                + 4.0f * myPixelSize.x();
    GLfloat anYTop    = bottomLeft.y() + rectSize.y() - 4.0f * myPixelSize.x();

    // setup vertices
    StArray<StGLVec4> aVertArray(COLOR_QUADS * VERT_PER_QUAD);
    for(size_t quadId = 0; quadId < COLOR_QUADS; ++quadId) {
        GLfloat anXLeft  = bottomLeft.x() + GLfloat(quadId + 0) * rectSize.x() + 4.0f * myPixelSize.x();
        GLfloat anXRight = bottomLeft.x() + GLfloat(quadId + 1) * rectSize.x() - 4.0f * myPixelSize.x();
        aVertArray[quadId * VERT_PER_QUAD + 0] = StGLVec4(anXLeft,  anYBottom, 0.0f, 1.0f);
        aVertArray[quadId * VERT_PER_QUAD + 1] = StGLVec4(anXRight, anYBottom, 0.0f, 1.0f);
        aVertArray[quadId * VERT_PER_QUAD + 2] = StGLVec4(anXRight, anYTop,    0.0f, 1.0f);
        aVertArray[quadId * VERT_PER_QUAD + 3] = StGLVec4(anXRight, anYTop,    0.0f, 1.0f);
        aVertArray[quadId * VERT_PER_QUAD + 4] = StGLVec4(anXLeft,  anYBottom, 0.0f, 1.0f);
        aVertArray[quadId * VERT_PER_QUAD + 5] = StGLVec4(anXLeft,  anYTop,    0.0f, 1.0f);
    }
    myColors.changeVBO(ST_VBO_VERTEX)->init(aCtx, aVertArray);

    // setup color
    StArray<StGLVec4> aColorsArray(COLOR_QUADS * VERT_PER_QUAD);
    setValues(aColorsArray, StGLVec4(0.0f, 0.0f, 1.0f, 1.0f), 0 * VERT_PER_QUAD, VERT_PER_QUAD); // blue
    setValues(aColorsArray, StGLVec4(0.0f, 1.0f, 1.0f, 1.0f), 1 * VERT_PER_QUAD, VERT_PER_QUAD); // aqua
    setValues(aColorsArray, StGLVec4(1.0f, 0.0f, 1.0f, 1.0f), 2 * VERT_PER_QUAD, VERT_PER_QUAD); // fuchsia
    setValues(aColorsArray, StGLVec4(1.0f, 0.0f, 0.5f, 1.0f), 3 * VERT_PER_QUAD, VERT_PER_QUAD); // ?
    setValues(aColorsArray, StGLVec4(1.0f, 0.0f, 0.0f, 1.0f), 4 * VERT_PER_QUAD, VERT_PER_QUAD); // red
    setValues(aColorsArray, StGLVec4(1.0f, 0.5f, 0.0f, 1.0f), 5 * VERT_PER_QUAD, VERT_PER_QUAD); // orange
    setValues(aColorsArray, StGLVec4(1.0f, 1.0f, 0.0f, 1.0f), 6 * VERT_PER_QUAD, VERT_PER_QUAD); // yellow
    setValues(aColorsArray, StGLVec4(0.0f, 1.0f, 0.0f, 1.0f), 7 * VERT_PER_QUAD, VERT_PER_QUAD); // green
    myColors.changeVBO(ST_VBO_COLORS)->init(aCtx, aColorsArray);
}
Ejemplo n.º 26
0
    /**
     * @brief Entity::drawResizeCorner
     * @param painter
     */
    void Entity::drawResizeCorner(QPainter *painter)
    {
        painter->save();

        painter->setRenderHint(QPainter::Antialiasing);

        painter->setPen(typeColor());

        QRectF rect(resizeCornerRect());
        QPointF bottomLeft(rect.bottomLeft());
        QPointF topRight(rect.topRight());

        // Draw hypotenuse
        painter->drawLine(bottomLeft, topRight);

        // Draw middle line
        bottomLeft.rx() += rect.width() / 2;
        topRight.ry() += rect.height() / 2;
        painter->drawLine(bottomLeft, topRight);

        painter->restore();
    }
Ejemplo n.º 27
0
void HitEffect::run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext) {
    assert(renderContext->args);
    assert(renderContext->args->hasViewFrustum());
    RenderArgs* args = renderContext->args;

    gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {

        glm::mat4 projMat;
        Transform viewMat;
        args->getViewFrustum().evalProjectionMatrix(projMat);
        args->getViewFrustum().evalViewTransform(viewMat);
        batch.setProjectionTransform(projMat);
        batch.setViewTransform(viewMat);
        batch.setModelTransform(Transform());

        batch.setPipeline(getHitEffectPipeline());

        glm::vec4 color(0.0f, 0.0f, 0.0f, 1.0f);
        glm::vec2 bottomLeft(-1.0f, -1.0f);
        glm::vec2 topRight(1.0f, 1.0f);
        DependencyManager::get<GeometryCache>()->renderQuad(batch, bottomLeft, topRight, color);
    });
}
void tst_QOpenGL::textureblitterPartOriginTopLeftSourceRectTransform()
{
    TestVertex3D topLeft(uv_top_left);
    TestVertex3D bottomLeft(uv_bottom_left);
    TestVertex3D topRight(uv_top_right);
    TestVertex3D bottomRight(uv_bottom_right);

    QRectF sourceRect(50,190,170,170);
    QSize textureSize(400,400);

    QMatrix3x3 sourceMatrix = QOpenGLTextureBlitter::sourceTransform(sourceRect, textureSize, QOpenGLTextureBlitter::OriginTopLeft);

    const float x_point_ratio = sourceRect.topLeft().x() / textureSize.width();
    const float y_point_ratio = sourceRect.topLeft().y() / textureSize.height();
    const float width_ratio = sourceRect.width() / textureSize.width();
    const float height_ratio = sourceRect.height() / textureSize.height();

    TestVertex3D uvTopLeft = sourceMatrix * topLeft;
    const float expected_top_left[] = { x_point_ratio, 1 - y_point_ratio - height_ratio, 1 };
    TestVertex3D expectedTopLeft(expected_top_left);
    QVERIFY(q_fuzzy_compare(uvTopLeft, expectedTopLeft));

    TestVertex3D uvBottomLeft = sourceMatrix * bottomLeft;
    const float expected_bottom_left[] = { x_point_ratio, 1 - y_point_ratio, 1 };
    TestVertex3D expectedBottomLeft(expected_bottom_left);
    QVERIFY(q_fuzzy_compare(uvBottomLeft, expectedBottomLeft));

    TestVertex3D uvTopRight = sourceMatrix * topRight;
    const float expected_top_right[] = { x_point_ratio + width_ratio, 1 - y_point_ratio - height_ratio, 1 };
    TestVertex3D expectedTopRight(expected_top_right);
    QVERIFY(q_fuzzy_compare(uvTopRight, expectedTopRight));

    TestVertex3D uvBottomRight = sourceMatrix * bottomRight;
    const float expected_bottom_right[] = { x_point_ratio + width_ratio, 1 - y_point_ratio, 1 };
    TestVertex3D expectedBottomRight(expected_bottom_right);
    QVERIFY(q_fuzzy_compare(uvBottomRight, expectedBottomRight));
}
Ejemplo n.º 29
0
void ApplicationOverlay::renderRearView(RenderArgs* renderArgs) {
    if (!qApp->isHMDMode() && Menu::getInstance()->isOptionChecked(MenuOption::MiniMirror) &&
        !Menu::getInstance()->isOptionChecked(MenuOption::FullscreenMirror)) {
        gpu::Batch& batch = *renderArgs->_batch;

        auto geometryCache = DependencyManager::get<GeometryCache>();

        auto framebuffer = DependencyManager::get<FramebufferCache>();
        auto selfieTexture = framebuffer->getSelfieFramebuffer()->getRenderBuffer(0);

        int width = renderArgs->_viewport.z;
        int height = renderArgs->_viewport.w;
        mat4 legacyProjection = glm::ortho<float>(0, width, height, 0, ORTHO_NEAR_CLIP, ORTHO_FAR_CLIP);
        batch.setProjectionTransform(legacyProjection);
        batch.setModelTransform(Transform());
        batch.setViewTransform(Transform());
        
        float screenRatio = ((float)qApp->getDevicePixelRatio());
        float renderRatio = ((float)qApp->getRenderResolutionScale());
        
        auto viewport = qApp->getMirrorViewRect();
        glm::vec2 bottomLeft(viewport.left(), viewport.top() + viewport.height());
        glm::vec2 topRight(viewport.left() + viewport.width(), viewport.top());
        bottomLeft *= screenRatio;
        topRight *= screenRatio;
        glm::vec2 texCoordMinCorner(0.0f, 0.0f);
        glm::vec2 texCoordMaxCorner(viewport.width() * renderRatio / float(selfieTexture->getWidth()), viewport.height() * renderRatio / float(selfieTexture->getHeight()));


        geometryCache->useSimpleDrawPipeline(batch, true);
        batch.setResourceTexture(0, selfieTexture);
        geometryCache->renderQuad(batch, bottomLeft, topRight, texCoordMinCorner, texCoordMaxCorner, glm::vec4(1.0f, 1.0f, 1.0f, 1.0f)); 

        batch.setResourceTexture(0, renderArgs->_whiteTexture);
        geometryCache->useSimpleDrawPipeline(batch, false);
    }
}
Ejemplo n.º 30
0
void RectTool::updateHandles()
{
	if (d->selectedLayerInfos.size() == 1 && d->mode == NoOperation)
	{
		auto rectLayer = d->selectedLayerInfos.at(0).rectLayer;
		if (rectLayer)
		{
			for (auto handle : d->handles)
				handle->setVisible(true);
			
			auto rect = rectLayer->rect();
			
			// get vertices in scene coordinates
			auto transformToWindow = canvas()->transforms()->sceneToWindow;
			auto topLeft = rect.topLeft() * transformToWindow;
			auto topRight = rect.topRight() * transformToWindow;
			auto bottomLeft = rect.bottomLeft() * transformToWindow;
			auto bottomRight = rect.bottomRight() * transformToWindow;
			
			d->findHandle(Left)->setPos( (topLeft + bottomLeft) * 0.5 );
			d->findHandle(Right)->setPos( (topRight + bottomRight) * 0.5 );
			d->findHandle(Top)->setPos( (topLeft + topRight) * 0.5 );
			d->findHandle(Bottom)->setPos( (bottomLeft + bottomRight) * 0.5 );
			
			d->findHandle(Left | Top)->setPos(topLeft);
			d->findHandle(Left | Bottom)->setPos(bottomLeft);
			d->findHandle(Right | Top)->setPos(topRight);
			d->findHandle(Right | Bottom)->setPos(bottomRight);
			
			return;
		}
	}
	
	for (auto handle : d->handles)
		handle->setVisible(false);
}