Пример #1
0
 public Camera3DViewportListener(Viewport3D vp)
 {
     LastKnownX = 0;
     LastKnownY = 0;
     PositionKnown = false;
     FreeLook = false;
     FreeLookToggle = false;
     CursorVisible = true;
     Focus = false;
     Viewport = vp;
     Camera = vp.Camera;
     _downKeys = new List<Keys>();
 }
 public Camera3DViewportListener(Viewport3D vp)
 {
     LastKnownX = 0;
     LastKnownY = 0;
     PositionKnown = false;
     FreeLook = false;
     FreeLookToggle = false;
     CursorVisible = true;
     Focus = false;
     Viewport = vp;
     Camera = vp.Camera;
     _downKeys = new List<Keys>();
     _downMillis = _lastMillis = 0;
     _easing = Easing.FromType(EasingType.Sinusoidal, EasingDirection.Out);
 }
Пример #3
0
        public void Render3D(Viewport3D vp, MapObject o)
        {
            var right = vp.Camera.GetRight();
            var up = Vector3.Cross(right, (vp.Camera.LookAt - vp.Camera.Location).Normalized());
            var entity = (Entity) o;

            var orig = new Vector3((float)entity.Origin.X, (float)entity.Origin.Y, (float)entity.Origin.Z);
            if (entity.IsSelected)
            {
                orig = Vector3.TransformPosition(orig, Document.SelectListTransform);
            }
            var normal = Vector3.Subtract(vp.Camera.Location, orig);

            var tex = entity.Sprite;
            GL.Color3(Color.White);
            tex.Bind();

            if (entity.GameData != null)
            {
                var col = entity.GameData.Properties.FirstOrDefault(x => x.VariableType == VariableType.Color255);
                if (col != null)
                {
                    var val = entity.EntityData.Properties.FirstOrDefault(x => x.Key == col.Name);
                    if (val != null)
                    {
                        GL.Color3(val.GetColour(Color.White));
                    }
                }
            }

            var tup = Vector3.Multiply(up, (float)entity.BoundingBox.Height / 2f);
            var tright = Vector3.Multiply(right, (float)entity.BoundingBox.Width / 2f);

            GL.Begin(PrimitiveType.Quads);

            GL.Normal3(normal); GL.TexCoord2(1, 1); GL.Vertex3(Vector3.Subtract(orig, Vector3.Add(tup, tright)));
            GL.Normal3(normal); GL.TexCoord2(1, 0); GL.Vertex3(Vector3.Add(orig, Vector3.Subtract(tup, tright)));
            GL.Normal3(normal); GL.TexCoord2(0, 0); GL.Vertex3(Vector3.Add(orig, Vector3.Add(tup, tright)));
            GL.Normal3(normal); GL.TexCoord2(0, 1); GL.Vertex3(Vector3.Subtract(orig, Vector3.Subtract(tup, tright)));

            GL.End();
        }
Пример #4
0
        public void Render3D(Viewport3D vp, MapObject o)
        {
            // These billboards aren't perfect but they'll do (they rotate with the lookat vector rather than the location vector)

            var right = vp.Camera.GetRight();
            var up = vp.Camera.GetUp();
            var entity = (Entity) o;

            var orig = new Vector3((float)entity.Origin.X, (float)entity.Origin.Y, (float)entity.Origin.Z);
            var normal = Vector3.Subtract(vp.Camera.Location, orig);

            var tex = entity.Sprite;
            TextureHelper.EnableTexturing();
            GL.Color3(Color.White);
            tex.Bind();

            if (entity.GameData != null)
            {
                var col = entity.GameData.Properties.FirstOrDefault(x => x.VariableType == VariableType.Color255);
                if (col != null)
                {
                    var val = entity.EntityData.Properties.FirstOrDefault(x => x.Key == col.Name);
                    if (val != null)
                    {
                        GL.Color3(val.GetColour(Color.White));
                    }
                }
            }

            var tup = Vector3.Multiply(up, (float)entity.BoundingBox.Height / 2f);
            var tright = Vector3.Multiply(right, (float)entity.BoundingBox.Width / 2f);

            GL.Begin(BeginMode.Quads);

            GL.Normal3(normal); GL.TexCoord2(1, 1); GL.Vertex3(Vector3.Subtract(orig, Vector3.Add(tup, tright)));
            GL.Normal3(normal); GL.TexCoord2(1, 0); GL.Vertex3(Vector3.Add(orig, Vector3.Subtract(tup, tright)));
            GL.Normal3(normal); GL.TexCoord2(0, 0); GL.Vertex3(Vector3.Add(orig, Vector3.Add(tup, tright)));
            GL.Normal3(normal); GL.TexCoord2(0, 1); GL.Vertex3(Vector3.Subtract(orig, Vector3.Subtract(tup, tright)));

            GL.End();
        }
