void makeFromEditDataArea(ObjectItem *pObj, QVector4D *pqv4AreaMin, QVector4D *pqv4AreaMax, bool isRecursive)
{
    QMatrix4x4 mat = pObj->getDisplayMatrix(0);
    FrameData frameData = pObj->getDisplayFrameData(0);
    QVector3D v[4];
    frameData.getVertexApplyMatrix(v, mat);
    for (int i = 0; i < 4; i++)
    {
        if (pqv4AreaMin->x() > v[i].x())
            pqv4AreaMin->setX(v[i].x());
        if (pqv4AreaMin->y() > v[i].y())
            pqv4AreaMin->setY(v[i].y());
        if (pqv4AreaMin->z() > v[i].z())
            pqv4AreaMin->setZ(v[i].z());
        if (pqv4AreaMax->x() < v[i].x())
            pqv4AreaMax->setX(v[i].x());
        if (pqv4AreaMax->y() < v[i].y())
            pqv4AreaMax->setY(v[i].y());
        if (pqv4AreaMax->z() < v[i].z())
            pqv4AreaMax->setZ(v[i].z());
    }

    if (isRecursive == false)
        return;

    if (pObj->childCount())
    {
        for (int i = 0; i < pObj->childCount(); i++)
        {
            ObjectItem *pChild = pObj->child(i);
            makeFromEditDataArea(pChild, pqv4AreaMin, pqv4AreaMax, isRecursive);
        }
    }
}
Beispiel #2
0
void CAnm2D::setRect(AnmLayer *pLayer)
{
	bool valid0, valid1 ;
	FrameData data = pLayer->getDisplayFrameData(0, &valid0) ;
	QMatrix4x4 mat = pLayer->getDisplayMatrix(0, &valid1) ;
	if ( valid0 && valid1 ) {
		QVector3D v[4] ;
		data.getVertexApplyMatrix(v, mat) ;

		for ( int i = 0 ; i < 4 ; i ++ ) {
			if ( m_rect.left() > v[i].x() ) { m_rect.setLeft(v[i].x()) ; }
			if ( m_rect.right() < v[i].x() ) { m_rect.setRight(v[i].x()) ; }
			if ( m_rect.top() > v[i].y() ) { m_rect.setTop(v[i].y()) ; }
			if ( m_rect.bottom() < v[i].y() ) { m_rect.setBottom(v[i].y()) ; }
		}
	}

	for ( int i = 0 ; i < pLayer->childPtrs.size() ; i ++ ) {
		setRect(pLayer->childPtrs[i]) ;
	}
}
bool ObjectItem::isContain(FrameData &displayData, QPoint &pos, const QMatrix4x4 &matDisp)
{
    QVector3D v[4];
    displayData.getVertexApplyMatrix(v, matDisp);
    QVector3D tri[2][3] = {
        {
            v[0],
            v[2],
            v[1],
        },
        {
            v[2],
            v[1],
            v[3],
        }
    };
    for (int i = 0; i < 3; i++)
    {
        tri[0][i].setZ(0);
        tri[1][i].setZ(0);
    }

    QVector3D p = QVector3D(pos.x(), pos.y(), 0);
    for (int i = 0; i < 2; i++)
    {
        QVector3D p0 = tri[i][0] - p;
        QVector3D p1 = tri[i][1] - p;
        QVector3D p2 = tri[i][2] - p;
        QVector3D c0 = QVector3D::crossProduct(p0, p1);
        QVector3D c1 = QVector3D::crossProduct(p1, p2);
        QVector3D c2 = QVector3D::crossProduct(p2, p0);
        if (QVector3D::dotProduct(c0, c1) > 0 && QVector3D::dotProduct(c1, c2) > 0 && QVector3D::dotProduct(c2, c0) > 0)
        {
            return true;
        }
    }

    return false;
}