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); } }
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)); }
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(); }
protected override void Render3D(Viewport3D vp) { base.Render3D(vp); if (_currentTool != null) _currentTool.Render3D(vp); TextureHelper.DisableTexturing(); 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(BeginMode.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, Sledge.Settings.View.CameraFOV); Matrix.Set(MatrixMode.Modelview); Matrix.Identity(); vp.Camera.Position(); TextureHelper.EnableTexturing(); } // Render out the solid previews GL.Color3(Color.White); var faces = _copies.Keys.SelectMany(x => x.Faces).ToList(); DataStructures.Rendering.Rendering.DrawFilled(faces, Color.Empty); DataStructures.Rendering.Rendering.DrawFilled(faces.Where(x => !x.IsSelected), Color.FromArgb(64, Color.Green)); DataStructures.Rendering.Rendering.DrawFilled(faces.Where(x => x.IsSelected), Color.FromArgb(64, Color.Red)); GL.Color3(Color.Pink); DataStructures.Rendering.Rendering.DrawWireframe(faces, true); }