Example #1
0
        public override void MouseDown(ViewportBase viewport, ViewportEvent e)
        {
            var vp = viewport as Viewport3D;
            if (vp == null || e.Button != MouseButtons.Left) return;

            // Do selection
            e.Handled = true;
            var ray = vp.CastRayFromScreen(e.X, e.Y);
            var hits = MainTool.GetCopies().Where(x => x.BoundingBox.IntersectsWith(ray));
            var clickedFace = hits.SelectMany(f => f.Faces)
                .Select(x => new { Item = x, Intersection = x.GetIntersectionPoint(ray) })
                .Where(x => x.Intersection != null)
                .OrderBy(x => (x.Intersection - ray.Start).VectorMagnitude())
                .Select(x => x.Item)
                .FirstOrDefault();

            var faces = new List<Face>();
            if (clickedFace != null)
            {
                if (KeyboardState.Shift) faces.AddRange(clickedFace.Parent.Faces);
                else faces.Add(clickedFace);
            }

            if (!KeyboardState.Ctrl) _selection.Clear();
            _selection.AddRange(faces);

            UpdateSelection();
        }
Example #2
0
 public void Render(ViewportBase viewport)
 {
     var vp2 = viewport as Viewport2D;
     var vp3 = viewport as Viewport3D;
     foreach (var helper in _helpers)
     {
         // Render document
         if (helper.IsDocumentHelper)
         {
             helper.RenderDocument(viewport, _document);
         }
         // Render 2D
         if (helper.Is2DHelper && vp2 != null && _helperCache.ContainsKey(helper))
         {
             helper.BeforeRender2D(vp2);
             foreach (var obj in _helperCache[helper])
             {
                 helper.Render2D(vp2, obj);
             }
             helper.AfterRender2D(vp2);
         }
         // Render 3D
         if (helper.Is3DHelper && vp3 != null && _helperCache.ContainsKey(helper))
         {
             helper.BeforeRender3D(vp3);
             foreach (var obj in _helperCache[helper])
             {
                 helper.Render3D(vp3, obj);
             }
             helper.AfterRender3D(vp3);
         }
     }
 }
Example #3
0
        public void Draw2D(ViewportBase context, Matrix4 viewport, Matrix4 camera, Matrix4 modelView)
        {
            UpdateCache();

            RenderGrid(((Viewport2D)context).Zoom);

            Matrix4 current;
            GL.GetFloat(GetPName.ModelviewMatrix, out current);
            GL.MatrixMode(MatrixMode.Modelview);
            GL.MultMatrix(ref modelView);

            // Draw unselected stuff
            MapObjectRenderer.DrawWireframe(_unselected.Where(x => x.Parent == null || !x.Parent.IsRenderHidden2D), false);
            MapObjectRenderer.DrawWireframe(_decals.Where(x => !x.IsSelected && !x.IsRenderHidden2D).SelectMany(x => x.GetDecalGeometry()), false);
            MapObjectRenderer.DrawWireframe(_models.Where(x => !x.IsSelected && !x.IsRenderHidden2D).SelectMany(x => x.GetBoxFaces()), false);

            // Draw selection (untransformed)
            GL.Color4(Color.FromArgb(128, 0, 0));
            MapObjectRenderer.DrawWireframe(_selected.Where(x => x.Parent == null || !x.Parent.IsRenderHidden2D), true);
            MapObjectRenderer.DrawWireframe(_decals.Where(x => x.IsSelected && !x.IsRenderHidden2D).SelectMany(x => x.GetDecalGeometry()), true);
            MapObjectRenderer.DrawWireframe(_models.Where(x => x.IsSelected && !x.IsRenderHidden2D).SelectMany(x => x.GetBoxFaces()), true);

            GL.LoadMatrix(ref current);
            GL.MultMatrix(ref modelView);
            GL.MultMatrix(ref _selectionTransform);

            // Draw selection (transformed)
            GL.Color4(Color.Red);
            MapObjectRenderer.DrawWireframe(_selected.Where(x => x.Parent == null || !x.Parent.IsRenderHidden2D), true);
            MapObjectRenderer.DrawWireframe(_decals.Where(x => x.IsSelected && !x.IsRenderHidden2D).SelectMany(x => x.GetDecalGeometry()), true);
            MapObjectRenderer.DrawWireframe(_models.Where(x => x.IsSelected && !x.IsRenderHidden2D).SelectMany(x => x.GetBoxFaces()), true);

            GL.LoadMatrix(ref current);
        }