Пример #5
0
 public void BeforeRender3D(Viewport3D viewport)
 {
     throw new NotImplementedException();
 }
Пример #6
0
 protected override void Render3D(Viewport3D viewport)
 {
     base.Render3D(viewport);
     if (ShouldDraw3DBox() && _preview != null)
     {
         GL.Disable(EnableCap.CullFace);
         TextureHelper.Unbind();
         if (viewport.Type != Viewport3D.ViewType.Flat) MapObjectRenderer.EnableLighting();
         MapObjectRenderer.DrawFilled(_preview, GetRenderColour(), false);
         MapObjectRenderer.DisableLighting();
         GL.Color4(Color.GreenYellow);
         MapObjectRenderer.DrawWireframe(_preview, true, false);
     }
 }
Пример #7
0
 protected override void MouseMove3D(Viewport3D viewport, ViewportEvent e)
 {
     base.MouseMove3D(viewport, e);
 }
Пример #8
0
        private void UpdateCurrentFace(Viewport3D viewport, ViewportEvent e)
        {
            var ray = viewport.CastRayFromScreen(e.X, e.Y);

            // The face doesn't change when drawing, just update the intersection
            if (_state == SketchState.DrawingBase || _state == SketchState.DrawingVolume)
            {
                _intersection = (_state == SketchState.DrawingBase ? _currentFace.Plane : _volumePlane).GetIntersectionPoint(ray, true, true);
                return;
            }

            var isect = Document.Map.WorldSpawn.GetAllNodesIntersectingWith(ray)
                .OfType<Solid>()
                .SelectMany(x => x.Faces)
                .Select(x => new { Item = x, Intersection = x.GetIntersectionPoint(ray) })
                .Where(x => x.Intersection != null)
                .OrderBy(x => (x.Intersection - ray.Start).VectorMagnitude())
                .FirstOrDefault();

            if (isect != null)
            {
                if (_currentFace != isect.Item)
                {
                    _cloneFace = isect.Item.Clone();
                    _cloneFace.Transform(new UnitTranslate(isect.Item.Plane.Normal * 0.1m), TransformFlags.None);
                }

                _currentFace = isect.Item;
                _intersection = isect.Intersection;
                _state = SketchState.Ready;
            }
            else
            {
                _cloneFace = null;
                _currentFace = null;
                _intersection = null;
                _state = SketchState.None;
            }
        }
Пример #9
0
 public abstract List<VMPoint> GetVerticesAtPoint(int x, int y, Viewport3D viewport);
