예제 #1
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();
        }
예제 #2
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";         */
        }
예제 #3
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);
        }