Ejemplo n.º 1
0
	std::pair<CVolumetricLightScattering::ScatteringParams, bool> CVolumetricLightScattering::getClosestLightSource(const std::list<ScatteringParams>& lightList) {
		std::pair<ScatteringParams, bool> closestLightSrc;
		closestLightSrc.second = false;

		// Obtenemos el puntero a la entidad del jugador que en este caso es lo que nos interesa
		Logic::CEntity* player = Input::CServer::getSingletonPtr()->getPlayerController()->getControllerAvatar();
		if(player != NULL) {
			Vector3 playerPosition = player->getPosition();
			Vector2 playerPos2d(playerPosition.x, playerPosition.z);

			auto it = lightList.begin();
			Vector2 pos2d(it->lightPosition.x, it->lightPosition.z);
			auto closestLight = it++;
			float closestDist = (playerPos2d - pos2d).length();
			float dist;

			for(; it != lightList.end(); ++it) {
				pos2d.x = it->lightPosition.x;
				pos2d.y = it->lightPosition.z;

				dist = (playerPos2d - pos2d).length();
				if(dist < closestDist) {
					closestLight = it;
					closestDist = dist;
				}
			}

			closestLightSrc.second = true;
			closestLightSrc.first = *closestLight;
		}

		return closestLightSrc;
	}
Ejemplo n.º 2
0
void Draw::DrawPoint(const fPoint &pos, const cColorRGBA &color)
{
	VertexDraw2D *buffer = LE_DrawManager.GetVertexBuffer2D(1);
	fVector3 pos2d(pos.x, pos.y, 0.0f);
    fSize screenSize(LE_DrawManager.GetVirtualScreenSize());
	buffer->SetPosition(pos2d/screenSize);
	buffer->SetColor(color);
    LE_DrawManager.Draw2DFlush(GraphicsFlag::PT_POINTLIST);
}
Ejemplo n.º 3
0
void csMeshGenerator::UpdateForPosition (const csVector3& pos)
{
  csVector3 delta = pos - last_pos;

  last_pos = pos;
  SetupSampleBox ();

  for (size_t i = 0 ; i < geometries.GetSize () ; i++) 
  { 
    geometries[i]->UpdatePosition (pos); 
  } 

  int cellx = GetCellX (pos.x);
  int cellz = GetCellZ (pos.z);

  // Total maximum distance for all geometries.
  float md = GetTotalMaxDist ();
  float sqmd = md * md;
  // Same in cell counts:
  int cell_x_md = 1+int (md * samplefact_x);
  int cell_z_md = 1+int (md * samplefact_z);

  // @@@ This can be done more efficiently.
  csVector2 pos2d (pos.x, pos.z);
  int x, z;

  int minz = cellz - cell_z_md;
  if (minz < 0) minz = 0;
  int maxz = cellz + cell_z_md+1;
  if (maxz > cell_dim) maxz = cell_dim;

  int minx = cellx - cell_x_md;
  if (minx < 0) minx = 0;
  int maxx = cellx + cell_x_md+1;
  if (maxx > cell_dim) maxx = cell_dim;

  // Calculate the intersection of minx, ... with prev_minx, ...
  // This intersection represent all cells that are not used this frame
  // but may potentially have gotten meshes the previous frame. We need
  // to free those meshes.
  csRect cur_cells (minx, minz, maxx, maxz);
  if (!prev_cells.IsEmpty ())
  {
    for (z = prev_cells.ymin ; z < prev_cells.ymax ; z++)
      for (x = prev_cells.xmin ; x < prev_cells.xmax ; x++)
        if (!cur_cells.Contains (x, z))
        {
          int cidx = z*cell_dim + x;
          csMGCell& cell = cells[cidx];
          FreeMeshesInBlock (cidx, cell);
        }
  }
  prev_cells = cur_cells;

  int total_needed = 0;

  // Now allocate the cells that are close enough.
  for (z = minz ; z < maxz ; z++)
  {
    int cidx = z*cell_dim + minx;
    for (x = minx ; x < maxx ; x++)
    {
      csMGCell& cell = cells[cidx];
      float sqdist = cell.box.SquaredPosDist (pos2d);

      if (sqdist < sqmd)
      {
        total_needed++;
        if (total_needed >= max_blocks)
        {
          engine->Error (
            "The mesh generator needs more blocks than %d!", max_blocks);
          return;	// @@@ What to do here???
        }
        AllocateBlock (cidx, cell);
        AllocateMeshes (cidx, cell, pos, delta);
      }
      else
      {
        // Block is out of range. We keep the block in the cache
        // but free all meshes that are in it.
        FreeMeshesInBlock (cidx, cell);
      }
      cidx++;
    }
  }

  // Housekeeping
  size_t i;
  for (i = 0 ; i < geometries.GetSize () ; i++)
  {
    geometries[i]->FinishUpdate ();
  }
}