Пример #1
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;
             s.World.regions[loc.RegionIndex].RemoveVoxel(loc.VoxelLoc.X, loc.VoxelLoc.Y, loc.VoxelLoc.Z);
         }
     }
     else if(button == MouseButton.Right) {
         VoxLocation? vl = VRayHelper.GetOuter(r, s);
         if(vl.HasValue) {
             var loc = vl.Value;
             s.World.regions[loc.RegionIndex].AddVoxel(loc.VoxelLoc.X, loc.VoxelLoc.Y, loc.VoxelLoc.Z, CurVoxID);
         }
     }
 }
Пример #2
0
 public override void OnMouseClick(VoxState s, FreeCamera camera, Vector2 mPos, MouseButton button, Viewport vp) {
     List<VoxLocation> locs = new List<VoxLocation>();
     if(button == MouseButton.Left) {
         foreach(var r in GetRays(mPos, Vector2.One * 2, new Point(25, 25), camera, vp)) {
             VoxLocation? vl = VRayHelper.GetLevel(r, s, HEIGHT);
             if(vl.HasValue) locs.Add(vl.Value);
         }
         foreach(var loc in locs.Distinct())
             s.World.regions[loc.RegionIndex].RemoveVoxel(loc.VoxelLoc.X, loc.VoxelLoc.Y, loc.VoxelLoc.Z);
     }
     else if(button == MouseButton.Right) {
         foreach(var r in GetRays(mPos, Vector2.One * 2, new Point(25, 25), camera, vp)) {
             VoxLocation? vl = VRayHelper.GetLevel(r, s, HEIGHT);
             if(vl.HasValue) locs.Add(vl.Value);
         }
         foreach(var loc in locs.Distinct())
             s.World.regions[loc.RegionIndex].AddVoxel(loc.VoxelLoc.X, loc.VoxelLoc.Y, loc.VoxelLoc.Z, CurVoxID);
     }
 }
Пример #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 void OnMousePress(Vector2 location, MouseButton b)
        {
            if (Camera == null)
            {
                return;
            }
            Camera.Controller.IsActive = false;

            Point pl = new Point((int)location.X, (int)location.Y);

            if (UI != null && UI.Inside(pl.X, pl.Y))
            {
                // Check UI Actions
                OnUIPress(pl, b);
            }
            else
            {
                // Action In The World
                if (b == BUTTON_ACTION)
                {
                    if (Camera == null)
                    {
                        return;
                    }
                    Ray ray = Camera.GetViewRay(location);

                    // Check Building Placement
                    if (buildingToPlace != null)
                    {
                        ray.Position  *= new Vector3(0.5f, 1f, 0.5f);
                        ray.Direction *= new Vector3(0.5f, 1f, 0.5f);
                        ray.Direction.Normalize();
                        var nvl = VRayHelper.GetOuter(ray, GameState.VoxState);
                        if (nvl.HasValue)
                        {
                            Vector3 rh = new Vector3(
                                nvl.Value.RegionLoc.X * Region.WIDTH + nvl.Value.VoxelLoc.X,
                                nvl.Value.VoxelLoc.Y,
                                nvl.Value.RegionLoc.Y * Region.DEPTH + nvl.Value.VoxelLoc.Z
                                );
                            rh *= new Vector3(2f, 1f, 2f);
                            Point bp = HashHelper.Hash(new Vector2(rh.X, rh.Z), GameState.CGrid.numCells, GameState.CGrid.size);
                            AddEvent(new SpawnBuildingEvent(TeamIndex, buildingToPlace.Index, bp));
                            AddEvent(new ImpactEvent(TeamIndex, new Vector2(bp.X, bp.Y), buildingToPlace.Impact));
                        }
                        if (!isShiftPressed)
                        {
                            buildingToPlace = null;
                        }
                        return;
                    }

                    // Get Ray From Mouse Position
                    IEntity se = SelectFromRay(ray);
                    if (se != null)
                    {
                        // Use Entity As A Target
                        AddEvent(new SetTargetEvent(TeamIndex, se));
                    }
                    else if (!HasSelectedEnemy)
                    {
                        // Add A Waypoint Event
                        ray.Position  *= new Vector3(0.5f, 1f, 0.5f);
                        ray.Direction *= new Vector3(0.5f, 1f, 0.5f);
                        ray.Direction.Normalize();
                        var nvl = VRayHelper.GetOuter(ray, GameState.VoxState);
                        if (nvl.HasValue)
                        {
                            Vector3 rh = new Vector3(
                                nvl.Value.RegionLoc.X * Region.WIDTH + nvl.Value.VoxelLoc.X,
                                nvl.Value.VoxelLoc.Y,
                                nvl.Value.RegionLoc.Y * Region.DEPTH + nvl.Value.VoxelLoc.Z
                                );
                            rh   *= new Vector3(2f, 1f, 2f);
                            rh.X += 1f; rh.Z += 1f;
                            GameState.AddParticle(new AlertParticle(
                                                      rh, 1f, Color.Purple, rh + Vector3.Up * 2f, 0.2f, Color.Green, GameState.TotalGameTime, 4f
                                                      ));
                            AddEvent(new SetWayPointEvent(TeamIndex, new Vector2(rh.X, rh.Z)));
                        }
                    }
                }
                else if (b == BUTTON_SELECT)
                {
                    buildingToPlace    = null;
                    useSelectRect      = true;
                    selectionRectStart = location;
                }
            }
        }