Skip to content

Instantly share code, notes, and snippets.

@StillManic
Created June 21, 2015 19:58
Show Gist options
  • Save StillManic/f6c2932aaefd3896379e to your computer and use it in GitHub Desktop.
Save StillManic/f6c2932aaefd3896379e to your computer and use it in GitHub Desktop.
@SuppressWarnings("unchecked")
private final void putVertexData(Vertex v, TextureCoordinate t, Normal n, TextureAtlasSprite sprite)
{
int oldPos = buffer.position();
Number[] ns = new Number[16];
for (int i = 0; i < ns.length; i++)
ns[i] = 0f;
for (VertexFormatElement e : (List<VertexFormatElement>) format.getElements())
{
switch (e.getUsage())
{
case POSITION:
put(e, v.position.x, v.position.y, v.position.z, 1f);
break;
case COLOR:
if (v.color != null)
put(e, v.color.x, v.color.y, v.color.z, v.color.w);
else
put(e, 1f, 1f, 1f, 1f);
break;
case UV:
if (t != null)
{
put(e, sprite.getInterpolatedU(t.getPosition().x * 16), sprite.getInterpolatedV(t.getPosition().y * 16), 0f, 1f);
}
else
put(e, 0f, 0f, 0f, 1f);
break;
case NORMAL:
put(e, n.normal.x, n.normal.y, n.normal.z, 1f);
break;
case GENERIC:
put(e, 0f, 0f, 0f, 0f);
break;
default:
break;
}
}
buffer.position(oldPos + format.getNextOffset());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment