Esempio n. 1
0
void GraphicsTextItem::hitFrame(QGraphicsSceneHoverEvent *event)
{
    if(hasFocus())
    {
        //setCursor(Qt::SizeAllCursor);
        //QMessageBox::information(NULL, "info", QString(tr("hoverMoveEvent")));
        QPointF curPoint(event->scenePos());
        qreal x=curPoint.x(),y=curPoint.y();

        const QRectF parentRect = boundingRect();
        QPointF topLeft = parentRect.topLeft();
        qreal xr = pos().x();//topLeft.x();
        qreal yr = pos().y();//topLeft.y();
        qreal wr = parentRect.width();
        qreal hr = parentRect.height();

        //QMessageBox::information(NULL, "info", QString(tr("hoverEnterEvent. x: %1 y: %2 xr: %3 yr: %4 wr: %5 hr: %6")).arg(x).arg(y).arg(xr).arg(yr).arg(wr).arg(hr));

        qreal tmpMargin=3;
        if( ( ( (x>=xr && x<=(xr+tmpMargin)) || (x>=(xr+wr-tmpMargin) && x<=(xr+wr)) ) && (y>=yr && y<=(yr+hr) ))
         || ( ( (y>=yr && y<=(yr+tmpMargin)) || (y>=(yr+hr-tmpMargin) && y<=(yr+hr)) ) && (x>=xr && x<=(xr+wr) )) )
        {
            setCursor(Qt::SizeAllCursor);
            //QMessageBox::information(NULL, "info", QString(tr("hoverEnterEvent. x: %1 y: %2 xr: %3 yr: %4 wr: %5 hr: %6")).arg(x).arg(y).arg(xr).arg(yr).arg(wr).arg(hr));
            //QMessageBox::information(NULL, "info", QString(tr("hoverEnterEvent")));
        }
        else
        {
            setCursor(Qt::IBeamCursor);
        }
    }
}
Esempio n. 2
0
void previousPoint()
{
	if(cur_point_ptr==0)
	{
		printf("the first point\n");
		return;
	}
	cur_point_ptr--;
	curPoint();
}
Esempio n. 3
0
void nextPoint()
{
	if(cur_point_ptr==(point_set_cnt-1))
	{
		printf("the last point\n");
		return;
	}
	cur_point_ptr++;
	curPoint();
}
Esempio n. 4
0
void BasicOpenGLView::mouseMoveEvent(QMouseEvent *event)
{
    float eventX = (float)event->x() / width();
    float eventY = 1.0f - (float) event->y() / height();

    eventX -= 0.5f;
    eventY -= 0.5f;
    eventX *= 2.0f;
    eventY *= 2.0f;

    Vector3 curPoint(eventX, eventY);

    if(mFirstFrameDragging)
    {
        mLastMousePos = curPoint;
        mFirstFrameDragging = false;
        return;
    }

    Vector3 difference;
    for(size_t i = 0; i < 3; ++i)
    {
        difference.elements[i] = curPoint.elements[i] - mLastMousePos.elements[i];
    }

    /**
     *  @todo assignment two
     *  use the mouse input to modify mViewMatrix to work as an arc-ball interface,
     *  or to rotate the viewer in the XZ plane, depending on the selected mode in the
     *  UI (Arc Ball or World crawler)
     */

    Matrix4x4 rotationX = Matrix4x4::RotationX(-difference.elements[1]);
    Matrix4x4 rotationY = Matrix4x4::RotationY(difference.elements[0]);

    Vector3 oldForward(mViewMatrix[2], mViewMatrix[6], mViewMatrix[10]);
    oldForward.normalize();
    oldForward *= -mDistance;

    Matrix4x4 translateToOrigin = Matrix4x4::Translation(oldForward);
    mViewMatrix = mViewMatrix * translateToOrigin;

    mViewMatrix = (mViewMatrix * rotationX) * rotationY;

    Vector3 newForward(mViewMatrix[2], mViewMatrix[6], mViewMatrix[10]);
    newForward.normalize();
    newForward *= mDistance;

    Matrix4x4 translateFromOrigin = Matrix4x4::Translation(newForward);

    mViewMatrix = mViewMatrix * translateFromOrigin;

    mLastMousePos = curPoint;
}
Esempio n. 5
0
void Sphere::insertIntoGrid(Grid *g, Matrix *m)
{
#ifdef DEBUG
    printf("Sphere::insertIntoGrid.\n");
#endif
    int i;
    int j;
    int k;

    if (mpBox == NULL)
        return;

    Vec3f minp = mpBox->getMin();
    Vec3f maxp = mpBox->getMax();

    float xBox = maxp.x() - minp.x();
    float yBox = maxp.y() - minp.y();
    float zBox = maxp.z() - minp.z();

    int xSize = g->getXSize();
    int ySize = g->getYSize();
    int zSize = g->getZSize();

    float xDelta = xBox / xSize;
    float yDelta = yBox / ySize;
    float zDelta = zBox / zSize;

    for (k = 0; k < zSize; k++)
    for (j = 0; j < ySize; j++)
    for (i = 0; i < xSize; i++)
    {
        //Get the min point
        Vec3f curPoint(minp.x() + (i + 0.5)*xDelta,
                       minp.y() + (j + 0.5)*yDelta,
                       minp.z() + (k + 0.5)*zDelta );

        //Computing the distance between the voxel and the center point;
        Vec3f temp = curPoint - mCenterPoint;
        float distance = temp.Length();

        if (distance <= mRadius) {
            printf("Overlapped in %d %d %d\n", i, j, k);
            g->AddObjectToGrid(this, i, j, k);
        }
    }
    g->dumpObjectInfo();
}
Esempio n. 6
0
 void EObject::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
 {
	 if(myMode == RESIZE)
	 {
		 QPointF curPoint(event->scenePos());

		 qreal curX = margin, curY = margin, curWidth = width-margin*2, curHeight = height-margin*2;
		 qreal wChanging = curPoint.x()-lastPoint.x(), hChanging = curPoint.y()-lastPoint.y();

		 EResizeFocus::PosInHost pos = curResizeFocus->getInHost();
		 switch(pos){
			case EResizeFocus::NORTH_MIDDLE:
				curY += hChanging; curHeight-=hChanging;
				break;
			case EResizeFocus::SOUTH_MIDDLE:
				curHeight+=hChanging;
				break;
			case EResizeFocus::EAST_MIDDLE:
				curWidth+=wChanging;
				break;
			case EResizeFocus::WEST_MIDDLE:
				curX+=wChanging; curWidth-=wChanging;
				break;
			case EResizeFocus::NORTH_WEST:
				curX+=wChanging; curY+=hChanging; curWidth-=wChanging; curHeight-=hChanging;
				break;
			case EResizeFocus::SOUTH_EAST:
				curWidth+=wChanging; curHeight+=hChanging;
				break;
			case EResizeFocus::NORTH_EAST:
				curY+=hChanging; curWidth+=wChanging; curHeight-=hChanging;
				break;
			case EResizeFocus::SOUTH_WEST:
				curX+=wChanging; curWidth-=wChanging; curHeight+=hChanging;
				break;
			default:
				break;
		}
		if(curWidth < 20 ||curHeight <20) return; //!minimal size
		dashRect->setRect(curX,curY,curWidth,curHeight);
	 }
	 else
		QGraphicsItem::mouseMoveEvent(event);
 }
