A [[../../99 Old/03 Games/GAM200/Engine/gfx/Texture]] transform is a [[Transformation]] that maps [[Object Space]] to [[Texture Coordinates|Texture Space]].
To render a [[../../99 Old/03 Games/GAM200/Engine/gfx/Mesh]] using a [[../../99 Old/03 Games/GAM200/Engine/gfx/Texture]], you need to assign [[Texture Coordinates]] to each [[Vertex]] of the [[../../99 Old/03 Games/GAM200/Engine/gfx/Mesh]] to be able to calculate the the [[Texture Coordinates]] to use for each [[Pixel]] while rendering the [[../../99 Old/03 Games/GAM200/Engine/gfx/Mesh]].
## Vertex Position -> UV Coordinates
### Non Tiled Image
Of some mesh $M$ with some [[Axis Aligned]] [[Bounding Box]] $B$ with a bottom left position $\vec B_ p$ and size $\vec B_s$, the [[Texture Transform]] to map $M$ to [[Texture Coordinates]] / some [[Bounding Box|Rectangle]] $R$ inside the [[Standard Square]] is:
$\huge
\begin{align}
\mathcal C _{O\to T} &=
T_{\vec R_{p}}
S_{\ang{\vec R_{s}}} \cdot
S_{\ang{\vec B_s}}^{-1} \cdot
T_{\vec R_{p}}^{-1}
\\&=
\mat{
1&0& R_{px} \\
0&1& R_{py} \\
0&0&1
} \cdot
\mat{
\frac{R_{sx}}{B_{sx}} & 0 & 0 \\
0 & \frac{R_{sx}}{B_{sx}} & 0 \\
0&0&1
}
\cdot\mat{
1&0& -B_{p_{}x} \\
0&1& -B_{p_{}y} \\
0&0&1
} \\ &=
\mat{
\frac{R_{sx}}{B_{sx}} & 0 & R_{px} \\
0 & \frac{R_{sx}}{B_{sx}} & R_{py} \\
0&0&1
}
\cdot\mat{
1&0& -B_{p_{}x} \\
0&1& -B_{p_{}y} \\
0&0&1
}
\end{align}
$
### Tiled Image
For a tiled image (assuming [[Texture Wrapping]]), you do the previous [[Texture Transform#Non Tiled Image|transformation]] and apply [[Texture Wrapping]] to that.
To turn a given vertex $V$ into [[Texture Coordinates]] with [[Texture Wrapping]],
$\huge
\tilde T = \op{fract}\pa{\op{fract}\pa{\mathcal C_{O\to T} \tilde V}+1}
$