void BoxCenterMovable::_updateRenderQueue(Ogre::RenderQueue* queue)
    { 
		if(!object.lock())
			return;

        getBoundingBoxCenter();

        // Project the sphere onto the camera
        Ogre::Real left, right, top, bottom;
        Ogre::Sphere sphere(mCenterPosWC,PointPixelSize);

        if (m_pCamera->projectSphere(sphere, &left, &top, &right, &bottom))
        {
            int iLeft, iTop, iWidth, iHeight;
            mViewport->getActualDimensions(iLeft, iTop, iWidth, iHeight);
            size_t szLeft, szRight, szTop, szBottom;

            szLeft = (size_t)(iLeft + ((left + 1) * 0.5 * iWidth));
            szRight = (size_t)(iLeft + ((right + 1) * 0.5 * iWidth));
            szTop = (size_t)(iTop + ((-top + 1) * 0.5 * iHeight));
            szBottom = (size_t)(iTop + ((-bottom + 1) * 0.5 * iHeight));

            mCenterPosSC.x = ( szLeft + szRight ) / 2;
            mCenterPosSC.y = ( szTop + szBottom ) / 2;
        }

        int nTop = mCenterPosSC.y  - PointPixelSize/2;
        int nLeft = mCenterPosSC.x  - PointPixelSize/2;

        mObjectCenterPointRect->setTop(nTop);
        mObjectCenterPointRect->setLeft(nLeft);
        mObjectCenterPointRect->setWidth(PointPixelSize);
        mObjectCenterPointRect->setHeight(PointPixelSize);
    }
Exemple #2
0
void SceneGraph::zoomAllViewpoint() 
{
	float	bboxCenter[3];
	float	bboxSize[3];

	getBoundingBoxCenter(bboxCenter);
	getBoundingBoxSize(bboxSize);

	ViewpointNode *view = getViewpointNode();
	if (view == NULL)
		view = getDefaultViewpointNode();

	float fov = view->getFieldOfView();
	float zoffset = bboxSize[0] / (float)tan(fov);
	view->setPosition(bboxCenter[0], bboxCenter[1], bboxCenter[2] + zoffset*5.0f);
	view->setOrientation(0.0f, 0.0f, 1.0f, 0.0f);
}
    void 
    BoxCenterMovable::init(const ObjectPtr& obj,Ogre::SceneManager* mgr,Ogre::Viewport* viewport,Ogre::Camera* camera)
    {
        object = obj;
        m_pParentSceneManager = mgr;
        mViewport = viewport;
        m_pCamera = camera;

        getBoundingBoxCenter();
        
        float baseExtent = 25.0f;
        float dist = (camera->getPosition() - mCenterPosWC).length();    
        float farClip = camera->getFarClipDistance();
        float nearClip = camera->getNearClipDistance();
        float extent = 2.0f * dist / (farClip + nearClip) * baseExtent;

        Ogre::AxisAlignedBox box((mCenterPosWC + Ogre::Vector3(-extent,-extent,-extent)),(mCenterPosWC + Ogre::Vector3(extent,extent,extent)));
       
        setBoundingBox(box);

        createGuiElements();
    }