我该如何申请正确的观点这个OpenGL

我该如何申请正确的观点这个OpenGL

本文介绍了我该如何申请正确的观点这个OpenGL ES的质地?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想说明我的目标,并获得建议的解决方案的一些反馈。我是很新的OpenGL ES的(或OpenGL在所有的),所以请温柔。我也想提一提,该平台是iPad的(IOS)与它的属于限制。

I would like to describe my objective and get some feedback of a proposed solution. I am quite new to OpenGL ES (or OpenGL at all), so please be gentle. I would also like to mention that the platform is iPad (iOS) with it's belonging restrictions.

目标:让用户处的顶点,其中,质地应在适当的正确的观点(或至少是可调节的角度)绘制。为了解释我的意思,请看下面的例子。

Objective: To let the user place vertices in which a texture should be drawn properly in the correct perspective (or at least adjustable perspective). To explain what I mean, consider the following example.

让我们说,我们有一所房子,在它前面相应的草坪的照片。现在,我要走出一条(用户)指定用砖(纹理)的路径,这样的角度看起来正确。如果视图仅仅是正交的,瓷砖将完全正方形具有图像中的某种深度时,这是不现实的。

Let's say that we have a photograph of a house with a corresponding lawn in front of it. Now, I want to pave a (user) specified path with tiles (texture) such that the perspective looks right. If the view is just orthogonal, the tiles will be completely square which is not realistic when having some sort of depth in the image.

现在,一种方法是建立与OpenGL ES的截锥体的透视图。然后把一个平面(如下图所示),并把图像纹理它对于初学者。

Now, one approach would be to set up an perspective view with a frustum on OpenGL ES. Then put a plane (like below) and put the image texture on it for starters.

现在,你从上图的外观期望,图像将被扭曲。但是,这很好,因为如果我们向后倾斜的平面(使其适合显示的边界完全)的图像会出现平方米。

Now as you expect from the look of the image above, the image will be distorted. But it's fine because if we tilt the plane backwards (so that it fit the bounds of the display perfectly) the image will appear square.

如果现在用户定义的区域进行铺设,我们可以把这些点在同一角度的倾斜面,然后只要把方形瓷砖纹理的话,他们会出现一个视角。如果我们的倾斜角是不正确时,用户可以手动调整它,然后什么情况是,在上述图中的平面的拐角角度将被调整,以及面将倾斜不同,以适合显示。然后切片纹理将出现从一个不同的角度。

If the user now defines the area to be paved, we can put those points in the same angle as the tilted plane, and then just put a texture with square tiles in it, and they will appear with a perspective. If our tilt angle is incorrect, the user can adjust it manually, what then happens is that the corner angles of the plane in the above figure will be adjusted and the plane will tilt differently to fit the display. The tiles texture will then appear from a different angle.

这是一个可行的办法或者是有一些其他的,更好的方法来做到这一点?我认为这是可能都与我的3D编程技能有限的丑陋的黑客攻击。

Is this a workable approach or is there some other, better way to do this? I think it's an ugly hack that might have to do with my limited skills in 3D programming.

推荐答案

如果你想要做的是应用透视图像,你可能甚至不需要的OpenGL ES了点。你可以简单地创建一个适当的CATransform3D并设置在我描述这个答案的方式一个UIView或CALayer的。关键是变换矩阵的 M34 部分。

If all you want to do is apply perspective to an image, you may not even need OpenGL ES for that. You could simply create a proper CATransform3D and set that to a UIView or CALayer in the manner that I describe in this answer. The key is the m34 component of the transform matrix.

如果您仍然希望使用OpenGL ES和纹理做到这一点,你可以申请转换到纹理的四边形的顶点来创建一个透视效果。这方面的例子在这里可以看到:

If you still want to do this with OpenGL ES and a texture, you could apply a transformation to the vertices of your textured quad to create a perspective effect. An example of this can be seen here:

我的变换显示摄像机输入的纹理,使其具有应用了透视效果。这使用以下顶点着色器完成的:

where I transform a texture displaying camera input so that it has a perspective effect applied to it. This was done using the following vertex shader:

 attribute vec4 position;
 attribute vec4 inputTextureCoordinate;

 uniform mat4 transformMatrix;
 uniform mat4 orthographicMatrix;

 varying vec2 textureCoordinate;

 void main()
 {
     gl_Position = transformMatrix * vec4(position.xyz, 1.0) * orthographicMatrix;
     textureCoordinate = inputTextureCoordinate.xy;
 }

,其中我会产生以下述方式基于一个CATransform3D一个矩阵:

where I'd generated a matrix based on a CATransform3D in the following manner:

 CATransform3D perspectiveTransform = CATransform3DIdentity;
 perspectiveTransform.m34 = 0.4;
 perspectiveTransform.m33 = 0.4;
 perspectiveTransform = CATransform3DScale(perspectiveTransform, 0.75, 0.75, 0.75);
 perspectiveTransform = CATransform3DRotate(perspectiveTransform, rotation, 0.0, 1.0, 0.0);

和再转换的CATransform3D到一个mat4(它有一个4×4矩阵的内部结构,所以这是很容易做到)。如果你想看到这个动作,抢code在我的 GPUImage 的FilterShowcase示例应用程序框架和尝试的3-D变换条目。在code是所有在GPUImageTransformFilter,应该是比较容易理解。

and then converted the CATransform3D to a mat4 (it has a 4x4 matrix internal structure, so this is fairly easy to do). If you want to see this in action, grab the code for the FilterShowcase sample application in my GPUImage framework and try the 3-D Transform entry. The code is all in the GPUImageTransformFilter and should be reasonably easy to follow.

这篇关于我该如何申请正确的观点这个OpenGL ES的质地?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 15:50