Esempio n. 1
0
void HeightMapGen::CreateHeightmap (int heightmap_res, iCollideSystem* cdsys, 
                                     iSector* sector, csRGBpixel* hmap_dst, 
                                     float* height_dst, 
                                     const csBox3& box)
{
  csPrintf ("Creating heightmap...\n"); fflush (stdout);

  float dx = (box.MaxX () - box.MinX () - 0.2) / float (heightmap_res-1);
  float dz = (box.MaxZ () - box.MinZ () - 0.2) / float (heightmap_res-1);
  for (int z = 0 ; z < heightmap_res ; z++)
  {
    for (int x = 0 ; x < heightmap_res ; x++)
    {
      csVector3 start, end;
      start.x = box.MinX () + (float)x * dx + 0.1;
      start.y = box.MaxY () + 10.0;
      start.z = box.MinZ () + (heightmap_res-z-1) * dz + 0.1;
      end = start;
      end.y = box.MinY () - 10.0;
      csVector3 isect;
      //mesh->HitBeamObject (start, end, isect, 0, 0);
      csIntersectingTriangle closest_tri;
      csColliderHelper::TraceBeam (cdsys, sector, start, end,
      	false, closest_tri, isect);
      float y = (isect.y - box.MinY ()) / (box.MaxY () - box.MinY ());
      if (y < 0) y = 0;
      else if (y > 0.9999f) y = 0.9999f;
      *height_dst++ = y;
      y *= 256.0;
      hmap_dst->Set (int (y), int (y), int (y));
      hmap_dst++;
    }
  }
}
void csBox3::ManhattanDistance (const csBox3& other, csVector3& dist) const
{
  if (other.MinX () >= MaxX ()) dist.x = other.MinX () - MaxX ();
  else if (MinX () >= other.MaxX ()) dist.x = MinX () - other.MaxX ();
  else dist.x = 0;
  if (other.MinY () >= MaxY ()) dist.y = other.MinY () - MaxY ();
  else if (MinY () >= other.MaxY ()) dist.y = MinY () - other.MaxY ();
  else dist.y = 0;
  if (other.MinZ () >= MaxZ ()) dist.z = other.MinZ () - MaxZ ();
  else if (MinZ () >= other.MaxZ ()) dist.z = MinZ () - other.MaxZ ();
  else dist.z = 0;
}
bool csBox3::AdjacentZ (const csBox3& other) const
{
  if (ABS (other.MinZ () - MaxZ ()) < SMALL_EPSILON ||
      ABS (other.MaxZ () - MinZ ()) < SMALL_EPSILON)
  {
    if (MaxX () < other.MinX () || MinX () > other.MaxX ()) return false;
    if (MaxY () < other.MinY () || MinY () > other.MaxY ()) return false;
    return true;
  }
  return false;
}
Esempio n. 4
0
File: box.cpp Progetto: garinh/cs
bool csBox3::AdjacentZ (const csBox3 &other, float epsilon) const
{
    if (
        ABS (other.MinZ () - MaxZ ()) < epsilon ||
        ABS (other.MaxZ () - MinZ ()) < epsilon)
    {
        if (MaxX () < other.MinX () || MinX () > other.MaxX ()) return false;
        if (MaxY () < other.MinY () || MinY () > other.MaxY ()) return false;
        return true;
    }

    return false;
}
Esempio n. 5
0
File: haze.cpp Progetto: garinh/cs
float csHazeMeshObject::GetScreenBoundingBox (long cameranr,
      long movablenr, float fov, float sx, float sy,
      const csReversibleTransform& trans, csBox2& sbox, csBox3& cbox)
{
  csVector2 oneCorner;

  GetTransformedBoundingBox (cameranr, movablenr, trans, cbox);

  // if the entire bounding box is behind the camera, we're done
  if ((cbox.MinZ () < 0) && (cbox.MaxZ () < 0))
  {
    return -1;
  }

  // Transform from camera to screen space.
  if (cbox.MinZ () <= 0)
  {
    // Sprite is very close to camera.
    // Just return a maximum bounding box.
    sbox.Set (-10000, -10000, 10000, 10000);
  }
  else
  {
    Perspective (cbox.Max (), oneCorner, fov, sx, sy);
    sbox.StartBoundingBox (oneCorner);
    csVector3 v (cbox.MinX (), cbox.MinY (), cbox.MaxZ ());
    Perspective (v, oneCorner, fov, sx, sy);
    sbox.AddBoundingVertexSmart (oneCorner);
    Perspective (cbox.Min (), oneCorner, fov, sx, sy);
    sbox.AddBoundingVertexSmart (oneCorner);
    v.Set (cbox.MaxX (), cbox.MaxY (), cbox.MinZ ());
    Perspective (v, oneCorner, fov, sx, sy);
    sbox.AddBoundingVertexSmart (oneCorner);
  }

  return cbox.MaxZ ();
}