Ejemplo n.º 1
0
GeoBounds
FlatProjection::Unproject(const FlatBoundingBox &bb) const
{
    assert(IsValid());

    return GeoBounds(Unproject(bb.GetTopLeft()), Unproject(bb.GetBottomRight()));
}
Ejemplo n.º 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);
		}
Ejemplo n.º 3
0
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)));
}
Ejemplo n.º 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;
}
Ejemplo n.º 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);
}
Ejemplo n.º 6
0
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;
}
Ejemplo n.º 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;
}
Ejemplo n.º 8
0
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);
}
Ejemplo n.º 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;
}