我開始在畫布上用Path對象繪製六邊形網格。我根據六邊形尺寸對所有顯示器上顯示的六邊形數進行了所有計算。將畫布座標系轉換爲OpenGLES 2.0座標
我有我所有的六角形座標計算取決於畫布。但現在,我有嚴重的性能問題,必須將其移植到OpenGL。
由於該算法在畫布中工作,我試圖用GLU.gluUnProject將這些「畫布」六角形座標轉換爲OpenGL座標系。
「for循環」
float near[] = { 0.0f, 0.0f, 0.0f, 0.0f };
GLU.gluUnProject(b.hexes[ii][jj].points[ii].x,
b.hexes[ii][jj].points[ii].y, 0, mg.mModelView, 0,
mg.mProjection, 0, viewport, 0, near, 0);
vertices[zz] = (float) ((near[0])/near[3]);
zz++;
vertices[zz] = (float) ((near[1])/near[3]);
zz++;
vertices[zz] = 0;
因爲我缺乏OpenGL的知識,我不知道如何glViewport,gluPerspective,的glTranslatef設置爲2D的世界,是 「相同的」 帆布。
所以我的問題是:
如何設置這三個東西,我的第一個六邊形(在畫布上,第一個是左上)是在OpenGL繪圖表面世界平等嗎?
更新
謝謝大家對你的幫助我的問題不感興趣。但是:
我現在將我的18個浮點頂點數組設置如下: [20.0,0.0,0.0,60.0,0.0,0.0,80.0,34.641018,0.0,60.0,69.282036,0.0,20.0,69.282036,0.0,0.0 ,34.641018,0.0] Z是始終爲0。
ByteBuffer vertexByteBuffer = ByteBuffer
.allocateDirect(vertices.length * 4);
vertexByteBuffer.order(ByteOrder.nativeOrder());
vertexBuffer = vertexByteBuffer.asFloatBuffer();
vertexBuffer.put(vertices);
vertexBuffer.position(0);
和繪製:
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glColor4f(0.0f, 1.0f, 0.0f, 0.5f);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0, vertices.length/3);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
繪製之前我設置: onDrawFrame()
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glTranslatef(0.0f, 0.0f, -5.0f);
onSurfaceChanged()
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrthof(0, width, height, 0, -1, 1);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
gluUnProject似乎是錯誤的方式去這裏。如果你只是想從畫布座標系統直接移植到OpenGL,你知道你可以設置opengl座標系爲你想要的任何東西嗎?你應該可以在OpenGL中使用相同的座標而不會出現問題。你能舉一個你正在使用什麼樣的畫布座標的例子,並且想複製嗎? – Tim
好吧,六邊形是由6個x,y座標組成,這是左上角的十六進制座標: 「b.hexes [0] [0] .points [ii] .x」\t 20.0 \t 「b.hexes [0] [0] .points [II] .Y 「\t 0.0 」b.hexes [0] [0] .points [II] .X「 \t \t 60.0 」 b.hexes [0] [0 ] .points [II] .Y 「\t \t 0.0 」b.hexes [0] [0] .points [II] .X「 \t \t 80.0 」 b.hexes [0] [0] .points [ ii] .y「\t 34.641018 \t 「b.hexes [0] [0] .points [II] .X」 \t \t 60.0 「b.hexes [0] [0] .points [II] .Y」 \t \t 69.282036 「 b.hexes [0] [0] .points [II] .X 「\t \t 20.0 」b.hexes [0] [0] .points [II] .Y「 \t \t 69.282036 」 b.hexes [ 0] [0] .points [ii] .x「\t 0.0 \t 」b.hexes [0] [0] .points [ii] .y「\t 34.641018 – Cacamas