1
我正在嘗試使窗口展開時,其中的對象保持大小。調整窗口大小時的Java OpenGL 3D對象不保持大小
我繪製的頂部2D圖像(圖片中的白色圖標)在調整大小,保持大小和位置時工作得很好,而首先繪製的3D無法保持大小和位置。
這裏是我的投影矩陣功能:
public static FloatMatrix getPerspectiveMatrix(
Double fov, float w, float h, float near, float far
){
float asp = w/h;
float fov_cos = (float) Math.cos(fov/2.0d);
float fov_sin = (float) Math.sin(fov/2.0d);
float fov_cot = fov_cos/fov_sin;
float a_0 = fov_cot/asp;
float a_3 = (far + near)/(near-far);
float a_43 = (2.0f * far * near)/(near-far);
float[] an = {
a_0, 0.0f, 0.0f, 0.0f,
0.0f, fov_cot, 0.0f, 0.0f,
0.0f, 0.0f, a_3, -1.0f,
0.0f, 0.0f, a_43, 0.0f,
};
return new FloatMatrix(an, 4, 4);
}
這是我得到的矩陣在我的渲染功能:
FloatMatrix proj = FloatMatrix.getPerspectiveMatrix(
Math.PI/2.0d, this.width, this.height, 0.1f, 200.0f
);
正交矩陣:
public static FloatMatrix getOrtographicMatrix(
float left, float right, float bottom, float top, float near, float far
){
float a_0 = 2.0f/(right - left);
float a_22 = 2/(top - bottom);
float a_33 = -2/(far - near);
float tx = -(right + left)/(right - left);
float ty = -(top + bottom)/(top - bottom);
float tz = -(far + near)/(far - near);
float[] an = {
a_0, 0.0f, 0.0f, 0.0f,
0.0f, a_22, 0.0f, 0.0f,
0.0f, 0.0f, a_33, 0.0f,
tx, ty, tz, 1.0f
};
return new FloatMatrix(an, 4, 4);
}
我在渲染如何獲得奧托:
FloatMatrix.getOrtographicMatrix(
-this.width/30.0f, this.width/30.0f, -this.height/30.0f, this.height/30.0f, 1.0f, 1.1f
);
圖片示例:
較小的512×512
全屏幕(1080)