Exemple #1
0
GeoBounds
FlatProjection::Unproject(const FlatBoundingBox &bb) const
{
    assert(IsValid());

    return GeoBounds(Unproject(bb.GetTopLeft()), Unproject(bb.GetBottomRight()));
}
Exemple #2
0
		void RenderFrustum(dword color = 0xFFFFFFFF)
		{
			Update(); // hack

			//vec3 vOrigin = (m_vPos * m_mVP);
			//vec3 vDirection = vec3(0, 0, 5).Rotate(m_mVP);

			vec3 pRayBL[2];
			vec3 pRayBR[2];
			vec3 pRayTR[2];
			vec3 pRayTL[2];

			Unproject(pRayBL, ivec2(0, 0));
			Unproject(pRayBR, ivec2(m_viewport.x, 0));
			Unproject(pRayTR, ivec2(m_viewport.x, m_viewport.y));
			Unproject(pRayTL, ivec2(0, m_viewport.y));

			g_pEngine->PushLine(pRayBL[0], pRayBL[1], color);
			g_pEngine->PushLine(pRayBR[0], pRayBR[1], color);
			g_pEngine->PushLine(pRayTR[0], pRayTR[1], color);
			g_pEngine->PushLine(pRayTL[0], pRayTL[1], color);

			// near plane
			g_pEngine->PushLine(pRayBL[0], pRayBR[0], color);
			g_pEngine->PushLine(pRayBR[0], pRayTR[0], color);
			g_pEngine->PushLine(pRayTR[0], pRayTL[0], color);
			g_pEngine->PushLine(pRayTL[0], pRayBL[0], color);

			// far plane
			g_pEngine->PushLine(pRayBL[1], pRayBR[1], color);
			g_pEngine->PushLine(pRayBR[1], pRayTR[1], color);
			g_pEngine->PushLine(pRayTR[1], pRayTL[1], color);
			g_pEngine->PushLine(pRayTL[1], pRayBL[1], color);
		}
