Attributes.put (de)normalization now works as intended

This commit is contained in:
RainWarrior 2015-02-16 03:52:51 +03:00
parent f6ca556a38
commit d741b1bafc
2 changed files with 16 additions and 16 deletions

View file

@ -70,7 +70,7 @@ public class Attributes
return true;
}
public static void put(ByteBuffer buf, VertexFormatElement e, boolean normalize, Number fill, Number... ns)
public static void put(ByteBuffer buf, VertexFormatElement e, boolean denormalize, Number fill, Number... ns)
{
if(e.getElementCount() > ns.length && fill == null) throw new IllegalArgumentException("not enough elements");
Number n;
@ -81,22 +81,22 @@ public class Attributes
switch(e.getType())
{
case BYTE:
buf.put(normalize ? (byte)(n.floatValue() / (Byte.MAX_VALUE - 1)) : n.byteValue());
buf.put(denormalize ? (byte)(n.floatValue() * (Byte.MAX_VALUE - 1)) : n.byteValue());
break;
case UBYTE:
buf.put(normalize ? (byte)(n.floatValue() / ((byte) -1)) : n.byteValue());
buf.put(denormalize ? (byte)(n.floatValue() * ((1 << Byte.SIZE) - 1)) : n.byteValue());
break;
case SHORT:
buf.putShort(normalize ? (short)(n.floatValue() / (Short.MAX_VALUE - 1)) : n.shortValue());
buf.putShort(denormalize ? (short)(n.floatValue() * (Short.MAX_VALUE - 1)) : n.shortValue());
break;
case USHORT:
buf.putShort(normalize ? (short)(n.floatValue() / ((short) -1)) : n.shortValue());
buf.putShort(denormalize ? (short)(n.floatValue() * ((1 << Short.SIZE) - 1)) : n.shortValue());
break;
case INT:
buf.putInt(normalize ? (int)(n.doubleValue() / (Integer.MAX_VALUE - 1)) : n.intValue());
buf.putInt(denormalize ? (int)(n.doubleValue() * (Integer.MAX_VALUE - 1)) : n.intValue());
break;
case UINT:
buf.putInt(normalize ? (int)(n.doubleValue() / ((int) - 1)) : n.intValue());
buf.putInt(denormalize ? (int)(n.doubleValue() * ((1L << Integer.SIZE) - 1)) : n.intValue());
break;
case FLOAT:
buf.putFloat(n.floatValue());

View file

@ -470,9 +470,9 @@ public class B3DLoader implements ICustomModelLoader
return quads;
}
private void put(VertexFormatElement e, Number... ns)
private void put(VertexFormatElement e, Float... fs)
{
Attributes.put(buf, e, true, 0, ns);
Attributes.put(buf, e, true, 0f, fs);
}
@SuppressWarnings("unchecked")
@ -487,7 +487,7 @@ public class B3DLoader implements ICustomModelLoader
switch(e.getUsage())
{
case POSITION:
put(e, v.getPos().x, v.getPos().y, v.getPos().z, 1);
put(e, v.getPos().x, v.getPos().y, v.getPos().z, 1f);
break;
case COLOR:
if(v.getColor() != null)
@ -496,7 +496,7 @@ public class B3DLoader implements ICustomModelLoader
}
else
{
put(e, 1, 1, 1, 1);
put(e, 1f, 1f, 1f, 1f);
}
break;
case UV:
@ -506,22 +506,22 @@ public class B3DLoader implements ICustomModelLoader
put(e,
sprite.getInterpolatedU(v.getTexCoords()[0].x * 16),
sprite.getInterpolatedV(v.getTexCoords()[0].y * 16),
0,
1
0f,
1f
);
}
else
{
put(e, 0, 0, 0, 1);
put(e, 0f, 0f, 0f, 1f);
}
break;
case NORMAL:
// TODO
put(e, 0, 1, 0, 1);
put(e, 0f, 1f, 0f, 1f);
break;
case GENERIC:
// TODO
put(e, 0, 0, 0, 1);
put(e, 0f, 0f, 0f, 0f);
break;
default:
break;