Wow, those were a lot of smiley π I didn't see the review of my comment π however, that is my favorite emotion π
I rewrite the SpriteBatch in MonoGame so it accept the vertice in the same way with libgdx:
Here is the method
public void Draw (Texture2D texture, float[] vertices, Color color, float depth)
{
if (texture == null)
return;
CheckValid(texture);
if (vertices.Length != VertexSize)
throw new ArgumentException("Vertices length must be equal " + VertexSize);
DrawInternal(texture, vertices, color, depth);
}
Here is the DrawInternal:
internal void DrawInternal (Texture2D texture,
float[] vertices,
Color color,
float depth)
{
var item = _batcher.CreateBatchItem();
item.Depth = depth;
item.Texture = texture;
item.Set(vertices, color);
if (_sortMode == SpriteSortMode.Immediate)
_batcher.DrawBatch(_sortMode);
}
And here is the most important thing ( this is in SpriteBatchItem.cs - I add this method π ):
public void Set (float[] vertices, Color color)
{
// 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.
//because texture coordinate in libgdx and xna is different we have some change here
// U2V2 - BL
// U1V1 - TL
// U3V3 - TR
// U4V4 - BR
// bottom left world coor
vertexBL.Position.X = vertices[SpriteBatch.X1];
vertexBL.Position.Y = vertices[SpriteBatch.Y1];
vertexBL.Position.Z = Depth;
vertexBL.Color = color;
vertexBL.TextureCoordinate.X = vertices[SpriteBatch.U1];
vertexBL.TextureCoordinate.Y = vertices[SpriteBatch.V1];
// top left world coor
vertexTL.Position.X = vertices[SpriteBatch.X2];
vertexTL.Position.Y = vertices[SpriteBatch.Y2];
vertexTL.Position.Z = Depth;
vertexTL.Color = color;
vertexTL.TextureCoordinate.X = vertices[SpriteBatch.U2];
vertexTL.TextureCoordinate.Y = vertices[SpriteBatch.V2];
// top right
vertexTR.Position.X = vertices[SpriteBatch.X3];
vertexTR.Position.Y = vertices[SpriteBatch.Y3];
vertexTR.Position.Z = Depth;
vertexTR.Color = color;
vertexTR.TextureCoordinate.X = vertices[SpriteBatch.U3];
vertexTR.TextureCoordinate.Y = vertices[SpriteBatch.V3];
//bottom right
vertexBR.Position.X = vertices[SpriteBatch.X4];
vertexBR.Position.Y = vertices[SpriteBatch.Y4];
vertexBR.Position.Z = Depth;
vertexBR.Color = color;
vertexBR.TextureCoordinate.X = vertices[SpriteBatch.U4];
vertexBR.TextureCoordinate.Y = vertices[SpriteBatch.V4];
}
Here is my alias:
public const int X1 = 0;
public const int Y1 = 1;
public const int U1 = 2;
public const int V1 = 3;
//
public const int X2 = 4;
public const int Y2 = 5;
public const int U2 = 6;
public const int V2 = 7;
//
public const int X3 = 8;
public const int Y3 = 9;
public const int U3 = 10;
public const int V3 = 11;
//
public const int X4 = 12;
public const int Y4 = 13;
public const int U4 = 14;
public const int V4 = 15;
public const int VertexSize = 16;
However the UV in libgdx is not the same as MonoGame so you need a method to Convert it (RegionU,RegionV here is the uv,u2v2 of TextureReiogn in libgdx)
/// <summary>
/// Convert from uv,u2v2 to (BL,TL,TR,BR) vector
/// </summary>
public void ToTextureCoordinate (float[] vertices)
{
if (vertices.Length != 16)
return;
// ============= Bottom left (u v2) =============
vertices[GdnaBatch.U1] = RegionU;
vertices[GdnaBatch.V1] = RegionV2;
// ============= top left (u v) =============
vertices[GdnaBatch.U2] = RegionU;
vertices[GdnaBatch.V2] = RegionV;
// ============= top right (u2 v)=============
vertices[GdnaBatch.U3] = RegionU2;
vertices[GdnaBatch.V3] = RegionV;
// ============= bottom right (u2 v2) =============
vertices[GdnaBatch.U4] = RegionU2;
vertices[GdnaBatch.V4] = RegionV2;
}
I write it but now I forget whyπ maybe i will explain more when I remember how it work π