本文整理汇总了Java中com.badlogic.gdx.utils.BufferUtils.newShortBuffer方法的典型用法代码示例。如果您正苦于以下问题:Java BufferUtils.newShortBuffer方法的具体用法?Java BufferUtils.newShortBuffer怎么用?Java BufferUtils.newShortBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.badlogic.gdx.utils.BufferUtils
的用法示例。
在下文中一共展示了BufferUtils.newShortBuffer方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: IndexArrayEmulator
import com.badlogic.gdx.utils.BufferUtils; //导入方法依赖的package包/类
/**
* Creates a new IndexBufferObject to be used with vertex arrays.
*
* @param maxIndices
* the maximum number of indices this buffer can hold
*/
public IndexArrayEmulator(int maxIndices) {
this.isDirect = true;
buffer = BufferUtils.newShortBuffer(maxIndices);
buffer.flip();
bufferHandle = Gdx.gl20.glGenBuffer();
usage = GL20.GL_STATIC_DRAW;
}
示例2: IndexBufferObject
import com.badlogic.gdx.utils.BufferUtils; //导入方法依赖的package包/类
/** Creates a new IndexBufferObject.
*
* @param isStatic whether the index buffer is static
* @param maxIndices the maximum number of indices this buffer can hold */
public IndexBufferObject (boolean isStatic, int maxIndices) {
isDirect = true;
buffer = BufferUtils.newShortBuffer(maxIndices);
buffer.flip();
bufferHandle = Gdx.gl20.glGenBuffer();
usage = isStatic ? GL20.GL_STATIC_DRAW : GL20.GL_DYNAMIC_DRAW;
}
示例3: benchShort
import com.badlogic.gdx.utils.BufferUtils; //导入方法依赖的package包/类
private void benchShort () {
ShortBuffer sb = BufferUtils.newShortBuffer(1024 * 1024 / 2);
short[] shorts = new short[1024 * 1024 / 2];
int len = shorts.length;
// relative put
long start = TimeUtils.nanoTime();
for (int j = 0; j < NUM_MB; j++) {
sb.clear();
for (int i = 0; i < len; i++)
sb.put(shorts[i]);
}
Gdx.app.log("BufferUtilsTest", "ShortBuffer relative put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f);
// absolute put
start = TimeUtils.nanoTime();
for (int j = 0; j < NUM_MB; j++) {
sb.clear();
for (int i = 0; i < len; i++)
sb.put(i, shorts[i]);
}
Gdx.app.log("BufferUtilsTest", "ShortBuffer absolute put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f);
// bulk put
start = TimeUtils.nanoTime();
for (int j = 0; j < NUM_MB; j++) {
sb.clear();
sb.put(shorts);
}
Gdx.app.log("BufferUtilsTest", "ShortBuffer bulk put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f);
// JNI put
start = TimeUtils.nanoTime();
for (int j = 0; j < NUM_MB; j++) {
sb.clear();
BufferUtils.copy(shorts, 0, sb, len);
}
Gdx.app.log("BufferUtilsTest", "ShortBuffer native bulk put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f);
}
示例4: create
import com.badlogic.gdx.utils.BufferUtils; //导入方法依赖的package包/类
@Override
public void create () {
super.create();
world.maxSubSteps = 20;
world.add("ground", 0f, 0f, 0f).setColor(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(),
0.25f + 0.5f * (float)Math.random(), 1f);
// Note: not every model is suitable for a one on one translation with a soft body, a better model might be added later.
model = objLoader.loadModel(Gdx.files.internal("data/wheel.obj"));
MeshPart meshPart = model.nodes.get(0).parts.get(0).meshPart;
meshPart.mesh.scale(6, 6, 6);
indexMap = BufferUtils.newShortBuffer(meshPart.numVertices);
positionOffset = meshPart.mesh.getVertexAttribute(Usage.Position).offset;
normalOffset = meshPart.mesh.getVertexAttribute(Usage.Normal).offset;
softBody = new btSoftBody(worldInfo, meshPart.mesh.getVerticesBuffer(), meshPart.mesh.getVertexSize(), positionOffset,
normalOffset, meshPart.mesh.getIndicesBuffer(), meshPart.indexOffset, meshPart.numVertices, indexMap, 0);
// Set mass of the first vertex to zero so its unmovable, comment out this line to make it a fully dynamic body.
softBody.setMass(0, 0);
com.badlogic.gdx.physics.bullet.softbody.btSoftBody.Material pm = softBody.appendMaterial();
pm.setKLST(0.2f);
pm.setFlags(0);
softBody.generateBendingConstraints(2, pm);
// Be careful increasing iterations, it decreases performance (but increases accuracy).
softBody.setConfig_piterations(7);
softBody.setConfig_kDF(0.2f);
softBody.randomizeConstraints();
softBody.setTotalMass(1);
softBody.translate(tmpV.set(1, 5, 1));
((btSoftRigidDynamicsWorld)(world.collisionWorld)).addSoftBody(softBody);
world.add(entity = new BulletEntity(model, (btCollisionObject)null, 1, 5, 1));
}
示例5: create
import com.badlogic.gdx.utils.BufferUtils; //导入方法依赖的package包/类
@Override
public void create () {
super.create();
world.maxSubSteps = 20;
world.add("ground", 0f, 0f, 0f).setColor(0.25f + 0.5f * (float)Math.random(), 0.25f + 0.5f * (float)Math.random(),
0.25f + 0.5f * (float)Math.random(), 1f);
// Note: not every model is suitable for a one on one translation with a soft body, a better model might be added later.
model = objLoader.loadModel(Gdx.files.internal("data/wheel.obj"));
MeshPart meshPart = model.nodes.get(0).parts.get(0).meshPart;
meshPart.mesh.scale(6, 6, 6);
indexMap = BufferUtils.newShortBuffer(meshPart.numVertices);
positionOffset = meshPart.mesh.getVertexAttribute(Usage.Position).offset;
normalOffset = meshPart.mesh.getVertexAttribute(Usage.Normal).offset;
softBody = new btSoftBody(worldInfo, meshPart.mesh.getVerticesBuffer(), meshPart.mesh.getVertexSize(), positionOffset,
normalOffset, meshPart.mesh.getIndicesBuffer(), meshPart.indexOffset, meshPart.numVertices, indexMap, 0);
// Set mass of the first vertex to zero so its unmovable, comment out this line to make it a fully dynamic body.
// softBody.setMass(0, 0); // TODO CHANGED
com.badlogic.gdx.physics.bullet.softbody.btSoftBody.Material pm = softBody.appendMaterial();
pm.setKLST(0.2f);
// pm.setKVST(0.9f);
// softBody.setConfig_kDP(0.2f);
// softBody.setConfig_kCHR(0.99f);
// softBody.setConfig_kKHR(0.99f);
// softBody.setConfig_kSHR(0.99f);
// softBody.setConfig_kVC(0.5f);
// softBody.setConfig_kDF(0.99f);
softBody.setPose(false, false);
pm.setFlags(0);
softBody.generateBendingConstraints(2, pm);
// Be careful increasing iterations, it decreases performance (but increases accuracy).
softBody.setConfig_piterations(40);
softBody.randomizeConstraints();
softBody.setTotalMass(1);
softBody.translate(tmpV.set(5, 5, 5));
((btSoftRigidDynamicsWorld)(world.collisionWorld)).addSoftBody(softBody);
world.add(entity = new BulletEntity(model, (btCollisionObject)null, 1, 5, 1));
shoot(320f, 240f, 20f);
}
示例6: create
import com.badlogic.gdx.utils.BufferUtils; //导入方法依赖的package包/类
@Override
public void create () {
//Not emulated in gwt
//ByteBuffer bytebuffer = BufferUtils.newUnsafeByteBuffer(1000 * 1000);
//BufferUtils.disposeUnsafeByteBuffer(bytebuffer);
ByteBuffer bb = BufferUtils.newByteBuffer(8);
CharBuffer cb = BufferUtils.newCharBuffer(8);
ShortBuffer sb = BufferUtils.newShortBuffer(8);
IntBuffer ib = BufferUtils.newIntBuffer(8);
LongBuffer lb = BufferUtils.newLongBuffer(8);
FloatBuffer fb = BufferUtils.newFloatBuffer(8);
DoubleBuffer db = BufferUtils.newDoubleBuffer(8);
bb.position(4);
BufferUtils.copy(new byte[] {1, 2, 3, 4}, 0, bb, 4);
checkInt(bb.get(), 1);
checkInt(bb.get(), 2);
checkInt(bb.get(), 3);
checkInt(bb.get(), 4);
cb.position(4);
BufferUtils.copy(new char[] {1, 2, 3, 4}, 0, cb, 4);
checkInt(cb.get(), 1);
checkInt(cb.get(), 2);
checkInt(cb.get(), 3);
checkInt(cb.get(), 4);
sb.position(4);
BufferUtils.copy(new short[] {1, 2, 3, 4}, 0, sb, 4);
checkInt(sb.get(), 1);
checkInt(sb.get(), 2);
checkInt(sb.get(), 3);
checkInt(sb.get(), 4);
ib.position(4);
BufferUtils.copy(new int[] {1, 2, 3, 4}, 0, ib, 4);
checkInt(ib.get(), 1);
checkInt(ib.get(), 2);
checkInt(ib.get(), 3);
checkInt(ib.get(), 4);
lb.position(4);
BufferUtils.copy(new long[] {1, 2, 3, 4}, 0, lb, 4);
checkInt(lb.get(), 1);
checkInt(lb.get(), 2);
checkInt(lb.get(), 3);
checkInt(lb.get(), 4);
fb.position(4);
BufferUtils.copy(new float[] {1, 2, 3, 4}, 0, fb, 4);
checkFloat(fb.get(), 1);
checkFloat(fb.get(), 2);
checkFloat(fb.get(), 3);
checkFloat(fb.get(), 4);
if (Gdx.app.getType() != ApplicationType.WebGL) { // gwt throws: NYI: Numbers.doubleToRawLongBits
db.position(4);
BufferUtils.copy(new double[] {1, 2, 3, 4}, 0, db, 4);
checkFloat(db.get(), 1);
checkFloat(db.get(), 2);
checkFloat(db.get(), 3);
checkFloat(db.get(), 4);
}
ByteBuffer bb2 = BufferUtils.newByteBuffer(4);
bb.position(4);
BufferUtils.copy(bb, bb2, 4);
checkInt(bb2.get(), 1);
checkInt(bb2.get(), 2);
checkInt(bb2.get(), 3);
checkInt(bb2.get(), 4);
bench();
}