Ejemplo n.º 1
0
        /// <summary>
        /// Creates indices for a patch that is tessellated at the specified level.
        /// </summary>
        protected void CreatePatchIndices(IShapeBuilder builder, int tessellation, bool isMirrored)
        {
            int stride = tessellation + 1;

            for (int i = 0; i < tessellation; ++i)
            {
                for (int j = 0; j < tessellation; j++)
                {
                    // Make a list of six index values (two triangles).
                    int[] indices =
                    {
                        i *stride + j,
                        (i + 1) * stride + j,
                        (i + 1) * stride + j + 1,

                        i *stride + j,
                        (i + 1) * stride + j + 1,
                        i *stride + j + 1,
                    };

                    // If this patch is mirrored, reverse the
                    // indices to keep the correct winding order.
                    if (isMirrored)
                    {
                        Array.Reverse(indices);
                    }

                    // Create the indices.
                    foreach (int index in indices)
                    {
                        builder.AddIndex(builder.CurrentVertex + index);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public OleGraphicFrameHandler(ShapeContext.Builder shapeContextBuilder,
                               LocationParser transformFactory,
                               IShapeBuilder shapeBuilder)
 {
     _shapeContextBuilder = shapeContextBuilder ?? throw new ArgumentNullException(nameof(shapeContextBuilder));;
     _transformFactory    = transformFactory ?? throw new ArgumentNullException(nameof(transformFactory));
     _shapeBuilder        = shapeBuilder ?? throw new ArgumentNullException(nameof(shapeBuilder));
 }
Ejemplo n.º 3
0
 public TableGraphicFrameHandler(ShapeContext.Builder shapeContextBuilder,
                                 InnerTransformFactory transformFactory,
                                 IShapeBuilder shapeBuilder)
 {
     _shapeContextBuilder = shapeContextBuilder ?? throw new ArgumentNullException(nameof(shapeContextBuilder));
     _transformFactory    = transformFactory ?? throw new ArgumentNullException(nameof(transformFactory));
     _shapeBuilder        = shapeBuilder ?? throw new ArgumentNullException(nameof(shapeBuilder));
 }
Ejemplo n.º 4
0
 //TODO: inject interface instead
 public SdkShapeHandler(ShapeContext.Builder shapeContextBuilder,
                        LocationParser transformFactory,
                        IGeometryFactory geometryFactory,
                        IShapeBuilder shapeBuilder)
 {
     _shapeContextBuilder = shapeContextBuilder ?? throw new ArgumentNullException(nameof(shapeContextBuilder));
     _transformFactory    = transformFactory ?? throw new ArgumentNullException(nameof(transformFactory));
     _geometryFactory     = geometryFactory ?? throw new ArgumentNullException(nameof(geometryFactory));
     _shapeBuilder        = shapeBuilder ?? throw new ArgumentNullException(nameof(shapeBuilder));
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Registers a new shape builder that will be used for the given shape name.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="shapeBuilder"></param>
        /// <returns>Whether the builder has been successfully registered.</returns>
        public bool Register(string name, IShapeBuilder shapeBuilder)
        {
            var key = name.ToLowerInvariant();

            if (builders_.ContainsKey(key))
            {
                return(false);
            }
            builders_[name.ToLowerInvariant()] = shapeBuilder;
            return(true);
        }
Ejemplo n.º 6
0
 public PictureHandler(IPreSettings preSettings,
                       SlidePlaceholderFontService sldFontService,
                       SlidePart sdkSldPart,
                       InnerTransformFactory transformFactory,
                       IShapeBuilder shapeBuilder)
 {
     _preSettings      = preSettings ?? throw new ArgumentNullException(nameof(preSettings));
     _sldFontService   = sldFontService ?? throw new ArgumentNullException(nameof(sldFontService));
     _sdkSldPart       = sdkSldPart ?? throw new ArgumentNullException(nameof(sdkSldPart));
     _transformFactory = transformFactory ?? throw new ArgumentNullException(nameof(transformFactory));
     _shapeBuilder     = shapeBuilder;
 }
Ejemplo n.º 7
0
 public PictureHandler(ShapeContext.Builder shapeContextBuilder,
                       InnerTransformFactory transformFactory,
                       IGeometryFactory geometryFactory,
                       SlidePart sdkSldPart,
                       IShapeBuilder shapeBuilder)
 {
     _shapeContextBuilder = shapeContextBuilder ?? throw new ArgumentNullException(nameof(shapeContextBuilder));
     _transformFactory    = transformFactory ?? throw new ArgumentNullException(nameof(transformFactory));
     _shapeBuilder        = shapeBuilder ?? throw new ArgumentNullException(nameof(shapeBuilder));
     _sdkSldPart          = sdkSldPart ?? throw new ArgumentNullException(nameof(sdkSldPart));
     _geometryFactory     = geometryFactory ?? throw new ArgumentNullException(nameof(geometryFactory));
 }
Ejemplo n.º 8
0
        public CanvasController(IShapeBuilder shapeBuilder, IDocumentLogic documentLogic)
        {
            _shapes = new List<IShape>();

            IsNewShape = false;
            EnableCreateShape = false;
            _shapeBuilder = shapeBuilder;
            _documentLogic = documentLogic;
            _shapeMoving = false;
            _startMovingLocationX = 0;
            _startMovingLocationY = 0;
            _startShapeMovingLocationX = 0;
            _startShapeMovingLocationY = 0;
        }
Ejemplo n.º 9
0
        /// <inheritdoc />
        protected override void OnBuild(IShapeBuilder builder)
        {
            int p = 0;

            for (int i = 0; i < Polygons.Length; i++)
            {
                var poly = Polygons[i];
                for (int j = 2; j < poly.Vertices.Count; j++)
                {
                    builder.AddVertex(poly.Vertices[0]);
                    builder.AddIndex(p++);

                    builder.AddVertex(poly.Vertices[j - 1]);
                    builder.AddIndex(p++);

                    builder.AddVertex(poly.Vertices[j]);
                    builder.AddIndex(p++);
                }
            }
        }
Ejemplo n.º 10
0
        protected override void OnBuild(IShapeBuilder builder)
        {
            for (int i = 0; i < normals.Length; i++)
            {
                var normal = normals[i];

                Vector3 side1 = new Vector3(normal.Y, normal.Z, normal.X);
                Vector3 side2 = Vector3.Cross(normal, side1);

                builder.AddIndex(builder.CurrentVertex + 0);
                builder.AddIndex(builder.CurrentVertex + 1);
                builder.AddIndex(builder.CurrentVertex + 2);

                builder.AddIndex(builder.CurrentVertex + 0);
                builder.AddIndex(builder.CurrentVertex + 2);
                builder.AddIndex(builder.CurrentVertex + 3);

                builder.AddVertex(new Vertex(Position + (((normal - side1 - side2) / 2) * Size), normal, Vector2.Zero));
                builder.AddVertex(new Vertex(Position + (((normal - side1 + side2) / 2) * Size), normal, Vector2.UnitX));
                builder.AddVertex(new Vertex(Position + (((normal + side1 + side2) / 2) * Size), normal, Vector2.One));
                builder.AddVertex(new Vertex(Position + (((normal + side1 - side2) / 2) * Size), normal, Vector2.UnitY));
            }
        }
Ejemplo n.º 11
0
 public void ChangeBuilder(IShapeBuilder builder)
 {
     CurBuilder = builder;
 }
Ejemplo n.º 12
0
Archivo: Dome.cs Proyecto: Kaydax/CSG
 protected override void OnBuild(IShapeBuilder builder)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Creates vertices for a patch that is tessellated at the specified level.
        /// </summary>
        protected void CreatePatchVertices(IShapeBuilder builder, Vector3[] patch, int tessellation, bool isMirrored)
        {
            Debug.Assert(patch.Length == 16);

            for (int i = 0; i <= tessellation; ++i)
            {
                float ti = (float)i / tessellation;

                for (int j = 0; j <= tessellation; j++)
                {
                    float tj = (float)j / tessellation;

                    // Perform four horizontal bezier interpolations
                    // between the control points of this patch.
                    Vector3 p1 = BezierInterpolate(patch[0], patch[1], patch[2], patch[3], ti);
                    Vector3 p2 = BezierInterpolate(patch[4], patch[5], patch[6], patch[7], ti);
                    Vector3 p3 = BezierInterpolate(patch[8], patch[9], patch[10], patch[11], ti);
                    Vector3 p4 = BezierInterpolate(patch[12], patch[13], patch[14], patch[15], ti);

                    // Perform a vertical interpolation between the results of the
                    // previous horizontal interpolations, to compute the position.
                    Vector3 position = BezierInterpolate(p1, p2, p3, p4, tj);

                    // Perform another four bezier interpolations between the control
                    // points, but this time vertically rather than horizontally.
                    Vector3 q1 = BezierInterpolate(patch[0], patch[4], patch[8], patch[12], tj);
                    Vector3 q2 = BezierInterpolate(patch[1], patch[5], patch[9], patch[13], tj);
                    Vector3 q3 = BezierInterpolate(patch[2], patch[6], patch[10], patch[14], tj);
                    Vector3 q4 = BezierInterpolate(patch[3], patch[7], patch[11], patch[15], tj);

                    // Compute vertical and horizontal tangent vectors.
                    Vector3 tangentA = BezierTangent(p1, p2, p3, p4, tj);
                    Vector3 tangentB = BezierTangent(q1, q2, q3, q4, ti);

                    // Cross the two tangent vectors to compute the normal.
                    Vector3 normal = Vector3.Cross(tangentA, tangentB);

                    if (normal.Length() > 0.0001f)
                    {
                        normal = Vector3.Normalize(normal);

                        // If this patch is mirrored, we must invert the normal.
                        if (isMirrored)
                        {
                            normal = -normal;
                        }
                    }
                    else
                    {
                        // In a tidy and well constructed bezier patch, the preceding
                        // normal computation will always work. But the classic teapot
                        // model is not tidy or well constructed! At the top and bottom
                        // of the teapot, it contains degenerate geometry where a patch
                        // has several control points in the same place, which causes
                        // the tangent computation to fail and produce a zero normal.
                        // We 'fix' these cases by just hard-coding a normal that points
                        // either straight up or straight down, depending on whether we
                        // are on the top or bottom of the teapot. This is not a robust
                        // solution for all possible degenerate bezier patches, but hey,
                        // it's good enough to make the teapot work correctly!

                        if (position.Y > 0)
                        {
                            normal = Vector3.UnitY;
                        }
                        else
                        {
                            normal = -Vector3.UnitY;
                        }
                    }

                    // Create the vertex.
                    builder.AddVertex(position, normal);
                }
            }
        }