Textured polygon in D3D

BlitzMax Forums/BlitzMax Programming/Textured polygon in D3D

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) :

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