public override void SetGripPointAt(int index, GripPoint gripPoint, CADPoint newPosition) { switch (gripPoint.Type) { case GripPointType.End: { this.SetPointAt(index, newPosition); } break; case GripPointType.Mid: { int numOfVertices = NumberOfVertices; int i = index - numOfVertices; if (i >= 0 && i <= numOfVertices - 1) { int vIndex1st = i; int vIndex2nd = i + 1; if (vIndex2nd == numOfVertices) { vIndex2nd = 0; } CADVector t = newPosition - gripPoint.Position; this.SetPointAt(vIndex1st, (CADPoint)gripPoint.xData1 + t); this.SetPointAt(vIndex2nd, (CADPoint)gripPoint.xData2 + t); } } break; default: break; } }
internal LitMath.Vector2 Snap(LitMath.Vector2 posInCanvas) { LitMath.Vector2 posInModel = _presenter.CanvasToModel(posInCanvas); foreach (KeyValuePair <ObjectId, List <GripPoint> > kvp in _gripPnts) { int index = -1; foreach (GripPoint gripPnt in kvp.Value) { ++index; double width = 10; double height = 10; LitMath.Vector2 gripPosInCanvas = _presenter.ModelToCanvas(gripPnt.position); gripPosInCanvas.x -= width / 2; gripPosInCanvas.y -= height / 2; LitMath.Rectangle2 rect = new LitMath.Rectangle2(gripPosInCanvas, width, height); if (MathUtils.IsPointInRectangle(posInCanvas, rect)) { _currGripPoint = gripPnt; _currGripEntityId = kvp.Key; _currGripPointIndex = index; return(gripPnt.position); } } } _currGripPoint = null; _currGripEntityId = ObjectId.Null; _currGripPointIndex = -1; return(posInModel); }
public override List <GripPoint> GetGripPoints() { List <GripPoint> gripPnts = new List <GripPoint>(); int numOfVertices = NumberOfVertices; for (int i = 0; i < numOfVertices; ++i) { gripPnts.Add(new GripPoint(GripPointType.End, _vertices[i])); } for (int i = 0; i < numOfVertices - 1; ++i) { GripPoint midGripPnt = new GripPoint(GripPointType.Mid, (_vertices[i] + _vertices[i + 1]) / 2); midGripPnt.xData1 = _vertices[i]; midGripPnt.xData2 = _vertices[i + 1]; gripPnts.Add(midGripPnt); } if (_closed && numOfVertices > 2) { GripPoint midGripPnt = new GripPoint(GripPointType.Mid, (_vertices[0] + _vertices[numOfVertices - 1]) / 2); midGripPnt.xData1 = _vertices[0]; midGripPnt.xData2 = _vertices[numOfVertices - 1]; gripPnts.Add(midGripPnt); } return(gripPnts); }
public override void SetGripPointAt(int index, GripPoint gripPoint, CADPoint newPosition) { if (index == 0) { _center = newPosition; } else if (index >= 1 && index <= 3) { CADPoint startPoint = this.startPoint; CADPoint endPoint = this.endPoint; CADPoint middlePoint = this.middlePoint; if (index == 1) { startPoint = newPosition; middlePoint = (CADPoint)gripPoint.xData1; } else if (index == 2) { endPoint = newPosition; middlePoint = (CADPoint)gripPoint.xData1; } else if (index == 3) { middlePoint = newPosition; } Circle2 newCircle = Circle2.From3Points( startPoint, middlePoint, endPoint); if (newCircle.radius > 0) { CADVector xPositive = new CADVector(1, 0); double startAngle = CADVector.SignedAngleInRadian(xPositive, startPoint - newCircle.center); double endAngle = CADVector.SignedAngleInRadian(xPositive, endPoint - newCircle.center); double middleAngle = CADVector.SignedAngleInRadian(xPositive, middlePoint - newCircle.center); startAngle = MathUtils.NormalizeRadianAngle(startAngle); endAngle = MathUtils.NormalizeRadianAngle(endAngle); middleAngle = MathUtils.NormalizeRadianAngle(middleAngle); _center = newCircle.center; _radius = newCircle.radius; if (AngleInArcRange(middleAngle, startAngle, endAngle)) { this.startAngle = startAngle; this.endAngle = endAngle; } else { this.startAngle = endAngle; this.endAngle = startAngle; } } } }
public override void SetGripPointAt(int index, GripPoint gripPoint, CADPoint newPosition) { if (index == 0) { _center = newPosition; } else if (index >= 1 && index <= 4) { _radius = (newPosition - _center).Length; } }
/// <summary> /// 构造函数 /// </summary> public GripPointMoveCmd(Entity entity, int index, GripPoint gripPoint) { _entity = entity; _entityCopy = entity.Clone() as Entity; _index = index; _gripPoint = gripPoint; _originalGripPos = _gripPoint.position; _resultGripPos = _gripPoint.position; _mousePosInWorld = _gripPoint.position; }
public override void SetGripPointAt(int index, GripPoint gripPoint, CADPoint newPosition) { if (index == 0) { _startPoint = newPosition; } else if (index == 1) { _endPoint = newPosition; } }
public override void SetGripPointAt(int index, GripPoint gripPoint, CADPoint newPosition) { if (index == 0) { _basePoint = newPosition; } else if (index == 1 || index == 2) { CADVector dir = (newPosition - _basePoint).normalized; if (!dir.Equals(new CADVector(0, 0))) { _direction = dir; } } }
public override List <GripPoint> GetGripPoints() { List <GripPoint> gripPnts = new List <GripPoint>(); // gripPnts.Add(new GripPoint(GripPointType.Center, _center)); // GripPoint startGripPnt = new GripPoint(GripPointType.End, startPoint); startGripPnt.xData1 = middlePoint; gripPnts.Add(startGripPnt); // GripPoint endGripPnt = new GripPoint(GripPointType.End, endPoint); endGripPnt.xData1 = middlePoint; gripPnts.Add(endGripPnt); // gripPnts.Add(new GripPoint(GripPointType.Mid, middlePoint)); return(gripPnts); }
public CADGripVisual(IDrawing drawing, GripPoint gripPoint) : base(drawing) { _gripPoint = gripPoint; }
public virtual void SetGripPointAt(int index, GripPoint gripPoint, CADPoint newPosition) { }
// Start is called before the first frame update void Start() { gp = GetComponent <GripPoint>(); }
public void UpdateGripPointFlow(float dt) { //create and destroy grippoints currentgGripPointSpawnTimer -= dt; if (currentgGripPointSpawnTimer < 0) { if (connected == null || GripPoint.lifeTimeConnected > 0.01) { GripPoint gp = Instantiate(gripPointPrefab).GetComponent <GripPoint>(); gp.InitLifeTime(); gp.transform.SetParent(transform); gp.p = p; gripPoints.Add(gp); if (connected) { gp.lifeTime *= GripPoint.lifeTimeConnected; } } currentgGripPointSpawnTimer = gripPointSpawnTimer; } List <GripPoint> remove = new List <GripPoint>(); int gps = gripPoints.Count; foreach (GripPoint gp in gripPoints) { if (gp.lifeTime < 0 || gps > maxGripPoints) { remove.Add(gp); --gps; } } foreach (GripPoint r in remove) { gripPoints.Remove(r); Destroy(r.gameObject); } //add flow force Vector3 flowDir = p - parentCell.center; flowDir.Normalize(); if (connected == null) { p += flowDir * flowForce; } else { if (connectionModel == OriginPointConnectionModel.ToMidPoint) { Vector3 c = (p + connected.p) * 0.5f; Vector3 diff = c - p; p += diff; connected.p -= diff; } else if (connectionModel == OriginPointConnectionModel.ToSurfaceOfCell) { Vector3 diff = p - connected.parentCell.center; float distance = diff.magnitude; if (distance > 0.001f) { p -= diff * (distance - connected.parentCell.r) / distance; } } else { p = connected.parentCell.center; connected.p = parentCell.center; } } }
public CADGripVisual(IDrawing drawing, GripPoint gripPoint, IDrawingVisual associatedVisual) : base(drawing) { _gripPoint = gripPoint; AssociatedVisual = associatedVisual; }