コード例 #1
0
ファイル: V-Modifier.cs プロジェクト: NaTure77/CubeWorld
        public void fire_Moving_Cube(XYZ_d position, XYZ size, double speed)
        {
            XYZ_d delta   = new XYZ_d(rayDelta).Mul(speed);
            XYZ_d pointer = new XYZ_d(rayDelta).Mul(30).Add(position);

            Object c = new Cube(pointer, size);

            SetColor(c, 0, 255, 255);

            XYZ_d  vector = new XYZ_d(-Camera.instance.GetCursorPos().y, 0, Camera.instance.GetCursorPos().x);
            Matrix mat    = new Matrix(Spin_matrix_x) + new Matrix(Spin_matrix_z);

            SpinObject(c, vector, mat);
            DrawObject(c);
            mat = new Matrix(Spin_matrix_y) + new Matrix(Spin_matrix_x) + new Matrix(Spin_matrix_z);
            XYZ_d rotateDelta = new XYZ_d(0, 6, 0);

            Task.Factory.StartNew(() =>
            {
                while (world.isIn(pointer))
                {
                    pointer.Add(delta);
                    MoveObject(c, delta);

                    vector.Add(rotateDelta);
                    SpinObject(c, vector, mat);
                    vector.Remain(360);
                    Thread.Sleep(5);
                }
                DeleteObject(c);
            });
        }
コード例 #2
0
ファイル: V-Modifier.cs プロジェクト: NaTure77/CubeWorld
        public void fire_LightSphere(int radius, int range, int level)
        {
            int   diameter  = range * 2;
            XYZ_d rs_origin = new XYZ_d(rayStrike);
            XYZ_d rs        = new XYZ_d(rs_origin);

            Task.Factory.StartNew(() =>
            {
                for (int i = 0; i < diameter; i++)
                {
                    for (int j = 0; j < diameter; j++)
                    {
                        for (int k = 0; k < diameter; k++)
                        {
                            rs.Set(rs_origin);
                            rs.Add(i - range, j - range, k - range);
                            if (!world.isIn(rs))
                            {
                                continue;
                            }
                            double distance = Math.Sqrt(Math.Pow(i - range, 2) + Math.Pow(j - range, 2) + Math.Pow(k - range, 2));
                            if (distance <= radius && distance > radius - 2)
                            {
                                world.SetLevel(rs, 10);
                            }
                            else if (distance > radius && distance < range)
                            {
                                world.AddLevel(rs, (int)(level * (range - distance) / range));
                            }
                        }
                    }
                    Thread.Sleep(1);
                }
            });
        }
コード例 #3
0
 protected override void DoSomething()
 {
     modifier.SpinObject(obj, degree);
     modifier.MoveObject(obj, moveDelta);
     Thread.Sleep(10);
     degree.Add(rotateDelta);
     degree.Remain(360);
 }
コード例 #4
0
 public void Move(double x, double y, double z)
 {
     Spin_matrix_z(x, y, z, camera.GetCursorPos().x, scalaVector, XYZ_d.ZERO);
     if (!Check_Wall(scalaVector))
     {
         Position.Add(scalaVector);
     }
 }
コード例 #5
0
        protected override void DoSomething()
        {
            delta.Set(target).Sub(obj.Position);
            direction.Add(delta).Div(4);
            delta.Set(direction).Div(direction.Length()).Mul(speed);
            delta.z = (target.z - obj.Position.z - 20) / 20;

            modifier.MoveObject(obj, delta);
            Thread.Sleep(1);
        }
コード例 #6
0
ファイル: V-Controller.cs プロジェクト: NaTure77/CubeWorld
        public void Move(double x, double y, double z, double degree)
        {
            Spin_matrix_z(x, y, degree, scalaVector);
            scalaVector.Mul(speed);
            //scalaVector.Set(camera.rayDelta).Mul(y,y,y).Add(camera.basisX.x * x,camera.basisX.y * x,0).Mul(speed);

            if (!Check_Wall(scalaVector))
            {
                Position.Add(scalaVector);
                world.ConvertToInfinity(Position);
            }
            else
            {
                XYZ_d pos   = new XYZ_d(Position).Add(scalaVector);
                XYZ   index = new XYZ();
                world.GetFrameIndex(pos, index);
                if (!world.isFrameEnabled(index))
                {
                    Vector.z = -40;
                }
            }
        }
