Ejemplo n.º 1
0
// selectObject
// detect list objs at rect
void CDocument::selectObject( int x, int y, int w, int h, bool isControlHold )
{
	IView *pView = getIView();
	ISceneManager *smgr = pView->getSceneMgr();	
	
	ICameraSceneNode *camera = smgr->getActiveCamera();

	// if no camera
	if (  camera == NULL )
		return;

	const SViewFrustum* viewFrustum = camera->getViewFrustum();
	ISceneCollisionManager *collMan = smgr->getSceneCollisionManager();

	int screenX = -1, screenY = -1;
		
	ArrayZoneIter iZone = m_zones.begin(), iEnd = m_zones.end();
	while ( iZone != iEnd )
	{
		ArrayGameObject* listObj = (*iZone)->getChilds();
		ArrayGameObjectIter iObj = listObj->begin(), objEnd = listObj->end();
		ISceneNode *pNode = NULL;

		while ( iObj != objEnd )
		{
			CGameObject *pGameObj = (CGameObject*)(*iObj);
			
			pNode = pGameObj->getSceneNode();
			
			if ( pNode != NULL && pGameObj->isVisible() )
			{
				core::vector3df center = pGameObj->getPosition();

				// check object is in frustum
				if ( viewFrustum->getBoundingBox().isPointInside( center ) )
				{					
					if ( pView->getScreenCoordinatesFrom3DPosition( center, &screenX, &screenY ) )
					{
						if ( x <= screenX && screenX <= x + w && y <= screenY && screenY <= y + h )
						{
							
							if ( isControlHold == false || pGameObj->getObjectState() == CGameObject::Normal )
								m_selectObjects.push_back( pGameObj );							

						}	// inselect
					}	// getScreenCoordinatesFrom3DPosition			
				} // frustum
			}

			iObj++;
		}

		iZone++;
	}

}
Ejemplo n.º 2
0
// selectObject
// detect list objs at mouse xy	
void CDocument::selectObject( int mouseX, int mouseY, bool isControlHold )
{	
	ISceneManager *smgr = getIView()->getSceneMgr();	
	
	ICameraSceneNode *camera = smgr->getActiveCamera();

	// if no camera
	if (  camera == NULL )
		return;

	ISceneCollisionManager *collMan = smgr->getSceneCollisionManager();

	// get select ray
	core::line3df selectRay = getIView()->getSelectRay();
	
	// check hit test
	core::vector3df intersection;
	core::triangle3df hitTriangle;

	// check select
	ISceneNode *selectedSceneNode = collMan->getSceneNodeAndCollisionPointFromRay
		(
			selectRay,
			intersection,
			hitTriangle
		);
	
	if ( selectedSceneNode )
	{
		CGameObject *pObj =	searchObject( selectedSceneNode->getID() );
		
		// try find parent
		while ( pObj == NULL )
		{
			selectedSceneNode = selectedSceneNode->getParent();
			if ( selectedSceneNode == NULL )
				break;
			pObj = searchObject( selectedSceneNode->getID() );
		}

		// add to select list
		if ( pObj && pObj->isVisible() )
		{
			if ( isControlHold == false || pObj->getObjectState() == CGameObject::Normal )
				m_selectObjects.push_back( pObj );
			else
			{
				pObj->setObjectState( CGameObject::Normal );
				ArrayGameObjectIter i = m_selectObjects.begin(), iEnd = m_selectObjects.end();
				while ( i != iEnd )
				{
					if ( (*i) == pObj )
					{
						m_selectObjects.erase( i );
						break;
					}
					i++;
				}
			}
		}

	}

}