public void CanTurnByRadians(float r1, float radians, float r2) { var rot = new Rotation2d(r1); rot.Turn(radians); DolphAssert.EqualF(r2, rot.Radians); }
public override void Draw(Entity entity) { var sprite = entity.GetComponent <SpriteComponent>(); if (!TryGetAnimatedSprite(sprite, out Rect2d src) && !TryGetStaticSprite(sprite, out src)) { // Can't determine a valid sprite to draw return; } Rect2d dest = entity.Space; // Get the origin before any transformations are applied Vector2d origin = (dest.GetOriginPosition() - dest.TopLeft).ToVector(); Rotation2d rotation = sprite.Rotation; if (sprite.RotationAnimation != null) { rotation.Turn(sprite.RotationAnimation.GetFrame(this.Timer.Total)); } dest.Shift(sprite.Offset); if (sprite.OffsetAnimation != null) { dest.Shift(sprite.OffsetAnimation.GetFrame(this.Timer.Total)); } dest.Scale(sprite.Scale); if (sprite.ScaleAnimation != null) { var animScale = sprite.ScaleAnimation.GetFrame(this.Timer.Total); dest.Scale(animScale); } entity.SetDirective <SpriteDirective>("simple-sprite", sd => { sd.Asset = sprite.SpriteSheet.Name; sd.Source = src; sd.Destination = dest.GetOriginPosition(); sd.Size = dest.GetSize(); sd.Rotation = rotation.Radians; sd.Origin = origin; }); if (sprite.EnableBoxOutline) { entity.SetDirective <PolygonDirective>("simple-sprite-box-outline", pd => { pd.Color = new ColorRGBA(255, 255, 0); pd.Points = dest.ToPolygon().Points; }); } }
public void TestHashCode() { var rot1 = new Rotation2d(5); var rot2 = new Rotation2d(5); Assert.Equal(rot1.GetHashCode(), rot2.GetHashCode()); rot2.Turn(0.1f); Assert.NotEqual(rot1.GetHashCode(), rot2.GetHashCode()); }