Exemplo n.º 1
0
        public World(XYZ worldSize)
        {
            this.worldSize = worldSize;
            frameSize.Set(worldSize);
            //Map = new byte[frameSize.x,frameSize.y,frameSize.z];
            Map2 = new Block[frameSize.x, frameSize.y, frameSize.z];

            for (int i = 0; i < frameSize.x; i++)
            {
                for (int j = 0; j < frameSize.y; j++)
                {
                    for (int k = 0; k < frameSize.z; k++)
                    {
                        Map2[i, j, k] = new Block(0, new XYZ_b());
                    }
                }
            }

            for (int i = 0; i < frameSize.x; i++)
            {
                for (int j = 0; j < frameSize.y; j++)
                {
                    for (int k = frameSize.z / 2; k < frameSize.z; k++)
                    {
                        //Map[i,j,k] = (byte)((i * j * k / 11) % 6 + 1);
                        Map2[i, j, k].color.Set
                            ((byte)(255 - 255 * ((i * j) / (worldSize.x * worldSize.y * 1f))),
                            (byte)(255 - 255 * ((j * k) / (worldSize.y * worldSize.z * 1f))),
                            (byte)(255 - 255 * ((i * k) / (worldSize.x * worldSize.z * 1f))));
                        Map2[i, j, k].code = 1;
                        /* if(k < frameSize.z/2 + 4) Map[i,j,k] = (byte)15; */
                    }
                }
            }
        }
Exemplo n.º 2
0
        public World(XYZ worldSize)
        {
            this.worldSize = worldSize;
            frameSize.Set(worldSize);
            Map = new byte[frameSize.x, frameSize.y, frameSize.z];
            bool Xaxis = false;
            bool Yaxis = false;
            bool Zaxis = false;

            /* for(int i = 0; i < frameSize.x; i++)
             * for(int j = 0; j < frameSize.y; j++)
             * for(int k = 0; k < frameSize.z; k++)
             * {
             *      Map[i,j,k] = 0;
             *      Xaxis = (Math.Abs(i - frameSize.x/2) > frameSize.x/2 - 3);
             *      Yaxis = (Math.Abs(i - frameSize.y/2) > frameSize.y/2 - 3);
             *      Zaxis = (Math.Abs(i - frameSize.z/2) > frameSize.z/2 - 3);
             *      if(Xaxis && Yaxis) Map[i,j,k] = 3;
             *      if(Yaxis && Zaxis) Map[i,j,k] = 3;
             *      if(Xaxis && Zaxis) Map[i,j,k] = 3;
             * } */
            for (int i = 0; i < frameSize.x; i++)
            {
                for (int j = 0; j < frameSize.y; j++)
                {
                    for (int k = frameSize.z / 2; k < frameSize.z; k++)
                    {
                        Map[i, j, k] = (byte)((i * j * k / 11) % 6 + 1);
                        /* if(k < frameSize.z/2 + 4) Map[i,j,k] = (byte)15; */
                    }
                }
            }
        }
Exemplo n.º 3
0
 public void Resize(int x, int y, int z)
 {
     camSize.Set(x, y, z);
     camPoint.Set(camSize).Div(2);
     SetPerspArray();
     deleteFrameIndex = frameBoard[camPoint.x, camPoint.z];
 }
