www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/04/05/12:21:43

From: ovek AT arcticnet DOT no (Ove Kaaven)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Allegro Spheres (was: Re: Z-bufering)
Date: Thu, 03 Apr 1997 12:32:59 GMT
Organization: Vplan Programvare AS
Message-ID: <5i51ei$qs8$1@troll.powertech.no>
References: <33414D32 DOT 147D AT geocities DOT com> <5htheu$cf0$1 AT news0 DOT xs4all DOT nl> <33433811 DOT 455 AT cam DOT org> <5i17tl$h97$1 AT news0 DOT xs4all DOT nl>
NNTP-Posting-Host: alwayscold.darkness.arcticnet.no
Lines: 27
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019