Esempio n. 7
0
GlyphToSVGHelper::GlyphToSVGHelper(QPainterPath path, QTransform tf)
    :m_path(path), m_transform(tf)
{
    QStringList data;
    QPointF curPos;
    for (int i = 0; i < path.elementCount(); ++i)
    {
        QPainterPath::Element cur = path.elementAt(i);
        QPointF curPoint(tf.map(cur));
        if(cur.isMoveTo())
        {
            curPos = curPoint;
            data << QString("M %1 %2").arg(curPos.x()).arg(curPos.y());
        }
        else if(cur.isLineTo())
        {
            curPos = curPoint;
            data << QString("L %1 %2").arg(curPos.x()).arg(curPos.y());
        }
        else if(cur.isCurveTo())
        {
            QPointF c1 = tf.map(path.elementAt(i + 1));
            QPointF c2 = tf.map(path.elementAt(i + 2));
            data << QString("C %1 %2 %3 %4 %5 %6")
                    .arg(curPoint.x()).arg(curPoint.y())
                    .arg(c1.x()).arg(c1.y())
                    .arg(c2.x()).arg(c2.y());

//             qDebug(data.last().toUtf8());

            i += 2;
            curPos = c2;
        }
        else
            qDebug("Unknown point type");
    }

    m_svg += QString("<path d=\"%1\" fill=\"%2\" />").arg(data.join(" ")).arg("black");

}
Esempio n. 8
0
void testApp::updateOsc() {
	ofxOscMessage message;
	message.setAddress("mouse");

	vector<ofxCvBlob>& blobs = finder.blobs;
	for(int i = 0; i < blobs.size(); i++) {
		ofxVec2f curPoint(blobs[i].centroid);
		// squeeze because the floor has a different aspect ratio than the camera
		curPoint.x = ofMap(curPoint.x, 0, 640, .15, .85);
		curPoint.y = ofMap(curPoint.y, 0, 480, 0, 1);
 
		//project forward
		message.addFloatArg(curPoint.x);
		message.addFloatArg(.8);
 
		// project upward
		message.addFloatArg(curPoint.x);
		message.addFloatArg(ofMap(curPoint.y, 0, 1, 0, .6));
	}
 
	oscSender.sendMessage(message);
}
MStatus DDConvexHullUtils::generateMayaHull(MObject &output,
                                const MPointArray &vertices,
                                const DDConvexHullUtils::hullOpts &hullOptions)
{
    // Allocate and push the vert list into the new array Mem Cleanup req.
    uint numInputVerts = vertices.length();
    double *inputVerts = new double[numInputVerts*3];
    for (uint i=0; i < numInputVerts; i++)
    {
        uint offset = i*3;
        inputVerts[offset]   = vertices[i].x;
        inputVerts[offset+1] = vertices[i].y;
        inputVerts[offset+2] = vertices[i].z;
    }
    
    // Setup the flags
    uint hullFlags = QF_DEFAULT;
    if (hullOptions.forceTriangles)
    {
        hullFlags |= QF_TRIANGLES;
    }
    if (hullOptions.useSkinWidth)
    {
        hullFlags |= QF_SKIN_WIDTH;
    }
    if (hullOptions.reverseTriangleOrder)
    {
        hullFlags |= QF_REVERSE_ORDER;
    }
    
    // Create the description
    HullDesc hullDescription;
    hullDescription.mFlags = hullFlags;
    hullDescription.mMaxVertices = hullOptions.maxOutputVertices;
    hullDescription.mSkinWidth = hullOptions.skinWidth;
    hullDescription.mNormalEpsilon = hullOptions.normalEpsilon;
    hullDescription.mVertexStride = sizeof(double)*3;
    hullDescription.mVcount = numInputVerts;
    hullDescription.mVertices = inputVerts;
    
    // Create the hull
    HullLibrary hullComputer;
    HullResult hullResult;
    HullError err = hullComputer.CreateConvexHull(hullDescription, hullResult);
    MStatus hullStat = MStatus::kSuccess;
    if (err == QE_OK)
    {
        // Grab the verts
        MPointArray outPoints;
        for (uint i=0; i < hullResult.mNumOutputVertices; i++)
        {
            uint offset = i*3;
            MPoint curPoint(hullResult.mOutputVertices[offset],
                            hullResult.mOutputVertices[offset+1],
                            hullResult.mOutputVertices[offset+2]);
            outPoints.append(curPoint);
        }
        
        // Check if the results are in polygons, or triangles. Depending on
        // which for the result is in, the way the face indices are setup
        // is different.
        MIntArray polyCounts;
        MIntArray vertexConnects;
        
        if (hullResult.mPolygons)
        {
            const uint *idx = hullResult.mIndices;
            for (uint i=0; i < hullResult.mNumFaces; i++)
            {
                uint pCount = *idx++;
                polyCounts.append(pCount);
                
                for (uint j=0; j < pCount; j++)
                {
                    uint val = idx[0];
                    vertexConnects.append(val);
                    idx++;
                }
            }
        }
        else
        {
            polyCounts.setLength(hullResult.mNumFaces);
            for (uint i=0; i < hullResult.mNumFaces; i++)
            {
                
                polyCounts[i] = 3;
                uint *idx = &hullResult.mIndices[i*3];
                
                vertexConnects.append(idx[0]);
                vertexConnects.append(idx[1]);
                vertexConnects.append(idx[2]);
            }
        }
        // Setup the outmesh
        MFnMesh outMeshFn(output);
        outMeshFn.create(hullResult.mNumOutputVertices,
                         hullResult.mNumFaces,
                         outPoints,
                         polyCounts,
                         vertexConnects,
                         output,
                         &hullStat);
    }
    else
    {
        hullStat = MStatus::kFailure;
    }
    
    // Mem Cleanup
    hullComputer.ReleaseResult(hullResult);
    delete[] inputVerts;
    
    return hullStat;
}
// отрисовка из прошлой лабы, только берём цвета из текстуры
void Triangle::draw(Canvas& canvas, Texture* texture = 0) {
    std::vector<TexturedPoint> points;

    // преобразование и упорядочивание по x
    transform(points);
    std::sort(points.begin(), points.end());

    std::vector<Edge> edges;

    // установка границ
    int minY = (points.front().y() < 0) ? 0: points.front().y();
    int maxY = (points.back().y() < this->maxY) ? points.back().y() : this->maxY - 1;

    int curY = minY;
    int i = 0;

    while (curY < maxY) {
        int nextY = maxY;

        while ( i != (int)points.size() && trunc( points[i].y()) <= curY ){
            TexturedPoint a = points[i];
            TexturedPoint b = points[(points.size() - i - 1 ) % points.size()];
            TexturedPoint c = points[(i + 1) % points.size()];

            if (b.y() > curY ) {
                edges.push_back(Edge(a,b));
                if ( b.y() < nextY ) {
                    nextY = b.y() ;
                }
            }
            if (c.y() > curY) {
                edges.push_back(Edge(a,c));
                if ( c.y() < nextY) {
                    nextY = c.y();
                }
            }
            ++i;
        }

        while(curY <= nextY && curY <= maxY) {

            std::vector<TexturedPoint> borderX;
            for (int i = 0; i < (int)edges.size(); ++i) {
                int n = curY - edges[i].getA().y();
                double curX = (edges[i].getA().x()) + n * edges[i].getK();
                TexturedPoint texCoord(curX, curY);
                texCoord.calcTextureCoordinates(edges[i].getA(), edges[i].getB());
                borderX.push_back(texCoord);
            }

            std::sort(borderX.begin(), borderX.end(), TexturedPoint::compX);
            int begin = borderX.front().x() > 0 ? borderX.front().x() : 0;

            for (int x = begin; x < borderX.back().x() && x < maxX; ++x) {
                TexturedPoint curPoint(x, curY);

                curPoint.calcTextureCoordinates(borderX.front(),borderX.back());

                if (0 == texture) {
                    // если текстуры нет( то как градиент )
                    canvas.drawPixel(x, curY, TexturedPoint::transformToColor(curPoint.getTexX(), curPoint.getTexY()));
                } else {
                    canvas.drawPixel(x, curY, texture->get_color(curPoint));
                }
            }

            ++curY;
        }

        std::vector<Edge>::iterator iter = edges.begin();
        while (iter != edges.end()) {
           if ( (*iter).getB().y() < curY) {
               edges.erase(iter);
           }
           else {
               ++iter;
           }
        }

   }
}
Esempio n. 11
0
void KUnitItem::slotMouseMove(QGraphicsSceneMouseEvent *event)
{
    if (myMode == MouseMode_RESIZE)
    {
        QPointF curPoint(event->scenePos());
        QPointF curPointItem = this->mapFromScene(curPoint);

        bool flagx = lastPoint.x() > oppositePos.x();
        bool flagx1 = curPointItem.x() > oppositePos.x();
        bool flagy = lastPoint.y() > oppositePos.y();
        bool flagy1 = curPointItem.y() > oppositePos.y();


        qreal dist = 0;

        QRectF rectf;
        rectf.setRect(m_frame.x()
                      , m_frame.y()
                      , m_frame.width()
                      , m_frame.height());


        KResizeFocus::PosInHost pos = curResizeFocus->getInHost();
        if (pos == KResizeFocus::NORTH_MIDDLE)
        {
            QPointF br = dashRect->rect().bottomRight();
            dist = Util::GetPointDistLine(oppositePos,br,curPointItem);

            if (dist < 20 || flagy != flagy1)
            {
                if (flagy)
                {
                    curPointItem.setY(oppositePos.y() + 20);
                }
                else
                {
                    curPointItem.setY(oppositePos.y() - 20);
                }
                dist = 20;
            }
            rectf.setY(curPointItem.y());
            rectf.setHeight(dist);
        }
        else if(pos == KResizeFocus::SOUTH_MIDDLE)
        {
            QPointF br = dashRect->rect().topRight();
            dist = Util::GetPointDistLine(oppositePos,br,curPointItem);

            if (dist < 20 || flagy != flagy1)
            {
                if (flagy)
                {
                    curPointItem.setY(oppositePos.y() + 20);
                }
                else
                {
                    curPointItem.setY(oppositePos.y() - 20);
                }
                dist = 20;
            }
            rectf.setHeight(dist);
        }
        else if(pos == KResizeFocus::EAST_MIDDLE)
        {
            QPointF br = dashRect->rect().bottomLeft();
            dist = Util::GetPointDistLine(oppositePos,br,curPointItem);

            if (dist < 20 || flagx != flagx1)
            {
                if (flagx)
                {
                    curPointItem.setX(oppositePos.x() + 20);
                }
                else
                {
                    curPointItem.setX(oppositePos.x() - 20);
                }
                dist = 20;
            }
            rectf.setWidth(dist);
        }
        else if(pos == KResizeFocus::WEST_MIDDLE)
        {
            QPointF br = dashRect->rect().bottomRight();
            dist = Util::GetPointDistLine(oppositePos,br,curPointItem);

            if (dist < 20 || flagx != flagx1)
            {
                if (flagx)
                {
                    curPointItem.setX(oppositePos.x() + 20);
                }
                else
                {
                    curPointItem.setX(oppositePos.x() - 20);
                }
                dist = 20;
            }
            rectf.setX(curPointItem.x());
            rectf.setWidth(dist);
        }
        else if(pos == KResizeFocus::NORTH_WEST)
        {
            QPointF topRight = dashRect->rect().topRight();
            QPointF bottomLeft = dashRect->rect().bottomLeft();

            qreal distx = Util::GetPointDistLine(oppositePos,topRight,curPointItem);
            qreal disty = Util::GetPointDistLine(oppositePos,bottomLeft,curPointItem);

            if (distx < 20 || flagx != flagx1)
            {
                if (flagx)
                {
                    curPointItem.setX(oppositePos.x() + 20);
                }
                else
                {
                    curPointItem.setX(oppositePos.x() - 20);
                }
                distx = 20;
            }
            if (disty < 20 || flagy != flagy1)
            {
                if (flagy)
                {
                    curPointItem.setY(oppositePos.y() + 20);
                }
                else
                {
                    curPointItem.setY(oppositePos.y() - 20);
                }
                disty = 20;
            }

            rectf.setTopLeft(curPointItem);
        }
        else if(pos == KResizeFocus::NORTH_EAST)
        {
            QPointF topLeft = dashRect->rect().topLeft();
            QPointF bottomRight = dashRect->rect().bottomRight();

            qreal distx = Util::GetPointDistLine(oppositePos,topLeft,curPointItem);
            qreal disty = Util::GetPointDistLine(oppositePos,bottomRight,curPointItem);

            if (distx < 20 || flagx != flagx1)
            {
                if (flagx)
                {
                    curPointItem.setX(oppositePos.x() + 20);
                }
                else
                {
                    curPointItem.setX(oppositePos.x() - 20);
                }
                distx = 20;
            }
            if (disty < 20 || flagy != flagy1)
            {
                if (flagy)
                {
                    curPointItem.setY(oppositePos.y() + 20);
                }
                else
                {
                    curPointItem.setY(oppositePos.y() - 20);
                }
                disty = 20;
            }

            rectf.setTopRight(curPointItem);
        }
        else if(pos == KResizeFocus::SOUTH_EAST)
        {
            QPointF topRight = dashRect->rect().topRight();
            QPointF bottomLeft = dashRect->rect().bottomLeft();

            qreal disty = Util::GetPointDistLine(oppositePos,topRight,curPointItem);
            qreal distx = Util::GetPointDistLine(oppositePos,bottomLeft,curPointItem);

            if (distx < 20 || flagx != flagx1)
            {
                if (flagx)
                {
                    curPointItem.setX(oppositePos.x() + 20);
                }
                else
                {
                    curPointItem.setX(oppositePos.x() - 20);
                }
                distx = 20;
            }
            if (disty < 20 || flagy != flagy1)
            {
                if (flagy)
                {
                    curPointItem.setY(oppositePos.y() + 20);
                }
                else
                {
                    curPointItem.setY(oppositePos.y() - 20);
                }
                disty = 20;
            }

            rectf.setBottomRight(curPointItem);
        }
        else if(pos == KResizeFocus::SOUTH_WEST)
        {
            QPointF topLeft = dashRect->rect().topLeft();
            QPointF bottomRight = dashRect->rect().bottomRight();

            qreal disty = Util::GetPointDistLine(oppositePos,topLeft,curPointItem);
            qreal distx = Util::GetPointDistLine(oppositePos,bottomRight,curPointItem);

            if (distx < 20 || flagx != flagx1)
            {
                if (flagx)
                {
                    curPointItem.setX(oppositePos.x() + 20);
                }
                else
                {
                    curPointItem.setX(oppositePos.x() - 20);
                }
                distx = 20;
            }
            if (disty < 20 || flagy != flagy1)
            {
                if (flagy)
                {
                    curPointItem.setY(oppositePos.y() + 20);
                }
                else
                {
                    curPointItem.setY(oppositePos.y() - 20);
                }
                disty = 20;
            }
            rectf.setBottomLeft(curPointItem);
        }

        dashRect->setRect(rectf);
    }
    else if(myMode == MouseMode_ROTATE)
    {
        QPointF curPos = event->scenePos();
        QPointF cpos = this->mapToScene(frame().center());
//        qDebug()<<cpos;
		qreal angleLast = Util::ComputeAngle(mLastRotatePoint, cpos);
		qreal angleCur = Util::ComputeAngle(curPos, cpos);
        qreal angle = angleCur - angleLast;

        setAngle(angle);
        mLastRotatePoint = curPos;
        onRotate();
    }
    else if(myMode == MouseMode_MOVE)
    {
        onMoving();
    }
    else
    {
        QGraphicsItem::mouseMoveEvent(event);
    }
}
Esempio n. 12
0
int GeoMapEditor::processMouseEvent(int event, int x, int y, int flags)
{
  //switch (mouseScenario)
  //{

  //}

  //cout << "event=" << event << " coords=" << x << " " << y << " flags=" << flags << endl;

  string objtype = objType(); // тип объекта, с которым работаем
  bool object_poligonal = (objtype == "AGM_Segm" );
  ///bool object_segment_based = (objtype == "AFO_Segm"); // либо производные двух точечные отрезкообразные
  cv::Point curPoint(x,y);
  int max_poly_points=1000;
  if (objtype == "AGM_Segm")
    max_poly_points=2;

  //cout << "GeoMap:objtype" << objtype << endl;

  switch (event)
  {
    case CV_EVENT_LBUTTONDOWN   : // =1,0,
    case CV_EVENT_RBUTTONDOWN   : // =1,0,
      if (object_poligonal)
      {
        if ( rubbering_pts.size() == 0 ) // первая точка
        {
          rubbering_pts.push_back(curPoint);
          rubbering_pts.push_back(curPoint); // создали вырожденный первый сегмент, вторую точку будем корректировать на mousemove 
          rubbering_mode = RUBBERING_SEGMENT;
        }
        else
//           if (rubbering_pts.size()>=2 && // если последний сегмент не вырожденный -- начнем новый
//           l2norm( rubbering_pts[rubbering_pts.size()-2], rubbering_pts[rubbering_pts.size()-1] ) >= 25  )
        {
          rubbering_pts.push_back(curPoint);
          rubbering_mode = RUBBERING_SEGMENT;
        }             
      }
      else
      {
        rubbering_pts.clear();
        rubbering_pts.push_back(curPoint);
        rubbering_pts.push_back(curPoint); // создали вырожденный ректангл 
        rubbering_mode = RUBBERING_RECTANGLE; // пока так, грубо.
      }
      rubber_by_left_button = (event == CV_EVENT_LBUTTONDOWN);
      return finishMouseEvent();

    case CV_EVENT_MOUSEMOVE     : // =0,
      if (rubbering_mode == RUBBERING_NOTHING)
        break;
      if (rubbering_mode == RUBBERING_RECTANGLE)
      {
        assert(rubbering_pts.size() == 2);
        rubbering_pts[1] = curPoint; // обновили точку
        return finishMouseEvent();
      }
      if (rubbering_mode == RUBBERING_SEGMENT)
      {
        assert(rubbering_pts.size() >=2);
        ////if (rubbering_pts.size() == 2) 
          rubbering_pts.back() = curPoint; // обновили точку
        return finishMouseEvent();
      }
//       if (rubbering_mode == RUBBERING_POLYGON) // уже вытянута часть многоугольника, и мы свободно водим мышкой планируя начать вытягивать следующее ребро многоугольника
//       {
//         assert(rubbering_pts.size() >=2);
//         // ничего не делаем, пока выбор пользователя не понятен и отрисовка не меняется
//         //return 0;
//         rubbering_pts.back() = curPoint;
//         return finishMouseEvent();
//       }

    //case CV_EVENT_RBUTTONDOWN   : // =2,
    //case CV_EVENT_MBUTTONDOWN   : // =3,
    case CV_EVENT_LBUTTONUP     : // =4,
    case CV_EVENT_RBUTTONUP     : // =4,
      if (rubbering_mode == RUBBERING_NOTHING)
        break;
      if (rubbering_mode == RUBBERING_RECTANGLE) 
      {
        assert(rubbering_pts.size() == 2);
        rubbering_pts[1] = curPoint; // скорректировали
        cv::Rect rect(rubbering_pts[0], rubbering_pts[1]);
        //cout << "rect.x =" << rect.x << " rect.y =" << rect.y;
        //cout << "rect.width =" << rect.width << " rect.height =" << rect.height << endl;
        int flags = ADD_OBJECT_RECT | (rubber_by_left_button ? ADD_OBJECT_MOUSE_LEFT : ADD_OBJECT_MOUSE_RIGHT);
        rubbering_mode = RUBBERING_NOTHING;
        rubbering_pts.clear();
        return addMouseObject(rect, flags);
      }

      if (rubbering_mode == RUBBERING_SEGMENT)
      {
        assert(rubbering_pts.size() >= 2);
        rubbering_pts.back() = curPoint;
//         if ( l2norm( rubbering_pts[0], curPoint) < 100 // замкнули или просто клик был. конец банкета
//           //////||
//           //////  (object_segment_based && rubbering_pts.size() == 2 )
//           || rubbering_pts.size() == max_poly_points+1
//             ) 
//         {
//           if (rubbering_pts.size() > 2)
//             rubbering_pts.back() = rubbering_pts[0]; // скорректировали последнюю точку прилепив к начальной
//           int flags = ADD_OBJECT_RECT | (rubber_by_left_button ? ADD_OBJECT_MOUSE_LEFT : ADD_OBJECT_MOUSE_RIGHT);
//           if (l2norm( rubbering_pts[rubbering_pts.size()-2], rubbering_pts[rubbering_pts.size()-1] ) < 25)
//           { // удаляем последнее ребро если оно вырожденное
//             rubbering_pts[rubbering_pts.size()-2] = rubbering_pts[0];
//             rubbering_pts.pop_back();
//           }
//           rubbering_mode = RUBBERING_NOTHING;
//           int res = addMouseObject(rubbering_pts, flags);
//           rubbering_pts.clear();
//           return res;
//         }        
        rubbering_mode = RUBBERING_NOTHING;
        int res = addMouseObject(rubbering_pts, flags);
        rubbering_pts.clear();
        return res;
//         }
        // не замкнулись, продолжаем, надо перерисовать
//         rubbering_pts.back() = curPoint;
//         rubbering_mode = RUBBERING_POLYGON;

//        return finishMouseEvent();
      }
      break;
    //case CV_EVENT_RBUTTONUP     : // =5,
    //case CV_EVENT_MBUTTONUP     : // =6,
    //case CV_EVENT_LBUTTONDBLCLK : // =7,
    //case CV_EVENT_RBUTTONDBLCLK : // =8,
    //case CV_EVENT_MBUTTONDBLCLK : // =9
  }
  return finishMouseEvent();
}
Esempio n. 13
0
	void Scene::GetGestures()
	{
		TouchManager& manager = TouchManager::GetInstance();
		
		const TouchList& touches = manager.Touches();
		
		//Single touch
		if (touches.size() == 1)
		{
			TouchRef touch = touches[0];
			
			// gets touches for blueprint button
			float touchConvX = touch->x /32;
			float touchConvY = touch->y /32;
			
			if ((!m_touchedDown && (touch->state == kTouchBegan)) ||
				(m_touchedDown && (touch->state == kTouchEnded || touch->state == kTouchCancelled)))
			{
				bool pressed = mr_missionBrief->touchHit( Vect2(touchConvX, touchConvY), mp_bluePrintButton, mr_camera);
				if (pressed) 
				{
					if(m_touchedDown)
					{
						// activate blueprint
						if(!mr_missionBrief->IsVisible())
						{
							mr_missionBrief->Show();
						}
						else 
						{
							mr_missionBrief->Hide();
						}
					
						m_infoButtonTimer = 0;
					}
					else 
					{
						m_touchedDown = true;
					}

				}
				else 
				{
					m_touchedDown = false;
				}
			}
			else
			{
				//Figure out vector
				b2Vec2 curPoint(touch->x, touch->y);
				b2Vec2 oldPoint(touch->prevX, touch->prevY);
			
				m_Avatar->MoveAvatar(.15f * (curPoint-oldPoint));
			}			
		}
		
		// PINCH
		if (manager.CurrentPinch().isValid())
		{
			static bool debounce = true;
			float scale = manager.CurrentPinch().getScale();
			if (debounce)
			{
				if (scale < PINCH_CONSTRAINT || scale > PINCH_HIGH)
				{
					debounce = false;
					if (!m_Avatar->IsMagnetOn())
					{
						m_Avatar->ActivateMagnet();
					}
                    else
					{
						m_Avatar->DeactivateMagnet();
					}
				}
			}
			else if(scale >PINCH_CONSTRAINT && scale < PINCH_HIGH)
			{
				debounce = true;
			}
		}
	}
