Reputation: 123
After this question Warp texture with opengles I tried to unwrap donut shape texture to a rectangular. but I have some problems to do this.
To decide the enter, inner radius, outer radius of the donut shape I took a screenshot of the current camera preview and got the actual bitmap/jpg file. Then pick each coordinates for calculating above values then normalize it for texture.
But in Android the Camera Preview is not 1:1 ratio so my screenshot size like 1920x1080 etc..
As you see the donut shape looks just a circle not an ellipse.. but the radius for actual warping is different at horizontal and vertical so when I warp it the result is weired. But If i choose the camera preview in 1:1(I'm using galaxy s6 for this and it supports 1:1 preview size(1088, 1088)) and it correctly warp.
My question is how to get the correct radius? or Is there any different way to warp it in not 1:1 aspect ratio or do I have to only use the camera preview that has 1:1 ratio? Thanks in advance.
Upvotes: 1
Views: 141
Reputation: 1773
Reusing BDL code from previous question, you can apply the aspect ratio to the y component of the direction from center
//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)]
// apply aspect ratio to direction
aspect_ratio = 1920.0 / 1080.0
d.y *= aspect_ratio
//final coordinates
[s_tex, t_tex] = C + d * r
Upvotes: 1