Equation of a plane.
Transforming the plane space to texture space.
Let C = Point on the polygon to be the texture map's origin. Let P = Any Point on the polygon which will be linked to a texture coordinate. [1, 0, 0, -Cx] [Px] [Px - Cx] [0, 1, 0, -Cy] * [Py] = [Py - Cy] [0, 0, 1, -Cz] [Pz] [Pz - Cz] [0, 0, 0, 1 ] [ 1] [ 1 ]
Rotating a point using three orthogonal unit vectors:
Let P = Point to be rotated around the origin.
Let N = Normalized vector that is orthogonal to the polygon's plane.
Let U = Normalized vector on the polygon's plane that points in the
direction of increasing x in the texture space.
Let V = Normalized vector on the polygon's plane that points in the
direction of increasing y in the texture space.
[Ux, Vx, Nx, 0] [Px] [Ux*Px + Vx*Py + Nx*Pz]
[Uy, Vy, Ny, 0] * [Py] = [Uy*Px + Vy*Py + Ny*Pz]
[Uz, Vz, Nz, 0] [Pz] [Uz*Px + Vz*Py + Nz*Pz]
[ 0, 0, 0, 1] [ 1] [ 1 ]
Rotating a point from the polygon's space to texture space:
Let P = Point in polygon space.
Let N = Normalized vector that is orthogonal to the polygon's plane.
Let U = Normalized vector on the polygon's plane that points in the
direction of increasing x in the texture space.
Let V = Normalized vector on the polygon's plane that points in the
direction of increasing y in the texture space.
[Ux, Uy, Uz, 0] [Px] [Ux*Px + Uy*Py + Uz*Pz]
[Vx, Vy, Vz, 0] * [Py] = [Vx*Px + Vy*Py + Vz*Pz]
[Nx, Ny, Nz, 0] [Pz] [Nx*Px + Ny*Py + Nz*Pz]
[ 0, 0, 0, 1] [ 1] [ 1 ]
Moving from polygon space to texture space:
Let P = Any Point on the polygon which will be linked to a texture coordinate.
Let C = Point on the polygon to be the texture map's origin.
Let N = Normalized vector that is orthogonal to the polygon's plane.
Let U = Normalized vector on the polygon's plane that points in the
direction of increasing x in the texture space.
Let V = Normalized vector on the polygon's plane that points in the
direction of increasing y in the texture space.
[Ux, Uy, Uz, 0] [1, 0, 0, -Cx] [Px]
[Vx, Vy, Vz, 0] * [0, 1, 0, -Cy] * [Py] =
[Nx, Ny, Nz, 0] [0, 0, 1, -Cz] [Pz]
[ 0, 0, 0, 1] [0, 0, 0, 1 ] [ 1]
[Ux*(Px-Cx) + Uy*(Py-Cy) + Uz*(Pz-Cz)]
[Vx*(Px-Cx) + Vy*(Py-Cy) + Vz*(Pz-Cz)]
[Wx*(Px-Cx) + Wy*(Py-Cy) + Wz*(Pz-Cz)]
[ 1 ]
Transforming from screen space to polygon space.
Transforming a point from 3D space to screen space: Let d = The distance between the screen and the focal point. Let P = The 3D point. [d, 0, 0, 0] [Px] [d * Px] [(d * Px) / Pz] [0, d, 0, 0] * [Py] = [d * Py] = [(d * Py) / Pz] [0, 0, 0, 1] [Pz] [ 1 ] [ 1 / Pz ] [0, 0, 1, 0] [ 1] [ Pz ] [ 1 ]
Finding the point on the polygon's plane:
Let N = The plane's normal vector.
Let P = Any point on the plane.
Let (Nx*x) + (Ny*y) + (Nz*z) = (Nx*Px + Ny*Py + Nz*Pz) be the equation of
a plane.
x' = ((d * x) / z)
x = (x' * z) / d
y' = ((d * y) / z)
y = (y' * z) / d
(Nx*((x'*z)/d)) + (Ny((y'*z)/d)) + (Nz*z) = (Nx*Px + Ny*Py + Nz*Pz)
z * (((Nx * x') / d) + ((Ny * y') / d) + Nz) = Nx*Px + Ny*Py + Nz*Pz
z = (Nx*Px + Ny*Py + Nz*Pz) / (((Nx*x')/d) + ((Ny*y')/d) + Nz)
Transforming from screen space to texture space.
Moving from screen space to texture space:
Let (x', y') = The screen coordinates.
Let P = Any Point on the polygon's plane.
Let T = Texture point in texture coordinates.
Let C = Point on the polygon to be the texture map's origin.
Let N = Normalized vector that is orthogonal to the polygon's plane
Let U = Normalized vector on the polygon's plane that points in the
direction of increasing x in the texture space.
Let V = Normalized vector on the polygon's plane that points in the
direction of increasing y in the texture space.
(x'* z ) (y'* z ) ( )
Tx = Ux * (----- - Cx) + Uy * (----- - Cy) + Uz * (z - Cz)
( d ) ( d ) ( )
d * Tx = Ux*x'*z + Uy*y'*z + Uz*d*z - d*(Ux*Cx + Uy*Cy + Uz*Cz)
= z*(Ux*x' + Uy*y' + Uz*d) - d*(Ux*Cx + Uy*Cy + Uz*Cz)
= z*[U,(x', y', d)] - d*[U,C]
z = (Nx*Px + Ny*Py + Nz*Pz) / (((Nx*x')/d) + ((Ny*y')/d) + Nz)
= [N,P] / [N,(x'/d, y'/d, 1)]
d * Tx = ([N,P] / [N,(x'/d, y'/d, 1)])*[U,(x', y', d)] - d*[U,C]
= d * ([N,P] / [N,(x', y', d)])*[U, (x', y', d)] - d*[U,C]
Tx = (([N,P] / [N,(x', y', d)]) * [U, (x', y', d)]) - [U,C]
Ty = (([N,P] / [N,(x', y', d)]) * [V, (x', y', d)]) - [V,C]
Tz = 0
Advanced analysis of the result.
Applying the equations in a program.
Special thanks to: