public static Matrix4 GetProjectionMatrix(this ViewPort viewPort, double width, double height, ProjectionStyle projectionStyle) { // create transform Matrix4 transform; switch (projectionStyle) { case ProjectionStyle.OriginTopLeft: transform = viewPort.GetTransformationMatrixWindowsStyle(width, height); break; case ProjectionStyle.OriginBottomLeft: transform = viewPort.GetTransformationMatrixCartesianStyle(width, height); break; case ProjectionStyle.OriginCenter: transform = viewPort.GetTransformationMatrixDirect3DStyle(width, height); break; default: throw new NotSupportedException(); } return(transform); }
public static IEnumerable <ProjectedEntity> ProjectTo2D(Drawing drawing, ViewPort viewPort, double width, double height, ProjectionStyle projectionStyle) { // create transform Matrix4 transform; switch (projectionStyle) { case ProjectionStyle.OriginTopLeft: transform = viewPort.GetTransformationMatrixWindowsStyle(width, height); break; case ProjectionStyle.OriginBottomLeft: transform = viewPort.GetTransformationMatrixCartesianStyle(width, height); break; case ProjectionStyle.OriginCenter: transform = viewPort.GetTransformationMatrixDirect3DStyle(width, height); break; default: throw new NotSupportedException(); } // project all entities var entities = new List <ProjectedEntity>(); foreach (var layer in from l in drawing.GetLayers() where l.EntityCount > 0 orderby l.Name select l) { foreach (var entity in layer.GetEntities().OrderBy(x => x.Id)) { var projected = Project(entity, layer, transform); if (projected != null) { entities.Add(projected); } } } return(entities); }
public void TransformationMatrixDirect3DTest() { var viewPort = new ViewPort(Point.Origin, Vector.ZAxis, Vector.YAxis, 100.0); var transform = viewPort.GetTransformationMatrixDirect3DStyle(200, 100); var inverse = transform.Inverse(); // view port // 0,100 200,100 // // 0,0 200,0 // // screen // -1,1 1,1 // // -1,-1 1,-1 // center Assert.Equal(new Point(0, 0, 0), transform.Transform(new Point(100, 50, 0))); Assert.Equal(new Point(100, 50, 0), inverse.Transform(new Point(0, 0, 0))); // bottom left Assert.Equal(new Point(-1, -1, 0), transform.Transform(new Point(0, 0, 0))); Assert.Equal(new Point(0, 0, 0), inverse.Transform(new Point(-1, -1, 0))); // bottom right Assert.Equal(new Point(1, -1, 0), transform.Transform(new Point(200, 0, 0))); Assert.Equal(new Point(200, 0, 0), inverse.Transform(new Point(1, -1, 0))); // top left Assert.Equal(new Point(-1, 1, 0), transform.Transform(new Point(0, 100, 0))); Assert.Equal(new Point(0, 100, 0), inverse.Transform(new Point(-1, 1, 0))); // top right Assert.Equal(new Point(1, 1, 0), transform.Transform(new Point(200, 100, 0))); Assert.Equal(new Point(200, 100, 0), inverse.Transform(new Point(1, 1, 0))); }