Java OpenGL/Android——设置与屏幕像素匹配的2D OpenGL正交坐标系
我正在尝试使用OpenGLES1.5在android屏幕上绘制一些圆圈。他们画图,但我希望能够输入x=300,y=500,它将画出以该坐标为中心的圆(例如,在屏幕上的(300500)像素处)。目前,我画并翻译圆圈,但它并不精确,我不知道如何准确地得到我想要的地方:下面是我上次尝试的一些错误代码: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
//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 < 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坐标不对齐。它们倾斜且偏离中心,我正在寻找精确的控制。