Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java OpenGL/Android——设置与屏幕像素匹配的2D OpenGL正交坐标系_Java_Android_Math_Graphics_Opengl Es - Fatal编程技术网

Java OpenGL/Android——设置与屏幕像素匹配的2D OpenGL正交坐标系

Java OpenGL/Android——设置与屏幕像素匹配的2D OpenGL正交坐标系,java,android,math,graphics,opengl-es,Java,Android,Math,Graphics,Opengl Es,我正在尝试使用OpenGLES1.5在android屏幕上绘制一些圆圈。他们画图,但我希望能够输入x=300,y=500,它将画出以该坐标为中心的圆(例如,在屏幕上的(300500)像素处)。目前,我画并翻译圆圈,但它并不精确,我不知道如何准确地得到我想要的地方:下面是我上次尝试的一些错误代码: //doesn't take w/h ratio into consideration, not sure how to implement that gl.glViewport(0, 0, windo

我正在尝试使用OpenGLES1.5在android屏幕上绘制一些圆圈。他们画图,但我希望能够输入x=300,y=500,它将画出以该坐标为中心的圆(例如,在屏幕上的(300500)像素处)。目前,我画并翻译圆圈,但它并不精确,我不知道如何准确地得到我想要的地方:下面是我上次尝试的一些错误代码:

//doesn't take w/h ratio into consideration, not sure how to implement that
gl.glViewport(0, 0, windowWidth, windowHeight);
gl.glOrthof(0,windowWidth,   0, windowHeight,    1, 2);
GLU.gluLookAt(gl,   0, 0, 5,    0, 0, 0,    0, 1, 0);

//And for drawing a circle, with the desired x and y coordinates:
for (int j = 0; j &lt number_Triangles; j++) {
  x = Math.cos(theta) + xCoor;
  y = Math.sin(theta) + yCoor;
  z = 1;
 theta += 2 * Math.PI / (number_Triangles);
}

如果你在做2D图形,我建议你使用2D(左、右、下、上)。这样,您就可以精确地控制哪些坐标将映射到屏幕的每个边缘

例如,您可以:

gl.glViewport(0,0,窗宽,窗高); GLU.gluOrtho2D(-2.0f,2.0f,-2.0f,2.0f)


对于(int j=……

“但它不精确”:你是什么意思?圆圈的坐标与我使用关卡编辑器生成的x,y坐标不对齐。它们倾斜且偏离中心,我正在寻找精确的控制。