-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
Copy pathSpriteBatchItem.cs
99 lines (86 loc) · 3.72 KB
/
SpriteBatchItem.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// MonoGame - Copyright (C) MonoGame Foundation, Inc
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
using System;
namespace Microsoft.Xna.Framework.Graphics
{
internal class SpriteBatchItem : IComparable<SpriteBatchItem>
{
public Texture2D Texture;
public float SortKey;
public VertexPositionColorTexture vertexTL;
public VertexPositionColorTexture vertexTR;
public VertexPositionColorTexture vertexBL;
public VertexPositionColorTexture vertexBR;
public SpriteBatchItem ()
{
vertexTL = new VertexPositionColorTexture();
vertexTR = new VertexPositionColorTexture();
vertexBL = new VertexPositionColorTexture();
vertexBR = new VertexPositionColorTexture();
}
public void Set ( float x, float y, float dx, float dy, float w, float h, float sin, float cos, Color color, Vector2 texCoordTL, Vector2 texCoordBR, float depth )
{
// TODO, Should we be just assigning the Depth Value to Z?
// According to http://blogs.msdn.com/b/shawnhar/archive/2011/01/12/spritebatch-billboards-in-a-3d-world.aspx
// We do.
vertexTL.Position.X = x+dx*cos-dy*sin;
vertexTL.Position.Y = y+dx*sin+dy*cos;
vertexTL.Position.Z = depth;
vertexTL.Color = color;
vertexTL.TextureCoordinate.X = texCoordTL.X;
vertexTL.TextureCoordinate.Y = texCoordTL.Y;
vertexTR.Position.X = x+(dx+w)*cos-dy*sin;
vertexTR.Position.Y = y+(dx+w)*sin+dy*cos;
vertexTR.Position.Z = depth;
vertexTR.Color = color;
vertexTR.TextureCoordinate.X = texCoordBR.X;
vertexTR.TextureCoordinate.Y = texCoordTL.Y;
vertexBL.Position.X = x+dx*cos-(dy+h)*sin;
vertexBL.Position.Y = y+dx*sin+(dy+h)*cos;
vertexBL.Position.Z = depth;
vertexBL.Color = color;
vertexBL.TextureCoordinate.X = texCoordTL.X;
vertexBL.TextureCoordinate.Y = texCoordBR.Y;
vertexBR.Position.X = x+(dx+w)*cos-(dy+h)*sin;
vertexBR.Position.Y = y+(dx+w)*sin+(dy+h)*cos;
vertexBR.Position.Z = depth;
vertexBR.Color = color;
vertexBR.TextureCoordinate.X = texCoordBR.X;
vertexBR.TextureCoordinate.Y = texCoordBR.Y;
}
public void Set(float x, float y, float w, float h, Color color, Vector2 texCoordTL, Vector2 texCoordBR, float depth)
{
vertexTL.Position.X = x;
vertexTL.Position.Y = y;
vertexTL.Position.Z = depth;
vertexTL.Color = color;
vertexTL.TextureCoordinate.X = texCoordTL.X;
vertexTL.TextureCoordinate.Y = texCoordTL.Y;
vertexTR.Position.X = x + w;
vertexTR.Position.Y = y;
vertexTR.Position.Z = depth;
vertexTR.Color = color;
vertexTR.TextureCoordinate.X = texCoordBR.X;
vertexTR.TextureCoordinate.Y = texCoordTL.Y;
vertexBL.Position.X = x;
vertexBL.Position.Y = y + h;
vertexBL.Position.Z = depth;
vertexBL.Color = color;
vertexBL.TextureCoordinate.X = texCoordTL.X;
vertexBL.TextureCoordinate.Y = texCoordBR.Y;
vertexBR.Position.X = x + w;
vertexBR.Position.Y = y + h;
vertexBR.Position.Z = depth;
vertexBR.Color = color;
vertexBR.TextureCoordinate.X = texCoordBR.X;
vertexBR.TextureCoordinate.Y = texCoordBR.Y;
}
#region Implement IComparable
public int CompareTo(SpriteBatchItem other)
{
return SortKey.CompareTo(other.SortKey);
}
#endregion
}
}