Пример #10
0
        protected override void Render3D(Viewport3D vp)
        {
            base.Render3D(vp);

            if (_currentTool != null) _currentTool.Render3D(vp);

            TextureHelper.Unbind();

            if (_currentTool == null || _currentTool.DrawVertices())
            {
                // Get us into 2D rendering
                Matrix.Set(MatrixMode.Projection);
                Matrix.Identity();
                Graphics.Helpers.Viewport.Orthographic(0, 0, vp.Width, vp.Height);
                Matrix.Set(MatrixMode.Modelview);
                Matrix.Identity();

                var half = new Coordinate(vp.Width, vp.Height, 0) / 2;
                // Render out the point handles
                GL.Begin(PrimitiveType.Quads);
                foreach (var point in Points)
                {
                    var c = vp.WorldToScreen(point.Coordinate);
                    if (c == null || c.Z > 1) continue;
                    c -= half;

                    GL.Color3(Color.Black);
                    GL.Vertex2(c.DX - 4, c.DY - 4);
                    GL.Vertex2(c.DX - 4, c.DY + 4);
                    GL.Vertex2(c.DX + 4, c.DY + 4);
                    GL.Vertex2(c.DX + 4, c.DY - 4);

                    GL.Color3(point.GetColour());
                    GL.Vertex2(c.DX - 3, c.DY - 3);
                    GL.Vertex2(c.DX - 3, c.DY + 3);
                    GL.Vertex2(c.DX + 3, c.DY + 3);
                    GL.Vertex2(c.DX + 3, c.DY - 3);
                }
                GL.End();

                // Get back into 3D rendering
                Matrix.Set(MatrixMode.Projection);
                Matrix.Identity();
                Graphics.Helpers.Viewport.Perspective(0, 0, vp.Width, vp.Height, View.CameraFOV);
                Matrix.Set(MatrixMode.Modelview);
                Matrix.Identity();
                vp.Camera.Position();
            }

            var type = vp.Type;
            bool shaded = type == Viewport3D.ViewType.Shaded || type == Viewport3D.ViewType.Textured,
                 textured = type == Viewport3D.ViewType.Textured,
                 wireframe = type == Viewport3D.ViewType.Wireframe;

            // Render out the solid previews
            GL.Color3(Color.White);
            var faces = _copies.Keys.SelectMany(x => x.Faces).ToList();

            if (!wireframe)
            {
                if (shaded) MapObjectRenderer.EnableLighting();
                GL.Enable(EnableCap.Texture2D);
                MapObjectRenderer.DrawFilled(faces.Where(x => !x.IsSelected), Color.FromArgb(255, 64, 192, 64), textured);
                MapObjectRenderer.DrawFilled(faces.Where(x => x.IsSelected), Color.FromArgb(255, 255, 128, 128), textured);
                GL.Disable(EnableCap.Texture2D);
                MapObjectRenderer.DisableLighting();

                GL.Color3(Color.Pink);
                MapObjectRenderer.DrawWireframe(faces, true);
            }
            else
            {
                GL.Color4(Color.FromArgb(255, 64, 192, 64));
                MapObjectRenderer.DrawWireframe(faces.Where(x => !x.IsSelected), true);
                GL.Color4(Color.FromArgb(255, 255, 128, 128));
                MapObjectRenderer.DrawWireframe(faces.Where(x => x.IsSelected), true);
            }
        }
