18 Spring/4611 Programming Interative Graphics and Games/Assignments/a6-harold/sky.cc
/// Projects a 2D normalized screen point (e.g., the mouse position in normalized
/// device coordinates) to a 3D point on the "sky", which is really a huge sphere
/// (radius = 1500) that the viewer is inside.  This function should always return
/// true since any screen point can successfully be projected onto the sphere.
/// sky_point is set to the resulting 3D point.  Note, this function only checks
/// to see if the ray passing through the screen point intersects the sphere; it
/// does not check to see if the ray hits the ground or anything else first.
Projects a 2D normalized screen point  to a 3D point on the "sky", which is really a huge sphere
(radius = 1500) that the viewer is inside.  This function should always return
true since any screen point can successfully be projected onto the sphere.
sky_point is set to the resulting 3D point.  Note, this function only checks
to see if the ray passing through the screen point intersects the sphere; it
does not check to see if the ray hits the ground or anything else first.
Projects a 2D normalized screen point to a 3D point on the " sky " which is really a huge sphere ( radius = 1500 ) that the viewer is inside . This function should always return true since any screen point can successfully be projected onto the sphere . sky_point is set to the resulting 3D point . Note this function only checks to see if the ray passing through the screen point intersects the sphere ; it does not check to see if the ray hits the ground or anything else first .
bool Sky::ScreenPtToSky(const Matrix4 &view_matrix, const Matrix4 &proj_matrix,
                        const Point2 &normalized_screen_pt, Point3 *sky_point)
{
    Matrix4 camera_matrix = view_matrix.Inverse();
    Point3 eye = camera_matrix.ColumnToPoint3(3);
    Point3 pt3d = GfxMath::ScreenToNearPlane(view_matrix, proj_matrix, normalized_screen_pt);
    Ray ray(eye, (pt3d - eye).ToUnit());
    float t;
    return ray.IntersectSphere(Point3::Origin(), 1500.0, &t, sky_point);
}
bool Sky :: ScreenPtToSky ( const Matrix4 & view_matrix , const Matrix4 & proj_matrix , const Point2 & normalized_screen_pt , Point3 * sky_point ) { Matrix4 camera_matrix = view_matrix . Inverse ( ) ; Point3 eye = camera_matrix . ColumnToPoint3 ( 3 ) ; Point3 pt3d = GfxMath :: ScreenToNearPlane ( view_matrix , proj_matrix , normalized_screen_pt ) ; Ray ray ( eye , ( pt3d - eye ) . ToUnit ( ) ) ; float t ; return ray . IntersectSphere ( Point3 :: Origin ( ) , 1500.0 , & t , sky_point ) ; }
Projects a 2D normalized screen point (e.g., the mouse position in normalized
device coordinates) to a 3D point on the "sky", which is really a huge sphere
(radius = 1500) that the viewer is inside.
Projects a 2D normalized screen point ( e . g . the mouse position in normalized device coordinates ) to a 3D point on the " sky " which is really a huge sphere ( radius = 1500 ) that the viewer is inside .