Exemplo n.º 1
0
void QDecTouchArea::updateTouchData(QEvent *event)
{  
    QTouchEvent *e = static_cast<QTouchEvent*>(event);
    QList<QTouchEvent::TouchPoint> listTouchPts = e->touchPoints();
    for(int i=0; i < listTouchPts.count(); i++)
    {
        int touchPtId = listTouchPts[i].id();
        Qt::TouchPointState touchPtState = listTouchPts[i].state();
        QPointF touchPtPos = listTouchPts[i].pos();

        QDecTouchPoint * qDecTouchPt = m_listTouchPoints[touchPtId];

        // set touch point active/inactive
        if(touchPtState & Qt::TouchPointPressed)  {
            qDecTouchPt->setActive(true);
            qDecTouchPt->setX(touchPtPos.x());
            qDecTouchPt->setY(touchPtPos.y());
            emit touchPointPressed(touchPtId);
        }
        else if(touchPtState & Qt::TouchPointReleased)  {
            qDecTouchPt->setActive(false);
            qDecTouchPt->setX(touchPtPos.x());
            qDecTouchPt->setY(touchPtPos.y());
            emit touchPointReleased(touchPtId);
        }

        // if point moved, set new position
        if(touchPtState & Qt::TouchPointMoved)  {
            qDecTouchPt->setX(touchPtPos.x());
            qDecTouchPt->setY(touchPtPos.y());
            emit touchPointMoved(touchPtId);
        }
    }

    // handle two touch inputs
    if(listTouchPts.count() == 2)
    {
        QTouchEvent::TouchPoint tp1 = listTouchPts.at(0);
        QTouchEvent::TouchPoint tp2 = listTouchPts.at(1);

        QPointF tp1LastPos = tp1.lastPos();
        QPointF tp2LastPos = tp2.lastPos();
        QPointF tp1Pos = tp1.pos();
        QPointF tp2Pos = tp2.pos();

        QPointF deltaA = tp1LastPos - tp2LastPos;
        QPointF deltaB = tp1Pos - tp2Pos;

        qreal distanceA = sqrt(pow(deltaA.x(),2.0)+pow(deltaA.y(),2.0));
        qreal distanceB = sqrt(pow(deltaB.x(),2.0)+pow(deltaB.y(),2.0));

        if (distanceA != 0 && distanceB != 0) {
            m_diffScaleFactor = (distanceB/distanceA);
            m_totalScaleFactor *= m_diffScaleFactor;
            emit(scaleFactorChanged());
        }

        QLineF lineA(tp1LastPos, tp2LastPos);
        QLineF lineB(tp1Pos,tp2Pos);
        m_diffRotationAngle = lineA.angleTo(lineB);
        m_totalRotationAngle -= m_diffRotationAngle;

        if(m_totalRotationAngle > 360)  {
            m_totalRotationAngle -= 360;
        }
        else if(m_totalRotationAngle < -360)  {
            m_totalRotationAngle += 360;
        }

        emit(rotationAngleChanged());
    }

//    // handle two touch inputs
//    if(listTouchPts.count() == 2)
//    {
//        QTouchEvent::TouchPoint tp1 = listTouchPts.at(0);
//        QTouchEvent::TouchPoint tp2 = listTouchPts.at(1);

//        QPointF tp1Prv = tp1.lastPos();
//        QPointF tp2Prv = tp2.lastPos();

//        QPointF tp1New = tp1.pos();
//        QPointF tp2New = tp2.pos();

//        // get previous and current distances
//        qreal distPrv = sqrt(pow(tp1Prv.x()-tp2Prv.x(),2) +
//                             pow(tp1Prv.y()-tp2Prv.y(),2));

//        qreal distNew = sqrt(pow(tp1New.x()-tp2New.x(),2) +
//                             pow(tp1New.y()-tp2New.y(),2));

//        if(distPrv !=0 && distNew != 0)  {
//            if(fabs(distNew/distPrv - 1) > 0.008)  {
//                m_diffScaleFactor = (distNew/distPrv);
//                m_totalScaleFactor *= m_diffScaleFactor;
//                emit(scaleFactorChanged());
//            }
//        }

//        // get previous and current angles
//        QLineF linePrv(tp1Prv,tp2Prv);
//        QLineF lineNew(tp1New,tp2New);
//        m_diffRotationAngle = linePrv.angleTo(lineNew);
//        m_totalRotationAngle -= m_diffRotationAngle;

//        if(m_totalRotationAngle > 360)  {
//            m_totalRotationAngle -= 360;
//        }
//        else if(m_totalRotationAngle < -360)  {
//            m_totalRotationAngle += 360;
//        }

//        emit(rotationAngleChanged());
//    }
}
Exemplo n.º 2
0
    void Polygon::Draw()
    {
        //Safety check the shader
        if(m_Shader == nullptr)
        {
            return;
        }
        
        //If the model matrix is dirty, reset it
        if(IsModelMatrixDirty() == true)
        {
            ResetModelMatrix();
        }
    
        //Use the shader
        m_Shader->Use();
        
        //Set the point size attribute
        int pointSizeIndex = m_Shader->GetAttribute("a_pointSize");
        glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
        glVertexAttrib1f(pointSizeIndex, m_PointSize);
        
        //Cache the graphics service
        Graphics* graphics = ServiceLocator::GetGraphics();
    
        //Bind the vertex array object
        graphics->BindVertexArray(m_VertexArrayObject);

        //Set the model view projection matrix
        mat4 mvp = graphics->GetProjectionMatrix() * graphics->GetViewMatrix() * m_ModelMatrix;
        glUniformMatrix4fv(m_Shader->GetModelViewProjectionUniform(), 1, 0, &mvp[0][0]);
        
        //Validate the shader
        if(m_Shader->Validate() == false)
        {
            Error(false, "Can't draw Polygon, shader failed to validate");
            return;
        }
        
        //Disable blending, if we did in fact have it enabled
        if(m_Color.Alpha() != 1.0f)
        {
            graphics->EnableBlending();
        }
        
        //Render the polygon
        glDrawArrays(m_RenderMode, 0, (GLsizei)m_Vertices.size());
        
        //Disable blending, if we did in fact have it enabled
        if(m_Color.Alpha() != 1.0f)
        {
            graphics->DisableBlending();
        }
        
        //Unbind the vertex array
        ServiceLocator::GetGraphics()->BindVertexArray(0);
        
        //Draw the debug anchor point
        #if DRAW_POLYGON_ANCHOR_POINT
        if(GetType() != "Point" && GetType() != "Line")
        {
            Line lineA(m_AnchorLocation, vec2(m_AnchorLocation.x, m_AnchorLocation.y + DRAW_POLYGON_ANCHOR_POINT_SIZE));
            lineA.SetLocalAngle(GetWorldAngle());
            lineA.SetColor(Color::RedColor());
            lineA.Draw();
        
            Line lineB(m_AnchorLocation, vec2(m_AnchorLocation.x + DRAW_POLYGON_ANCHOR_POINT_SIZE, m_AnchorLocation.y));
            lineB.SetLocalAngle(GetWorldAngle());
            lineB.SetColor(Color::GreenColor());
            lineB.Draw();
        }
        #endif
        
        //Call the GameObject's Draw() method, this will ensure that any children will also get drawn
        GameObject::Draw();
    }