Пример #11
0
        private void RenderCircleTypeNone(Viewport3D viewport, Document document)
        {
            var center = _pivotPoint;
            var origin = new Vector3((float)center.DX, (float)center.DY, (float)center.DZ);
            var distance = (viewport.Camera.Location - origin).Length;

            if (distance <= 1) return;

            var radius = 0.15f * distance;

            var normal = Vector3.Subtract(viewport.Camera.Location, origin).Normalized();
            var right = Vector3.Cross(normal, Vector3.UnitZ).Normalized();
            var up = Vector3.Cross(normal, right).Normalized();

            GL.Disable(EnableCap.DepthTest);
            GL.Disable(EnableCap.Texture2D);

            const int sides = 32;
            const float diff = (float)(2 * Math.PI) / sides;

            GL.Begin(PrimitiveType.Lines);
            for (var i = 0; i < sides; i++)
            {
                var cos1 = (float)Math.Cos(diff * i);
                var sin1 = (float)Math.Sin(diff * i);
                var cos2 = (float)Math.Cos(diff * (i + 1));
                var sin2 = (float)Math.Sin(diff * (i + 1));
                GL.Color4(Color.DarkGray);
                GL.Vertex3(origin + right * cos1 * radius + up * sin1 * radius);
                GL.Vertex3(origin + right * cos2 * radius + up * sin2 * radius);
                GL.Color4(_mouseOver == CircleType.Outer ? Color.White : Color.LightGray);
                GL.Vertex3(origin + right * cos1 * radius * 1.2f + up * sin1 * radius * 1.2f);
                GL.Vertex3(origin + right * cos2 * radius * 1.2f + up * sin2 * radius * 1.2f);
            }
            GL.End();

            GL.Enable(EnableCap.ClipPlane0);
            GL.ClipPlane(ClipPlaneName.ClipPlane0, new double[] { normal.X, normal.Y, normal.Z, -Vector3.Dot(origin, normal) });

            GL.LineWidth(2);
            GL.Begin(PrimitiveType.Lines);
            for (var i = 0; i < sides; i++)
            {
                var cos1 = (float)Math.Cos(diff * i) * radius;
                var sin1 = (float)Math.Sin(diff * i) * radius;
                var cos2 = (float)Math.Cos(diff * (i + 1)) * radius;
                var sin2 = (float)Math.Sin(diff * (i + 1)) * radius;

                GL.Color4(_mouseOver == CircleType.Z ? Color.Blue : Color.DarkBlue);
                GL.Vertex3(origin + Vector3.UnitX * cos1 + Vector3.UnitY * sin1);
                GL.Vertex3(origin + Vector3.UnitX * cos2 + Vector3.UnitY * sin2);

                GL.Color4(_mouseOver == CircleType.X ? Color.Red : Color.DarkRed);
                GL.Vertex3(origin + Vector3.UnitY * cos1 + Vector3.UnitZ * sin1);
                GL.Vertex3(origin + Vector3.UnitY * cos2 + Vector3.UnitZ * sin2);

                GL.Color4(_mouseOver == CircleType.Y ? Color.Lime : Color.LimeGreen);
                GL.Vertex3(origin + Vector3.UnitZ * cos1 + Vector3.UnitX * sin1);
                GL.Vertex3(origin + Vector3.UnitZ * cos2 + Vector3.UnitX * sin2);
            }
            GL.End();
            GL.LineWidth(1);

            GL.Disable(EnableCap.ClipPlane0);

            GL.Enable(EnableCap.DepthTest);
        }
Пример #12
0
        private void RenderAxisRotating(Viewport3D viewport, Document document)
        {
            var axis = Vector3.UnitX;
            var c = Color.Red;

            if (_mouseDown == CircleType.Y)
            {
                axis = Vector3.UnitY;
                c = Color.Lime;
            }

            if (_mouseDown == CircleType.Z)
            {
                axis = Vector3.UnitZ;
                c = Color.Blue;
            }

            if (_mouseDown == CircleType.Outer)
            {
                var vp3 = _activeViewport as Viewport3D;
                if (vp3 != null) axis = (vp3.Camera.LookAt - vp3.Camera.Location).Normalized();
                c = Color.White;
            }

            if (_activeViewport != viewport || _mouseDown != CircleType.Outer)
            {
                GL.Begin(PrimitiveType.Lines);

                var zero = new Vector3((float) _pivotPoint.DX, (float) _pivotPoint.DY, (float) _pivotPoint.DZ);

                GL.Color4(c);
                GL.Vertex3(zero - axis * 100000);
                GL.Vertex3(zero + axis * 100000);

                GL.End();
            }

            if (_activeViewport == viewport)
            {
                GL.Disable(EnableCap.DepthTest);
                GL.Enable(EnableCap.LineStipple);
                GL.LineStipple(5, 0xAAAA);
                GL.Begin(PrimitiveType.Lines);

                GL.Color4(Color.FromArgb(64, Color.Gray));
                GL.Vertex3(_pivotPoint.ToVector3());
                GL.Vertex3(viewport.ScreenToWorld(_mouseDownPoint).ToVector3());

                GL.Color4(Color.LightGray);
                GL.Vertex3(_pivotPoint.ToVector3());
                GL.Vertex3(viewport.ScreenToWorld(_mouseMovePoint).ToVector3());

                GL.End();
                GL.Disable(EnableCap.LineStipple);
                GL.Enable(EnableCap.DepthTest);
            }
        }
