Пример #1
0
void CreateCamera(int width, int height, vector3df position, vector3df target)
{
  //Build camera
  ISceneManager* sm = g_GameGraph->GetSceneManager();
  WorldState* worldState =
      static_cast<WorldState*> (g_GameGraph->GetWorldState());
  HexMap* hm = worldState->GetCurrentMap();

  if (NULL != sm)
  {
    if (NULL != hm)
    {
      ICameraSceneNode* orthoCam = sm->addCameraSceneNode(
          sm->getRootSceneNode(), position, target);

      matrix4 projMat;
      projMat.buildProjectionMatrixOrthoLH(width, height, -5, 5);
      orthoCam->setProjectionMatrix(projMat, true);
      orthoCam->bindTargetAndRotation(true);
      if (orthoCam->isOrthogonal())
      {
        CameraAnimator* cameraAnim = new CameraAnimator(position, width,
            height, hm->GetMapDimensions().Height,
            hm->GetMapDimensions().Width, worldState->GetHero(),
            hm->GetCoordinateTranslator());
        orthoCam->addAnimator(cameraAnim);
        cameraAnim->drop();
        cameraAnim = NULL;

        if (width > height)
        {
          LOGI("Creating a landscape camera.");
          landscapeCamera = orthoCam;
        }
        else
        {
          LOGI("Creating a portrait camera");
          portraitCamera = orthoCam;
        }
      }
      else
      {
        LOGE("The created camera is not orthoganol, something is wrong with the perspective matrix.");
      }
    }
    else
    {
      LOGE("The hex map created in the WorldState is NULL.");
    }
  }
  else
  {
    LOGE("The scene manager cannot be loaded from the device.");
  }
}
Пример #2
0
ISceneNode* CCombatSimulatorView::SelectNode(position2di mouse_pos)
{

	scene::ISceneCollisionManager* pCollMgr = p_smgr->getSceneCollisionManager();


	vector2d<s32> cursor = p_device->getCursorControl()->getPosition();

	core::line3d<f32> ln(0,0,0,0,0,0);

	ICameraSceneNode* camera = p_smgr->getActiveCamera();

	const scene::SViewFrustum* f = camera->getViewFrustum();

	core::vector3df farLeftUp = f->getFarLeftUp();
	core::vector3df lefttoright = f->getFarRightUp() - farLeftUp;
	core::vector3df uptodown = f->getFarLeftDown() - farLeftUp;

	RECT m_rect;
	this->GetWindowRect( &m_rect);



	f32 dx = (cursor.X + m_rect.left)  / (f32) (m_rect.right - m_rect.left) ;
	f32 dy = (cursor.Y + m_rect.top) / (f32) (m_rect.bottom - m_rect.top);

	if (camera->isOrthogonal())
		ln.start = f->cameraPosition + (lefttoright * (dx-0.5f)) + (uptodown * (dy-0.5f));
	else
		ln.start = f->cameraPosition;

	ln.end = farLeftUp + (lefttoright * dx) + (uptodown * dy);

	if ( ln.start == ln.end )
		return 0;


	ISceneNode* pNode = pCollMgr->getSceneNodeFromRayBB(ln, 0, true, p_ShipParent);

	if( pNode )
	{
		irr::core::list<ISceneNode*> list = pNode->getChildren();
		irr::core::list<ISceneNode*>::Iterator it = list.begin();
		ESCENE_NODE_TYPE t = pNode->getType();
		if (pNode->getType() == ESNT_SPHERE)
			pNode->setVisible(false);
		for (it;it != list.end(); it++)
		{
			if ((*it)->getType() ==ESNT_SPHERE)
			{
				if ( (*it)->isVisible())
					(*it)->setVisible(false);
				else
					(*it)->setVisible(true);
			}
		}

	}


	return pNode;


}