예제 #1
0
csBox3 csReversibleTransform::This2Other (const csBox3 &box) const
{
  if (m_t2o.IsIdentity())
  {
    csBox3 newBox (box);
    newBox.SetCenter (This2Other (box.GetCenter()));
    return newBox;
  }
  else
  {
    const csVector3 minA = box.Min ();
    const csVector3 maxA = box.Max ();

    csVector3 minB (v_o2t);
    csVector3 maxB (v_o2t);

    for (size_t i = 0; i < 3; ++i)
    {
      const csVector3 row = m_t2o.Row (i);
      for (size_t j = 0; j < 3; ++j)
      {
        float a = row[j] * minA[j];
        float b = row[j] * maxA[j];
        if (a < b)
        {
          minB[i] += a;
          maxB[i] += b;
        }
        else
        {
          minB[i] += b;
          maxB[i] += a;
        }
      }
    }

    return csBox3 (minB, maxB);
  }
}
예제 #2
0
파일: procmesh.cpp 프로젝트: garinh/cs
void csMeshOnTexture::ScaleCamera (iMeshWrapper* mesh, int txtw, int txth)
{
  UpdateView (txtw, txth);
  const csBox3 mesh_box = mesh->GetWorldBoundingBox ();
  const csVector3 mesh_center = mesh_box.GetCenter ();
  const iPerspectiveCamera* camera = view->GetPerspectiveCamera ();
  const float aspect = camera->GetFOV ();
  const float shift_x = camera->GetShiftX ();
  const float shift_y = camera->GetShiftY ();
  int i;
  float maxz = -100000000.0f;
  for (i = 0 ; i < 8 ; i++)
  {
    csVector3 corner = mesh_box.GetCorner (i) - mesh_center;
    float z = (corner.x * aspect) / (1.0f - shift_x);
    if (z < 0) z = (corner.x * aspect) / (float (txtw) - shift_x);
    z += corner.z;
    if (z > maxz) maxz = z;

    z = (corner.y * aspect) / (1.0f - shift_y);
    if (z < 0) z = (corner.y * aspect) / (float (txth) - shift_y);
    z += corner.z;
    if (z > maxz) maxz = z;
  }

  csVector3 cam_pos = mesh_center;
  cam_pos.z -= maxz;
  for (i = 0 ; i < 8 ; i++)
  {
    csVector3 corner = mesh_box.GetCorner (i) - cam_pos;
    csVector2 p = view->GetCamera()->Perspective (corner);
  }

  view->GetCamera()->GetTransform ().Identity ();
  view->GetCamera()->GetTransform ().SetOrigin (cam_pos);
}