Example #4
0
 public void RenderDocument(ViewportBase viewport, Document document)
 {
     if (!document.Map.Cordon || document.Map.CordonBounds.IsEmpty()) return;
     if (ToolManager.ActiveTool != null && ToolManager.ActiveTool.GetHotkeyToolType() == HotkeyTool.Cordon) return;
     if (viewport is Viewport2D) Render2D((Viewport2D)viewport, document);
     if (viewport is Viewport3D) Render3D((Viewport3D)viewport, document);
 }
Example #5
0
        public void RenderDocument(ViewportBase viewport, Document document)
        {
            if (document.Pointfile == null) return;
            var pf = document.Pointfile;
            var vp2 = viewport as Viewport2D;
            Func<Coordinate, Coordinate> transform = x => x;
            if (vp2 != null) transform = vp2.Flatten;

            TextureHelper.Unbind();
            GL.LineWidth(3);
            GL.Begin(PrimitiveType.Lines);

            var r = 1f;
            var g = 0.5f;
            var b = 0.5f;
            var change = 0.5f / pf.Lines.Count;

            foreach (var line in pf.Lines)
            {
                var start = transform(line.Start);
                var end = transform(line.End);

                GL.Color3(r, g, b);
                GL.Vertex3(start.DX, start.DY, start.DZ);

                r -= change;
                b += change;

                GL.Color3(r, g, b);
                GL.Vertex3(end.DX, end.DY, end.DZ);
            }

            GL.End();
            GL.LineWidth(1);
        }
Example #6
0
 public IEnumerable<MapObject> Order(ViewportBase viewport, IEnumerable<MapObject> mapObjects)
 {
     var vp3 = viewport as Viewport3D;
     if (vp3 == null) return mapObjects;
     var cam = vp3.Camera.Location.ToCoordinate();
     return mapObjects.OrderByDescending(x => (x.BoundingBox.Center - cam).LengthSquared());
 }
Example #7
0
 public override void MouseDown(ViewportBase viewport, ViewportEvent e)
 {
     if (!(viewport is Viewport3D) || (e.Button != MouseButtons.Left && e.Button != MouseButtons.Right)) return;
     _multiplier = e.Button == MouseButtons.Left ? 1 : -1;
     //PaintCurrentPoint((Viewport3D) viewport);
     _mouseDown = true;
     _moveCount = 0;
 }
Example #8
0
 public void AddNonSelectionItems(Document doc, ViewportBase viewport)
 {
     Items.Clear();
     Add("Paste", HotkeysMediator.OperationsPaste, Clipboard.ClipboardManager.CanPaste());
     Add("Paste Special", HotkeysMediator.OperationsPasteSpecial, Clipboard.ClipboardManager.CanPaste());
     Items.Add(new ToolStripSeparator());
     Add(doc.History.GetUndoString(), HotkeysMediator.HistoryUndo, doc.History.CanUndo());
     Add(doc.History.GetRedoString(), HotkeysMediator.HistoryRedo, doc.History.CanRedo());
 }
Example #9
0
 public ViewportEvent(ViewportBase sender, KeyEventArgs e)
 {
     Sender = sender;
     Modifiers = e.Modifiers;
     Control = e.Control;
     Shift = e.Shift;
     Alt = e.Alt;
     KeyCode = e.KeyCode;
     KeyValue = e.KeyValue;
 }
Example #10
0
 public ViewportEvent(ViewportBase sender, MouseEventArgs e)
 {
     Sender = sender;
     Button = e.Button;
     Clicks = e.Clicks;
     X = e.X;
     Y = e.Y;
     Delta = e.Delta;
     Location = e.Location;
 }
Example #11
0
 public override void KeyDown(ViewportBase viewport, ViewportEvent e)
 {
     switch (e.KeyCode)
     {
         case Keys.Enter:
             CreateEntity(_location);
             _state = EntityState.None;
             break;
         case Keys.Escape:
             _state = EntityState.None;
             break;
     }
 }
