android - Convert canvas coordinate system to OpenGLES 2.0 coordinates -
i started drawing hexagonal grid on canvas path object. did calculations on how many hexagons go on particular display, depending on hexagon size.
i have hexagon coordinates calculated depending on canvas. now, have serious performance issues , have port opengl.
because algorithm works in canvas, i'm trying convert "canvas" hexagon coordinates opengl coordinate system glu.gluunproject.
"for loop"
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; because lack opengl knowledge, dont know how set glviewport,gluperspective,gltranslatef 2d world "the same" canvas.
so question is:
how set 3 thing first hexagon (on canvas, first 1 top left) equal on opengl drawing surface world?
update
thank you're interest of helping on problem. but:
i set 18 float vertices array follows: [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); and draw:
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); before draw set: 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();
you have no need transform vertices coordinates. have provide correct projection matrix opengl.
basically, along lines of :
glviewport(0, 0, canvaswidth, canvasheight); glmatrixmode(gl_projection); // or matrix uniform if using shaders glloadidentity(); glortho(0, canvaswidth, canvasheight, 0, -1, 1); // allow pass vertices in 'canvas pixel' coordinates glmatrixmode(gl_modelview); glloadidentity(); depending on order in you're passing vertices, might want make culling disabled.
Comments
Post a Comment