Пример #1
0
 public VoxLocation(Vector3I loc)
 {
     RegionLoc = new Point(loc.X >> Region.XZ_SHIFT, loc.Z >> Region.XZ_SHIFT);
     VoxelLoc = new Vector3I(
         loc.X & ((0x01 << Region.XZ_SHIFT) - 1),
         loc.Y,
         loc.Z & ((0x01 << Region.XZ_SHIFT) - 1)
         );
 }
Пример #2
0
        public MeshedFace(Vector3I rmin, Vector3I axisX, Vector3I axisY, Point size, int id, int face)
        {
            RXNYN = rmin;
            Size = size;

            RXPYN = rmin;
            RXPYN.X += Size.X * axisX.X;
            RXPYN.Y += Size.X * axisX.Y;
            RXPYN.Z += Size.X * axisX.Z;

            RXNYP = rmin;
            RXNYP.X += Size.Y * axisY.X;
            RXNYP.Y += Size.Y * axisY.Y;
            RXNYP.Z += Size.Y * axisY.Z;

            RXPYP = RXPYN;
            RXPYP.X += Size.Y * axisY.X;
            RXPYP.Y += Size.Y * axisY.Y;
            RXPYP.Z += Size.Y * axisY.Z;

            ID = id;
            Face = face;
        }
Пример #3
0
 public override void OnMouseClick(VoxState s, FreeCamera camera, Vector2 mPos, MouseButton button, Viewport vp)
 {
     Ray r = camera.GetViewRay(mPos, vp.Width, vp.Height);
     if(button == MouseButton.Left) {
         VoxLocation? vl = VRayHelper.GetInner(r, s);
         if(vl.HasValue) {
             var loc = vl.Value;
             if(hasStart) {
                 Vector3I end = new Vector3I(
                     loc.RegionLoc.X * Region.WIDTH + loc.VoxelLoc.X,
                     loc.VoxelLoc.Y,
                     loc.RegionLoc.Y * Region.DEPTH + loc.VoxelLoc.Z
                     );
                 Vector3I min = new Vector3I(Math.Min(start.X, end.X), Math.Min(start.Y, end.Y), Math.Min(start.Z, end.Z));
                 Vector3I max = new Vector3I(Math.Max(start.X, end.X), Math.Max(start.Y, end.Y), Math.Max(start.Z, end.Z));
                 for(int ry = min.Y; ry <= max.Y; ry++) {
                     for(int rz = min.Z; rz <= max.Z; rz++) {
                         for(int rx = min.X; rx <= max.X; rx++) {
                             loc = new VoxLocation(new Vector3I(rx, ry, rz));
                             s.World.regions[loc.RegionIndex].RemoveVoxel(loc.VoxelLoc.X, loc.VoxelLoc.Y, loc.VoxelLoc.Z);
                         }
                     }
                 }
                 hasStart = false;
             }
             else {
                 start = new Vector3I(
                     loc.RegionLoc.X * Region.WIDTH + loc.VoxelLoc.X,
                     loc.VoxelLoc.Y,
                     loc.RegionLoc.Y * Region.DEPTH + loc.VoxelLoc.Z
                     );
                 hasStart = true;
             }
         }
     }
     else if(button == MouseButton.Right) {
         VoxLocation? vl = VRayHelper.GetOuter(r, s);
         if(vl.HasValue) {
             var loc = vl.Value;
             if(hasStart) {
                 Vector3I end = new Vector3I(
                     loc.RegionLoc.X * Region.WIDTH + loc.VoxelLoc.X,
                     loc.VoxelLoc.Y,
                     loc.RegionLoc.Y * Region.DEPTH + loc.VoxelLoc.Z
                     );
                 Vector3I min = new Vector3I(Math.Min(start.X, end.X), Math.Min(start.Y, end.Y), Math.Min(start.Z, end.Z));
                 Vector3I max = new Vector3I(Math.Max(start.X, end.X), Math.Max(start.Y, end.Y), Math.Max(start.Z, end.Z));
                 for(int ry = min.Y; ry <= max.Y; ry++) {
                     for(int rz = min.Z; rz <= max.Z; rz++) {
                         for(int rx = min.X; rx <= max.X; rx++) {
                             loc = new VoxLocation(new Vector3I(rx, ry, rz));
                             s.World.regions[loc.RegionIndex].AddVoxel(loc.VoxelLoc.X, loc.VoxelLoc.Y, loc.VoxelLoc.Z, CurVoxID);
                         }
                     }
                 }
                 hasStart = false;
             }
             else {
                 start = new Vector3I(
                     loc.RegionLoc.X * Region.WIDTH + loc.VoxelLoc.X,
                     loc.VoxelLoc.Y,
                     loc.RegionLoc.Y * Region.DEPTH + loc.VoxelLoc.Z
                     );
                 hasStart = true;
             }
         }
     }
 }
Пример #4
0
 public static int ToIndex(Vector3I v)
 {
     return ToIndex(v.X, v.Y, v.Z);
 }
Пример #5
0
 public static bool IsInBounds(Vector3I v)
 {
     return
         v.X >= 0 && v.X < VoxWorld.WIDTH * Region.WIDTH &&
         v.Y >= 0 && v.Y < Region.HEIGHT &&
         v.Z >= 0 && v.Z < VoxWorld.DEPTH * Region.DEPTH
         ;
 }