考虑一个应该在道路上向前移动的汽车对象。我还没有汽车对象,但我稍后会添加那个形状。我现在有一个正方形而不是一辆车,我怎样才能以特定的速度向前移动它?
有任何想法吗?
这是我的代码
public class GLqueue {
private float vertices[] = { 1, 1, -1, // topfront
1, -1, -1, // bofrontright
-1, -1, -1, // botfrontleft
-1, 1, -1,
1, 1, 1,
1, -1, 1,
-1, -1, 1,
-1, 1, 1,
};
private FloatBuffer vertBuff;
private short[] pIndex = { 3, 4, 0, 0, 4, 1, 3, 0, 1,
3, 7, 4, 7, 6, 4, 7, 3, 6,
3, 1, 2, 1, 6, 2, 6, 3, 2,
1, 4, 5, 5, 6, 1, 6, 5, 4,
};
private ShortBuffer pBuff;
public GLqueue() {
ByteBuffer bBuff = ByteBuffer.allocateDirect(vertices.length * 4);
bBuff.order(ByteOrder.nativeOrder());
vertBuff = bBuff.asFloatBuffer();
vertBuff.put(vertices);
vertBuff.position(0);
ByteBuffer pbBuff = ByteBuffer.allocateDirect(pIndex.length * 4);
pbBuff.order(ByteOrder.nativeOrder());
pBuff = pbBuff.asShortBuffer();
pBuff.put(pIndex);
pBuff.position(0);
}
public void draw(GL10 gl) {
gl.glFrontFace(GL10.GL_CW);
gl.glEnable(GL10.GL_CULL_FACE);
gl.glCullFace(GL10.GL_BACK);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glVertexPointer(2, GL10.GL_FLOAT, 0, vertBuff);
gl.glDrawElements(GL10.GL_TRIANGLES, pIndex.length,
GL10.GL_UNSIGNED_SHORT, pBuff);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
gl.glDisable(GL10.GL_CULL_FACE);
}
}