Example #12
0
        public override void MouseMove(ViewportBase viewport, ViewportEvent e)
        {
            var vp = viewport as Viewport3D;
            if (vp == null) return;

            _mousePos.X = e.X;
            _mousePos.Y = e.Y;

            if (_currentPoint == null) return;

            if (_mouseDown)
            {
                _moveCount++;
                //PaintCurrentPoint(vp);
            }
        }
Example #13
0
        public override void MouseDown(ViewportBase viewport, ViewportEvent e)
        {
            return;

            var vp = viewport as Viewport3D;
            if (vp == null || (e.Button != MouseButtons.Left && e.Button != MouseButtons.Right)) return;

            var ray = vp.CastRayFromScreen(e.X, e.Y);
            var hits = Document.Map.WorldSpawn.GetAllNodesIntersectingWith(ray).OfType<Solid>();
            var clickedFace = hits.SelectMany(f => f.Faces)
                .Select(x => new { Item = x, Intersection = x.GetIntersectionPoint(ray) })
                .Where(x => x.Intersection != null)
                .OrderBy(x => (x.Intersection - ray.Start).VectorMagnitude())
                .Select(x => x.Item)
                .FirstOrDefault();
            // TODO: Select
            //TextureItem itemToSelect = null;
            // if ((behaviour == SelectBehaviour.Select || behaviour == SelectBehaviour.LiftSelect) && !KeyboardState.Ctrl)
            // {
            //     Selection.Clear();
            // }
            //if (clickedFace != null)
            //{
            //    var faces = new List<Face>();
            //    if (KeyboardState.Shift) faces.AddRange(clickedFace.Parent.Faces);
            //    else faces.Add(clickedFace);
            //    if (behaviour == SelectBehaviour.Select || behaviour == SelectBehaviour.LiftSelect)
            //    {
            //        foreach (var face in faces)
            //        {
            //            if (face.IsSelected) Selection.Deselect(face);
            //            else Selection.Select(face);
            //        }
            //    }
            //    if (behaviour == SelectBehaviour.Lift || behaviour == SelectBehaviour.LiftSelect)
            //    {
            //        var tex = faces.Where(face => face.Texture.Texture != null).FirstOrDefault();
            //        itemToSelect = tex != null ? TexturePackage.GetItem(tex.Texture.Name) : null;
            //    }
            //}
            //Document.UpdateDisplayLists();
            //_form.SelectionChanged();
            //if (itemToSelect != null)
            //{
            //    _form.SelectTexture(itemToSelect);
            //}
        }
Example #14
0
 public override void BoxDrawnConfirm(ViewportBase viewport)
 {
     var box = new Box(State.BoxStart, State.BoxEnd);
     if (box.Start.X != box.End.X && box.Start.Y != box.End.Y && box.Start.Z != box.End.Z)
     {
         CreateBrush(box);
         _lastBox = box;
     }
     _preview = null;
     base.BoxDrawnConfirm(viewport);
     if (Select.SwitchToSelectAfterCreation)
     {
         Mediator.Publish(HotkeysMediator.SwitchTool, HotkeyTool.Selection);
     }
     if (Select.ResetBrushTypeOnCreation)
     {
         Mediator.Publish(EditorMediator.ResetSelectedBrushType);
     }
 }
Example #15
0
        public void Draw2D(ViewportBase context, Matrix4 viewport, Matrix4 camera, Matrix4 modelView)
        {
            UpdateCache();

            RenderGrid(((Viewport2D)context).Zoom);

            Matrix4 current;
            GL.GetFloat(GetPName.ModelviewMatrix, out current);
            GL.MatrixMode(MatrixMode.Modelview);
            GL.MultMatrix(ref modelView);

            GL.CallList(_listUntransformed2D);

            GL.LoadMatrix(ref current);
            GL.MultMatrix(ref modelView);
            GL.MultMatrix(ref _selectionTransform);

            GL.CallList(_listTransformed2D);

            GL.LoadMatrix(ref current);
        }
        public void Draw2D(ViewportBase context, Matrix4 viewport, Matrix4 camera, Matrix4 modelView)
        {
            UpdateCache();

            RenderGrid(((Viewport2D)context).Zoom);

            Matrix4 current;
            GL.GetFloat(GetPName.ModelviewMatrix, out current);
            GL.MatrixMode(MatrixMode.Modelview);
            GL.MultMatrix(ref modelView);

            DataStructures.Rendering.Rendering.DrawWireframe(_unselected.Where(x => x.Parent == null || !x.Parent.IsRenderHidden2D), false);
            GL.Color4(Color.Red);

            GL.LoadMatrix(ref current);
            GL.MultMatrix(ref modelView);
            GL.MultMatrix(ref _selectionTransform);
            DataStructures.Rendering.Rendering.DrawWireframe(_selected.Where(x => x.Parent == null || !x.Parent.IsRenderHidden2D), true);

            GL.LoadMatrix(ref current);
        }
