Game Development Reference
In-Depth Information
Cylindrical mapping
Cylindrical mapping is a little more complex than planar mapping, since
we need to wrap a 2D image around on itself. Again, we first need to
know which axis we are using. Let us consider what happens when the
image is wrapped around the y -axis. First, we need to know where this
vertical line is centred in the x and z directions. In the same manner as
the planar example, we step through each polygon in the object that
uses this surface, and for each polygon we step through the vertices
one by one.
To determine the centre we interate through all the polygons and
create a minimum and maximum vector defining a bounding box. The
size is found by deleting the minimum from the maximum and the centre
is found by halving the size and adding it to the minimum vector.
The first step in determining the texture coordinates is to create a
vector from the texture's centre to the current vertex. Viewing the object
from above and looking down, we need to determine a value from the
texture image for each vertex in the object. The problem is principally a
2D one; from the x and z values we need to create a value between 0
and 1 that chooses a point from the image between 0 and the width in
pixels of the image. In order to decide this value we will need to
determine the angle, looking straight down from above, between the
z -axis and the vector we have created. The trigonometric function tan is
a ratio of the length of the opposite side over the adjacent side to an
angle. Imagine a right angled triangle with the x value of the vector as
one side and the z value as another. In this case the tangent of the
angle is given by the length along the z -axis divided by the length along
the x -axis. If we know the value of the tangent of an angle, then we can
calculate the angle by using the inverse function arctan. The arctan
function gives values from 0 to 2
. We need values from 0 to 1, so
we must scale the result by dividing by 2
×
. Therefore, in order to
calculate the u value from the texture, that is how far across the bitmap,
we need to determine the angle from the length of the two known sides
of the triangle using the arctan function.
A simple cylindrical map will wrap a texture once around the object.
Toon3D allows this wrap to be tiled so that a single image maps an
arbitrary number of times around the object. If the image should only
map to 60° then repeat, then the wrap would be six times, 360/60.
Equally, the wrap could be less than one; if the wrap was 0.5, then in a
full wrap around the object, only half the texture image width would be
used. We need to take this width wrap into consideration when
determining the texture coordinate. All trig functions use radians, where
Search Nedrilad ::




Custom Search