GeoBounds
FlatProjection::Unproject(const FlatBoundingBox &bb) const
{
  assert(IsValid());

  return GeoBounds(Unproject(FlatGeoPoint(bb.GetLowerLeft().longitude,
                                          bb.GetUpperRight().latitude)),
                   Unproject(FlatGeoPoint(bb.GetUpperRight().longitude,
                                          bb.GetLowerLeft().latitude)));
}
Exemple #4
0
void
FlatProjection::SetCenter(const GeoPoint &_center)
{
    assert(_center.IsValid());

    center = _center;

    cos = center.latitude.fastcosine() * fixed_scale;
    r_cos = 1. / cos;
    approx_scale = Unproject(FlatGeoPoint(0,-1)).DistanceS(Unproject(FlatGeoPoint(0,1))) / 2;
}
Exemple #5
0
void Touch(float x, float y)
{
    Debug("Click at %g;%g", x,y);
    TGVectorF4 click;
    Bug(!Unproject(x,y, click), "Unproject failed");
    Debug("Got: %g; %g; %g", click.X, click.Y, click.Z);

    Clicker.Click(click.X, click.Z);
}
void MouseCoordsToWorldPointAndRay( const LMatrix4& _proj, const LMatrix4& _view, float mx, float my, LVector3& srcPoint, LVector3& dir )
{
	LVector3 screenPoint ( 2.0f * mx - 1.0f, -2.0f * my + 1.0f, 0.0f );
	LVector3 worldPoint = Unproject( _proj, _view, screenPoint );

	LMatrix4 CamRotation;
	DecomposeCameraTransformation( _view, srcPoint, CamRotation );

	dir = worldPoint - srcPoint;
}
Exemple #7
0
bool UnprojectFull( const Vector4& windowPos,
                    const Matrix& modelView,
                    const Matrix& projection,
                    float viewportWidth,
                    float viewportHeight,
                    Vector4& objectPos )
{
  Matrix invertedMvp( false ); // Don't initialize.
  Matrix::Multiply( invertedMvp, modelView, projection );

  if (invertedMvp.Invert())
  {
    return Unproject( windowPos, invertedMvp, viewportWidth, viewportHeight, objectPos );
  }

  return false;
}
void CCollisionMgr::OnScreenTouch(glm::vec2 _vTouchPoint)
{ 
    m_bIsTouch = true; 
    m_vTouch2DPoint = _vTouchPoint;
    
    ICamera* pCamera = CSceneMgr::Instance()->Get_Camera();
    if(pCamera == NULL)
    {
        return;
    }
    
    glm::mat4x4 mView = pCamera->Get_View();
    glm::mat4x4 mProjection = pCamera->Get_Projection();
    
    glm::ivec4 vViewport;
    vViewport[0] = 0;
    vViewport[1] = 0;
    vViewport[2] = CWindow::Get_ScreenHeight();
    vViewport[3] = CWindow::Get_ScreenWidth();

    m_vTouchRay = Unproject(m_vTouch2DPoint, mView, mProjection, vViewport);
    CEventMgr::Instance()->OnEvent(CEventMgr::E_EVENT_TOUCH);
}
Exemple #9
0
GameObject* PickObject(const Vec2f& mouseScreen)
{
  // Get object carried by player - don't pick
  Ve1Object* carried = 0;
  Player* player = GetLocalPlayer();
  if (player)
  {
    carried = player->GetCarrying();
  }

  Vec3f mouseWorldNear;
  Vec3f mouseWorldFar;

  Unproject(mouseScreen, 0, &mouseWorldNear);
  Unproject(mouseScreen, 1, &mouseWorldFar);
  LineSeg lineSeg(mouseWorldNear, mouseWorldFar);

  GameObject* selectedObj = 0;
  GameObjects* objs = TheGame::Instance()->GetGameObjects();
  float bestDist = 9e20f;
  for (GameObjects::iterator it = objs->begin(); it != objs->end(); ++it)
  {
    GameObject* pgo = it->second;
    Assert(pgo);
    Ve1Object* v = dynamic_cast<Ve1Object*>(pgo);
    Assert(v);
    if (!v->IsPickable())
    {
#ifdef PICK_DEBUG
std::cout << " Obj " << pgo->GetId() << " is not pickable.\n";
#endif
      continue;
    }
    if (v == carried)
    {
      // Can't select it then!
      std::cout << "Skipping carried object " << *v << "\n";
      continue;
    }

    const AABB& aabb = pgo->GetAABB();
    if (Clip(lineSeg, aabb, 0))
    {
#ifdef PICK_DEBUG
std::cout << " Obj " << pgo->GetId() << " IS PICKED!\n";
#endif

      // Line seg intersects this box
      // Choose object whose centre (position) is closest to line seg..?

//      float dist = LineSeg(mouseWorldNear, mouseWorldFar).SqDist(pgo->GetPos());
      float dist = (mouseWorldNear - pgo->GetPos()).SqLen(); // pick closest

      // Treat skybox as least attractive option, followed by terrain
      if (dynamic_cast<Skybox*>(v))
      {
#ifdef PICK_DEBUG
std::cout << " Obj " << pgo->GetId() << " skybox so treated as far away\n";
#endif
        dist = 9e19f; 
      }
      else if (dynamic_cast<Terrain*>(v))
      {
#ifdef PICK_DEBUG
std::cout << " Obj " << pgo->GetId() << " terrain so treated as far away\n";
#endif
        dist = 9e18f; 
      }
#ifdef PICK_DEBUG
std::cout << " Obj " << pgo->GetId() << " sqDist: " << dist << "\n";
#endif

      if (dist < bestDist)
      {
#ifdef PICK_DEBUG
std::cout << " Obj " << pgo->GetId() << " AND IS CLOSEST!\n";
#endif

        bestDist = dist;
        selectedObj = pgo;
      }
    }
    else 
    {
#ifdef PICK_DEBUG
std::cout << " Obj " << pgo->GetId() << " is not picked.\n";
#endif
    }
  }

  return selectedObj;
}