Example #17
0
        public override void MouseDown(ViewportBase viewport, ViewportEvent e)
        {
            var vp = viewport as Viewport3D;
            if (vp == null) return;

            // Get the ray that is cast from the clicked point along the viewport frustrum
            var ray = vp.CastRayFromScreen(e.X, e.Y);

            // Grab all the elements that intersect with the ray
            var hits = Document.Map.WorldSpawn.GetAllNodesIntersectingWith(ray);

            // Sort the list of intersecting elements by distance from ray origin and grab the first hit
            var hit = hits
                .Select(x => new {Item = x, Intersection = GetIntersectionPoint(x, ray)})
                .Where(x => x.Intersection != null)
                .OrderBy(x => (x.Intersection - ray.Start).VectorMagnitude())
                .FirstOrDefault();

            if (hit == null) return; // Nothing was clicked

            CreateDecal(hit.Intersection);
        }
Example #18
0
 public void AddSelectionItems(Document doc, ViewportBase viewport)
 {
     Items.Clear();
     Add("Cut", HotkeysMediator.OperationsCut);
     Add("Copy", HotkeysMediator.OperationsCopy);
     Add("Delete", HotkeysMediator.OperationsDelete);
     Add("Paste Special", HotkeysMediator.OperationsPasteSpecial, Clipboard.ClipboardManager.CanPaste());
     Items.Add(new ToolStripSeparator());
     Add("Transform...", HotkeysMediator.Transform);
     Items.Add(new ToolStripSeparator());
     Add(doc.History.GetUndoString(), HotkeysMediator.HistoryUndo, doc.History.CanUndo());
     Add(doc.History.GetRedoString(), HotkeysMediator.HistoryRedo, doc.History.CanRedo());
     Items.Add(new ToolStripSeparator());
     Add("Carve", HotkeysMediator.Carve);
     Add("Hollow", HotkeysMediator.MakeHollow);
     Items.Add(new ToolStripSeparator());
     Add("Group", HotkeysMediator.GroupingGroup);
     Add("Ungroup", HotkeysMediator.GroupingUngroup);
     Items.Add(new ToolStripSeparator());
     Add("Tie To Entity", HotkeysMediator.TieToEntity);
     Add("Move To World", HotkeysMediator.TieToWorld);
     Items.Add(new ToolStripSeparator());
     var vp = viewport as Viewport2D;
     if (vp != null)
     {
         var flat = vp.Flatten(new Coordinate(1, 2, 3));
         var left = flat.X == 1 ? HotkeysMediator.AlignXMin : (flat.X == 2 ? HotkeysMediator.AlignYMin : HotkeysMediator.AlignZMin);
         var right = flat.X == 1 ? HotkeysMediator.AlignXMax : (flat.X == 2 ? HotkeysMediator.AlignYMax : HotkeysMediator.AlignZMax);
         var bottom = flat.Y == 1 ? HotkeysMediator.AlignXMin : (flat.Y == 2 ? HotkeysMediator.AlignYMin : HotkeysMediator.AlignZMin);
         var top = flat.Y == 1 ? HotkeysMediator.AlignXMax : (flat.Y == 2 ? HotkeysMediator.AlignYMax : HotkeysMediator.AlignZMax);
         Items.Add(new ToolStripMenuItem("Align", null,
                                         CreateMenuItem("Top", top),
                                         CreateMenuItem("Left", left),
                                         CreateMenuItem("Right", right),
                                         CreateMenuItem("Bottom", bottom)));
     }
     Add("Properties", HotkeysMediator.ObjectProperties);
 }
