public void UpdateVelocity_CLIENT(Vector2 position, Vector2 velocity, float rotation) { curVelocity = velocity; curRotation = rotation; float distance = Vector2.Distance(position, Owner.Transform.GlobalPositionInternal); if (distance >= 32f) { Owner.Transform.Position = position; } else if (distance >= 6f) { snapPosition = position; snapMaxTime = 0.05f; snapTime = 0f; } }
private void Update(EvaluationContext context) { if (IsActve.GetValue(context)) { _maxPointCount = MaxPointCount.GetValue(context); if (TriggerReset.GetValue(context)) { Reset(); } var isMouseDown = IsMouseButtonDown.GetValue(context); if (!isMouseDown && _mouseWasDown) { if (_currentStrokeLength == 1 && _writeIndex > 0) // add to points for single click to make it visible as a dot { var lastPoint = _pointList.TypedElements[_writeIndex - 1]; lastPoint.Position = PointFromMousePos(context, _lastMousePos + new Vector2(0, 0.01f)); AppendPoint(lastPoint); } AppendPoint(Point.Separator()); _currentStrokeLength = 0; } else if (isMouseDown) { var mousePos = MousePos.GetValue(context); if (!_mouseWasDown || Vector2.Distance(_lastMousePos, mousePos) > 0.001f) { AppendPoint(new Point() { Position = PointFromMousePos(context, mousePos), Orientation = Quaternion.Identity, W = 1, }); AppendPoint(Point.Separator(), advanceIndex: false); _currentStrokeLength++; } _lastMousePos = mousePos; } _mouseWasDown = isMouseDown; } PointList.Value = _pointList; }
private void GrowSeed(Seed seed) { Contract.Requires(seed != null); //Decide how far we're going to grow this seed var length = _seedDistance.SelectFloatValue(_random, _metadata); if (length < 0) { throw new InvalidOperationException("Seed distance must be > 0"); } //Find the first edge which is parallel with this one var firstParallel = FindFirstParallelEdge( seed, length * _parallelLengthMultiplier.SelectFloatValue(_random, _metadata), _parallelCheckWidth.SelectFloatValue(_random, _metadata), _cosineParallelAngleThreshold.SelectFloatValue(_random, _metadata) ); //Check for intersections with other edges var firstIntersection = FindFirstIntersection(seed, length + _seedDistance.MinValue); //Reject seeds with parallel edges in certain circumstances if (firstParallel.HasValue) { //There's a parallel edge and we don't intersect anything, so just ignore this seed altogether if (!firstIntersection.HasValue) { return; } //There's a parallel edge and the first intersection if *after* the parallelism starts, so ignore this seed altogether if (firstIntersection.Value.Value.DistanceAlongB > firstParallel.Value.Value) { return; } } if (firstIntersection.HasValue) { var intersectVert = _mesh.GetOrConstructVertex(firstIntersection.Value.Value.Position); if (intersectVert.Equals(seed.Origin)) { return; } //If the edge doesn't contain this vertex already then split the edge we've hit if (!firstIntersection.Value.Key.ConnectsTo(intersectVert)) { HalfEdge ab, bc; _mesh.Split(firstIntersection.Value.Key, intersectVert, out ab, out bc); var t = firstIntersection.Value.Key.Tag ?? firstIntersection.Value.Key.Pair.Tag; ab.Tag = new FloorplanHalfEdgeTag(t.IsImpassable); bc.Tag = new FloorplanHalfEdgeTag(t.IsImpassable); } //Create an edge to this intersection point _mesh.GetOrConstructHalfEdge(seed.Origin, intersectVert).Tag = new FloorplanHalfEdgeTag(false); //If this is not an external wall we can create a seed continuing forward var tag = firstIntersection.Value.Key.Tag ?? firstIntersection.Value.Key.Pair.Tag; var continuationChance = _intersectionContinuationChance.SelectFloatValue(_random, _metadata); if (!tag.IsImpassable && _random.RandomBoolean(1 - continuationChance)) { //New wall will be perpendicular to the wall we've hit... var direction = firstIntersection.Value.Key.Segment.Line.Direction.Perpendicular(); //...but which perpendicular? var dotRight = Vector2.Dot(direction, seed.Direction); var dotLeft = Vector2.Dot(-direction, seed.Direction); if (dotLeft > dotRight) { direction *= -1; } //create new seed var wallLength = Vector2.Distance(seed.Origin.Position, intersectVert.Position); CreateSeed(intersectVert, direction, seed.T + wallLength); } } else { //Create edge along this distance var end = _mesh.GetOrConstructVertex(seed.Origin.Position + seed.Direction * length); _mesh.GetOrConstructHalfEdge(seed.Origin, end).Tag = new FloorplanHalfEdgeTag(false); float seedChance = _seedChance.SelectFloatValue(_random, _metadata); if (_random.RandomBoolean(seedChance)) { CreateSeed(end, seed.Direction, seed.T + length); } else { // Choose which directions to grow in (LF, LR, FR, LFR) we're going to do var newWalls = _random.RandomInteger(0, 3); //Put some seeds at the end (right, left and straight on) if (newWalls != 0) { CreateSeed(end, seed.Direction.Perpendicular(), seed.T + length); } if (newWalls != 2) { CreateSeed(end, -seed.Direction.Perpendicular(), seed.T + length); } if (newWalls != 1) { CreateSeed(end, seed.Direction, seed.T + length); } } } }