Пример #13
0
 private bool MouseOver(CircleType type, ViewportEvent ev, Viewport3D viewport)
 {
     var cache = _cachedLines.FirstOrDefault(x => x.Viewport3D == viewport);
     if (cache == null) return false;
     var lines = cache.Cache[type];
     var point = new Coordinate(ev.X, viewport.Height - ev.Y, 0);
     return lines.Any(x => (x.ClosestPoint(point) - point).VectorMagnitude() <= 8);
 }
Пример #14
0
        private Matrix4? GetTransformationMatrix(Viewport3D viewport)
        {
            if (_mouseMovePoint == null || _mouseDownPoint == null || _pivotPoint == null) return null;

            var originPoint = viewport.WorldToScreen(_pivotPoint);
            var origv = (_mouseDownPoint - originPoint).Normalise();
            var newv = (_mouseMovePoint - originPoint).Normalise();
            var angle = DMath.Acos(Math.Max(-1, Math.Min(1, origv.Dot(newv))));
            if ((origv.Cross(newv).Z < 0)) angle = 2 * DMath.PI - angle;

            var shf = KeyboardState.Shift;
            var def = Select.RotationStyle;
            var snap = (def == RotationStyle.SnapOnShift && shf) || (def == RotationStyle.SnapOffShift && !shf);
            if (snap)
            {
                var deg = angle * (180 / DMath.PI);
                var rnd = Math.Round(deg / 15) * 15;
                angle = rnd * (DMath.PI / 180);
            }

            Vector3 axis;
            var dir = (viewport.Camera.Location - _pivotPoint.ToVector3()).Normalized();
            switch (_mouseDown)
            {
                case CircleType.Outer:
                    axis = dir;
                    break;
                case CircleType.X:
                    axis = Vector3.UnitX;
                    break;
                case CircleType.Y:
                    axis = Vector3.UnitY;
                    break;
                case CircleType.Z:
                    axis = Vector3.UnitZ;
                    break;
                default:
                    return null;
            }
            var dirAng = Math.Acos(Vector3.Dot(dir, axis)) * 180 / Math.PI;
            if (dirAng > 90) angle = -angle;

            var rotm = Matrix4.CreateFromAxisAngle(axis, (float)angle);
            var mov = Matrix4.CreateTranslation(-_pivotPoint.ToVector3());
            var rot = Matrix4.Mult(mov, rotm);
            return Matrix4.Mult(rot, Matrix4.Invert(mov));
        }
Пример #15
0
        private void MouseDown(Viewport3D vp, ViewportEvent e)
        {
            if (vp == null || e.Button != MouseButtons.Left) 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 = x.GetIntersectionPoint(ray) })
                .Where(x => x.Intersection != null)
                .OrderBy(x => (x.Intersection - ray.Start).VectorMagnitude())
                .FirstOrDefault();

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

            CreateEntity(hit.Intersection);
        }
Пример #16
0
 public override void Render3D(Viewport3D viewport)
 {
 }
Пример #17
0
 public List<VMPoint> GetVerticesAtPoint(int x, int y, Viewport3D viewport)
 {
     var l = viewport.Camera.Location;
     var pos = new Coordinate((decimal) l.X, (decimal) l.Y, (decimal) l.Z);
     var p = new Coordinate(x, y, 0);
     const int d = 5;
     return (from point in Points
             let c = viewport.WorldToScreen(point.Coordinate)
             where c != null && c.Z <= 1
             where p.X >= c.X - d && p.X <= c.X + d && p.Y >= c.Y - d && p.Y <= c.Y + d
             orderby (pos - point.Coordinate).LengthSquared()
             select point).ToList();
 }