コード例 #7
0
ファイル: V-Modifier.cs プロジェクト: NaTure77/CubeWorld
        public void fire_Moving_Sphere(XYZ_d position, int radius, double speed)
        {
            XYZ_d delta   = new XYZ_d(rayDelta);
            XYZ_d pointer = new XYZ_d(rayDelta).Mul(30).Add(position);

            Object s = new Sphere(pointer, radius);

            SetColor(s, 139, 0, 0);
            DrawObject(s);

            Task.Factory.StartNew(() =>
            {
                while (world.isIn(pointer))
                {
                    pointer.Add(delta);
                    MoveObject(s, delta);
                    Thread.Sleep(5);
                }
                DeleteObject(s);
            });
        }
コード例 #8
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]);
        }
コード例 #9
0
ファイル: V-Controller.cs プロジェクト: NaTure77/CubeWorld
        void RegistKey(Camera camera)
        {
            InputManager.Regist(Keys.W, new Func(() => { Move(0, 1, 0, camera.GetCursorPos().x); }), true);
            InputManager.Regist(Keys.S, new Func(() => { Move(0, -1, 0, camera.GetCursorPos().x); }), true);
            InputManager.Regist(Keys.D, new Func(() => { Move(1, 0, 0, camera.GetCursorPos().x); }), true);
            InputManager.Regist(Keys.A, new Func(() => { Move(-1, 0, 0, camera.GetCursorPos().x); }), true);
            InputManager.Regist(Keys.E, new Func(() => { Shoot(new XYZ_b(255, 0, 0), camera.rayDelta); }), false);
            InputManager.Regist(Keys.R, new Func(() => { Shoot(new XYZ_b(0, 255, 0), camera.rayDelta); }), false);
            InputManager.Regist(Keys.T, new Func(() => { Shoot(new XYZ_b(0, 0, 255), camera.rayDelta); }), false);
            // InputManager.Regist(Keys.C, new Func(() => { Move(0, 0, 1); }), true);
            // InputManager.Regist(Keys.V, new Func(() => { Move(0, 0, -1); }), true);
            InputManager.Regist(Keys.V, new Func(() => { if (isJumpable)
                                                         {
                                                             Vector.z = -80; isJumpable = false;
                                                         }
                                                 }), true);
            InputManager.Regist(Keys.Q, new Func(() => {
                double boostSpeed = 50;
                Vector.Add(camera.rayDelta.x * boostSpeed, camera.rayDelta.y * boostSpeed, camera.rayDelta.z * boostSpeed);
                //Vector.z += boostSpeed;
            }), true);

            InputManager.Regist(Keys.P, new Func(() => { camera.gridEnabled = !camera.gridEnabled; }), false);

            /* InputManager.Regist(Keys.D2, new Func(() => { color = (byte)15; }), false);
             * InputManager.Regist(Keys.D3, new Func(() => { color = (byte)14; }), false);
             * InputManager.Regist(Keys.D4, new Func(() => { color = (byte)4; }), false);
             * InputManager.Regist(Keys.D5, new Func(() => { color = (byte)5; }), false);
             * InputManager.Regist(Keys.D6, new Func(() => { color = (byte)6; }), false);
             * InputManager.Regist(Keys.D7, new Func(() => { color = (byte)7; }), false);
             * InputManager.Regist(Keys.D8, new Func(() => { code = (byte)14; }), false);
             * InputManager.Regist(Keys.D9, new Func(() => { code = (byte)15; }), false);
             * InputManager.Regist(Keys.D0, new Func(() => { code = (byte)1; }), false); */
            InputManager.Regist(Keys.D0, new Func(() => { renderer = world.renderer_block; }), false);
            InputManager.Regist(Keys.D1, new Func(() => { renderer = world.renderer_air; }), false);
            InputManager.Regist(Keys.D2, new Func(() => { renderer = world.renderer_mirror; }), false);
            InputManager.Regist(Keys.Space, new Func(() => { AddBlock(camera.addFrameIndex, camera.PositionIndex); }), false);
            InputManager.Regist(Keys.X, new Func(() => { DeleteBlock(camera.deleteFrameIndex); }), false);

            InputManager.Regist(Keys.M, new Func(() =>
            {
                if (camera.viewer.qualityLevel > -2)
                {
                    camera.Resize(camera.camSize.x / 2, camera.camSize.y, camera.camSize.z / 2);
                    camera.viewer.UpdateBufferSize(camera.camSize);
                    camera.viewer.qualityLevel--;
                }
            }), false);
            InputManager.Regist(Keys.N, new Func(() =>
            {
                if (camera.viewer.qualityLevel < 2)
                {
                    camera.Resize(camera.camSize.x * 2, camera.camSize.y, camera.camSize.z * 2);
                    camera.viewer.UpdateBufferSize(camera.camSize);
                    camera.viewer.qualityLevel++;
                }
            }), false);
            camera.viewer.SetKeyDownEvent((sender, e) =>
            {
                InputManager.AddLongClick(e.KeyCode);
                InputManager.DoOneClick(e.KeyCode);
            });

            camera.viewer.SetKeyUpEvent((sender, e) =>
            {
                InputManager.SubLongClick(e.KeyCode);
            });
        }
コード例 #10
0
        public Camera(XYZ cs, XYZ_d cPos, World w)
        {
            instance  = this;
            camSize   = cs;
            Position  = cPos;
            world     = w;
            worldSize = w.GetWorldSize();
            camPoint  = new XYZ(camSize).Div(2);
            position  = new XYZ_d(Position);

            board = new char[camSize.z, camSize.x];

            color      = new XYZ_b[camSize.z, camSize.x];       //ConsoleColor[camSize.z,camSize.x];
            perspArray = new XYZ_d[camSize.x, camSize.z];
            indexArray = new XYZ_d[camSize.x, camSize.z];
            spinArray  = new XYZ_d[camSize.x, camSize.z];
            deltaArray = new XYZ_d[camSize.x, camSize.z];

            lightArray = new double[camSize.x, camSize.y, camSize.z];
            circle     = new bool[camPoint.x, camPoint.x];

            //double rc_ratio = (1f * camSize.x) / camSize.z;

            double fov = 1d / 60;

            for (int i = 0; i < camSize.x; i++)
            {
                for (int j = 0; j < camSize.z; j++)
                {
                    color[j, i]        = new XYZ_b();
                    perspArray[i, j]   = new XYZ_d();
                    perspArray[i, j].x = (i - camPoint.x) * (camSize.y - 1) * fov;
                    perspArray[i, j].y = camSize.y - 1;
                    perspArray[i, j].z = (j - camPoint.z) * (camSize.y - 1) * fov;

                    indexArray[i, j] = new XYZ_d();
                    spinArray[i, j]  = new XYZ_d();
                    deltaArray[i, j] = new XYZ_d();
                }
            }


            for (int i = 0; i < camPoint.x; i++)
            {
                for (int j = 0; j < camPoint.x; j++)
                {
                    circle[i, j] = false;
                }
            }

            XYZ_d newPos = new XYZ_d();

            for (int i = 0; i < camPoint.x / 2; i++)
            {
                for (double d = 0; d < 360; d += 0.1d)
                {
                    Spin_matrix_z(i, 0, 0, Math.Sin(d * PI), Math.Cos(d * PI), newPos);
                    newPos.Add(camPoint.x / 2);
                    int x = newPos.iX;
                    int y = newPos.iY;
                    if (x < camPoint.x && x >= 0 && y < camPoint.x && y >= 0)
                    {
                        circle[x, y] = true;
                    }
                }
            }

            for (int i = 0; i < camSize.x; i++)
            {
                for (int j = 0; j < camSize.y; j++)
                {
                    for (int k = 0; k < camSize.z; k++)
                    {
                        lightArray[i, j, k] = 0;
                    }
                }
            }

            Spin_Light2();
            rayDelta  = new XYZ_d();
            rayStrike = new XYZ_d();
            viewer    = new Viewer(this, camSize, 5);
        }
