WIl*_*JBD 0 java android opengl-es
这是我用来飞过我的精灵表的方法.在对象类中,我跟踪信息并进行所有循环,这基本上只需要分配纹理映射坐标.只是它似乎没有工作.但我记录了我翻转行/列的方式,它正确循环.但就纹理而言,我什么都看不到.一点都不 我错过了什么吗?
public void SetToAnimatedTexture(int NumFramesWide, int NumFramesTall, int CurrentRow, int CurrentColumn) {
/*****************************************************************************************
* This Assembles our Vertices in the correct spots by disassembling
* our custom rectangles corners, and adds animation. Call this after creating the meshRect
* *****************************************************************************************/
float frameWidth = 1/NumFramesWide;
float frameHeight = 1/NumFramesTall;
float u1 = frameWidth*CurrentColumn;
float u2 = (frameWidth*CurrentColumn) + frameWidth;
float u3 = (frameWidth*CurrentColumn) + frameWidth;
float u4 = frameWidth*CurrentColumn;
float v1 = (frameHeight*CurrentRow) + frameHeight;
float v2 = (frameHeight*CurrentRow) + frameHeight;
float v3 = frameHeight*CurrentRow;
float v4 = frameHeight*CurrentRow;
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(4 * VERTEX_SIZE);
byteBuffer.order(ByteOrder.nativeOrder());
vertices = byteBuffer.asFloatBuffer();
float x1 = (float) rect.BottomLeftCorner.x;
float x2 = (float) rect.BottomRightCorner.x;
float x3 = (float) rect.TopRightCorner.x;
float x4 = (float) rect.TopLeftCorner.x;
float y1 = (float) rect.BottomLeftCorner.y;
float y2 = (float) rect.BottomRightCorner.y;
float y3 = (float) rect.TopRightCorner.y;
float y4 = (float) rect.TopLeftCorner.y;
vertices.put(new float[] { x1, y1, 1, 1, 1, 1, u1, v1,
x2, y2, 1, 1, 1, 1, u2, v2,
x3, y3, 1, 1, 1, 1, u3, v3,
x4, y4, 1, 1, 1, 1, u4, v4 });
// x y r g b A u|s v|t
// x,y are coordinates
// rgba = color red green blue alpha
// u|s v|t = UV or ST texture coordinates
vertices.flip();
byteBuffer = ByteBuffer.allocateDirect(6 * 2);
byteBuffer.order(ByteOrder.nativeOrder());
indices = byteBuffer.asShortBuffer();
indices.put(new short[] { 0, 1, 2,
2, 3, 0 });
indices.flip();
}
Run Code Online (Sandbox Code Playgroud)
这是我为自己设定的框架的一部分.
好的,通过做一些日志记录找出问题.这就是问题
float frameWidth = 1/NumFramesWide;
float frameHeight = 1/NumFramesTall;
Run Code Online (Sandbox Code Playgroud)
它说这两个值都返回0
1/2=0 , 1/4=0
Run Code Online (Sandbox Code Playgroud)
我检查了所有变量的值,这就是问题所在.
它首先进行整数除法然后进行赋值.由于1和NumFrames*整数都是整数,因此最终为0.
您可以通过将代码更改为来解决此问题
float frameWidth = 1.f/NumFramesWide;
float frameHeight = 1.f/NumFramesTall;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1344 次 |
| 最近记录: |