Esempio n. 1
0
ezUInt32 ez2DGridUtils::FloodFill(ezInt32 iStartX, ezInt32 iStartY, EZ_RASTERIZED_POINT_CALLBACK Callback, void* pPassThrough /* = NULL */, ezDeque<ezVec2I32>* pTempArray /* = NULL */)
{
  ezUInt32 uiFilled = 0;

  ezDeque<ezVec2I32> FallbackQueue;

  if (pTempArray == NULL)
    pTempArray = &FallbackQueue;

  pTempArray->Clear();
  pTempArray->PushBack(ezVec2I32(iStartX, iStartY));

  while (!pTempArray->IsEmpty())
  {
    ezVec2I32 v = pTempArray->PeekBack();
    pTempArray->PopBack();

    if (Callback(v.x, v.y, pPassThrough) == ezCallbackResult::Continue)
    {
      ++uiFilled;

      // put the four neighbors into the queue
      pTempArray->PushBack(ezVec2I32(v.x - 1, v.y));
      pTempArray->PushBack(ezVec2I32(v.x + 1, v.y));
      pTempArray->PushBack(ezVec2I32(v.x, v.y - 1));
      pTempArray->PushBack(ezVec2I32(v.x, v.y + 1));
    }
  }

  return uiFilled;
}
Esempio n. 2
0
ezEditorInput ezConeAngleGizmo::DoMouseMoveEvent(QMouseEvent* e)
{
  if (!IsActiveInputContext())
    return ezEditorInput::MayBeHandledByOthers;

  const ezTime tNow = ezTime::Now();

  if (tNow - m_LastInteraction < ezTime::Seconds(1.0 / 25.0))
    return ezEditorInput::WasExclusivelyHandled;

  m_LastInteraction = tNow;

  const ezVec2I32 vNewMousePos = ezVec2I32(e->globalPos().x(), e->globalPos().y());
  const ezVec2I32 vDiff = vNewMousePos - m_LastMousePos;

  m_LastMousePos = UpdateMouseMode(e);

  const float fSpeed = 0.02f;
  const ezAngle aSpeed = ezAngle::Degree(1.0f);

  {
    m_Angle += vDiff.x * aSpeed;
    m_Angle -= vDiff.y * aSpeed;

    m_Angle = ezMath::Clamp(m_Angle, ezAngle(), ezAngle::Degree(179.0f));

    m_fAngleScale = ezMath::Tan(m_Angle * 0.5f);
  }

  // update the scale
  OnTransformationChanged(GetTransformation());

  ezGizmoEvent ev;
  ev.m_pGizmo = this;
  ev.m_Type = ezGizmoEvent::Type::Interaction;
  m_GizmoEvents.Broadcast(ev);

  return ezEditorInput::WasExclusivelyHandled;
}
Esempio n. 3
0
void GameRenderer::RenderGrid()
{
  const ezVec3 vCellSize = m_pGrid->GetWorldSpaceCellSize();
  const ezVec3 vCellSize2 (vCellSize.x, 0.1f, vCellSize.z);

  for (ezUInt32 z = 0; z < m_pGrid->GetGridHeight(); ++z)
  {
    for (ezUInt32 x = 0; x < m_pGrid->GetGridWidth(); ++x)
    {
      const GameCellData& cd = m_pGrid->GetCell(ezVec2I32(x, z));

      const ezUInt32 uiVisibility = CVarVisFogOfWar ? cd.m_uiVisibility : 255;

      if (uiVisibility == 0)
      {
        glColor3ub(20, 20, 20);
        RenderCube(m_pGrid->GetCellWorldSpaceOrigin(ezVec2I32(x, z)), vCellSize2, false);
        continue;
      }

      bool bColor = true;
      float fFade = 1.0f;

      if (uiVisibility <= 100)
        fFade = uiVisibility / 100.0f;

      fFade = ezMath::Max(fFade, 50.0f / 255.0f);

      if (CVarVisThreat && cd.m_iThreat > 0)
      {
        glColor3ub(255, 0, 220);
        RenderCube(m_pGrid->GetCellWorldSpaceOrigin(ezVec2I32(x, z)), vCellSize2, false, fFade);
      }

      //if (!cd.m_hUnit.IsInvalidated())
      //{
      //  glColor3ub(0, 100, 0);
      //  RenderCube(m_pGrid->GetCellWorldSpaceOrigin(ezVec2I32(x, z)), vCellSize2, false, fFade);
      //}
      //else
      {
        if (cd.m_iCellType == 1)
          RenderCube(m_pGrid->GetCellWorldSpaceOrigin(ezVec2I32(x, z)), vCellSize, true, fFade);
        else
          RenderCube(m_pGrid->GetCellWorldSpaceOrigin(ezVec2I32(x, z)), vCellSize2, true, fFade);
      }
    }
  }
  
  if (CVarVisNavmeshCells)
  {
    ezUInt8 uiGreen = 30;

    for (ezUInt32 ca = 0; ca < m_pNavmesh->GetNumConvexAreas(); ++ca)
    {
      const ezRectU32& r = m_pNavmesh->GetConvexArea(ca).m_Rect;

      const ezVec2I32 ll(r.x, r.y);
      const ezVec2I32 tr(r.x + r.width, r.y + r.height);

      const ezVec3 vLL = m_pGrid->GetCellWorldSpaceOrigin(ll);
      const ezVec3 vTR = m_pGrid->GetCellWorldSpaceOrigin(tr);

      glColor3ub(uiGreen, 20, 20);
      uiGreen += 30;
      ezVec3 vHalfWidth = (vTR - vLL);
      vHalfWidth.y = 0.5f;
      RenderCube(vLL + ezVec3(0.1f, 0, 0.1f), vHalfWidth - ezVec3(0.2f, 0, 0.2f), false);

    }
  }

  if (CVarVisNavmeshEdges)
  {
    ezUInt8 uiGreen = 30;

    for (ezUInt32 ca = 0; ca < m_pNavmesh->GetNumAreaEdges(); ++ca)
    {
      const ezGridNavmesh::AreaEdge& r = m_pNavmesh->GetAreaEdge(ca);

      const ezVec2I32 ll(r.m_EdgeRect.x, r.m_EdgeRect.y);
      const ezVec2I32 tr(r.m_EdgeRect.x + r.m_EdgeRect.width, r.m_EdgeRect.y + r.m_EdgeRect.height);

      const ezVec3 vLL = m_pGrid->GetCellWorldSpaceOrigin(ll);
      const ezVec3 vTR = m_pGrid->GetCellWorldSpaceOrigin(tr);

      glColor3ub(20, 20, uiGreen);
      uiGreen += 30;
      ezVec3 vHalfWidth = (vTR - vLL);
      vHalfWidth.y = 0.5f;
      RenderCube(vLL + ezVec3(0.1f, 0, 0.1f), vHalfWidth - ezVec3(0.2f, 0, 0.2f), false);

    }
  }
}