Exemplo n.º 4
0
        public void MakeSphere(XYZ pos, int radius, byte code, XYZ_b color)
        {
            Func <XYZ_d, XYZ, XYZ, int, bool> renderer = (XYZ_d delta, XYZ deltaSign, XYZ frameIndex, int nextDir) => { return(false); };

            XYZ    temp     = new XYZ();
            double distance = 0;

            for (int i = -radius; i < radius; i++)
            {
                for (int j = -radius; j < radius; j++)
                {
                    for (int k = -radius; k < radius; k++)
                    {
                        temp.Set(pos).Add(i, j, k);
                        distance = pos.Distance(temp);
                        if (distance < radius && distance > radius - 1)
                        {
                            if (IsInFrame(temp))
                            {
                                // Map[temp.x, temp.y, temp.z].code = code;
                                Map[temp.x, temp.y, temp.z].color.Set(color);
                                Map[temp.x, temp.y, temp.z].OnRendered = renderer_block;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        //camera.PositionIndex
        public void CrushFrame(int scale, XYZ positionIndex)
        {
            XYZ temp = Vector.ToXYZ();

            temp.Div((int)(temp.Length() / (scale / 4 * 3)));
            XYZ brokePos = new XYZ(positionIndex).Sub(temp);
            XYZ lightPos = new XYZ(positionIndex);
            int maxScale = 60;

            if (scale > maxScale)
            {
                scale = maxScale;
            }
            int lightScale = scale + 2;
            XYZ color      = new XYZ(255 * scale / 30, 0, 0);
            XYZ gap        = new XYZ();

            for (int i = -lightScale; i < lightScale; i++)
            {
                for (int j = -lightScale; j < lightScale; j++)
                {
                    for (int k = -lightScale; k < lightScale; k++)
                    {
                        temp.Set(brokePos).Add(i, j, k);
                        world.ConvertToInfinity(temp);
                        //if (!world.IsInFrame(temp)) continue;
                        if (Math.Sqrt(i * i + j * j + k * k) < scale)
                        {
                            world.SetFrame(temp, false);
                        }
                        //double distance = lightPos.Distance(temp);
                        //if (distance < scale)
                        //{
                        //    XYZ_b c = world.GetColor(temp);
                        //    if (world.isFrameEnabled(temp))
                        //    {
                        //        gap.x = (int)color.x - (int)c.x;
                        //        gap.y = (int)color.y - (int)c.y;
                        //        gap.z = (int)color.z - (int)c.z;
                        //        gap.Mul((int)(maxScale - distance)).Div(maxScale);
                        //        c.x = (byte)(c.x + gap.x);
                        //        c.y = (byte)(c.y + gap.y);
                        //        c.z = (byte)(c.z + gap.z);
                        //    }
                        //}
                    }
                }
            }
        }
Exemplo n.º 6
0
        public World(XYZ worldSize)
        {
            image          = new Bitmap(Application.StartupPath + @"\MapImage\example.jpg");
            this.worldSize = worldSize;
            frameSize.Set(worldSize);
            realSize.Set(worldSize).Mul(frameLength);
            //Map = new byte[frameSize.x,frameSize.y,frameSize.z];
            Map = new Block[frameSize.x, frameSize.y, frameSize.z];
            for (int i = 0; i < frameSize.x; i++)
            {
                for (int j = 0; j < frameSize.y; j++)
                {
                    for (int k = 0; k < frameSize.z; k++)
                    {
                        Map[i, j, k] = new Block(false, new XYZ_b(), renderer_air);
                    }
                }
            }
            DrawMap(image);
            image = new Bitmap(Application.StartupPath + @"\MapImage\CloudShape.png");
            DrawCloud(image, frameSize.z / 3);

            image = new Bitmap(Application.StartupPath + @"\MapImage\Building.png");
            DrawBuilding(image, new XYZ(280, 280, 100));
            //Random rand = new Random();
            //for (int i = 0; i < frameSize.x; i++)
            //    for (int j = 0; j < frameSize.y; j++)
            //        for (int k = frameSize.z / 2; k < frameSize.z; k++)
            //        {
            //            //Map[i,j,k] = (byte)((i * j * k / 11) % 6 + 1);
            //            //Map[i,j,k].color.Set
            //            //            ((byte)128,
            //            //           (byte)128,(byte)rand.Next(100, 255));
            //            // Map[i, j, k].color.Set((byte)(Math.Sin(i) * 200 + 100), (byte)(Math.Sin(j) *200 + 100), (byte)(Math.Sin(k) * 200 + 100));
            //            // Map[i, j, k].color.Add((byte)(Math.Cos(i) * 200 + 100), (byte)(Math.Cos(j) *200 + 100), (byte)(Math.Cos(k) * 200 + 100));
            //            //Map[i,j,k].color.Set((byte)((i * j * k) % 256), (byte)((i * j * k) % 256), 255);


            //            Map[i, j, k].code = 1;
            //            //Map[i, j, k].color.Set((byte)rand.Next(100, 255));
            //            Map[i, j, k].color.Set(0);
            //        }
        }
Exemplo n.º 7
0
        public void Spin_XZAxis5()
        {
            position.Set(Position);
            cursor.x += (Cursor.Position.X - screenPoint.X) * sensitivity;
            cursor.y += (Cursor.Position.Y - screenPoint.Y) * sensitivity;

            cursor.x %= 360;
            cursor.y %= 360;

            cursor.y = cursor.y > 90 ? 90 :
                       (cursor.y < -90 ? -90 : cursor.y);
            Cursor.Position = screenPoint;
            double degreeX = cursor.y * -PI;
            double degreeY = cursor.x * PI;
            double sinX    = Math.Sin(degreeX);
            double sinY    = Math.Sin(degreeY);
            double cosX    = Math.Cos(degreeX);
            double cosY    = Math.Cos(degreeY);


            bool isTargetSet = false;

            basisX.Set(1, 0, 0);
            basisY.Set(0, camSize.y - 1, 0);
            basisZ.Set(0, 0, 1);

            Spin_matrix_x(basisX.x, basisX.y, basisX.z, sinX, cosX, basisX);
            Spin_matrix_z(basisX.x, basisX.y, basisX.z, sinY, cosY, basisX);

            Spin_matrix_x(basisY.x, basisY.y, basisY.z, sinX, cosX, basisY);
            Spin_matrix_z(basisY.x, basisY.y, basisY.z, sinY, cosY, basisY);

            Spin_matrix_x(basisZ.x, basisZ.y, basisZ.z, sinX, cosX, basisZ);
            Spin_matrix_z(basisZ.x, basisZ.y, basisZ.z, sinY, cosY, basisZ);
            world.GetFrameIndex(position, PositionIndex);
            Parallel.For(0, camSize.z, (int k) =>
            {
                Parallel.For(0, camSize.x, (int i) =>
                {
                    int depth   = 0;
                    board[k, i] = ' ';

                    perspBasisX[i, k].Set(basisX).Mul(perspArray[i, k].x);
                    perspBasisZ[i, k].Set(basisZ).Mul(perspArray[i, k].z);

                    spinArray[i, k].Set(perspBasisX[i, k]).Add(basisY).Add(perspBasisZ[i, k]);

                    XYZ_d delta = deltaArray[i, k].Set(spinArray[i, k]).Div(camSize.y);
                    XYZ_d index = indexArray[i, k].Set(position);

                    XYZ_d gap               = new XYZ_d();
                    XYZ_d lpos              = new XYZ_d();
                    XYZ frameIndex          = new XYZ();
                    XYZ nextFrameIndexDelta = new XYZ();
                    XYZ_d target            = new XYZ_d();
                    XYZ_d deltaSign         = new XYZ_d();

                    if (delta.x != 0)
                    {
                        deltaSign.x = (Math.Abs(delta.x) / delta.x);
                    }
                    if (delta.y != 0)
                    {
                        deltaSign.y = (Math.Abs(delta.y) / delta.y);
                    }
                    if (delta.z != 0)
                    {
                        deltaSign.z = (Math.Abs(delta.z) / delta.z);
                    }
                    frameIndex.Set(PositionIndex);
                    double numOfDelta = 0;

                    for (int j = 0; j < camSize.y; j++)
                    {
                        if (!world.IsInFrame(frameIndex) || j == camSize.y - 1)
                        {
                            depth = depth < 0 ? 0 :
                                    depth > 9 ? 9 : depth;
                            board[k, i] = level[depth];
                            break;
                        }

                        world.ConvertToFramePos(lpos.Set(index), frameIndex);

                        if (world.IsExistPixelInFrame(frameIndex))
                        {
                            if (i == camPoint.x && k == camPoint.z && !isTargetSet)
                            {
                                deleteFrameIndex.Set(frameIndex);
                                addFrameIndex.Set(frameIndex).Sub(nextFrameIndexDelta);
                                isTargetSet = true;
                            }
                            if (frameIndex.Equal(deleteFrameIndex))
                            {
                                depth += 3;                                                              //쳐다보는 블록 색깔
                            }
                            world.GetFrameIndex(index, gap);
                            if (gridEnabled && gap.Distance(PositionIndex) < 3)                            //3칸블록 이내 범위있을 경우 경계선표시.
                            {
                                bool Xaxis    = Math.Abs(lpos.x) > world.frameLength / 2 - 1;              //경계선 테두리 크기 1
                                bool Yaxis    = Math.Abs(lpos.y) > world.frameLength / 2 - 1;
                                bool Zaxis    = Math.Abs(lpos.z) > world.frameLength / 2 - 1;
                                int inv_color = world.GetColor(frameIndex);
                                if (inv_color > 5)
                                {
                                    if (inv_color == 14)
                                    {
                                        inv_color = 9;
                                    }
                                    else
                                    {
                                        inv_color = 0;
                                    }
                                }
                                else
                                {
                                    inv_color = 9;
                                }
                                inv_color += (5 - inv_color) / 5 * 2;
                                if (Xaxis && Yaxis)
                                {
                                    board[k, i] = level[inv_color]; break;
                                }
                                if (Yaxis && Zaxis)
                                {
                                    board[k, i] = level[inv_color]; break;
                                }
                                if (Zaxis && Xaxis)
                                {
                                    board[k, i] = level[inv_color]; break;
                                }
                            }
                            if (world.GetColor(frameIndex) == 14)                            // 거울만나면 반사.
                            {
                                if (nextFrameIndexDelta.x != 0)
                                {
                                    delta.x     = -delta.x;
                                    deltaSign.x = -deltaSign.x;
                                }
                                else if (nextFrameIndexDelta.y != 0)
                                {
                                    delta.y     = -delta.y;
                                    deltaSign.y = -deltaSign.y;
                                }
                                else if (nextFrameIndexDelta.z != 0)
                                {
                                    delta.z     = -delta.z;
                                    deltaSign.z = -deltaSign.z;
                                }
                                frameIndex.Sub(nextFrameIndexDelta);                                 // 일보후퇴
                                continue;
                            }
                            else if (world.GetColor(frameIndex) == 15)                            // 유리만나면 살짝 하얘지고 계속 진행.
                            {
                                depth = depth > 3 ? 3 : depth + 1;
                            }
                            else
                            {
                                depth += (int)(world.GetColor(frameIndex));
                                depth  = depth < 0 ? 0 :
                                         depth > 9 ? 9 : depth;
                                board[k, i] = level[depth];
                                break;
                            }
                        }
                        //현위치에서 delta벡터방향으로 이동할 경우 가장 먼저 만나는 경계면 구하기.
                        target.Set(world.frameLength / 2);
                        target.Mul(deltaSign);                        //delta벡터 방향으로 이동시 접촉가능한 경계면들 구하기.
                        target.Sub(lpos).Div(delta);                  //경계면들로부터 현재위치의 거리를 구하고 delta로 나누기. deltasign으로 한번 곱했었기때문에 x,y,z축 서로에 대한 정확한 비교값이 나오게된다.
                        nextFrameIndexDelta.Set(0);
                        if (target.x < target.y && target.x < target.z)
                        {
                            numOfDelta            = target.x;
                            nextFrameIndexDelta.x = (int)deltaSign.x;
                        }
                        else if (target.y < target.x && target.y < target.z)
                        {
                            numOfDelta            = target.y;
                            nextFrameIndexDelta.y = (int)deltaSign.y;
                        }
                        else if (target.z < target.x && target.z < target.y)
                        {
                            numOfDelta            = target.z;
                            nextFrameIndexDelta.z = (int)deltaSign.z;
                        }
                        frameIndex.Add(nextFrameIndexDelta);                        //가장가까운 경계면에 해당하는 블록으로 이동.
                        index.Add(gap.Set(delta).Mul(numOfDelta));                  //delta방향으로 가장 가까운 경계면으로 이동.
                        //여기까지 수정
                    }
                });
            });
            rayDelta.Set(deltaArray[camPoint.x, camPoint.z]);
        }
Exemplo n.º 8
0
        void Shoot(XYZ_b color, XYZ_d rayDelta)
        {
            XYZ_d delta      = new XYZ_d(rayDelta);
            XYZ_d lpos       = new XYZ_d(delta).Mul(world.frameLength * 2).Add(Position);
            XYZ   frameIndex = new XYZ();

            world.GetFrameIndex(lpos, frameIndex);
            world.ConvertToFramePos(frameIndex, lpos);
            XYZ   frameIndex2   = new XYZ(frameIndex);
            int   nextDir       = 0;
            XYZ_d target        = new XYZ_d();
            XYZ_d deltaSign     = new XYZ_d();
            XYZ_d maxNumOfDelta = new XYZ_d(world.frameLength);

            if (delta.x != 0)
            {
                deltaSign.x = (Math.Abs(delta.x) / delta.x);
            }
            if (delta.y != 0)
            {
                deltaSign.y = (Math.Abs(delta.y) / delta.y);
            }
            if (delta.z != 0)
            {
                deltaSign.z = (Math.Abs(delta.z) / delta.z);
            }

            maxNumOfDelta.Mul(deltaSign).Div(delta);
            target.Set(world.halfFrameLength).Mul(deltaSign); //delta벡터 방향으로 이동시 접촉가능한 경계면들 구하기.
            target.Sub(lpos).Div(delta);                      //경계면들로부터 현재위치의 거리를 구하고 delta로 나누기. deltasign으로 한번 곱했었기때문에 x,y,z축 서로에 대한 정확한 비교값이 나오게된다.
            Task.Factory.StartNew(() =>
            {
                while (!world.isFrameEnabled(frameIndex))
                {
                    world.ConvertToInfinity(frameIndex);
                    world.SetFrame(frameIndex2, false);
                    world.SetFrame(frameIndex, true);
                    world.SetColor(frameIndex, color);

                    if (target.x < target.y)
                    {
                        if (target.x < target.z)
                        {
                            nextDir = 0;
                        }
                        else
                        {
                            nextDir = 2;
                        }
                    }
                    else
                    if (target.y < target.z)
                    {
                        nextDir = 1;
                    }
                    else
                    {
                        nextDir = 2;
                    }
                    target.element[nextDir] += maxNumOfDelta.element[nextDir];
                    frameIndex2.Set(frameIndex);
                    frameIndex.element[nextDir] += (int)deltaSign.element[nextDir];
                    Thread.Sleep(10);
                }

                world.SetFrame(frameIndex2, false);
                XYZ temp        = new XYZ();
                int scale       = 10;
                double distance = 0;
                for (int i = -scale; i < scale; i++)
                {
                    for (int j = -scale; j < scale; j++)
                    {
                        for (int k = -scale; k < scale; k++)
                        {
                            temp.Set(frameIndex).Add(i, j, k);
                            distance = frameIndex.Distance(temp);
                            if (distance < scale)
                            {
                                world.ConvertToInfinity(temp);
                                XYZ_b c = world.GetColor(temp);
                                //gap.x = (int)color.x - (int)c.x;
                                //gap.y = (int)color.y - (int)c.y;
                                //gap.z = (int)color.z - (int)c.z;
                                //gap.Mul((int)(scale - distance)).Div(scale);
                                //c.x = (byte)(c.x + gap.x);
                                //c.y = (byte)(c.y + gap.y);
                                //c.z = (byte)(c.z + gap.z);
                                temp.x = (int)color.x * (int)(scale - distance) / scale;
                                temp.y = (int)color.y * (int)(scale - distance) / scale;
                                temp.z = (int)color.z * (int)(scale - distance) / scale;
                                c.Add((byte)temp.x, (byte)temp.y, (byte)temp.z);
                                // world.SetFrame(temp, false);
                                //world.SetColor(temp, 255, 0, 0);
                            }
                        }
                    }
                }
            });
        }
Exemplo n.º 9
0
 public void GetFrameIndex(XYZ_d p, XYZ i)
 {
     i.Set(p.iX / frameLength, p.iY / frameLength, p.iZ / frameLength);
 }
Exemplo n.º 10
0
        public XYZ_b[,] MakeImage()
        {
            int pointDir = lposDirectBoard[camPoint.x, camPoint.z];

            if (deleteFrameIndex.x != -1)
            {
                addFrameIndex.Set(deleteFrameIndex);

                if (basisY.element[pointDir] > 0)
                {
                    addFrameIndex.element[pointDir] -= 1;
                }

                else
                {
                    addFrameIndex.element[pointDir] += 1;
                }

                world.ConvertToInfinity(addFrameIndex);
            }
            if (gridEnabled)
            {
                XYZ vector = new XYZ(addFrameIndex).Sub(deleteFrameIndex);

                int inSideArea = world.halfFrameLength - 4;
                Parallel.For(0, camSize.z, (int k) =>
                             //for(int k = 0; k < camSize.z; k++)
                {
                    Parallel.For(0, camSize.x, (int i) =>
                                 //for (int i = 0; i < camSize.x; i++)
                    {
                        if (frameBoard[i, k].x != -1)
                        {
                            Block block     = world.GetBlock(frameBoard[i, k]);
                            XYZ_b inv_color = new XYZ_b(255).Sub(block.color);
                            if (frameBoard[i, k].Equal(deleteFrameIndex) && lposDirectBoard[i, k] == pointDir)                          //쳐다보는 블록면 강조
                            {
                                finalBoard[i, k].Set(inv_color);
                            }
                            //if (block.code != 14)// 경계선표시.
                            {
                                bool Xaxis = Math.Abs(lposBoard[i, k].x) > inSideArea;                                 //경계선 테두리 크기 1
                                bool Yaxis = Math.Abs(lposBoard[i, k].y) > inSideArea;
                                bool Zaxis = Math.Abs(lposBoard[i, k].z) > inSideArea;
                                if (Xaxis && Yaxis || Yaxis && Zaxis || Zaxis && Xaxis)
                                {
                                    finalBoard[i, k].Set(inv_color);
                                }
                                //else if () { finalBoard[i, k].Set(inv_color); }
                                //else if () { finalBoard[i, k].Set(inv_color); }
                                //else finalBoard[i, k].Set(block.color);
                            }
                        }
                    });
                });
            }
            for (int i = camPoint.z - 3; i < camPoint.z + 3; i++)
            {
                for (int j = camPoint.x - 3; j < camPoint.x + 3; j++)
                {
                    if (Math.Pow(i - camPoint.z, 2) + Math.Pow(j - camPoint.x, 2) < 8 &&
                        Math.Pow(i - camPoint.z, 2) + Math.Pow(j - camPoint.x, 2) > 4)
                    {
                        finalBoard[j, i].Set(255);
                    }
                }
            }
            return(finalBoard);
        }
Exemplo n.º 11
0
 public void GetFrameIndex(XYZ_d p, XYZ i)
 {
     i.Set(p.ToXYZ().Div(frameLength));
     //ConvertToInfinity(i);
 }
Exemplo n.º 12
0
        public void MakeMirror(XYZ pos)
        {
            XYZ   temp = new XYZ(pos);
            Block block;

            for (int w = -1; w < 21; w++)
            {
                for (int h = -1; h < 11; h++)
                {
                    temp.Set(pos.x + w, pos.y - 5, frameSize.z / 2 - h).Rem(worldSize);
                    //Map[pos.x + w, pos.y-5, frameSize.z / 2 - h].code = (byte)1;
                    block            = GetBlock(temp);
                    block.touchable  = true;
                    block.OnRendered = renderer_block;
                    block.color.Set(100, 100, 255);
                    //Map[pos.x + w, pos.y-5, frameSize.z / 2 - h].touchable = true;
                    //Map[pos.x + w, pos.y-5, frameSize.z / 2 - h].OnRendered = renderer_block;
                    //Map[pos.x + w, pos.y - 5, frameSize.z / 2 - h].color.Set(100,100,255);
                }
            }
            for (int w = -1; w < 21; w++)
            {
                for (int h = -1; h < 11; h++)
                {
                    temp.Set(pos.x + w, pos.y + 5, frameSize.z / 2 - h).Rem(worldSize);
                    block            = GetBlock(temp);
                    block.touchable  = true;
                    block.OnRendered = renderer_block;
                    block.color.Set(255, 100, 100);
                    //Map[pos.x + w, pos.y + 5, frameSize.z / 2 - h].code = (byte)1;
                    //Map[pos.x + w, pos.y + 5, frameSize.z / 2 - h].touchable = true;
                    //Map[pos.x + w, pos.y + 5, frameSize.z / 2 - h].OnRendered = renderer_block;
                    //Map[pos.x + w, pos.y + 5, frameSize.z / 2 - h].color.Set(255,100,100);
                }
            }

            for (int w = 0; w < 20; w++)
            {
                for (int h = 0; h < 10; h++)
                {
                    temp.Set(pos.x + w, pos.y - 5, frameSize.z / 2 - h).Rem(worldSize);
                    block            = GetBlock(temp);
                    block.touchable  = true;
                    block.OnRendered = renderer_mirror;
                    block.color.Set(0, 0, 0);
                    //Map[pos.x + w, pos.y - 5, frameSize.z / 2 - h].code = (byte)14;
                    //Map[pos.x + w, pos.y - 5, frameSize.z / 2 - h].touchable = true;
                    // Map[pos.x + w, pos.y - 5, frameSize.z / 2 - h].OnRendered = renderer_mirror;
                    // Map[pos.x + w, pos.y - 5, frameSize.z / 2 - h].color.Set(0, 0, 0);
                }
            }
            for (int w = 0; w < 20; w++)
            {
                for (int h = 0; h < 10; h++)
                {
                    temp.Set(pos.x + w, pos.y + 5, frameSize.z / 2 - h).Rem(worldSize);
                    block            = GetBlock(temp);
                    block.touchable  = true;
                    block.OnRendered = renderer_mirror;
                    block.color.Set(0, 0, 0);
                    //Map[pos.x + w, pos.y + 5, frameSize.z / 2 - h].code = (byte)14;
                    //Map[pos.x + w, pos.y + 5, frameSize.z / 2 - h].touchable = true;
                    // Map[pos.x + w, pos.y + 5, frameSize.z / 2 - h].OnRendered = renderer_mirror;
                    // Map[pos.x + w, pos.y + 5, frameSize.z / 2 - h].color.Set(0, 0, 0);
                }
            }
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    for (int k = 0; k < 4; k++)
                    {
                        temp.Set(pos.x + 10 - i, pos.y - j, frameSize.z / 2 - k).Rem(worldSize);
                        block            = GetBlock(temp);
                        block.touchable  = true;
                        block.OnRendered = renderer_block;
                        block.color.Set(80, 80, 80);
                        // Map[pos.x + 10 - i, pos.y - j, frameSize.z / 2 - k].code = (byte)1;
                        //Map[pos.x + 10 - i, pos.y - j, frameSize.z / 2 - k].touchable = true;
                        //Map[pos.x + 10 - i, pos.y - j, frameSize.z / 2 - k].OnRendered = renderer_block;
                        //Map[pos.x + 10 - i, pos.y - j, frameSize.z / 2 - k].color.Set((byte)0);
                    }
                }
            }
        }
Exemplo n.º 13
0
        public void Spin_XZAxis5()
        {
            position.Set(Position);
            cursor.x += (Cursor.Position.X - screenPoint.X) * sensitivity;
            cursor.y += (Cursor.Position.Y - screenPoint.Y) * sensitivity;

            cursor.x %= 360;
            cursor.y %= 360;

            cursor.y = cursor.y > 90 ? 90 :
                       (cursor.y < -90 ? -90 : cursor.y);
            Cursor.Position = screenPoint;
            double degreeX = cursor.y * -PI;
            double degreeY = cursor.x * PI;
            double sinX    = Math.Sin(degreeX);
            double sinY    = Math.Sin(degreeY);
            double cosX    = Math.Cos(degreeX);
            double cosY    = Math.Cos(degreeY);


            bool isTargetSet = false;

            basisX.Set(1, 0, 0);
            basisY.Set(0, camSize.y - 1, 0);
            basisZ.Set(0, 0, 1);

            Spin_matrix_x(basisX.x, basisX.y, basisX.z, sinX, cosX, basisX);
            Spin_matrix_z(basisX.x, basisX.y, basisX.z, sinY, cosY, basisX);

            Spin_matrix_x(basisY.x, basisY.y, basisY.z, sinX, cosX, basisY);
            Spin_matrix_z(basisY.x, basisY.y, basisY.z, sinY, cosY, basisY);

            Spin_matrix_x(basisZ.x, basisZ.y, basisZ.z, sinX, cosX, basisZ);
            Spin_matrix_z(basisZ.x, basisZ.y, basisZ.z, sinY, cosY, basisZ);
            world.GetFrameIndex(position, PositionIndex);
            //  Parallel.For(0,camSize.z,(int k) =>
            for (int k = 0; k < camSize.z; k++)
            {
                //Parallel.For(0,camSize.x,(int i) =>
                for (int i = 0; i < camSize.x; i++)
                {
                    XYZ_b color = new XYZ_b();
                    Block block;

                    perspBasisX[i, k].Set(basisX).Mul(perspArray[i, k].x);
                    perspBasisZ[i, k].Set(basisZ).Mul(perspArray[i, k].z);

                    spinArray[i, k].Set(perspBasisX[i, k]).Add(basisY).Add(perspBasisZ[i, k]);

                    XYZ_d delta = deltaArray[i, k].Set(spinArray[i, k]).Div(camSize.y);
                    XYZ_d index = indexArray[i, k].Set(position);

                    XYZ_d gap                 = new XYZ_d();
                    XYZ_d lpos                = new XYZ_d();
                    XYZ   frameIndex          = new XYZ();
                    XYZ   nextFrameIndexDelta = new XYZ();
                    XYZ_d target              = new XYZ_d();
                    XYZ_d deltaSign           = new XYZ_d();

                    if (delta.x != 0)
                    {
                        deltaSign.x = (Math.Abs(delta.x) / delta.x);
                    }
                    if (delta.y != 0)
                    {
                        deltaSign.y = (Math.Abs(delta.y) / delta.y);
                    }
                    if (delta.z != 0)
                    {
                        deltaSign.z = (Math.Abs(delta.z) / delta.z);
                    }
                    frameIndex.Set(PositionIndex);
                    double numOfDelta = 0;

                    for (int j = 0; j < camSize.y; j++)
                    {
                        if (!world.IsInFrame(frameIndex) || j == camSize.y - 1)
                        {
                            break;
                        }

                        world.ConvertToFramePos(lpos.Set(index), frameIndex);                        // index를 frameIndex에 해당하는 블록의 로컬포지션으로 변환.

                        if (world.IsExistPixelInFrame(frameIndex))
                        {
                            block       = world.GetBlock(frameIndex);
                            board[i, k] = index;
                            if (i == camPoint.x && k == camPoint.z && !isTargetSet)
                            {
                                deleteFrameIndex.Set(frameIndex);
                                addFrameIndex.Set(frameIndex).Sub(nextFrameIndexDelta);
                                isTargetSet = true;
                            }

                            XYZ_b inv_color = new XYZ_b(255).Sub(block.color);
                            if (frameIndex.Equal(deleteFrameIndex))//쳐다보는 블록면 강조
                            {
                                XYZ vector = new XYZ(addFrameIndex).Sub(deleteFrameIndex);

                                if (vector.x != 0 && lpos.x * vector.x > world.frameLength / 2 - 1)
                                {
                                    viewer.Draw(i, k, inv_color);
                                    break;
                                }
                                else if (vector.y != 0 && lpos.y * vector.y > world.frameLength / 2 - 1)
                                {
                                    viewer.Draw(i, k, inv_color);
                                    break;
                                }
                                else if (vector.z != 0 && lpos.z * vector.z > world.frameLength / 2 - 1)
                                {
                                    viewer.Draw(i, k, inv_color);
                                    break;
                                }
                            }
                            if (gridEnabled && block.code != 14)                           // 경계선표시.
                            {
                                bool Xaxis = Math.Abs(lpos.x) > world.frameLength / 2 - 1; //경계선 테두리 크기 1
                                bool Yaxis = Math.Abs(lpos.y) > world.frameLength / 2 - 1;
                                bool Zaxis = Math.Abs(lpos.z) > world.frameLength / 2 - 1;

                                if (Xaxis && Yaxis)
                                {
                                    viewer.Draw(i, k, inv_color); break;
                                }
                                if (Yaxis && Zaxis)
                                {
                                    viewer.Draw(i, k, inv_color); break;
                                }
                                if (Zaxis && Xaxis)
                                {
                                    viewer.Draw(i, k, inv_color); break;
                                }
                            }
                            if (block.code == 14)                            // 거울만나면 반사.
                            {
                                color.Set(block.color);
                                if (nextFrameIndexDelta.x != 0)
                                {
                                    delta.x     = -delta.x;
                                    deltaSign.x = -deltaSign.x;
                                }
                                else if (nextFrameIndexDelta.y != 0)
                                {
                                    delta.y     = -delta.y;
                                    deltaSign.y = -deltaSign.y;
                                }
                                else if (nextFrameIndexDelta.z != 0)
                                {
                                    delta.z     = -delta.z;
                                    deltaSign.z = -deltaSign.z;
                                }
                                frameIndex.Sub(nextFrameIndexDelta);                                 // 일보후퇴
                                continue;
                            }
                            else if (block.code == 15)                            // 유리만나면 살짝 하얘지고 계속 진행.
                            {
                                color.Add(10);
                            }
                            else
                            {
                                color.Add(block.color);
                                viewer.Draw(i, k, color);
                                break;
                            }
                        }
                        //현위치에서 delta벡터방향으로 이동할 경우 가장 먼저 만나는 경계면 구하기.
                        target.Set(world.frameLength / 2);
                        target.Mul(deltaSign);                        //delta벡터 방향으로 이동시 접촉가능한 경계면들 구하기.
                        target.Sub(lpos).Div(delta);                  //경계면들로부터 현재위치의 거리를 구하고 delta로 나누기. deltasign으로 한번 곱했었기때문에 x,y,z축 서로에 대한 정확한 비교값이 나오게된다.
                        nextFrameIndexDelta.Set(0);
                        if (target.x < target.y && target.x < target.z)
                        {
                            numOfDelta            = target.x;
                            nextFrameIndexDelta.x = (int)deltaSign.x;
                        }
                        else if (target.y < target.x && target.y < target.z)
                        {
                            numOfDelta            = target.y;
                            nextFrameIndexDelta.y = (int)deltaSign.y;
                        }
                        else if (target.z < target.x && target.z < target.y)
                        {
                            numOfDelta            = target.z;
                            nextFrameIndexDelta.z = (int)deltaSign.z;
                        }
                        frameIndex.Add(nextFrameIndexDelta);                        //가장가까운 경계면에 해당하는 블록으로 이동.
                        index.Add(gap.Set(delta).Mul(numOfDelta));                  //delta방향으로 가장 가까운 경계면으로 이동.
                        //여기까지 수정
                    }
                }
                //);
            }
            //);
            rayDelta.Set(deltaArray[camPoint.x, camPoint.z]);
            for (int i = camPoint.z - 3; i < camPoint.z + 3; i++)
            {
                for (int j = camPoint.x - 3; j < camPoint.x + 3; j++)
                {
                    if (Math.Pow(i - camPoint.z, 2) + Math.Pow(j - camPoint.x, 2) < 8 &&
                        Math.Pow(i - camPoint.z, 2) + Math.Pow(j - camPoint.x, 2) > 4)
                    {
                        viewer.Draw(j, i, new XYZ_b(255));
                    }
                }
            }
        }