예제 #1
0
        public static bool PickVoxel(EnvironmentObject env, GameSurfaceView view, IntVector2 screenPos, IntGrid3 cropGrid,
			MapControlPickMode pickMode, out IntVector3 pos, out Direction face)
        {
            var camera = view.Camera;

            var ray = Ray.GetPickRay(screenPos.X, screenPos.Y, view.ViewPort, view.Camera.View * view.Camera.Projection);

            IntVector3 outpos = new IntVector3();
            Direction outdir = Direction.None;

            var corner = cropGrid.Corner2;
            var size = new IntSize3(corner.X + 1, corner.Y + 1, corner.Z + 1);

            IntVector3 prevoutpos = new IntVector3();
            Direction prevoutdir = Direction.None;

            VoxelRayCast.RunRayCast(size, ray.Position, ray.Direction, view.Camera.FarZ,
                (x, y, z, dir) =>
                {
                    var p = new IntVector3(x, y, z);

                    if (cropGrid.Contains(p) == false)
                        return false;

                    var td = env.GetTileData(p);

                    switch (pickMode)
                    {
                        case MapControlPickMode.Underground:
                            if (!td.IsUndefined && !td.IsWall)
                                return false;

                            outpos = p;
                            outdir = dir;
                            return true;

                        case MapControlPickMode.AboveGround:
                            if (!td.IsUndefined && !td.IsWall)
                            {
                                prevoutpos = p;
                                prevoutdir = dir;
                                return false;
                            }

                            if (prevoutpos.IsNull)
                            {
                                outpos = p;
                                outdir = dir;
                            }
                            else
                            {
                                outpos = prevoutpos;
                                outdir = prevoutdir;
                            }
                            return true;

                        case MapControlPickMode.Constant:
                            if (p.Z > cropGrid.Z2)
                                return false;

                            outpos = p;
                            outdir = dir;
                            return true;

                        default:
                            throw new NotImplementedException();
                    }
                });

            pos = outpos;
            face = outdir;
            return face != Direction.None;
        }
예제 #2
0
        public static bool PickVoxel(EnvironmentObject env, GameSurfaceView view, IntVector2 screenPos, IntGrid3 cropGrid,
                                     MapControlPickMode pickMode, out IntVector3 pos, out Direction face)
        {
            var camera = view.Camera;

            var ray = Ray.GetPickRay(screenPos.X, screenPos.Y, view.ViewPort, view.Camera.View * view.Camera.Projection);

            IntVector3 outpos = new IntVector3();
            Direction  outdir = Direction.None;

            var corner = cropGrid.Corner2;
            var size   = new IntSize3(corner.X + 1, corner.Y + 1, corner.Z + 1);

            IntVector3 prevoutpos = new IntVector3();
            Direction  prevoutdir = Direction.None;

            VoxelRayCast.RunRayCast(size, ray.Position, ray.Direction, view.Camera.FarZ,
                                    (x, y, z, dir) =>
            {
                var p = new IntVector3(x, y, z);

                if (cropGrid.Contains(p) == false)
                {
                    return(false);
                }

                var td = env.GetTileData(p);

                switch (pickMode)
                {
                case MapControlPickMode.Underground:
                    if (!td.IsUndefined && !td.IsWall)
                    {
                        return(false);
                    }

                    outpos = p;
                    outdir = dir;
                    return(true);

                case MapControlPickMode.AboveGround:
                    if (!td.IsUndefined && !td.IsWall)
                    {
                        prevoutpos = p;
                        prevoutdir = dir;
                        return(false);
                    }

                    if (prevoutpos.IsNull)
                    {
                        outpos = p;
                        outdir = dir;
                    }
                    else
                    {
                        outpos = prevoutpos;
                        outdir = prevoutdir;
                    }
                    return(true);

                case MapControlPickMode.Constant:
                    if (p.Z > cropGrid.Z2)
                    {
                        return(false);
                    }

                    outpos = p;
                    outdir = dir;
                    return(true);

                default:
                    throw new NotImplementedException();
                }
            });

            pos  = outpos;
            face = outdir;
            return(face != Direction.None);
        }
예제 #3
0
 public static bool PickVoxel(MyGame game, IntVector2 screenPos, MapControlPickMode pickMode, out IntVector3 pos, out Direction face)
 {
     return MousePositionService.PickVoxel(game.Environment, game.Surfaces[0].Views[0], screenPos,
         game.ViewGridProvider.ViewGrid, pickMode, out pos, out face);
 }
예제 #4
0
 public static bool PickVoxel(MyGame game, IntVector2 screenPos, MapControlPickMode pickMode, out IntVector3 pos, out Direction face)
 {
     return(MousePositionService.PickVoxel(game.Environment, game.Surfaces[0].Views[0], screenPos,
                                           game.ViewGridProvider.ViewGrid, pickMode, out pos, out face));
 }