[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ] [ Search: ] Instructions for Texture Mapper

In the Crystal Space map file, the ‘orig’, ‘first’, and ‘second’ vertex keywords describe the texture plane. What Crystal Space does internally is to create a transformation matrix/vector which translates object space (3D coordinates) to texture space (u,v coordinates). Here is how this works.

First a few definitions:

Vo, V1 and V2 are vertices in object space. These define the local coordinate system for texture space. So we have the following mapping:

Vo ==> (0,0)
V1 ==> (L1,0)
V2 ==> (0,L2)

It is important to realize that the coordinate (0,0) in texture space is the top-left coordinate of the texture and (1,1) is the bottom-right corner. The coordinate (2,2) is thus the bottom-right corner of a tiled texture (2x2 times).

The conversion to the matrix happens as follows:

Vu = (len1 / l1) * (V1-Vo)
Vv = (len2 / l2) * (V2-Vo)

      / Vu.x Vv.x 1 \
Mot = | Vu.y Vv.y 1 |
      \ Vu.z Vv.z 1 /

The last column represents the W texture component which is not used.

Vot = <Vo.x Vo.y Vo.z>

So Mot and Vot are the transformation matrix/vector to go from object to texture space. Use these as follows:

T = Mot * (O - Vot)

With O being the object space vector that you want to convert and T the texture space vector. Only the x and y components are used of T. x represents u and y represents v.

Using the last equation you can convert every point of your polygon to texture space.

This document was generated using texi2html 1.76.