Пример #18
0
        private void UpdateCache(Viewport3D viewport, Document document)
        {
            var ccl = new Coordinate((decimal)viewport.Camera.Location.X, (decimal)viewport.Camera.Location.Y, (decimal)viewport.Camera.Location.Z);
            var ccla = new Coordinate((decimal)viewport.Camera.LookAt.X, (decimal)viewport.Camera.LookAt.Y, (decimal)viewport.Camera.LookAt.Z);

            var cache = _cachedLines.FirstOrDefault(x => x.Viewport3D == viewport);
            if (cache == null)
            {
                cache = new CachedLines(viewport);
                _cachedLines.Add(cache);
            }
            if (ccl == cache.CameraLocation && ccla == cache.CameraLookAt && cache.PivotPoint == _pivotPoint && cache.Width == viewport.Width && cache.Height == viewport.Height) return;

            var origin = _pivotPoint;
            var distance = (ccl - origin).VectorMagnitude();

            if (distance <= 1) return;

            cache.CameraLocation = ccl;
            cache.CameraLookAt = ccla;
            cache.PivotPoint = _pivotPoint;
            cache.Width = viewport.Width;
            cache.Height = viewport.Height;

            var normal = (ccl - origin).Normalise();
            var right = normal.Cross(Coordinate.UnitZ).Normalise();
            var up = normal.Cross(right).Normalise();

            var plane = new Plane(normal, origin.Dot(normal));

            const decimal sides = 32;
            var diff = (2 * DMath.PI) / sides;

            var radius = 0.15m * distance;

            cache.Cache[CircleType.Outer].Clear();
            cache.Cache[CircleType.X].Clear();
            cache.Cache[CircleType.Y].Clear();
            cache.Cache[CircleType.Z].Clear();

            for (var i = 0; i < sides; i++)
            {
                var cos1 = DMath.Cos(diff * i);
                var sin1 = DMath.Sin(diff * i);
                var cos2 = DMath.Cos(diff * (i + 1));
                var sin2 = DMath.Sin(diff * (i + 1));

                // outer circle
                AddLine(CircleType.Outer,
                    origin + right * cos1 * radius * 1.2m + up * sin1 * radius * 1.2m,
                    origin + right * cos2 * radius * 1.2m + up * sin2 * radius * 1.2m,
                    plane, cache);

                cos1 *= radius;
                sin1 *= radius;
                cos2 *= radius;
                sin2 *= radius;

                // X/Y plane = Z axis
                AddLine(CircleType.Z,
                    origin + Coordinate.UnitX * cos1 + Coordinate.UnitY * sin1,
                    origin + Coordinate.UnitX * cos2 + Coordinate.UnitY * sin2,
                    plane, cache);

                // Y/Z plane = X axis
                AddLine(CircleType.X,
                    origin + Coordinate.UnitY * cos1 + Coordinate.UnitZ * sin1,
                    origin + Coordinate.UnitY * cos2 + Coordinate.UnitZ * sin2,
                    plane, cache);

                // X/Z plane = Y axis
                AddLine(CircleType.Y,
                    origin + Coordinate.UnitZ * cos1 + Coordinate.UnitX * sin1,
                    origin + Coordinate.UnitZ * cos2 + Coordinate.UnitX * sin2,
                    plane, cache);
            }
        }
