简体   繁体   English

Android OpenGL ES 2.0 3D透视

[英]Android OpenGL ES 2.0 3D Perspective

I am new to OpenGL ES 2.0 on Android, I have managed to use Matrix.orthoM to create an orthographic view, but I am currently having problems trying to get a perspective view. 我是Android上的OpenGL ES 2.0的新手,我设法使用Matrix.orthoM创建正交视图,但是目前在尝试获取透视图时遇到问题。 I know that using LWJGL I can use GLU.gluPerspective to achieve this, and I know that you can do this on Android using OpenGL ES 1.0, but I don't know how to get this working in the same way in OpenGL ES 2.0. 我知道使用LWJGL可以使用GLU.gluPerspective来实现此目的,并且我知道您可以在使用OpenGL ES 1.0的Android上做到这一点,但是我不知道如何在OpenGL ES 2.0中以相同的方式工作。 I found out that there was a way to do this using Matrix.perspectiveM, but this is only available for API 14, so this is not really suitable. 我发现有一种使用Matrix.perspectiveM进行此操作的方法,但这仅适用于API 14,因此这实际上并不适合。 Is there another way I can get a perspective view working? 有没有其他方法可以使透视图起作用?

Thank you. 谢谢。

You can create your own perspective matrix. 您可以创建自己的透视矩阵。 See this link it can help you 看到此链接可以为您提供帮助

function sample to define the matrix(not tested): 函数样本以定义矩阵(未测试):

void setperspectivemat(float[] mat, float near, float far, float fov)
{

 float scale = 1 / Math.tan(Math.toRadians(fov * 0.5));
 mat[0] = scale;
 mat[5] = scale;
 mat[10] = - far / (far - near);
 mat[11] = - far * near / (far - near);
 mat[14] = - 1;
 mat[15] = 0;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM