Mail Archives: djgpp/1997/04/05/12:21:43
ellman AT xs4all DOT nl () wrote:
>Using that Z and the X and Y, I get the vector from the middle of the sphere to
>the point I've just calculated. This is divided by the radius (or multiplied
>by 1/radius which can be calculated outside the loop) to get the
>unit vector (the Y component is normalised outside the loop for drawing a
>line of pixels).
I think there was a question about how to texture-map a sphere. Using
the vector you've calculated there, it should be very simple,
depending on what kind of projection you prefer, of course.
The easiest projection I can think of can be done this way: First,
apply a rotation matrix to your vector, if you want your sphere to be
rotatable. Use the Y component of the result vector directly to get
TY. Pass the X and Z components to Allegro's fatan2() function to get
TX. Translate&scale these values into the appropriate range (texture
size), then you have TX and TY pointing to somewhere in the texture.
Then just apply that color to your sphere pixel.
This projection should be the appropriate one for applying, for
example, the Geosphere satellite image of the Earth. (I once wanted to
do this, but never got much longer than working out this math...)
(If you want to use the Mercator projection instead, TY can be
calculated from fasin(Y) or something, I think.)
- Raw text -