Example #19
0
        public override void MouseDown(ViewportBase viewport, ViewportEvent ve)
        {
            if (viewport is Viewport2D)
            {
                var vp2 = (Viewport2D)viewport;
                if (ve.Button == MouseButtons.Left && MouseOverPivot(vp2, ve))
                {
                    _movingPivot = true;
                    ve.Handled = true;
                }
                return;
            }

            var vp = viewport as Viewport3D;
            if (vp == null || vp != _activeViewport) return;

            if (ve.Button != MouseButtons.Left || _mouseOver == CircleType.None) return;
            _mouseDown = _mouseOver;
            _mouseDownPoint = new Coordinate(ve.X, vp.Height - ve.Y, 0);
            _mouseMovePoint = null;
            ve.Handled = true;
            vp.AquireInputLock(this);
        }
Example #20
0
        public void Draw2D(ViewportBase context, Matrix4 viewport, Matrix4 camera, Matrix4 modelView)
        {
            var opts = new Viewport2DRenderOptions
            {
                Viewport = viewport,
                Camera = camera,
                ModelView = Matrix4.Identity // modelView
            };

            _mapObject2DShader.Bind(opts);

            _mapObject2DShader.SelectionTransform = Matrix4.Identity;
            _mapObject2DShader.SelectedOnly = false;
            _mapObject2DShader.SelectedColour = new Vector4(0.5f, 0, 0, 1);

            if (Document.Map.Show2DGrid)
            {
                // Render grid
                var vp2 = (Viewport2D) context;
                if (GridArrays.ContainsKey(vp2)) GridArrays[vp2].Render(context.Context);
            }

            // Render wireframe (untransformed)
            _mapObject2DShader.ModelView = modelView;
            _array.RenderWireframe(context.Context);
            _decalArray.RenderWireframe(context.Context);

            // Render wireframe (transformed)
            _mapObject2DShader.SelectionTransform = _selectionTransform;
            _mapObject2DShader.SelectedOnly = true;
            _mapObject2DShader.SelectedColour = new Vector4(1, 0, 0, 1);
            _array.RenderWireframe(context.Context);
            _decalArray.RenderWireframe(context.Context);

            _mapObject2DShader.Unbind();
        }
Example #21
0
 public ToolViewportListener(ViewportBase viewport)
 {
     Viewport = viewport;
 }
Example #22
0
 public override void BoxDrawnCancel(Sledge.UI.ViewportBase viewport)
 {
     //
 }
Example #23
0
 public override void BoxDrawnConfirm(Sledge.UI.ViewportBase viewport)
 {
     //
 }
Example #24
0
 public override void MouseEnter(ViewportBase viewport, ViewportEvent e)
 {
     _activeViewport = viewport;
 }
Example #25
0
 public override void MouseDoubleClick(ViewportBase viewport, ViewportEvent e)
 {
 }
Example #26
0
 public override void KeyUp(ViewportBase viewport, ViewportEvent e)
 {
 }
Example #27
0
 public override void UpdateFrame(ViewportBase viewport, FrameInfo frame)
 {
 }
Example #28
0
 public override void MouseLeave(ViewportBase viewport, ViewportEvent e)
 {
     _activeViewport = null;
 }
 public RenderManagerRenderable(ViewportBase viewport, RenderManager manager)
 {
     _viewport = viewport;
     _manager = manager;
     _is3D = viewport is Viewport3D;
 }
Example #30
0
 public void Draw3D(ViewportBase context, Matrix4 viewport, Matrix4 camera, Matrix4 modelView)
 {
     _renderer.Draw3D(context, viewport, camera, modelView);
 }
Example #31
0
 public override void BoxDrawnCancel(ViewportBase viewport)
 {
     _lastBox = new Box(State.BoxStart, State.BoxEnd);
     _preview = null;
     base.BoxDrawnCancel(viewport);
 }
Example #32
0
 public override void UpdateFrame(ViewportBase viewport, FrameInfo frame)
 {
     if (_updatePreview && ShouldDrawBox(viewport))
     {
         var box = new Box(State.BoxStart, State.BoxEnd);
         var brush = GetBrush(box, new IDGenerator());
         _preview = new List<Face>();
         CollectFaces(_preview, new[] { brush });
         var color = GetRenderBoxColour();
         _preview.ForEach(x => { x.Colour = color; });
     }
     _updatePreview = false;
 }