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;
}
Exemple #2
0
int csBox3::Adjacent (const csBox3 &other, float epsilon) const
{
    if (AdjacentX (other, epsilon))
    {
        if (other.MaxX () > MaxX ())
            return CS_BOX_SIDE_X;
        else
            return CS_BOX_SIDE_x;
    }

    if (AdjacentY (other, epsilon))
    {
        if (other.MaxY () > MaxY ())
            return CS_BOX_SIDE_Y;
        else
            return CS_BOX_SIDE_y;
    }

    if (AdjacentZ (other, epsilon))
    {
        if (other.MaxZ () > MaxZ ())
            return CS_BOX_SIDE_Z;
        else
            return CS_BOX_SIDE_z;
    }

    return -1;
}
static csVector3 FindBiggestHorizontalMovement (
    const csBox3& box1, const csReversibleTransform& trans1,
    const csBox3& box2, const csReversibleTransform& trans2)
{
  // The origin of the second box in the 3D space of the first box.
  csVector3 o2Tr = trans1.Other2This (trans2.GetOrigin ());
  // Transformed bounding box.
  csBox3 box2Tr;
  box2Tr.StartBoundingBox (trans1.Other2ThisRelative (trans2.This2OtherRelative (box2.GetCorner (0))));
  box2Tr.AddBoundingVertexSmart (trans1.Other2ThisRelative (trans2.This2OtherRelative (box2.GetCorner (1))));
  box2Tr.AddBoundingVertexSmart (trans1.Other2ThisRelative (trans2.This2OtherRelative (box2.GetCorner (2))));
  box2Tr.AddBoundingVertexSmart (trans1.Other2ThisRelative (trans2.This2OtherRelative (box2.GetCorner (3))));
  box2Tr.AddBoundingVertexSmart (trans1.Other2ThisRelative (trans2.This2OtherRelative (box2.GetCorner (4))));
  box2Tr.AddBoundingVertexSmart (trans1.Other2ThisRelative (trans2.This2OtherRelative (box2.GetCorner (5))));
  box2Tr.AddBoundingVertexSmart (trans1.Other2ThisRelative (trans2.This2OtherRelative (box2.GetCorner (6))));
  box2Tr.AddBoundingVertexSmart (trans1.Other2ThisRelative (trans2.This2OtherRelative (box2.GetCorner (7))));

  float xr = o2Tr.x - box1.MaxX () + box2Tr.MinX ();
  float xl = box1.MinX () - o2Tr.x - box2Tr.MaxX ();
  float zr = o2Tr.z - box1.MaxZ () + box2Tr.MinZ ();
  float zl = box1.MinZ () - o2Tr.z - box2Tr.MaxZ ();
  csVector3 newpos = trans2.GetOrigin ();
  if (xr >= xl && xr >= zr && xr >= zl)
    newpos = trans1.This2Other (o2Tr + csVector3 (-xr, 0, -o2Tr.z));
  else if (xl >= xr && xl >= zr && xl >= zl)
    newpos = trans1.This2Other (o2Tr + csVector3 (xl, 0, -o2Tr.z));
  else if (zr >= xl && zr >= xr && zr >= zl)
    newpos = trans1.This2Other (o2Tr + csVector3 (-o2Tr.x, 0, -zr));
  else if (zl >= xl && zl >= xr && zl >= zr)
    newpos = trans1.This2Other (o2Tr + csVector3 (-o2Tr.x, 0, zl));
  return newpos;
}
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++;
    }
  }
}
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;
}
Exemple #6
0
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;
}
Exemple #7
0
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 ();
}
int csBox3::Adjacent (const csBox3& other) const
{
  if (AdjacentX (other))
  {
    if (other.MaxX () > MaxX ()) return BOX_SIDE_X;
    else return BOX_SIDE_x;
  }
  if (AdjacentY (other))
  {
    if (other.MaxY () > MaxY ()) return BOX_SIDE_Y;
    else return BOX_SIDE_y;
  }
  if (AdjacentZ (other))
  {
    if (other.MaxZ () > MaxZ ()) return BOX_SIDE_Z;
    else return BOX_SIDE_z;
  }
  return -1;
}