Пример #19
0
        private void MouseDown(Viewport3D vp, ViewportEvent e)
        {
            if (!_currentTool.NoSelection())
            {
                var vtxs = _currentTool.GetVerticesAtPoint(e.X, vp.Height - e.Y, vp);

                if (vtxs.Any())
                {
                    // Use the topmost vertex as the control point
                    var vtx = vtxs.First();

                    // Mouse down on a point
                    if (vtx.IsSelected && KeyboardState.Ctrl && _currentTool.ShouldDeselect(vtxs))
                    {
                        // If the vertex is selected and ctrl is down, deselect the vertices
                        vtxs.ForEach(x => x.IsSelected = false);
                    }
                    else
                    {
                        if (!vtx.IsSelected && !KeyboardState.Ctrl && _currentTool.ShouldDeselect(vtxs))
                        {
                            // If we aren't clicking on a selected point and ctrl is not down, deselect the others
                            Points.ForEach(x => x.IsSelected = false);
                            // If this point is already selected, don't deselect others. This is the same behaviour as 2D selection.
                        }
                        vtxs.ForEach(x => x.IsSelected = true);
                    }
                    VertexSelectionChanged();

                    // Don't do other click operations
                    return;
                }

                // Nothing clicked
                if (!KeyboardState.Ctrl)
                {
                    // Deselect all the points if not ctrl-ing
                    Points.ForEach(x => x.IsSelected = false);
                }
            }
            if (!_currentTool.No3DSelection())
            {
                // Do selection
                var ray = vp.CastRayFromScreen(e.X, e.Y);
                var hits = Document.Map.WorldSpawn.GetAllNodesIntersectingWith(ray, true);
                var solid = hits
                    .OfType<Solid>()
                    .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();

                if (solid != null)
                {
                    if (solid.IsSelected && KeyboardState.Ctrl)
                    {
                        // deselect solid
                        var select = new MapObject[0];
                        var deselect = new[] {solid};
                        Document.PerformAction("Deselect VM solid", new ChangeSelection(select, deselect));
                    }
                    else if (!solid.IsSelected)
                    {
                        // select solid
                        var select = new[] {solid};
                        var deselect = !KeyboardState.Ctrl ? Document.Selection.GetSelectedObjects() : new MapObject[0];
                        Document.PerformAction("Select VM solid", new ChangeSelection(select, deselect));
                    }

                    // Don't do other click operations
                    return;
                }
            }

            base.MouseDown(vp, e);
        }
Пример #20
0
 public CachedLines(Viewport3D viewport3D)
 {
     Viewport3D = viewport3D;
     Cache = new Dictionary<CircleType, List<Line>>
     {
         {CircleType.Outer, new List<Line>()},
         {CircleType.X, new List<Line>()},
         {CircleType.Y, new List<Line>()},
         {CircleType.Z, new List<Line>()}
     };
 }
Пример #21
0
 public abstract void Render3D(Viewport3D viewport);
Пример #22
0
        private void Render3D(Viewport3D vp)
        {
            if (_state == ClipState.None
                || _clipPlanePoint1 == null
                || _clipPlanePoint2 == null
                || _clipPlanePoint3 == null) return; // Nothing to draw at this point

            TextureHelper.DisableTexturing();

            // Draw points

            if (!_clipPlanePoint1.EquivalentTo(_clipPlanePoint2)
                    && !_clipPlanePoint2.EquivalentTo(_clipPlanePoint3)
                    && !_clipPlanePoint1.EquivalentTo(_clipPlanePoint3))
            {
                var plane = new Plane(_clipPlanePoint1, _clipPlanePoint2, _clipPlanePoint3);

                // Draw clipped solids
                GL.Enable(EnableCap.LineSmooth);
                GL.Hint(HintTarget.LineSmoothHint, HintMode.Nicest);

                var faces = new List<Face>();
                var idg = new IDGenerator();
                foreach (var solid in Document.Selection.GetSelectedObjects().OfType<Solid>().ToList())
                {
                    Solid back, front;
                    if (solid.Split(plane, out back, out front, idg))
                    {
                        faces.AddRange(back.Faces);
                        faces.AddRange(front.Faces);
                    }
                }
                GL.LineWidth(2);
                GL.Color3(Color.White);
                DataStructures.Rendering.Rendering.DrawWireframe(faces, true);
                GL.LineWidth(1);

                GL.Hint(HintTarget.LineSmoothHint, HintMode.Fastest);
                GL.Disable(EnableCap.LineSmooth);

                // Draw the clipping plane
                var u = plane.Normal.Cross(plane.GetClosestAxisToNormal() == Coordinate.UnitZ ? Coordinate.UnitX : Coordinate.UnitZ);
                var v = plane.Normal.Cross(u);
                var point = (_clipPlanePoint1 + _clipPlanePoint2 + _clipPlanePoint3) / 3;
                var dx = u * 10000;
                var dy = v * 10000;
                GL.Disable(EnableCap.CullFace);
                GL.Begin(BeginMode.Quads);
                GL.Color4(Color.FromArgb(100, Color.Turquoise));
                Action<Coordinate> render = c => GL.Vertex3(c.DX, c.DY, c.DZ);
                render(point - dx - dy);
                render(point + dx - dy);
                render(point + dx + dy);
                render(point - dx + dy);
                GL.End();

                GL.Enable(EnableCap.CullFace);
            }

            TextureHelper.EnableTexturing();
        }