コード例 #11
0
        public void Spin_XZAxis4()
        {
            isRendering = true;
            position.Set(Position);
            if (isLighting && isLightMove)
            {
                lightAngle.x += (Cursor.Position.X - screenPoint.X) * sensitivity;
                lightAngle.y += (Cursor.Position.Y - screenPoint.Y) * sensitivity;
                Spin_Light2();
            }
            else
            {
                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);

            for (int k = 0; k < camSize.z; k++)
            {
                Parallel.For(0, camSize.x, (int i) =>
                             //for (int i = 0; i < camSize.x; i++)
                {
                    int depth = 0;
                    Pixel pixel;
                    board[k, i] = ' ';
                    color[k, i].Set(0, 0, 0);                  // = ConsoleColor.Black;

                    Spin_matrix_x(perspArray[i, k].x, perspArray[i, k].y, perspArray[i, k].z, sinX, cosX, spinArray[i, k]);
                    Spin_matrix_z(spinArray[i, k].x, spinArray[i, k].y, spinArray[i, k].z, sinY, cosY, spinArray[i, k]);

                    int length = camSize.y;

                    XYZ_d delta = deltaArray[i, k].Set(spinArray[i, k]).Div(length * 2);
                    XYZ_d index = indexArray[i, k].Set(position);

                    for (int j = 0; j < length * 2; j++)
                    {
                        index.Add(delta);
                        pixel = world.GetPixel(index);

                        if (pixel != null)
                        {
                            if (pixel.Position == null)
                            {
                                break;
                            }
                            if (!pixel.isVisible)
                            {
                                continue;
                            }

                            if (isLighting)
                            {
                                /* depth = (int)(13 * (70 - position.Distance(pixel.Position)) / (70d));
                                 * depth = depth < 0 ? 0 :
                                 *              depth > 9 ? 9 : depth; */
                                depth += (int)lightArray[i, j / 2, k];
                            }
                            depth += world.GetLevel(index) + pixel.level;
                            depth  = depth < 0 ? 0 :
                                     depth > 9 ? 9 : depth;

                            board[k, i] = level[depth];
                            //  viewer.Draw(i,k,depth);
                            color[k, i].Set(pixel.color);
                            color[k, i].Add((byte)(12 * (depth)));

                            /* Console.Write(rayStrike.x);
                             * Console.Write(",");
                             * Console.Write(rayStrike.y);
                             * Console.Write(",");
                             * Console.Write(rayStrike.z);
                             * Console.WriteLine(); */
                            break;
                        }
                    }
                });
            }            //);
            isRendering = false;
            rayDelta.Set(spinArray[camPoint.x - 1, camPoint.z - 1]).Div(camSize.y);
            rayStrike.Set(indexArray[camPoint.x - 1, camPoint.z - 1]);
        }
