Added example function.
m (→The Image: Fixed markup) |
(Added example function.) |
||
| Line 125: | Line 125: | ||
LRy = (-D - AF + CD) / det = ( AF - (1-C)D ) / det | LRy = (-D - AF + CD) / det = ( AF - (1-C)D ) / det | ||
===Example Function=== | |||
The function below will take a texture t, and a matrix with 6 variables as its arguments, and apply the transformation to the texture using the SetTexCoord calculations above. | |||
function setCoords(t, A, B, C, D, E, F) | |||
local det = A*E - B*D; | |||
local ULx, ULy, LLx, LLy, URx, URy, LRx, LRy; | |||
ULx, ULy = ( -B + B*F - C*E ) / det, ( A - A*F + C*D ) / det; | |||
LLx, LLy = ( B*F - C*E ) / det, ( -(A*F) + C*D ) / det; | |||
URx, URy = ( E - B + B*F - C*E ) / det, ( -D + A -(A*F) + C*D ) / det; | |||
LRx, LRy = ( E + B*F - C*E ) / det, ( -D - A*F + C*D ) / det; | |||
t:SetTexCoord(ULx, ULy, LLx, LLy, URx, URy, LRx, LRy); | |||
end | |||
Applying transformations is then rather simple. To apply a rotation to the texture, we can use the rotation matrix below (assuming angle a): | |||
{| | |||
|(||cos(a)||sin(a)||0||) | |||
|- | |||
|(||-sin(a)||cos(a)||0||) | |||
|} | |||
Applying a rotation of 90 degrees can then be done by using: | |||
local cos, sin = math.cos, math.sin; | |||
local angle = math.rad(90); | |||
setCoords(texture, cos(angle), sin(angle), 0, -sin(angle), cos(angle), 0); | |||
[[Category:UI Technical Details]] | [[Category:UI Technical Details]] | ||