Exemple #1
0
        public void update(float tpf, long frametime)
        {
            UpdateCameraRotation();
            Point3D dir = new Point3D(0, 0, 0);

            if (Input.hasInput("W"))
            {
                dir.X += 1.4;
            }
            if (Input.hasInput("S"))
            {
                dir.X += -1.4;
            }
            if (Input.hasInput("A"))
            {
                dir.Z += -1.4;
            }
            if (Input.hasInput("D"))
            {
                dir.Z += 1.4;
            }
            switch (CameraPos)
            {
            case 1:
                Point Move = MathUtil.MathUtil.RotatePoint(new Point(dir.X, dir.Z), RotXZ);
                dir.X = Move.X;
                dir.Z = Move.Y;
                break;

            default:
                double tempX = dir.X;
                dir.X = dir.Z;
                dir.Z = -tempX;
                break;
            }

            float sx = (float)dir.X * tpf * vel;
            float sz = (float)dir.Z * tpf * vel;
            float sy = 0;

            Boolean[] value       = ChunkTracker.getVoxelValue(new Point3D(ModelPosition.X, Math.Floor(ModelPosition.Y), ModelPosition.Z));
            int       BinaryValue = 0;

            BinaryValue += value[0] ? 1 : 0;
            BinaryValue += value[1] ? 2 : 0;
            BinaryValue += value[2] ? 4 : 0;
            BinaryValue += value[3] ? 8 : 0;
            BinaryValue += value[4] ? 16 : 0;
            BinaryValue += value[5] ? 32 : 0;
            BinaryValue += value[6] ? 64 : 0;
            BinaryValue += value[7] ? 128 : 0;

            if (dir.X == 0 && dir.Z == 0)
            {
                if (BinaryValue == 255)
                {
                    sy = 0.32f;
                }
                else if (BinaryValue == 15)
                {
                    if (ModelPosition.Y % 1 < 0.5f)
                    {
                        ModelPosition = new Point3D(ModelPosition.X, ModelPosition.Y + (ModelPosition.Y % 0.5), ModelPosition.Z);
                    }
                }
                else if (!value[0] && !value[1] && !value[2] && !value[3])
                {
                    sy = -0.32f;
                }
            }
            else
            {
                float v1 = value[4] ? 1 : 0;
                float v2 = value[5] ? 1 : 0;
                float v3 = value[6] ? 1 : 0;
                float v4 = value[7] ? 1 : 0;

                if (BinaryValue == 255)
                {
                    sy = 0.32f;
                }
                else if (BinaryValue == 153)
                {
                    sx = sx > 0 ? sx : 0;
                }
                else if (BinaryValue == 204)
                {
                    sz = sz < 0 ? sz : 0;
                }
                else if (BinaryValue == 102)
                {
                    sx = sx < 0 ? sx : 0;
                }
                else if (BinaryValue == 51)
                {
                    sz = sz > 0 ? sz : 0;
                }
                else if (BinaryValue == 136 || BinaryValue == 221)
                {
                    sx = sx > 0 ? sx : 0;
                    sz = sz < 0 ? sz : 0;
                }
                else if (BinaryValue == 68 || BinaryValue == 238)
                {
                    sx = sx < 0 ? sx : 0;
                    sz = sz < 0 ? sz : 0;
                }
                else if (BinaryValue == 34 || BinaryValue == 119)
                {
                    sx = sx < 0 ? sx : 0;
                    sz = sz > 0 ? sz : 0;
                }
                else if (BinaryValue == 17 || BinaryValue == 187)
                {
                    sx = sx > 0 ? sx : 0;
                    sz = sz > 0 ? sz : 0;
                }
                else if (!value[0] && !value[1] && !value[2] && !value[3])
                {
                    sy = -0.32f;
                }
                else if (BinaryValue == 15)
                {
                    if (ModelPosition.Y % 1 < 0.5f)
                    {
                        ModelPosition = new Point3D(ModelPosition.X, ModelPosition.Y + (ModelPosition.Y % 0.5), ModelPosition.Z);
                    }
                }
                else
                {
                    sy = (MathUtil.MathUtil.bilerp((float)ModelPosition.X % 1, (float)ModelPosition.Z % 1, 0, 1, 0, 1, v1, v2, v3, v4));
                }
            }
            ModelPosition = new Point3D(ModelPosition.X + sx, ModelPosition.Y + sy, ModelPosition.Z + sz);
            TranslateTransform3D translation = new TranslateTransform3D(ModelPosition.X, ModelPosition.Y + 0.5f, ModelPosition.Z);

            Model.Transform = translation;

            if (Input.hasInput("F5"))
            {
                //toggle first/third person camera
                if (TimePassed > 250)
                {
                    //Debug.WriteLine(DateTime.Now.Millisecond - toggleTime);
                    CameraPos  = CameraPos >= CameraPosMax ? 0 : CameraPos + 1;
                    TimePassed = 0;
                }
            }
            //CameraDirection = new Vector3D(Math.Cos(MathUtil.MathUtil.GetRadian(radian)), 0, Math.Sin(MathUtil.MathUtil.GetRadian(radian)));
            DrawCubeOutLine();
            if (ModifyTimePassed > 16)
            {
                if (Input.hasInput("M2"))
                {
                    RayTest(true);
                }

                if (Input.hasInput("M1"))
                {
                    RayTest(false);
                }

                ModifyTimePassed = 0;
            }

            if (Input.hasInput("F"))
            {
                if (OutLineToggleTimePassed > 100)
                {
                    HasOutLineTool          = !HasOutLineTool;
                    OutLineToggleTimePassed = 0;
                }
            }

            TimePassed              += (long)(tpf * 1000);
            ModifyTimePassed        += (long)(tpf * 1000);
            OutLineToggleTimePassed += (long)(tpf * 1000);
            CreateCameraView();
        }