Beispiel #1
0
        public BezierCurve(float offsetX, float offsetY, CurveInitalizeData initData)
        {
            float initX = initData.HandlePosX + offsetX;
            float initY = initData.HandlePosY + offsetY;

            _nextLines = null;
            _nextCurve = null;
            _prevCurve = null;
            _prevLines = null;

            _lineTemplate = new LineGenerator();
            _lineTemplate.V1 = Vector2.Zero;
            _lineTemplate.V2 = Vector2.Zero;
            _lineTemplate.Color = Color.White;
            _lineTemplate.Depth = DepthLevel.Low;

            Vector2 component1 = Common.GetComponentFromAngle(initData.Angle, initData.Length1);
            Vector2 component2 = Common.GetComponentFromAngle((float) (initData.Angle - Math.PI), initData.Length2); // minus math.pi to reverse direction

            #region stuff for generating ui elements

            var buttonTemplate = new ButtonGenerator("HullEditorHandle.json");

            var lineTemplate = new LineGenerator("HullEditorLine.json");

            Handle = new CurveHandle(buttonTemplate, lineTemplate, new Vector2(initX, initY), component1, component2);

            #endregion
        }
Beispiel #2
0
        public void InsertBetweenCurves(BezierCurve prevCurve, BezierCurve nextCurve, float t)
        {
            _prevCurve = prevCurve;
            _nextCurve = nextCurve;

            _prevCurve.NextCurveReference = this;
            _nextCurve.PrevCurveReference = this;

            Vector2 pt1;
            Vector2 pt2;
            Bezier.GetBezierValue(out pt1, _prevCurve.NextHandlePos, _prevCurve.NextHandlePos, PrevHandlePos, CenterHandlePos, t);
            Bezier.GetBezierValue(out pt2, _prevCurve.NextHandlePos, _prevCurve.NextHandlePos, PrevHandlePos, CenterHandlePos, t + 0.001f); //limits are for fags

            //get tangent and set to angle
            Vector2 pt3 = pt1 - pt2;
            float angle, magnitude;

            Common.GetAngleFromComponents(out angle, out magnitude, pt3.X, pt3.Y);

            Handle.Angle = angle;
            if (_prevLines == null){
                _prevLines = new List<Line>(_linesPerSide);

                for (int i = 0; i < _linesPerSide; i++){
                    _prevLines.Add(_lineTemplate.GenerateLine());
                }
            }
            else{
                for (int i = 0; i < _linesPerSide; i++){
                    _prevLines[i].Dispose();
                    _prevLines[i] = _lineTemplate.GenerateLine();
                }
            }

            if (_nextLines == null){
                _nextLines = new List<Line>(_linesPerSide);
                for (int i = 0; i < _linesPerSide; i++){
                    _nextLines.Add(_lineTemplate.GenerateLine());
                }
            }
            else{
                for (int i = 0; i < _linesPerSide; i++){
                    _nextLines[i].Dispose();
                    _nextLines[i] = _lineTemplate.GenerateLine();
                }
            }

            Update();
        }
Beispiel #3
0
        public void SetPrevCurve(BezierCurve val)
        {
            _prevCurve = val;
            _prevCurve.NextCurveReference = this;
            Handle.PrevHandle = val.Handle;
            if (_prevLines == null){
                _prevLines = new List<Line>(_linesPerSide);

                for (int i = 0; i < _linesPerSide; i++){
                    _prevLines.Add(_lineTemplate.GenerateLine());
                }
            }
            else{
                for (int i = 0; i < _linesPerSide; i++){
                    _prevLines[i].Dispose();
                    _prevLines[i] = _lineTemplate.GenerateLine();
                }
            }
            Update();
        }
Beispiel #4
0
 public void Dispose()
 {
     Handle.Dispose();
     _lineTemplate = null;
     _nextCurve = null;
     _prevCurve = null;
     /*foreach (var line in _nextLines){
         line.Dispose();
     }
     foreach (var line in _prevLines) {
         line.Dispose();
     }
     _nextCurve.Dispose();
     _prevCurve.Dispose();*/
 }