public void ChangeType() { switch (currentType) { case BezierType.Berenstein: currentType = BezierType.BSpline; foreach (var pt in berensteinPoints) { pt.Visible = false; } foreach (var pt in points) { pt.Point.Visible = true; } break; case BezierType.BSpline: currentType = BezierType.Berenstein; foreach (var pt in berensteinPoints) { pt.Visible = true; } foreach (var pt in points) { pt.Point.Visible = false; } break; } }
public Bezier(BezierType type, ICollection<float> pointData, IList<PointF> pixels, Angle angle = default(Angle)) : this() { Bounds = InitializeBezier(type, pointData, pixels, out points, angle); Option = type; Angle = angle.AssignCenter(Bounds.Center()); ID = Factory.NewID(Name); }
/// <summary> /// Appends a series of Bezier curves to the end of the path, connected by an additional line segment if the first curve /// does not begin at the path's current endpoint. /// </summary> /// <param name="points">A list of points.</param> /// <param name="offset">The index of the first point to use from the list.</param> /// <param name="length">The number of points to use from the list.</param> /// <param name="bezierType">The type of Bezier</param> /// <remarks><para>For quadratic Bezier curves, the number of points defined by the parameters should be a multiple of 2 plus 1. /// For cubic Bezier curves, the number of points defined by the parameters should be a multiple of 3 plus 1. For each curve /// drawn after the first, the ending point of the previous curve is used as the starting point.</para></remarks> public void AddBeziers(IList <CCVector2> points, int offset, int length, BezierType bezierType) { if (offset < 0 || points.Count < offset + length) { throw new ArgumentOutOfRangeException("The offset and length are out of range for the given points argument."); } switch (bezierType) { case BezierType.Quadratic: if (length < 3) { throw new ArgumentOutOfRangeException("A quadratic bezier needs at least 3 points"); } for (int i = offset + 2; i < offset + length; i += 2) { AddBezier(points[i - 2], points[i - 1], points[i]); } break; case BezierType.Cubic: if (length < 4) { throw new ArgumentOutOfRangeException("A cubic bezier needs at least 4 points"); } for (int i = offset + 3; i < offset + length; i += 3) { AddBezier(points[i - 3], points[i - 2], points[i - 1], points[i]); } break; } }
public override BezierState OnBezierDisabled(BezierType type) { if (type == BezierType.Attack) { return(atkDefBezState); } return(null); }
public Bezier(BezierType type, Vector3 start, Vector3 end, Vector3 mid1, Vector3 mid2) { _iType = type; _vPosStart = start; _vPosEnd = end; _vPosMid1 = mid1; _vPosMid2 = mid2; }
public void Setup(IPositionObject target, Vector3[] points, float interval, BezierType type, System.Action <GameObject> onComplete) { this.bezierType = type; this.points = points; this.onComplete = onComplete; this.target = target; this.interval = interval; this.timer = 0f; target.SetPosition(points[0]); this.isStarted = true; }
public void Init(List <UnityEngine.GameObject> nodes, BezierType type, int bezierLength) { nodes.ForEach((obj) => { obj.transform.parent = transform; }); this.nodes = nodes; this.type = type; this.bezierLength = bezierLength; Created.Invoke(type); StartCoroutine(BuildBezier( nodes.ConvertAll((n) => n.GetComponent <Transform>().position).ToArray())); }
public BezierTool(BezierTool owner, eCurrentPoint id) { try { m_owner = owner; m_clone = m_owner.Clone() as BezierTool; m_pointId = id; Type = owner.Type; m_originalPoint = GetPoint(m_pointId); UseRoute = false; } catch (Exception ex) { throw ex; } }
public override BezierState OnBezierDisabled(BezierType type) { if (type == BezierType.Defense) { if (spawner.OnDefRadar) { return(atkDefBezState); } else { return(atkBezState); } } return(null); }
public override BezierState OnBezierDisabled(BezierType type) { if (type == BezierType.Attack) { return(atkRmDefBezState); } else if (spawner.OnDefRadar) { return(rmAtkDefBezState); } else { return(rmAtkBezState); } }
protected bool RemoveBezierNode(Vector3 clickPosition, BezierType type) { var nodeList = spawner.NodeListDictionary[type]; int activeNodeAtPosIndex = nodeList.FindIndex( (obj) => Vector3.Distance(obj.transform.position, clickPosition) <= spawner.RemovalNodeSenseDistance); if (activeNodeAtPosIndex != -1) { var activeNode = nodeList[activeNodeAtPosIndex]; nodeList.RemoveAt(activeNodeAtPosIndex); activeNode.GetComponent <BezierNodeComponent>().DestroyNode(); return(true); } return(false); }
/// <summary> /// Rendering a evaluator(a bezier curve or surface) and its control points. /// </summary> /// <param name="controlPoints"></param> /// <param name="type"></param> /// <param name="model"></param> /// <param name="shaderCodes"></param> /// <param name="attributeMap"></param> /// <param name="positionNameInIBufferable"></param> /// <param name="switches"></param> private BezierRenderer(IList<vec3> controlPoints, BezierType type, Points model, CSharpGL.ShaderCode[] shaderCodes, CSharpGL.AttributeMap attributeMap, string positionNameInIBufferable, params GLState[] switches) : base(model, shaderCodes, attributeMap, positionNameInIBufferable, switches) { switch (type) { case BezierType.Curve: this.Evaluator = new Evaluator1DRenderer(controlPoints);//, lengths); break; case BezierType.Surface: this.Evaluator = new Evaluator2DRenderer(controlPoints);//, lengths); break; default: throw new System.NotImplementedException(); } }
/// <summary> /// Rendering a evaluator(a bezier curve or surface) and its control points. /// </summary> /// <param name="controlPoints"></param> /// <param name="type"></param> /// <param name="model"></param> /// <param name="shaderProgramProvider"></param> /// <param name="attributeMap"></param> /// <param name="positionNameInIBufferable"></param> /// <param name="switches"></param> private BezierRenderer(IList <vec3> controlPoints, BezierType type, Points model, CSharpGL.IShaderProgramProvider shaderProgramProvider, CSharpGL.AttributeMap attributeMap, string positionNameInIBufferable, params GLState[] switches) : base(model, shaderProgramProvider, attributeMap, positionNameInIBufferable, switches) { switch (type) { case BezierType.Curve: this.Evaluator = new Evaluator1DRenderer(controlPoints); //, lengths); break; case BezierType.Surface: this.Evaluator = new Evaluator2DRenderer(controlPoints); //, lengths); break; default: throw new System.NotImplementedException(); } }
/// <summary> /// Creates a renderer that renders a evaluator(a bezier curve or surface) and its control points. /// </summary> /// <param name="controlPoints"></param> /// <param name="type"></param> /// <returns></returns> public static BezierRenderer Create(IList <vec3> controlPoints, BezierType type) { var shaderCodes = new ShaderCode[2]; shaderCodes[0] = new ShaderCode(ManifestResourceLoader.LoadTextFile(@"Resources\Points.vert"), ShaderType.VertexShader); shaderCodes[1] = new ShaderCode(ManifestResourceLoader.LoadTextFile(@"Resources\Points.frag"), ShaderType.FragmentShader); var map = new CSharpGL.AttributeMap(); map.Add("in_Position", Points.strposition); var model = new Points(controlPoints); var renderer = new BezierRenderer(controlPoints, type, model, shaderCodes, map, Points.strposition); renderer.ModelSize = model.Lengths; renderer.WorldPosition = model.WorldPosition; renderer.stateList.Add(new PointSizeState(10)); return(renderer); }
static IRectangleF InitializeBezier(BezierType type, ICollection<float> pointData, ICollection<PointF> pixels, out IList<PointF> points, Angle angle = default(Angle)) { IList<PointF> Source; if (pointData != null) Source = pointData.ToPoints(); else Source = pixels.ToArray(); var rc = Source.ToArea(); angle = angle.AssignCenter(rc); if (angle.Valid) Source = Source.Rotate(angle); points = InitializeBezier(type, Source); return rc; }
protected void BuildBezier(BezierType type) { UnityEngine.GameObject bezBuilder = spawner.BuilderPrefabs[type]; var nodeList = spawner.NodeListDictionary[type]; bezBuilder = UnityEngine.GameObject.Instantiate(bezBuilder); spawner.ActiveCurves.Add(type, bezBuilder); var builderComp = bezBuilder.GetComponent <BezierBuilderComponent>(); builderComp.Init(nodeList, type, spawner.BezierLength); builderComp.Disabled.AddListener(spawner.OnBezierDisabled); if (BezierType.Defense == type) { bezBuilder.GetComponent <FollowTargetComponent>().SetTargetToFollow(spawner.transform); nodeList.ForEach((obj) => UnityEngine.GameObject.Destroy(obj.GetComponent <FollowTargetComponent>())); } spawner.OnBezierCreated.Invoke(); }
static IList<PointF> InitializeBezier(BezierType type, IList<PointF> Source) { bool multiple = type.HasFlag(BezierType.Multiple); var points = new List<PointF>(100); if (multiple) { for (int k = 1; k < Source.Count; k++) { if (k % 3 == 0) { Geometry.GetBezierPoints(4, ref points, new PointF[] { Source[k - 3], Source[k - 2], Source[k - 1], Source[k] }); if (points.Count > 0) points.RemoveAt(points.Count - 1); } } } else Geometry.GetBezierPoints(4, ref points, Source); return points; }
/// <summary> /// Handles all the bezier logic for the user click. /// </summary> /// <param name="type">The bezier curve type</param> /// <param name="clickPosition"></param> /// <param name="nodeList"></param> protected BezierState HandleClick( BezierType type, Vector3 clickPosition ) { if (RemoveBezierNode(clickPosition, type)) { return(null); } var nodeList = spawner.NodeListDictionary[type]; if (nodeList.Count == 2 && type == BezierType.Defense && CheckBezierCrossingSpawner(new Vector3[] { nodeList[0].transform.position, nodeList[1].transform.position, clickPosition })) { spawner.OnFailPlacingNode(); return(null); } var node = spawner.NodePrefabs[type]; var instance = UnityEngine.GameObject.Instantiate(node); instance.transform.position = clickPosition; instance.GetComponent <FollowTargetComponent>()?.SetTargetToFollow(spawner.transform); nodeList.Add(instance); if (nodeList.Count == 3) { BuildBezier(type); if (type == BezierType.Attack) { return(BezierState.rmAtkDefBezState); } else { return(BezierState.atkRmDefBezState); } } return(null); }
public static IBezier newBezier(this IFactory factory, BezierType type, IList <PointF> points) => factory.newBezier(type, null, points, default(Angle));
public static IBezier newBezier(this IFactory factory, Angle angle, BezierType type, IList <PointF> points) => factory.newBezier(type, null, points, angle);
public static IBezier newBezier(this IFactory factory, BezierType type, params float[] points) => factory.newBezier(type, points, null, default(Angle));
public static IBezier newBezier(this IFactory factory, Angle angle, BezierType type, params float[] points) => factory.newBezier(type, points, null, angle);
public Bezier(BezierType type, params float[] points) : this(type, points as IList<float>) { }
/// <summary> /// Adds a series of primitive Bezier paths to the batch of figures to be rendered. /// </summary> /// <param name="pen">The pen supplying the color to render the path with.</param> /// <param name="points">A list of Bezier points.</param> /// <param name="bezierType">The type of Bezier curves to draw.</param> /// <param name="pathType">Whether the path is open or closed.</param> /// <remarks><para>For quadratic Bezier curves, the number of points defined by the parameters should be a multiple of 2 plus 1 /// for open curves or 2 for closed curves. For cubic Bezier curves, the number of points defined by the parameters should be /// a multiple of 3 plus 1 for open curves or 3 for closed curves. For each curve drawn after the first, the ending point of /// the previous curve is used as the starting point. For closed curves, the end point of the last curve is the start point /// of the first curve.</para></remarks> /// <exception cref="InvalidOperationException"><c>DrawPrimitiveBeziers</c> was called, but <see cref="Begin()"/> has not yet been called.</exception> public void DrawPrimitiveBeziers (Pen pen, IList<CCVector2> points, BezierType bezierType, PathType pathType) { DrawPrimitiveBeziers(pen, points, 0, points.Count, bezierType, pathType); }
/// <summary> /// Appends a series of Bezier curves to the end of the path, connected by an additional line segment if the first curve /// does not begin at the path's current endpoint. /// </summary> /// <param name="points">A list of points.</param> /// <param name="bezierType">The type of Bezier</param> /// <remarks><para>For quadratic Bezier curves, the number of points defined by the parameters should be a multiple of 2 plus 1. /// For cubic Bezier curves, the number of points defined by the parameters should be a multiple of 3 plus 1. For each curve /// drawn after the first, the ending point of the previous curve is used as the starting point.</para></remarks> public void AddBeziers(IList <CCVector2> points, BezierType bezierType) { AddBeziers(points, 0, points.Count, bezierType); }
/// <summary> /// Appends a series of Bezier curves to the end of the path, connected by an additional line segment if the first curve /// does not begin at the path's current endpoint. /// </summary> /// <param name="points">A list of points.</param> /// <param name="bezierType">The type of Bezier</param> /// <remarks><para>For quadratic Bezier curves, the number of points defined by the parameters should be a multiple of 2 plus 1. /// For cubic Bezier curves, the number of points defined by the parameters should be a multiple of 3 plus 1. For each curve /// drawn after the first, the ending point of the previous curve is used as the starting point.</para></remarks> public void AddBeziers (IList<Vector2> points, BezierType bezierType) { AddBeziers(points, 0, points.Count, bezierType); }
public Bezier(BezierType type, Angle angle, params float[] points) : this(type, points as IList<float>, angle) { }
protected void RemoveBezier(BezierType type) { spawner.ActiveCurves[type].GetComponent <HealthComponent>()?.ForceDeath(); }
public virtual BezierState OnBezierDisabled(BezierType type) { return(null); }
public Bezier(BezierType type, IList<float> points, Angle angle = default(Angle)) : this(type, points, null, angle) { }
public Bezier(BezierType type, IList<PointF> pixels, Angle angle = default(Angle)) : this(type, null, pixels, angle) { }
public virtual IBezier newBezier(BezierType type, IList <float> points, IList <PointF> pixels, Angle angle = default(Angle)) => new Bezier(type, points, pixels, angle);
/// <summary> /// Appends a series of Bezier curves to the end of the path, connected by an additional line segment if the first curve /// does not begin at the path's current endpoint. /// </summary> /// <param name="points">A list of points.</param> /// <param name="offset">The index of the first point to use from the list.</param> /// <param name="length">The number of points to use from the list.</param> /// <param name="bezierType">The type of Bezier</param> /// <remarks><para>For quadratic Bezier curves, the number of points defined by the parameters should be a multiple of 2 plus 1. /// For cubic Bezier curves, the number of points defined by the parameters should be a multiple of 3 plus 1. For each curve /// drawn after the first, the ending point of the previous curve is used as the starting point.</para></remarks> public void AddBeziers (IList<Vector2> points, int offset, int length, BezierType bezierType) { if (offset < 0 || points.Count < offset + length) throw new ArgumentOutOfRangeException("The offset and length are out of range for the given points argument."); switch (bezierType) { case BezierType.Quadratic: if (length < 3) throw new ArgumentOutOfRangeException("A quadratic bezier needs at least 3 points"); for (int i = offset + 2; i < offset + length; i += 2) AddBezier(points[i - 2], points[i - 1], points[i]); break; case BezierType.Cubic: if (length < 4) throw new ArgumentOutOfRangeException("A cubic bezier needs at least 4 points"); for (int i = offset + 3; i < offset + length; i += 3) AddBezier(points[i - 3], points[i - 2], points[i - 1], points[i]); break; } }
/// <summary> /// Creates a renderer that renders a evaluator(a bezier curve or surface) and its control points. /// </summary> /// <param name="controlPoints"></param> /// <param name="type"></param> /// <returns></returns> public static BezierRenderer Create(IList<vec3> controlPoints, BezierType type) { var shaderCodes = new ShaderCode[2]; shaderCodes[0] = new ShaderCode(ManifestResourceLoader.LoadTextFile(@"Resources\Points.vert"), ShaderType.VertexShader); shaderCodes[1] = new ShaderCode(ManifestResourceLoader.LoadTextFile(@"Resources\Points.frag"), ShaderType.FragmentShader); var map = new CSharpGL.AttributeMap(); map.Add("in_Position", Points.strposition); var model = new Points(controlPoints); var renderer = new BezierRenderer(controlPoints, type, model, shaderCodes, map, Points.strposition); renderer.ModelSize = model.Lengths; renderer.WorldPosition = model.WorldPosition; renderer.stateList.Add(new PointSizeState(10)); return renderer; }
/// <summary> /// Adds a series of primitive Bezier paths to the batch of figures to be rendered. /// </summary> /// <param name="pen">The pen supplying the color to render the path with.</param> /// <param name="points">A list of Bezier points.</param> /// <param name="offset">The index of the first start point in the list.</param> /// <param name="count">The number of points to use.</param> /// <param name="bezierType">The type of Bezier curves to draw.</param> /// <remarks><para>For quadratic Bezier curves, the number of points defined by the parameters should be a multiple of 2 plus 1 /// for open curves or 2 for closed curves. For cubic Bezier curves, the number of points defined by the parameters should be /// a multiple of 3 plus 1 for open curves or 3 for closed curves. For each curve drawn after the first, the ending point of /// the previous curve is used as the starting point. For closed curves, the end point of the last curve is the start point /// of the first curve.</para></remarks> /// <exception cref="InvalidOperationException"><c>DrawPrimitiveBeziers</c> was called, but <see cref="Begin()"/> has not yet been called.</exception> public void DrawPrimitiveBeziers (Pen pen, IList<CCVector2> points, int offset, int count, BezierType bezierType) { DrawPrimitiveBeziers(pen, points, offset, count, bezierType, PathType.Open); }
/// <summary> /// Computes and adds a series of Bezier paths to the batch of figures to be rendered. /// </summary> /// <param name="pen">The pen to render the path with.</param> /// <param name="points">A list of Bezier points.</param> /// <param name="bezierType">The type of Bezier curves to draw.</param> /// <remarks><para>For quadratic Bezier curves, the number of points defined by the parameters should be a multiple of 2 plus 1 /// for open curves or 2 for closed curves. For cubic Bezier curves, the number of points defined by the parameters should be /// a multiple of 3 plus 1 for open curves or 3 for closed curves. For each curve drawn after the first, the ending point of /// the previous curve is used as the starting point. For closed curves, the end point of the last curve is the start point /// of the first curve.</para></remarks> /// <exception cref="InvalidOperationException"><c>DrawBeziers</c> was called, but <see cref="Begin()"/> has not yet been called.</exception> public void DrawBeziers (Pen pen, IList<CCVector2> points, BezierType bezierType) { DrawBeziers(pen, points, 0, points.Count, bezierType, PathType.Open); }
/// <summary> /// Adds a series of primitive Bezier paths to the batch of figures to be rendered. /// </summary> /// <param name="pen">The pen supplying the color to render the path with.</param> /// <param name="points">A list of Bezier points.</param> /// <param name="offset">The index of the first start point in the list.</param> /// <param name="count">The number of points to use.</param> /// <param name="bezierType">The type of Bezier curves to draw.</param> /// <param name="pathType">Whether the path is open or closed.</param> /// <remarks><para>For quadratic Bezier curves, the number of points defined by the parameters should be a multiple of 2 plus 1 /// for open curves or 2 for closed curves. For cubic Bezier curves, the number of points defined by the parameters should be /// a multiple of 3 plus 1 for open curves or 3 for closed curves. For each curve drawn after the first, the ending point of /// the previous curve is used as the starting point. For closed curves, the end point of the last curve is the start point /// of the first curve.</para></remarks> /// <exception cref="InvalidOperationException"><c>DrawPrimitiveBeziers</c> was called, but <see cref="Begin()"/> has not yet been called.</exception> public void DrawPrimitiveBeziers (Pen pen, IList<CCVector2> points, int offset, int count, BezierType bezierType, PathType pathType) { if (!_inDraw) throw new InvalidOperationException(); if (pen == null) throw new ArgumentNullException("pen"); if (points.Count < offset + count) throw new ArgumentOutOfRangeException("The offset and count are out of range for the given points argument."); _pathBuilder.Reset(); _pathBuilder.CalculateLengths = pen.NeedsPathLength; switch (bezierType) { case BezierType.Quadratic: for (int i = offset + 2; i < offset + count; i += 2) _pathBuilder.AddBezier(points[i - 2], points[i - 1], points[i]); if (pathType == PathType.Closed) _pathBuilder.AddBezier(points[offset + count - 2], points[offset + count - 1], points[offset]); break; case BezierType.Cubic: for (int i = offset + 3; i < offset + count; i += 3) _pathBuilder.AddBezier(points[i - 3], points[i - 2], points[i - 1], points[i]); if (pathType == PathType.Closed) _pathBuilder.AddBezier(points[offset + count - 3], points[offset + count - 2], points[offset + count - 1], points[offset]); break; } switch (pathType) { case PathType.Open: DrawPrimitivePath(pen, _pathBuilder.Buffer, 0, _pathBuilder.Count, PathType.Open); break; case PathType.Closed: DrawPrimitivePath(pen, _pathBuilder.Buffer, 0, _pathBuilder.Count - 1, PathType.Closed); break; } //if (_sortMode == DrawSortMode.Immediate) // FlushBuffer(); }
public BezierTool(BezierType type) { Type = type; UseRoute = false; }