Пример #23
0
        /// <summary>
        /// When the mouse is pressed in the 3D view, we want to select the clicked object.
        /// </summary>
        /// <param name="viewport">The viewport that was clicked</param>
        /// <param name="e">The click event</param>
        protected override void MouseDown3D(Viewport3D viewport, ViewportEvent e)
        {
            // Do not perform selection if space is down
            if (KeyboardState.IsKeyDown(Keys.Space)) return;

            // First, get the ray that is cast from the clicked point along the viewport frustrum
            var ray = viewport.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
            IntersectingObjectsFor3DSelection = hits
                .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)
                .ToList();

            // By default, select the closest object
            ChosenItemFor3DSelection = IntersectingObjectsFor3DSelection.FirstOrDefault();

            // If Ctrl is down and the object is already selected, we should deselect it instead.
            var list = new[] {ChosenItemFor3DSelection};
            var desel = ChosenItemFor3DSelection != null && KeyboardState.Ctrl && ChosenItemFor3DSelection.IsSelected;
            SetSelected(desel ? list : null, desel ? null : list, !KeyboardState.Ctrl, IgnoreGrouping());

            State.ActiveViewport = null;
        }
Пример #24
0
 protected virtual void MouseUp3D(Viewport3D viewport, ViewportEvent e)
 {
     // Virtual
 }
Пример #25
0
 /// <summary>
 /// Once the mouse is released in the 3D view, the 3D select cycle has finished.
 /// </summary>
 /// <param name="viewport">The 3D viewport</param>
 /// <param name="e">The mouse event</param>
 protected override void MouseUp3D(Viewport3D viewport, ViewportEvent e)
 {
     IntersectingObjectsFor3DSelection = null;
     ChosenItemFor3DSelection = null;
 }
Пример #26
0
 protected virtual void Render3D(Viewport3D viewport)
 {
     if (State.Action == BoxAction.ReadyToDraw || State.Action == BoxAction.DownToDraw) return;
     if (ShouldDraw3DBox())
     {
         Render3DBox(viewport, State.BoxStart, State.BoxEnd);
     }
 }
Пример #27
0
 private void Render3D(Viewport3D viewport, Document document)
 {
     var box = document.Map.CordonBounds;
     TextureHelper.DisableTexturing();
     GL.Begin(BeginMode.Lines);
     GL.Color4(Color.Red);
     foreach (var line in box.GetBoxLines())
     {
         GL.Vertex3(line.Start.DX, line.Start.DY, line.Start.DZ);
         GL.Vertex3(line.End.DX, line.End.DY, line.End.DZ);
     }
     GL.End();
     TextureHelper.EnableTexturing();
 }
Пример #28
0
 protected virtual void Render3DBox(Viewport3D viewport, Coordinate start, Coordinate end)
 {
     var box = new Box(start, end);
     TextureHelper.Unbind();
     GL.Begin(PrimitiveType.Lines);
     GL.Color4(GetRenderBoxColour());
     foreach (var line in box.GetBoxLines())
     {
         Coord(line.Start);
         Coord(line.End);
     }
     GL.End();
 }
Пример #29
0
 public void Render3D(Viewport3D viewport, MapObject o)
 {
     throw new NotImplementedException();
 }
Пример #30
0
 public override List<VMPoint> GetVerticesAtPoint(int x, int y, Viewport3D viewport)
 {
     return MainTool.GetVerticesAtPoint(x, y, viewport);
 }