Example #1
0
        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);
        }
Example #2
0
        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);
        }