开发者

Calculating quad coordinates from known points on a texture

开发者 https://www.devze.com 2023-02-19 01:14 出处:网络
I have a texture with 3 specific points on it (in 2d pixel coordinates) mapped to 3d points in a text file.

I have a texture with 3 specific points on it (in 2d pixel coordinates) mapped to 3d points in a text file.

I need to开发者_开发百科 then create the quad to encompass the whole texture but am unsure of how to do this. Any ideas?

For example, the texture is 128x128 pixels, a point on the texture (10,10) is known to be mapped to a 3d coordinate. This goes for the other 2 known coordinates. What I want though is vert coords to encompass the whole texture.


Well, calculate the ratio of world coords to tex coords by getting the distance between two tex coords and the distance between their assigned world coords, as well as the direction vectors. Then generate the corresponding vertices for the quad.

Edit:

Example

  1. Tex(10,10) World (3,3,3)
  2. Tex(20,10) World (4,3,3)

-> pixel distance = 10, world distance = 1 -> 10 pixels represent one world unit.

Now calculate the direction vectors (I'll leave that for you :) ), then take (3,3,3) and add/subtract pixels * 1/10 world units in each of the calculated directions.

0

精彩评论

暂无评论...
验证码 换一张
取 消