Esempio n. 1
0
        public static bool Intersects(Sprite3D s, Vector2 pointer, Viewport v, Camera cam)
        {
            Vector3 nearPoint = new Vector3(pointer, 0);
            Vector3 farPoint = new Vector3(pointer, 1);

            nearPoint = v.Unproject(nearPoint, cam.Projection, cam.View, Matrix.Identity);
            farPoint = v.Unproject(farPoint, cam.Projection, cam.View, Matrix.Identity);

            Vector3 direction = farPoint - nearPoint;
            direction.Normalize();

            Ray r = new Ray(nearPoint, direction);

            BoundingSphere bs = s.GetBoundingSphere();

            return (bs.Intersects(r) != null) ? true : false;
        }