Kav/Geometry/Sprite.cs

58 lines
1.7 KiB
C#

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Kav
{
public struct Sprite
{
public Texture2D Texture { get; }
public Vector3 Position { get; }
public Vector2 Origin { get; }
public float Rotation { get; }
public Vector2 Scale { get; }
public SpriteBillboardConstraint BillboardConstraint { get; }
public Matrix TransformMatrix { get; }
public Sprite(
Texture2D texture,
Vector3 position,
Vector2 origin,
float rotation,
Vector2 scale,
SpriteBillboardConstraint billboardConstraint = SpriteBillboardConstraint.None
) {
Texture = texture;
Position = position;
Origin = origin;
Rotation = rotation;
Scale = scale;
BillboardConstraint = billboardConstraint;
TransformMatrix = ConstructTransformMatrix(Position, Scale);
}
public Sprite(
Texture2D texture,
Vector3 position,
SpriteBillboardConstraint billboardConstraint = SpriteBillboardConstraint.None
) {
Texture = texture;
Position = position;
Origin = Vector2.Zero;
Rotation = 0;
Scale = Vector2.One;
BillboardConstraint = billboardConstraint;
TransformMatrix = ConstructTransformMatrix(Position, Scale);
}
private static Matrix ConstructTransformMatrix(
Vector3 position,
Vector2 scale
) {
return
Matrix.CreateTranslation(position) *
Matrix.CreateScale(scale.X, scale.Y, 1);
}
}
}