Пример #1
0
        /// <summary>
        /// Constructor with 3 points. Throw exception if the given points cannot form a rectangle.
        /// </summary>
        /// <param name="point1">First point</param>
        /// <param name="point2">Second point</param>
        /// <param name="point3">Third point</param>
        public Rectangle(Point3D point1, Point3D point2, Point3D point3)
        {
            Point3D point4 = point1 + (point2 - point1) + (point3 - point1);

            if (Rectangle.Exists(point3, point1, point2, point4))
            {
                Point1 = point3;
                Point2 = point1;
                Point3 = point2;
                Point4 = point4;
            }
            else
            {
                point4 = point2 + (point1 - point2) + (point3 - point2);

                if (Rectangle.Exists(point1, point2, point3, point4))
                {
                    Point1 = point1;
                    Point2 = point2;
                    Point3 = point3;
                    Point4 = point4;
                }
                else
                {
                    point4 = point3 + (point1 - point3) + (point2 - point3);

                    if (Rectangle.Exists(point1, point3, point2, point4))
                    {
                        Point1 = point1;
                        Point2 = point3;
                        Point3 = point2;
                        Point4 = point4;
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
            }

            normal = Vector3D.CrossProduct(Point2 - Point1, Point3 - Point2);
            normal.Normalize();
        }
Пример #2
0
        /// <summary>
        /// Setup the camera before using it
        /// </summary>
        public void Setup()
        {
            viewDirection = LookAt - Location;
            viewDirection.Normalize();

            U = Vector3D.CrossProduct(viewDirection, new Vector3D(0, 1, 0));
            V = Vector3D.CrossProduct(U, viewDirection);

            U.Normalize();
            V.Normalize();

            double viewPlaneWidth  = Width / FocalLength;
            double viewPlaneHeight = Height / FocalLength;

            viewPlaneTopLeftPoint = LookAt - V * (viewPlaneHeight / 2) - U * (viewPlaneWidth / 2);
            xIncVector            = (U * viewPlaneWidth) / Width;
            yIncVector            = (V * viewPlaneHeight) / Height;

            //Console.WriteLine("xIncVec : " + xIncVector.ToString());
            //Console.WriteLine("yIncVec : " + yIncVector.ToString());
            //Console.WriteLine("Width : " + Width.ToString());
            //Console.WriteLine("Height : " + Height.ToString());
        }