コード例 #12
0
        /*public void Print()
         * {
         *       Console.SetCursorPosition(0,0);
         *      string a = "";
         *      Make_CrossHead();
         *
         *      ConsoleColor current = ConsoleColor.White;
         *
         *      for(int i = 0; i < camSize.z; i++)
         *      {
         *              for(int j = 0; j < camSize.x; j++)
         *              {
         *                      if(current!=color[i,j])
         *                      {
         *                              result.Add(new Ps(a,current));
         *                              a = "";
         *                              current = color[i,j];
         *                      }
         *                      a += board[i,j];
         *              }
         *              a += "\r\n";
         *      }
         *      result.Add(new Ps(a,current));
         *      foreach(Ps p in result)
         *      {
         *              p.Print();
         *      }
         *      result.Clear();
         *
         * }*/
        public void Spin_Light2()
        {
            double degreeX = -lightAngle.y * PI;
            double degreeY = lightAngle.x * PI;
            double sinX    = Math.Sin(degreeX);
            double sinY    = Math.Sin(degreeY);
            double cosX    = Math.Cos(degreeX);
            double cosY    = Math.Cos(degreeY);

            int   x = 0; int y = 0; int z = 0;
            XYZ_d startPos = new XYZ_d();
            XYZ_d endPos   = new XYZ_d();
            XYZ_d index    = new XYZ_d();

            for (int i = 0; i < camSize.x; i++)
            {
                for (int j = 0; j < camSize.y; j++)
                {
                    for (int k = 0; k < camSize.z; k++)
                    {
                        lightArray[i, j, k] = 0;
                    }
                }
            }

            int radius = camPoint.x / 2;

            for (int k = 0; k < camPoint.x; k++)
            {
                for (int i = 0; i < camPoint.x; i++)
                {
                    if (circle[i, k])
                    {
                        double length = 200;
                        Spin_matrix_x(i - radius, 0, k - radius, sinX, cosX, startPos);
                        Spin_matrix_z(startPos.x, startPos.y, startPos.z, sinY, cosY, startPos);

                        Spin_matrix_x(i - radius, length, k - radius, sinX, cosX, endPos);
                        Spin_matrix_z(endPos.x, endPos.y, endPos.z, sinY, cosY, endPos);
                        endPos.Sub(startPos).Div(length);
                        index.Set(startPos);
                        index.x += camPoint.x;
                        index.z += camPoint.z;
                        for (int j = 0; j < length; j++)
                        {
                            index.Add(endPos);
                            x = index.iX;
                            y = index.iY;
                            z = index.iZ;
                            if (x >= 0 && x < camSize.x && y >= 0 && y < camSize.y && z >= 0 && z < camSize.z)
                            {
                                double distance = Math.Sqrt(Math.Pow(i - radius, 2) + Math.Pow(k - radius, 2));
                                double power    = 14 * (camSize.y - j) / (camSize.y * 1f);
                                if (power < 1)
                                {
                                    power = 1;
                                }
                                lightArray[x, y, z] = power * (radius - distance) / radius;
                            }
                        }
                    }
                }
            }
        }
