PerspectiveTransform PerspectiveTransform::SquareToQuadrilateral(Point2i a, Point2i b,
                                                                 Point2i c, Point2i d)
{
   PerspectiveTransform pt;

   long dy2 = d.y - c.y;
   long dy3 = a.y - b.y + c.y - d.y;

   if (dy2 == 0 && dy3 == 0)
   {
      pt = PerspectiveTransform(b.x - a.x, c.x - b.x, a.x,
                                b.y - a.y, c.y - b.y, a.y,
                                0, 0, 1);
   }
   else
   {
      long dx1 = b.x - c.x;
      long dx2 = d.x - c.x;
      long dx3 = a.x - b.x + c.x - d.x;
      long dy1 = b.y - c.y;
      long denominator = dx1 * dy2 - dx2 * dy1;
      long a13 = (dx3 * dy2 - dx2 * dy3) / denominator;
      long a23 = (dx1 * dy3 - dx3 * dy1) / denominator;

      pt = PerspectiveTransform(b.x - a.x + a13 * b.x, d.x - a.x + a23 * d.x, a.x,
                                b.y - a.y + a13 * b.y, d.y - a.y + a23 * d.y, a.y,
                                a13, a23, 1);
   }

   return pt;
}
예제 #2
0
파일: Camera.cpp 프로젝트: davidsami/RayRay
void Camera::Init(Math::Transform aCameraToWorld, double aFov, uint32_t xDim, uint32_t yDim)
{
    mCameraToWorld = aCameraToWorld;
    mScreenToCamera = PerspectiveTransform(aFov, CAMERA_CLOSE_PLANE, CAMERA_FAR_PLANE, xDim, yDim);
    mX = xDim;
    mY = yDim;
}
예제 #3
0
파일: Camera.cpp 프로젝트: davidsami/RayRay
Camera::Camera():
    mCameraToWorld(Math::Transform::Identity()),
    mScreenToCamera(PerspectiveTransform(CAMERA_DEFAULT_FOV, CAMERA_CLOSE_PLANE, CAMERA_FAR_PLANE, CAMERA_DEFAULT_X, CAMERA_DEFAULT_Y)),
    mX(CAMERA_DEFAULT_X),
    mY(CAMERA_DEFAULT_Y)
{
}
PerspectiveTransform operator*(const PerspectiveTransform& a, const PerspectiveTransform& b)
{
   return PerspectiveTransform(a.m11 * b.m11 + a.m21 * b.m12 + a.m31 * b.m13,
                               a.m11 * b.m21 + a.m21 * b.m22 + a.m31 * b.m23,
                               a.m11 * b.m31 + a.m21 * b.m32 + a.m31 * b.m33,
                               a.m12 * b.m11 + a.m22 * b.m12 + a.m32 * b.m13,
                               a.m12 * b.m21 + a.m22 * b.m22 + a.m32 * b.m23,
                               a.m12 * b.m31 + a.m22 * b.m32 + a.m32 * b.m33,
                               a.m13 * b.m11 + a.m23 * b.m12 + a.m33 * b.m13,
                               a.m13 * b.m21 + a.m23 * b.m22 + a.m33 * b.m23,
                               a.m13 * b.m31 + a.m23 * b.m32 + a.m33 * b.m33);
}
PerspectiveTransform PerspectiveTransform::BuildAdjoint()
{
   return PerspectiveTransform(m22 * m33 - m23 * m32,
                               m23 * m31 - m21 * m33,
                               m21 * m32 - m22 * m31,
                               m13 * m32 - m12 * m33,
                               m11 * m33 - m13 * m31,
                               m12 * m31 - m11 * m32,
                               m12 * m23 - m13 * m22,
                               m13 * m21 - m11 * m23,
                               m11 * m22 - m12 * m21);
}