Exemplo n.º 1
0
const AABB& Sprite3D::getAABB() const
{
    Mat4 nodeToWorldTransform(getNodeToWorldTransform());
    
    // If nodeToWorldTransform matrix isn't changed, we don't need to transform aabb.
    if (memcmp(_nodeToWorldTransform.m, nodeToWorldTransform.m, sizeof(Mat4)) == 0 && !_aabbDirty)
    {
        return _aabb;
    }
    else
    {
        _aabb.reset();
        if (_meshes.size())
        {
            Mat4 transform(nodeToWorldTransform);
            for (const auto& it : _meshes) {
                if (it->isVisible())
                    _aabb.merge(it->getAABB());
            }
            
            _aabb.transform(transform);
            _nodeToWorldTransform = nodeToWorldTransform;
            _aabbDirty = false;
        }
    }
    
    return _aabb;
}
Exemplo n.º 2
0
CCPoint CCNode::convertToWorldSpace(CCPoint nodePoint)
{
	CCPoint ret;
	if(CC_CONTENT_SCALE_FACTOR() == 1)
	{
		ret = CCPointApplyAffineTransform(nodePoint, nodeToWorldTransform());
	}
	else 
	{
		ret = ccpMult( nodePoint, CC_CONTENT_SCALE_FACTOR() );
		ret = CCPointApplyAffineTransform(ret, nodeToWorldTransform());
		ret = ccpMult( ret, 1/CC_CONTENT_SCALE_FACTOR() );
	}

	return ret;
}
Exemplo n.º 3
0
    KKPoint convertToWorldSpace(const KKPoint &nodePoint)
    {
        kmMat4 *transform = nodeToWorldTransform();
        
        return KKPoint((float)((double)transform->mat[0]*nodePoint.x+(double)transform->mat[4]*nodePoint.y+transform->mat[12]), (float)((double)transform->mat[1]*nodePoint.x+(double)transform->mat[5]*nodePoint.y+transform->mat[13]));
        
        //TODO cocos2d-x
//        kmVec3 vec3 = {nodePoint.x, nodePoint.y, 0};
//        kmVec3 ret;
//        kmVec3Transform(&ret, &vec3, transform);
//        return KKPoint(ret.x, ret.y);
    }
Exemplo n.º 4
0
void CScrollView::visit()
{
	glEnable(GL_SCISSOR_TEST);

	CCRect rect = CCRectMake(0, 0, m_obContentSize.width, m_obContentSize.height);
	rect = CCRectApplyAffineTransform(rect, nodeToWorldTransform());

	CCEGLView::sharedOpenGLView()->setScissorInPoints(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
	CPanel::visit();

	glDisable(GL_SCISSOR_TEST);
}
Exemplo n.º 5
0
bool Container::checkTouch(CCTouch *pTouch){				//当需要更精确的tab判定时继承并修改修改即可
	if( getContentSize().width * getContentSize().height > 1.0f )
	{
		CCPoint pt = pTouch->getLocation();
		CCRect rcBoundingBox( 0, 0, getContentSize().width, getContentSize().height );
		rcBoundingBox = CCRectApplyAffineTransform( rcBoundingBox, nodeToWorldTransform() );
		//[PassMessageDebug] CCLOG("Check here:%f,%f in %f,%f,%f,%f",pt.x,pt.y,rcBoundingBox.origin.x,rcBoundingBox.origin.y,rcBoundingBox.size.width,rcBoundingBox.size.height);
		if( !rcBoundingBox.containsPoint( pt ) )
		{
			//[PassMessageDebug] CCLOG(">Check the collide rect:failed;");
			return false;
		}

	}else{
		return false;
	}
	return true;
}
Exemplo n.º 6
0
 kmMat4 *worldToNodeTransform()
 {
     kmMat4Inverse(_worldToNodeTransform, nodeToWorldTransform()); //反转矩阵
     return _worldToNodeTransform;
 }
Exemplo n.º 7
0
const CCRect& Layout::getClippingRect()
{
    if (_clippingRectDirty)
    {
        _handleScissor = true;
        CCPoint worldPos = convertToWorldSpace(CCPointZero);
        CCAffineTransform t = nodeToWorldTransform();
        float scissorWidth = _size.width*t.a;
        float scissorHeight = _size.height*t.d;
        CCRect parentClippingRect;
        Layout* parent = this;
        bool firstClippingParentFounded = false;
        while (parent)
        {
            parent = dynamic_cast<Layout*>(parent->getParent());
            if(parent)
            {
                if (parent->isClippingEnabled())
                {
                    if (!firstClippingParentFounded)
                    {
                        _clippingParent = parent;
                        firstClippingParentFounded = true;
                    }
                    
                    if (parent->_clippingType == LAYOUT_CLIPPING_SCISSOR)
                    {
                        _handleScissor = false;
                        break;
                    }
                }
            }
        }
        
        if (_clippingParent)
        {
            parentClippingRect = _clippingParent->getClippingRect();
            float finalX = worldPos.x - (scissorWidth * m_obAnchorPoint.x);
            float finalY = worldPos.y - (scissorHeight * m_obAnchorPoint.y);
            float finalWidth = scissorWidth;
            float finalHeight = scissorHeight;
            
            float leftOffset = worldPos.x - parentClippingRect.origin.x;
            if (leftOffset < 0.0f)
            {
                finalX = parentClippingRect.origin.x;
                finalWidth += leftOffset;
            }
            float rightOffset = (worldPos.x + scissorWidth) - (parentClippingRect.origin.x + parentClippingRect.size.width);
            if (rightOffset > 0.0f)
            {
                finalWidth -= rightOffset;
            }
            float topOffset = (worldPos.y + scissorHeight) - (parentClippingRect.origin.y + parentClippingRect.size.height);
            if (topOffset > 0.0f)
            {
                finalHeight -= topOffset;
            }
            float bottomOffset = worldPos.y - parentClippingRect.origin.y;
            if (bottomOffset < 0.0f)
            {
                finalY = parentClippingRect.origin.x;
                finalHeight += bottomOffset;
            }
            if (finalWidth < 0.0f)
            {
                finalWidth = 0.0f;
            }
            if (finalHeight < 0.0f)
            {
                finalHeight = 0.0f;
            }
            _clippingRect.origin.x = finalX;
            _clippingRect.origin.y = finalY;
            _clippingRect.size.width = finalWidth;
            _clippingRect.size.height = finalHeight;
        }
        else
        {
            _clippingRect.origin.x = worldPos.x - (scissorWidth * m_obAnchorPoint.x);
            _clippingRect.origin.y = worldPos.y - (scissorHeight * m_obAnchorPoint.y);
            _clippingRect.size.width = scissorWidth;
            _clippingRect.size.height = scissorHeight;
        }
        _clippingRectDirty = false;
    }
    return _clippingRect;
}
Exemplo n.º 8
0
CCPoint CCNode::convertToWorldSpace(const CCPoint& nodePoint)
{
	return nodeToWorldTransform().apply(nodePoint);
}