コード例 #13
0
ファイル: V-World.cs プロジェクト: NaTure77/CubeWorld
        public void MakeCone(XYZ_d pos, int radius, int height)
        {
            XYZ    frameIndex = new XYZ();
            XYZ_d  temp       = new XYZ_d();
            XYZ_d  temp2      = new XYZ_d();
            XYZ_d  temp3      = new XYZ_d();
            double distance   = 0;

            pos.z += height;
            XYZ_b color  = new XYZ_b(1, 1, 1);
            XYZ_b color2 = new XYZ_b(color).Mul(30);

            double degreeX = 30 * -Math.PI / 180d;
            double degreeY = 0 * Math.PI / 180d;
            double sinX    = Math.Sin(degreeX);
            double sinY    = Math.Sin(degreeY);
            double cosX    = Math.Cos(degreeX);
            double cosY    = Math.Cos(degreeY);
            XYZ_d  basisX  = new XYZ_d(cosY, -sinY, 0);
            XYZ_d  basisY  = new XYZ_d(cosX * sinY, cosX * cosY, -sinX);
            XYZ_d  basisZ  = new XYZ_d(sinX * sinY, sinX * cosY, cosX);

            for (int i = -radius - 1; i < radius + 1; i++)
            {
                for (int j = -radius - 1; j < radius + 1; j++)
                {
                    for (int k = -height - 1; k < -height / 2 + 1; k++)
                    {
                        temp.Set(pos).Add(i, j, k);
                        frameIndex = temp.ToXYZ();
                        ConvertToInfinity(frameIndex);
                        SetBlock(frameIndex, true);
                        SetColor(frameIndex, 0, 0, 0);
                        SetRender(frameIndex, renderer_block);
                        //SetColor(frameIndex,1,0,0);
                    }
                }
            }

            for (int i = -radius; i < radius; i++)
            {
                for (int j = -radius; j < radius; j++)
                {
                    for (int k = -height; k < -height / 2; k++)
                    {
                        temp.Set(pos).Add(i, j, k);
                        frameIndex = temp.ToXYZ();
                        ConvertToInfinity(frameIndex);
                        SetBlock(frameIndex, false);
                        SetRender(frameIndex, renderer_air);
                        //SetColor(frameIndex,1,0,0);
                    }
                }
            }
            //frameIndex = pos.ToXYZ();
            //ConvertToInfinity(frameIndex);
            //frameIndex.z -= height - 10;

            temp.Set(pos).Sub(0, 10, height - 10);
            for (int i = -2; i <= 2; i++)
            {
                for (int j = -2; j <= 2; j++)
                {
                    for (int k = -2; k <= 2; k++)
                    {
                        temp2.Set(temp).Add(i, j, k);
                        frameIndex = temp2.ToXYZ();
                        ConvertToInfinity(frameIndex);
                        SetBlock(frameIndex, true);
                        SetRender(frameIndex, renderer_block);
                    }
                }
            }

            for (int i = -radius; i < radius; i++)
            {
                for (int j = -radius; j < radius; j++)
                {
                    temp.Set(pos).Add(i, j, 0);
                    distance = pos.Distance(temp);
                    if (distance < radius)
                    {
                        frameIndex = temp.ToXYZ();
                        ConvertToInfinity(frameIndex);
                        //SetColor(frameIndex,color);

                        temp2.Set(temp).Sub(pos).Add(0, 0, height).Div(height);
                        temp2.Set(basisX.x * temp2.x + basisY.x * temp2.y + basisZ.x * temp2.z,
                                  basisX.y * temp2.x + basisY.y * temp2.y + basisZ.y * temp2.z,
                                  basisX.z * temp2.x + basisY.z * temp2.y + basisZ.z * temp2.z);
                        temp2.Div(temp2.Length());
                        //temp2.Set(temp3);
                        temp.Set(pos).Add(0, 0, -height);

                        /*******************************************************************************/

                        /*  frameIndex = temp.ToXYZ();
                         * XYZ deltaSign = new XYZ(Math.Sign(temp2.x),Math.Sign(temp2.y),Math.Sign(temp2.z));
                         * int nextDir = 0;
                         * XYZ_d maxNumOfDelta = new XYZ_d(frameLength).Mul(deltaSign).Div(temp2);
                         * XYZ_d target = new XYZ_d(halfFrameLength);
                         * target.Mul(deltaSign);//delta벡터 방향으로 이동시 접촉가능한 경계면들 구하기.
                         * target.Div(temp2);
                         */
                        //XYZ gap = new XYZ(frameIndex);

                        //color.Set(2,2,2);
                        //byte code = 0;
                        for (int k = 0; k < height * 1.5f; k++)
                        {
                            temp.Add(temp2);
                            frameIndex = temp.ToXYZ();

                            /* 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];
                            //frameIndex.element[nextDir] += deltaSign.element[nextDir];
                            ConvertToInfinity(frameIndex);
                            if (isFrameEnabled(frameIndex))
                            {
                                AddColor(frameIndex, color2);
                                break;
                            }
                            else
                            {
                                AddColor(frameIndex, color);
                            }
                            //SetBlock(frameIndex,code);

                            //gap.Set(frameIndex);

                            //Console.WriteLine(nextDir);
                        }
                    }
                }
            }
        }
コード例 #14
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));
                    }
                }
            }
        }