So how do you draw a textured polygon in direct3d?
Textured polygon in D3D
BlitzMax Forums/BlitzMax Programming/Textured polygon in D3D Golden! This works great! One question tough...
I'm using these functions to calculate the UV coordinates from the vertices..
However, the texture is stretched when the polygon is aligned in certain ways. Is there a better way to calculate this?
I'm using these functions to calculate the UV coordinates from the vertices..
Function GetU:Float(x:Float,y:Float) Return x/Sqr(x*x + y*y) EndFunction Function GetV:Float(x:Float, y:Float) Return y/Sqr(x*x + y*y) EndFunction
However, the texture is stretched when the polygon is aligned in certain ways. Is there a better way to calculate this?
U, V are the texture coordinates running from 0 to 1 .
X,Y are the geometrical coordinates running from anyvalue1 to anyvalue2.
U,V and X,Y are unrelated to each other until you define a relation: x0 equals 0, x1 equals 1.
Also U,V and X,Y are each orthogonal and linear independent from another so you don't have to invoke V and/or Y if you want to calculate U and vice versa.
Therefore I would code for Transformation (with wrapping) :
X,Y are the geometrical coordinates running from anyvalue1 to anyvalue2.
U,V and X,Y are unrelated to each other until you define a relation: x0 equals 0, x1 equals 1.
Also U,V and X,Y are each orthogonal and linear independent from another so you don't have to invoke V and/or Y if you want to calculate U and vice versa.
Therefore I would code for Transformation (with wrapping) :
Function GetU:Float(x;Int, x0:Int, x1:Int) Local DistX:Float =Abs(x -x0) Mod Float(x1 -x0) If x < x0 then DistX :+(x1 -x0) End If Return DistX /Float(x1- x0) End Function
thanks xMicky, works great!