Esempio n. 14
0
vector<int*> outPut::choosePoints()
{
    glfwEnable( GLFW_KEY_REPEAT );

    _points.clear();

    TwBar *b_points = TwNewBar("Points stratégiques");
    coords<int> curPoint((float)_dimensions.x/2.0, (float)_dimensions.y/2.0);
    bool done(false), addCurrent(false), addRandom(false);
    coords3d<float> vertex(0,0,0);

    TwAddVarRW(b_points, "x", TW_TYPE_INT32, &(curPoint.x), "keyincr = RIGHT keydecr = LEFT" );
    TwAddVarRW(b_points, "y", TW_TYPE_INT32, &(curPoint.y), "keyincr = UP keydecr = DOWN" );
    TwAddVarRW(b_points, "Fini", TW_TYPE_BOOLCPP, &(done), "key = RETURN" );
    TwAddVarRW(b_points, "Ajouter courant", TW_TYPE_BOOLCPP, &(addCurrent), "key = SPACE" );
    TwAddVarRW(b_points, "Ajouter au hasard", TW_TYPE_BOOLCPP, &(addRandom), "key = 'r'" );
    TwAddVarRW(b_points, "Pente max", TW_TYPE_INT32, &(_status.maxDiff), "keyincr=o keydecr=l");

    while((!done || _points.size() < 2) && _status.running)
    {
    setScene();
    drawScene();
    glDisable(GL_DEPTH_TEST);
    glUseProgram(_sNolight.getProgramID());

    curPoint.x = clamp(curPoint.x, 1, _dimensions.x-1);
    curPoint.y = clamp(curPoint.y, 1, _dimensions.y-1);
    vertex = getVertex<float>(curPoint.x,curPoint.y);
    _scene3d.focus.x = curPoint.x;
    _scene3d.focus.y = curPoint.y;

    if(addRandom)
    {
        addCurrent = true;
        addRandom = false;
        curPoint.x = rand()%(_dimensions.x-1);
        curPoint.y = rand()%(_dimensions.y-1);
    }

    if(addCurrent)
    {
        _points.push_back(curPoint);
        addCurrent = false;
    }

    glBegin(GL_POINTS);
    glColor3ub(0,255,0);
    glVertex3d(vertex.x, vertex.y, vertex.z);
    glEnd();
    display();
    }
    unsigned int n = _points.size();
    std::cout << "nb de bombes : " << n << std::endl;
    vector<int*> bombList(n, NULL);
    for(unsigned int i = 0; i<n;i++)
    {
        bombList[i] = new int[n+2];
        for(unsigned int j = 0; j < n+2; ++j)
        {
            bombList[i][j] = 0;
        }
        bombList[i][n+2-2] = _points[i].x;
        bombList[i][n+2-1] = _points[i].y;
    }

    TwDeleteBar(b_points);

    TwDefine(" Scene/x  keyincr = RIGHT keydecr = LEFT");
    TwDefine(" Scene/y  keyincr = UP keydecr = DOWN");

    return bombList;
}