示例#1
0
        //============================================================
        public void Export3d(FDrGeometry geometry, string filename)
        {
            string directory = geometry.Model.Directory;
            Bitmap low       = new Bitmap(directory + "/ms_001.low.png");
            Bitmap high      = new Bitmap(directory + "/ms_001.high.png");
            // 创建设备
            Bitmap normal = new Bitmap(1024, 1024, PixelFormat.Format32bppArgb);

            for (int y = 0; y < 1024; y++)
            {
                for (int x = 0; x < 1024; x++)
                {
                    Color         lc = low.GetPixel(x, y);
                    Color         hc = high.GetPixel(x, y);
                    SFloatVector3 n  = new SFloatVector3();
                    n.X = (float)(hc.R - lc.R) / 128;
                    n.Y = (float)(hc.G - lc.G) / 128;
                    n.Z = (float)(hc.B - lc.B) / 256;
                    //n.Normalize();
                    int r = (int)((n.X * 0.5 + 0.5) * 255);
                    r = Math.Max(Math.Min(r, 255), 0);
                    int g = (int)((n.Y * 0.5 + 0.5) * 255);
                    g = Math.Max(Math.Min(g, 255), 0);
                    int b = (int)(((1 - n.Z) * 0.5 + 0.5) * 255);
                    b = Math.Max(Math.Min(b, 255), 0);
                    normal.SetPixel(x, y, Color.FromArgb(r, g, b));
                }
            }
            normal.Save(directory + "/ms_001.normal.png");
            //QNormalMapForm form = new QNormalMapForm();
            //form.geometry = geometry;
            //Application.Run(form);
        }
示例#2
0
        //============================================================
        // <T>向左/向右旋转</T>
        //
        // @param angle 角度
        //============================================================
        public void DoYaw(float angle)
        {
            SFloatVector3 direction = new SFloatVector3();
            // 旋转Y轴
            SDxMatrix matrix = new SDxMatrix();

            matrix.ry = angle;
            matrix.UpdateForce();
            matrix.Transform3x3Vector3(direction, _direction);
            // 旋转方向
            direction.Normalize();
            _direction.Assign(direction);
            UpdateTarget();
        }
示例#3
0
        //============================================================
        // <T>向上/向下旋转</T>
        //
        // @param angle 角度
        //============================================================
        public void DoPitch(float angle)
        {
            SFloatVector3 axis   = new SFloatVector3();
            SFloatVector3 axisUp = new SFloatVector3(0, 1, 0);

            axisUp.Cross(_direction, axis);
            DxMatrix      dxMatrix  = DxMatrix.RotationAxis(new Vector3(axis.X, axis.Y, axis.Z), angle);
            SFloatVector3 direction = new SFloatVector3();
            // 旋转Y轴
            SDxMatrix matrix = new SDxMatrix();

            matrix.AssignNative(dxMatrix);
            matrix.UpdateData();
            matrix.Transform3x3Vector3(direction, _direction);
            // 旋转方向
            direction.Normalize();
            _direction.Assign(direction);
            UpdateTarget();
        }
示例#4
0
文件: FDrMap.cs 项目: whztt07/MoCross
        //============================================================
        public void RangeIncise()
        {
            FCompressFile file   = new FCompressFile();
            int           height = _size.Height;
            int           width  = _size.Width;

            for (int y = 0; y <= height; y++)
            {
                for (int x = 0; x <= width; x++)
                {
                    //............................................................
                    // 计算坐标位置
                    int positionX = x;
                    if (positionX >= _size.Width)
                    {
                        positionX = _size.Width - 1;
                    }
                    int positionY = y;
                    if (positionY >= _size.Height)
                    {
                        positionY = _size.Height - 1;
                    }
                    int   positionHeight = 2 * (_size.Width * positionY + positionX);
                    float h = _heightData[positionHeight] + _heightData[positionHeight + 1] * 256;
                    // 计算点高度(1, 0)
                    SFloatVector3 tangent = new SFloatVector3(1, 0, 0);
                    if (positionX < _size.Width - 1)
                    {
                        int   tangentPosition = 2 * (_size.Width * positionY + (positionX) + 1);
                        float h1 = _heightData[tangentPosition] + _heightData[tangentPosition + 1] * 256;
                        float dx = (h1 - h) / 65535 * _deep;
                        tangent.Set(1, dx, 0);
                    }
                    tangent.Normalize();
                    // 计算点高度(0, 1)
                    SFloatVector3 binormal = new SFloatVector3(0, 0, 1);
                    if (positionY < _size.Height - 1)
                    {
                        int   binormalPosition = 2 * (_size.Width * (positionY + 1) + positionX);
                        float h2 = _heightData[binormalPosition] + _heightData[binormalPosition + 1] * 256;
                        float dy = (h2 - h) / 65535 * _deep;
                        binormal.Set(0, dy, 1);
                    }
                    binormal.Normalize();
                    // 计算法线
                    SFloatVector3 normal = new SFloatVector3();
                    binormal.Cross(tangent, normal);
                    normal.Normalize();
                    //............................................................
                    // 输出像素的高度
                    file.WriteUint8(_heightData[positionHeight]);
                    file.WriteUint8(_heightData[positionHeight + 1]);
                    // 输出像素的颜色
                    Color color = _colorData.Bitmap.GetPixel(positionX, positionY);
                    file.WriteUint8(color.R);
                    file.WriteUint8(color.G);
                    file.WriteUint8(color.B);
                    // 输出像素的法线
                    file.WriteUint8((byte)((normal.X + 1) * 0.5 * 255));
                    file.WriteUint8((byte)((normal.Y + 1) * 0.5 * 255));
                    file.WriteUint8((byte)((normal.Z + 1) * 0.5 * 255));
                    // 输出像素的层数据
                    for (int n = 0; n < _layerCount; n++)
                    {
                        FBitmap layerData  = _layers[n].Bitmap;
                        Color   layerColor = layerData.Bitmap.GetPixel(positionX, positionY);
                        file.WriteUint8(layerColor.R);
                    }
                    x += 8;
                }
                y += 8;
            }
            /*string rangeFile = "tile_" + RInt.Pad(x, 2) + "_" + RInt.Pad(cy, 2) + ".swf";         */
        }
示例#5
0
文件: FDrMap.cs 项目: whztt07/MoCross
        //============================================================
        // <T>序列化数据。</T>
        //============================================================
        public void ExportRange(int cx, int cy)
        {
            FCompressFile file = new FCompressFile();

            // 存储编号
            file.WriteUint32((uint)_id);
            // 存储层数
            file.WriteUint16((ushort)_layerCount);
            // 当前地图的宽度和高度
            file.WriteUint16((ushort)_size.Width);
            file.WriteUint16((ushort)_size.Height);
            // 当前范围的宽度和高度
            file.WriteUint16((ushort)_range.Width);
            file.WriteUint16((ushort)_range.Height);
            file.WriteFloat(_deep);
            // 当前范围的位置坐标
            file.WriteUint16((ushort)cx);
            file.WriteUint16((ushort)cy);
            // 计算开始坐标
            int offsetX = _range.Width * cx;
            int offsetY = _range.Height * cy;
            // 输出数据
            int width  = _range.Width;
            int height = _range.Height;

            for (int y = 0; y <= height; y++)
            {
                for (int x = 0; x <= width; x++)
                {
                    //............................................................
                    // 计算坐标位置
                    int positionX = offsetX + x;
                    if (positionX >= _size.Width)
                    {
                        positionX = _size.Width - 1;
                    }
                    int positionY = _size.Height - (offsetY + y) - 1;
                    if (positionY < 0)
                    {
                        positionY = 0;
                    }
                    else if (positionY >= _size.Height)
                    {
                        positionY = _size.Height - 1;
                    }
                    int   positionHeight = 2 * (_size.Width * positionY + positionX);
                    float h = _heightData[positionHeight] + _heightData[positionHeight + 1] * 256;
                    // 计算点高度(1, 0)
                    SFloatVector3 tangent = new SFloatVector3(1, 0, 0);
                    if (positionX < _size.Width - 1)
                    {
                        int   tangentPosition = 2 * (_size.Width * positionY + (positionX) + 1);
                        float h1 = _heightData[tangentPosition] + _heightData[tangentPosition + 1] * 256;
                        float dx = (h1 - h) / 65535 * _deep;
                        tangent.Set(1, dx, 0);
                    }
                    tangent.Normalize();
                    // 计算点高度(0, 1)
                    SFloatVector3 binormal = new SFloatVector3(0, 0, 1);
                    if (positionY < _size.Height - 1)
                    {
                        int   binormalPosition = 2 * (_size.Width * (positionY + 1) + positionX);
                        float h2 = _heightData[binormalPosition] + _heightData[binormalPosition + 1] * 256;
                        float dy = (h2 - h) / 65535 * _deep;
                        binormal.Set(0, dy, 1);
                    }
                    binormal.Normalize();
                    // 计算法线
                    SFloatVector3 normal = new SFloatVector3();
                    binormal.Cross(tangent, normal);
                    normal.Normalize();
                    //............................................................
                    // 输出像素的高度
                    file.WriteUint8(_heightData[positionHeight]);
                    file.WriteUint8(_heightData[positionHeight + 1]);
                    // 输出像素的颜色
                    Color color = _colorData.Bitmap.GetPixel(positionX, positionY);
                    file.WriteUint8(color.R);
                    file.WriteUint8(color.G);
                    file.WriteUint8(color.B);
                    // 输出像素的法线
                    file.WriteUint8((byte)((normal.X + 1) * 0.5 * 255));
                    file.WriteUint8((byte)((normal.Y + 1) * 0.5 * 255));
                    file.WriteUint8((byte)((normal.Z + 1) * 0.5 * 255));
                    // 输出像素的层数据
                    for (int n = 0; n < _layerCount; n++)
                    {
                        FBitmap layerData  = _layers[n].Bitmap;
                        Color   layerColor = layerData.Bitmap.GetPixel(positionX, positionY);
                        file.WriteUint8(layerColor.R);
                    }
                }
            }
            // 输出文件
            string rangeFile = "tile_" + RInt.Pad(cx, 2) + "_" + RInt.Pad(cy, 2) + ".swf";

            file.SaveFile(_exportFilePath + "\\" + rangeFile);
        }