经纹理opengles [英] Warp texture with opengles

查看:115
本文介绍了经纹理opengles的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用opengles 2.0的Andr​​oid应用程序,我有相机preVIEW是这样的:

I'm making an Android app using opengles 2.0 and I have camera preview like this :

在这里输入的形象描述 ,并以此作为纹理。

and using this as a texture.

不过,我想简单地在红色圆环状的一侧弯曲。所以我想该部分从质地和裁剪的映射像一个长方形的形状。但我不知道,部分是究竟是如何农作物有什么方法做到这一点有效?

But I want simply warp in side of the red donut shape. So I'm trying to crop that part from the texture and mapping to a shape like a rectangular. But I don't know how exactly crop that part is there any ways to do that efficiently?

推荐答案

让我们假设我们有一个UV coordinages(S,T)的矩形R,其中S,T元素[0,1]。我们有一个中心C,一个内径里和外半径r给出环。

Lets assume we have a rectangle R with uv coordinages (s, t) where s,t element [0,1]. And we have the ring given by a center C, a inner radius ri and an outer radius ro.

如果我们想要的UV坐标(S,T)中的环的纹理坐标(s_tex,t_tex)映射,那么这可以通过使用以下的公式完成的:

If we want to map the uv coordinates (s,t) to coordinates in the ring texture (s_tex, t_tex), then this can be done by using the following formulas:

//alpha: angle
alpha = t * 2 * PI //maps the [0,1] range of t to [0, 2*PI] (circle)
//r: distance from the center 
r = ir + s * (or - ir) //maps s=[0,1] to [ir, or]

//d: direction from the center c
d = [sin(alpha), cos(alpha)]
//final coordinates
[s_tex, t_tex] = C + d * r

请注意,该 C,RI,RO 在环纹理贴图坐标被赋予。

Note, that C, ri, ro have to be given in texture coordinates of the ring texture.

根据你想拥有在环切(其中矩形的开始/结束映射到的位置),也可以是需要一个常数因子添加到阿尔法。此刻该因子为0时,这意味着该切口从C变为水平向右

Depending on where you want to have the cut in the ring (location where start/end of the rectangle are mapped to), it can be necessary to add a constant factor to alpha. At the moment this factor is 0, which means that the cut goes from C horizontally to the right.

这篇关于经纹理opengles的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