Ejemplo n.º 1
0
void MyPosition::RenderAccuracy(ScreenBase const & screen,
                        ref_ptr<dp::GpuProgramManager> mng,
                        dp::UniformValuesStorage const & commonUniforms)
{
  dp::UniformValuesStorage uniforms = commonUniforms;
  m2::PointD accuracyPoint(m_position.x + m_accuracy, m_position.y);
  float pixelAccuracy = (screen.GtoP(accuracyPoint) - screen.GtoP(m_position)).Length();

  uniforms.SetFloatValue("u_position", m_position.x, m_position.y, dp::depth::POSITION_ACCURACY);
  uniforms.SetFloatValue("u_accuracy", pixelAccuracy);
  uniforms.SetFloatValue("u_opacity", 1.0);
  RenderPart(mng, uniforms, MY_POSITION_ACCURACY);
}
Ejemplo n.º 2
0
void RulerHelper::Update(ScreenBase const & screen)
{
  m2::PointD pivot = screen.PixelRect().Center();
  int const minPxWidth = my::rounds(MinPixelWidth * df::VisualParams::Instance().GetVisualScale());
  m2::PointD pt1 = screen.PtoG(pivot);
  m2::PointD pt0 = screen.PtoG(pivot - m2::PointD(minPxWidth, 0));

  double const distanceInMetres = MercatorBounds::DistanceOnEarth(pt0, pt1);

  // convert metres to units for calculating m_metresDiff
  double metersDiff = CalcMetresDiff(distanceInMetres);

  bool const higherThanMax = metersDiff > MaxMetersWidth;
  bool const lessThanMin = metersDiff < MinMetersWidth;
  m_pixelLength = minPxWidth;

  if (higherThanMax)
    m_pixelLength = minPxWidth * 3 / 2;
  else if (!lessThanMin)
  {
    double const a = ang::AngleTo(pt1, pt0);
    pt0 = MercatorBounds::GetSmPoint(pt1, cos(a) * metersDiff, sin(a) * metersDiff);

    m_pixelLength = my::rounds(pivot.Length(screen.GtoP(pt0)));
  }

  int drawScale = df::GetDrawTileScale(screen);
  if (m_currentDrawScale < VISIBLE_RULER_BOTTOM_SCALE &&
      drawScale >= VISIBLE_RULER_BOTTOM_SCALE)
  {
    SetTextDirty();
  }

  m_currentDrawScale = drawScale;
}
Ejemplo n.º 3
0
bool IsPanningAndRotate(ScreenBase const & s1, ScreenBase const & s2)
{
  m2::RectD const & r1 = s1.GlobalRect().GetLocalRect();
  m2::RectD const & r2 = s2.GlobalRect().GetLocalRect();

  m2::PointD c1 = r1.Center();
  m2::PointD c2 = r2.Center();

  m2::PointD globPt(c1.x - r1.minX(),
                    c1.y - r1.minY());

  m2::PointD p1 = s1.GtoP(s1.GlobalRect().ConvertFrom(c1)) - s1.GtoP(s1.GlobalRect().ConvertFrom(c1 + globPt));
  m2::PointD p2 = s2.GtoP(s2.GlobalRect().ConvertFrom(c2)) - s2.GtoP(s2.GlobalRect().ConvertFrom(c2 + globPt));

  return p1.EqualDxDy(p2, 0.00001);
}
Ejemplo n.º 4
0
void SelectionShape::Render(ScreenBase const & screen, int zoomLevel, ref_ptr<dp::GpuProgramManager> mng,
                            dp::UniformValuesStorage const & commonUniforms)
{
  ShowHideAnimation::EState state = m_animation.GetState();
  if (state == ShowHideAnimation::STATE_VISIBLE ||
      state == ShowHideAnimation::STATE_SHOW_DIRECTION)
  {
    dp::UniformValuesStorage uniforms = commonUniforms;
    TileKey const key = GetTileKeyByPoint(m_position, ClipTileZoomByMaxDataZoom(zoomLevel));
    math::Matrix<float, 4, 4> mv = key.GetTileBasedModelView(screen);
    uniforms.SetMatrix4x4Value("modelView", mv.m_data);

    m2::PointD const pos = MapShape::ConvertToLocal(m_position, key.GetGlobalRect().Center(), kShapeCoordScalar);
    uniforms.SetFloatValue("u_position", pos.x, pos.y, -m_positionZ);

    float accuracy = m_mapping.GetValue(m_animation.GetT());
    if (screen.isPerspective())
    {
      m2::PointD const pt1 = screen.GtoP(m_position);
      m2::PointD const pt2(pt1.x + 1, pt1.y);
      float const scale = screen.PtoP3d(pt2).x - screen.PtoP3d(pt1).x;
      accuracy /= scale;
    }
    uniforms.SetFloatValue("u_accuracy", accuracy);
    uniforms.SetFloatValue("u_opacity", 1.0f);
    m_renderNode->Render(mng, uniforms);
  }
}
Ejemplo n.º 5
0
void MyPosition::RenderAccuracy(ScreenBase const & screen, int zoomLevel,
                                ref_ptr<dp::GpuProgramManager> mng,
                                dp::UniformValuesStorage const & commonUniforms)
{
  dp::UniformValuesStorage uniforms = commonUniforms;
  m2::PointD accuracyPoint(m_position.x + m_accuracy, m_position.y);
  float pixelAccuracy = (screen.GtoP(accuracyPoint) - screen.GtoP(m_position)).Length();

  TileKey const key = GetTileKeyByPoint(m_position, ClipTileZoomByMaxDataZoom(zoomLevel));
  math::Matrix<float, 4, 4> mv = key.GetTileBasedModelView(screen);
  uniforms.SetMatrix4x4Value("modelView", mv.m_data);

  m2::PointD const pos = MapShape::ConvertToLocal(m_position, key.GetGlobalRect().Center(), kShapeCoordScalar);
  uniforms.SetFloatValue("u_position", pos.x, pos.y, 0.0f);
  uniforms.SetFloatValue("u_accuracy", pixelAccuracy);
  uniforms.SetFloatValue("u_opacity", 1.0f);
  RenderPart(mng, uniforms, MY_POSITION_ACCURACY);
}
Ejemplo n.º 6
0
bool SelectionShape::IsVisible(ScreenBase const & screen, m2::PointD & pxPos) const
{
  m2::PointD const pt = screen.GtoP(m_position);
  ShowHideAnimation::EState state = m_animation.GetState();

  if ((state == ShowHideAnimation::STATE_VISIBLE || state == ShowHideAnimation::STATE_SHOW_DIRECTION) &&
      !screen.IsReverseProjection3d(pt))
  {
    pxPos = screen.PtoP3d(pt, -m_positionZ);
    return true;
  }
  return false;
}
Ejemplo n.º 7
0
math::Matrix<float, 4, 4> Arrow3d::CalculateTransform(ScreenBase const & screen, float dz) const
{
    double arrowScale = VisualParams::Instance().GetVisualScale() * kArrowSize;
    if (screen.isPerspective())
    {
        static double const kLog2 = log(2.0);
        double const kMaxZoom = scales::UPPER_STYLE_SCALE + 1.0;
        double const zoomLevel = my::clamp(fabs(log(screen.GetScale()) / kLog2), kArrow3dMinZoom, kMaxZoom);
        double const t = (zoomLevel - kArrow3dMinZoom) / (kMaxZoom - kArrow3dMinZoom);
        arrowScale *= (kArrow3dScaleMin * (1.0 - t) + kArrow3dScaleMax * t);
    }

    double const scaleX = arrowScale * 2.0 / screen.PixelRect().SizeX();
    double const scaleY = arrowScale * 2.0 / screen.PixelRect().SizeY();
    double const scaleZ = screen.isPerspective() ? (0.002 * screen.GetDepth3d()) : 1.0;

    m2::PointD const pos = screen.GtoP(m_position);
    double const dX = 2.0 * pos.x / screen.PixelRect().SizeX() - 1.0;
    double const dY = 2.0 * pos.y / screen.PixelRect().SizeY() - 1.0;

    math::Matrix<float, 4, 4> scaleM = math::Identity<float, 4>();
    scaleM(0, 0) = scaleX;
    scaleM(1, 1) = scaleY;
    scaleM(2, 2) = scaleZ;

    math::Matrix<float, 4, 4> rotateM = math::Identity<float, 4>();
    rotateM(0, 0) = cos(m_azimuth + screen.GetAngle());
    rotateM(0, 1) = -sin(m_azimuth + screen.GetAngle());
    rotateM(1, 0) = -rotateM(0, 1);
    rotateM(1, 1) = rotateM(0, 0);

    math::Matrix<float, 4, 4> translateM = math::Identity<float, 4>();
    translateM(3, 0) = dX;
    translateM(3, 1) = -dY;
    translateM(3, 2) = dz;

    math::Matrix<float, 4, 4> modelTransform = rotateM * scaleM * translateM;
    if (screen.isPerspective())
        return modelTransform * math::Matrix<float, 4, 4>(screen.Pto3dMatrix());

    return modelTransform;
}
Ejemplo n.º 8
0
void SelectionShape::Render(ScreenBase const & screen, ref_ptr<dp::GpuProgramManager> mng,
                            dp::UniformValuesStorage const & commonUniforms)
{
  ShowHideAnimation::EState state = m_animation.GetState();
  if (state == ShowHideAnimation::STATE_VISIBLE ||
      state == ShowHideAnimation::STATE_SHOW_DIRECTION)
  {
    dp::UniformValuesStorage uniforms = commonUniforms;
    uniforms.SetFloatValue("u_position", m_position.x, m_position.y, -m_positionZ);

    float accuracy = m_mapping.GetValue(m_animation.GetT());
    if (screen.isPerspective())
    {
      m2::PointD const pt1 = screen.GtoP(m_position);
      m2::PointD const pt2(pt1.x + 1, pt1.y);
      float const scale = screen.PtoP3d(pt2).x - screen.PtoP3d(pt1).x;
      accuracy /= scale;
    }
    uniforms.SetFloatValue("u_accuracy", accuracy);
    uniforms.SetFloatValue("u_opacity", 1.0f);
    m_renderNode->Render(mng, uniforms);
  }
}
Ejemplo n.º 9
0
 inline m2::PointD GtoP(m2::PointD const & p) const { return m_currentModelView.GtoP(p); }
Ejemplo n.º 10
0
 m2::PointD g2p(m2::PointD const & pt) const
 {
   return m_convertor->GtoP(pt);
 }
Ejemplo n.º 11
0
void Arrow3d::Render(ScreenBase const & screen, ref_ptr<dp::GpuProgramManager> mng)
{
  // Unbind current VAO, because glVertexAttributePointer and glEnableVertexAttribute can affect it.
  GLFunctions::glBindVertexArray(0);

  ref_ptr<dp::GpuProgram> prg = mng->GetProgram(gpu::ARROW_3D_PROGRAM);
  prg->Bind();

  if (!m_isInitialized)
  {
    Build(prg);
    m_isInitialized = true;
  }

  dp::ApplyState(m_state, prg);

  static double const kLog2 = log(2.0);
  double const kMaxZoom = scales::UPPER_STYLE_SCALE + 1.0;
  double const zoomLevel = my::clamp(fabs(log(screen.GetScale()) / kLog2), kArrow3dMinZoom, kMaxZoom);
  double const t = (zoomLevel - kArrow3dMinZoom) / (kMaxZoom - kArrow3dMinZoom);
  double const arrowScale = kArrow3dScaleMin * (1.0 - t) + kArrow3dScaleMax * t;

  double const scaleX = m_pixelWidth * arrowScale * 2.0 / screen.PixelRect().SizeX() / kArrowSizeX;
  double const scaleY = m_pixelHeight * arrowScale * 2.0 / screen.PixelRect().SizeY() / kArrowSizeY;
  double const scaleZ = scaleX;

  m2::PointD const pos = screen.GtoP(m_position);
  double const dX = 2.0 * pos.x / screen.PixelRect().SizeX() - 1.0;
  double const dY = 2.0 * pos.y / screen.PixelRect().SizeY() - 1.0;

  math::Matrix<float, 4, 4> scaleM = math::Identity<float, 4>();
  scaleM(0, 0) = scaleX;
  scaleM(1, 1) = scaleY;
  scaleM(2, 2) = scaleZ;

  math::Matrix<float, 4, 4> rotateM = math::Identity<float, 4>();
  rotateM(0, 0) = cos(m_azimuth + screen.GetAngle());
  rotateM(0, 1) = -sin(m_azimuth + screen.GetAngle());
  rotateM(1, 0) = -rotateM(0, 1);
  rotateM(1, 1) = rotateM(0, 0);

  math::Matrix<float, 4, 4> translateM = math::Identity<float, 4>();
  translateM(3, 0) = dX;
  translateM(3, 1) = -dY;

  math::Matrix<float, 4, 4> modelTransform = rotateM * scaleM * translateM;
  modelTransform = modelTransform * math::Matrix<float, 4, 4>(screen.Pto3dMatrix());

  dp::UniformValuesStorage uniforms;
  uniforms.SetMatrix4x4Value("m_transform", modelTransform.m_data);

  dp::ApplyUniforms(uniforms, prg);

  GLFunctions::glBindBuffer(m_bufferId, gl_const::GLArrayBuffer);
  GLFunctions::glEnableVertexAttribute(m_attributePosition);
  GLFunctions::glVertexAttributePointer(m_attributePosition, 3, gl_const::GLFloatType, false, 0, 0);

  GLFunctions::glBindBuffer(m_bufferNormalsId, gl_const::GLArrayBuffer);
  GLFunctions::glEnableVertexAttribute(m_attributeNormal);
  GLFunctions::glVertexAttributePointer(m_attributeNormal, 3, gl_const::GLFloatType, false, 0, 0);

  GLFunctions::glDrawArrays(gl_const::GLTriangles, 0, m_vertices.size() / 3);

  prg->Unbind();
  GLFunctions::glBindBuffer(0, gl_const::GLArrayBuffer);
}