1
我開始學習Android的OpenGL ES 2.0。據我的理解,我只能渲染其x和y座標在-1和1之間歸一化的那些值。但突然間,我的代碼行爲有所不同,並且呈現範圍爲-4到4的值。我的理解是正確的還是您是否正確認爲我的代碼有問題?對於投影矩陣OpenGL ES 2.0中的渲染點
MatrixHelper類:
public class MatrixHelper {
public static void perspectiveM(float[] m, float yFovInDegrees, float aspect,
float n, float f) {
final float angleInRadians = (float) (yFovInDegrees * Math.PI/180.0);
final float a = (float) (1.0/Math.tan(angleInRadians/2.0));
m[0] = a/aspect;
m[1] = 0f;
m[2] = 0f;
m[3] = 0f;
m[4] = 0f;
m[5] = a;
m[6] = 0f;
m[7] = 0f;
m[8] = 0f;
m[9] = 0f;
m[10] = -((f + n)/(f - n));
m[11] = -1f;
m[12] = 0f;
m[13] = 0f;
m[14] = -((2f * f * n)/(f - n));
m[15] = 0f;
}
}
這裏是我的同班同學畫線:
public class Well {
private static final int POSITION_COMPONENT_COUNT = 2;
private static final int COLOR_COMPONENT_COUNT = 3;
private static final int STRIDE =
(POSITION_COMPONENT_COUNT + COLOR_COMPONENT_COUNT) * BYTES_PER_FLOAT;
private static final float[] VERTEX_DATA = {
2.57088082911189f,2.70649737162497f, 1f, 0f, 0f,
2.57088082911189f,2.70649737162497f, 1f, 0f, 0f,
};
private final VertexArray vertexArray;
public Well() {
vertexArray = new VertexArray(VERTEX_DATA);
}
public void bindData(ColorShaderProgram colorProgram) {
vertexArray.setVertexAttribPointer(0, colorProgram.getPositionAttributeLocation(), POSITION_COMPONENT_COUNT, STRIDE);
vertexArray.setVertexAttribPointer(POSITION_COMPONENT_COUNT, colorProgram.getColorAttributeLocation(), COLOR_COMPONENT_COUNT, STRIDE);
}
public void draw() {
glDrawArrays(GL_LINE_STRIP, 0, 2);
}
}
默認視口覆蓋兩個座標軸的座標範圍-1到+1。它並不一定要 - 您需要定義投影矩陣和可能的相機轉換矩陣,以便將渲染對象正確映射到屏幕的幾何圖形:http://developer.android.com/guide/topics /graphics/opengl.html請澄清您的具體問題並顯示您的相關代碼。 – NigelK