public void Move() { if (k2 == 4 && d1 == Direction1.up) { d1 = Direction1.down; } else if (k2 == 4 && d1 == Direction1.down) { d1 = Direction1.up; } if (k2 == 8) { if (d2 == Direction2.right) { d2 = Direction2.left; } else { d2 = Direction2.right; } k2 = 0; } k2++; }
public Snake(int x, int y) { this.x = x; this.y = y; d1 = Direction1.up; d2 = Direction2.right; }
/// <summary> /// Calculate the CenterPoint base on Australia single-point layout algorithm. /// </summary> /// <param name="runWidth">Stairs Runwidth</param> /// <param name="offset1">CenterPoint Offset from the first inner boundary</param> /// <param name="offset2">CenterPoint Offset from the second inner boundary</param> public void Construct(double runWidth, double offset1, double offset2) { XYZ bisectDir = (Direction2 - Direction1).Normalize(); XYZ perpendicularDir1 = new XYZ(-Direction1.Y, Direction1.X, 0); XYZ perpendicularDir2 = new XYZ(-Direction2.Y, Direction2.X, 0); if (bisectDir.DotProduct(perpendicularDir1) < 0) { perpendicularDir1 = perpendicularDir1.Negate(); perpendicularDir2 = perpendicularDir2.Negate(); } Line line1Offset = Line.CreateUnbound( CornerPoint + perpendicularDir1 * (runWidth + offset1), Direction1); Line line2Offset = Line.CreateUnbound( CornerPoint + perpendicularDir2 * (runWidth + offset2), Direction2); IntersectionResultArray xsect; line1Offset.Intersect(line2Offset, out xsect); CenterPoint = xsect.get_Item(0).XYZPoint; Line line1 = Line.CreateUnbound(CornerPoint, Direction1.Negate()); Line line2 = Line.CreateUnbound(CornerPoint, Direction2); var proj1 = line1.Project(CenterPoint); var proj2 = line2.Project(CenterPoint); Distance1 = proj1.Parameter; Distance2 = proj2.Parameter; }
void Rotate(Direction1 direction) { _rotationDirection = direction; _moving = true; _totalRotation = 0; switch (_rotationDirection) { case Direction1.East: _pivot = transform.position + new Vector3(_scale.x, -_scale.y, 0); break; case Direction1.West: _pivot = transform.position + new Vector3(-_scale.x, -_scale.y, 0); break; case Direction1.North: _pivot = transform.position + new Vector3(0, -_scale.y, _scale.z); break; case Direction1.South: _pivot = transform.position + new Vector3(0, -_scale.y, -_scale.z); break; } if ((_rotationDirection == Direction1.East) || (_rotationDirection == Direction1.West)) { _axis = Vector3.forward; float temp = _scale.x; _scale.x = _scale.y; _scale.y = temp; } else { _axis = Vector3.right; float temp = _scale.z; _scale.z = _scale.y; _scale.y = temp; } }
/// <summary> Get the normal of the <see cref="AxisAlignedBox"/> at a specified <paramref name="position"/> </summary> /// <param name="position">The surface position to get the normal for</param> /// <returns>The normal at the specified <paramref name="position"/></returns> public Normal3 SurfaceNormal(Position3 position) { Direction3 direction = (position - Center) / (Position3.Origin + Size); Direction1 x = IDirection1.Abs(direction.X); Direction1 y = IDirection1.Abs(direction.Y); Direction1 z = IDirection1.Abs(direction.Z); Normal3 normal; if (x > y && x > z) { normal = direction.X > 0f ? Normal3.UnitX : -Normal3.UnitX; } else if (y > z) { normal = direction.Y > 0f ? Normal3.UnitY : -Normal3.UnitY; } else { normal = direction.Z > 0f ? Normal3.UnitZ : -Normal3.UnitZ; } return(normal); }