示例#1
0
        /// <summary>
        /// Convert a 3d point to a 2d point for GetPreview() methods.
        /// </summary>
        /// <param name="Point">Source 3D point.</param>
        /// <param name="Min">Minimum vector positions (used to centre render in viewport).</param>
        /// <param name="Max">Maximum vector positions (used to centre render in viewport).</param>
        /// <param name="ViewWidth">Width of viewport.</param>
        /// <param name="ViewHeight">Height of viewport.</param>
        /// <param name="RotateY">Amount to rotate around Y axis in degrees.</param>
        /// <returns>2D point for plotting in viewport</returns>
        private Point Get2dPoint(FaceUVTool.DFPurePoint Point, Vector3 Min, Vector3 Max, int ViewWidth, int ViewHeight, float RotateY)
        {
            // Get fractional point
            DFMesh.DFPoint point3d;
            point3d.X = Point.x >> 8;
            point3d.Y = Point.y >> 8;
            point3d.Z = Point.z >> 8;

            // Rotate around Y axis
            const double PIOVER180  = Math.PI / 180.0;
            double       degrees    = RotateY;
            double       cDegrees   = degrees * PIOVER180;
            double       cosDegrees = Math.Cos(cDegrees);
            double       sinDegrees = Math.Sin(cDegrees);
            double       xrot       = (point3d.X * cosDegrees) + (point3d.Z * sinDegrees);
            double       zrot       = (point3d.X * -sinDegrees) + (point3d.Z * cosDegrees);

            point3d.X = (float)xrot;
            point3d.Z = (float)zrot;

            // Centre vector
            float transX = (float)(Min.X + ((Max.X - Min.X) / 2));
            float transY = (float)(Min.Y + ((Max.Y - Min.Y) / 2));
            float transZ = (float)(Min.Z + ((Max.Z - Min.Z) / 2));

            point3d.X -= transX;
            point3d.Y -= transY;
            point3d.Z -= transZ;

            // Scale vector (large objects become smaller, small objects grow larger)
            Vector3 size  = new Vector3(Max.X - Min.X, Max.Y - Min.Y, Max.Z - Min.Z);
            float   scale = 1000.0f / (float)((size.X + size.Y + size.Z) / 3);

            point3d.X *= scale;
            point3d.Y *= scale;
            point3d.Z *= scale;

            // Set camera position and zoom
            float zoom = (float)(ViewWidth / 0.5);
            float camx = 0;
            float camy = 0;
            float camz = (float)(Max.Z - 4500);

            // Translate point into 2d space
            float z       = point3d.Z - camz;
            Point point2d = new Point();

            point2d.X = ViewWidth / 2 - (int)((camx - point3d.X) / z * zoom);
            point2d.Y = ViewHeight / 2 - (int)((camy - point3d.Y) / z * zoom);

            return(point2d);
        }
        /// <summary>
        /// Write a single point to buffer.
        /// </summary>
        /// <param name="srcPoint">Source point.</param>
        /// <param name="dstPlane">Destination plane buffer.</param>
        /// <implementation>
        /// Vector coordinates are divided by 256.0f, and texture coordinates by 16.0f.
        /// </implementation>
        private int WritePoint(ref FaceUVTool.DFPurePoint srcPoint, ref DFPlaneBuffer dstPlane)
        {
            // Copy point data
            int pointPos = dstPlane.PointCount;

            dstPlane.PointBuffer[pointPos].X  = srcPoint.x / pointDivisor;
            dstPlane.PointBuffer[pointPos].Y  = srcPoint.y / pointDivisor;
            dstPlane.PointBuffer[pointPos].Z  = srcPoint.z / pointDivisor;
            dstPlane.PointBuffer[pointPos].NX = srcPoint.nx / pointDivisor;
            dstPlane.PointBuffer[pointPos].NY = srcPoint.ny / pointDivisor;
            dstPlane.PointBuffer[pointPos].NZ = srcPoint.nz / pointDivisor;
            dstPlane.PointBuffer[pointPos].U  = srcPoint.u / textureDivisor;
            dstPlane.PointBuffer[pointPos].V  = srcPoint.v / textureDivisor;
            dstPlane.PointCount++;

            return(pointPos);
        }
示例#3
0
        /// <summary>
        /// Write a single point to buffer.
        /// </summary>
        /// <param name="SrcPoint">Source point.</param>
        /// <param name="DstPlane">Destination plane buffer.</param>
        /// <implementation>
        /// Vector coordinates are divided by 256.0f, and texture coordinates by 16.0f.
        /// </implementation>
        private int WritePoint(ref FaceUVTool.DFPurePoint SrcPoint, ref DFPlaneBuffer DstPlane)
        {
            // Copy point data
            int pointPos = DstPlane.PointCount;

            DstPlane.PointBuffer[pointPos].X  = SrcPoint.x / PointDivisor;
            DstPlane.PointBuffer[pointPos].Y  = SrcPoint.y / PointDivisor;
            DstPlane.PointBuffer[pointPos].Z  = SrcPoint.z / PointDivisor;
            DstPlane.PointBuffer[pointPos].NX = SrcPoint.nx / PointDivisor;
            DstPlane.PointBuffer[pointPos].NY = SrcPoint.ny / PointDivisor;
            DstPlane.PointBuffer[pointPos].NZ = SrcPoint.nz / PointDivisor;
            DstPlane.PointBuffer[pointPos].U  = SrcPoint.u / TextureDivisor;
            DstPlane.PointBuffer[pointPos].V  = SrcPoint.v / TextureDivisor;
            DstPlane.PointCount++;

            return(pointPos);
        }