![]() So, you need to loop through the square that contains the circle. The algorithms you need to use are the pythagorean theorem ( √(x² + y²)) and the width of a circle at a specific height ( 2√(r² + |y - cy|²) where cy is the y coordinate of the circle). You could try all kinds of other formulae, or even go for a perspective camera look instead of the orthographic version I've shown here.įirst of all, this is going to cut corners, as this API is very small (I have concerns about the maximum 8192 tokens rule, which technically makes this non-turing-complete). Of course these are just a few different ways you could get a bulged look. Closer to the center, this shrinks the length of our local offset vector (down to a controllable minimum set by the 0.35 linear interpolation constant), which has the effect of magnifying features close to the middle. If you're looking for something to give a more bulgy look without the trig, you can use something like a lens distortion for a cheap hack: scale = 0.35 * magSq + (1 - 0.35)Īt the edges of the disc, scale is 1 so there's no difference versus the flat version. This may or may not be an issue in your case. The downside is that transcendentals like the arcsine function can be expensive. This gives the version second from the right, which you can see is a very good match for rendering a real 3D sphere (far right). The idea is to map asin(-1).asin(1) back into the range -1.1) If using another unit, divide by whatever value corresponds to 90 degrees, instead of by pi/2. (This assumes asin's return value is in radians. If we want an exactly correct sphere as viewed by an orthographic camera, we can use inverse trig functions to convert to latitude & longitude: widthAtHeight = sqrt(1 - py * py) Here's an equivalent implementation of Bálint's suggestion in this form: widthAtHeight = sqrt(1 - py * py) If you just use this as-is, you'll get the left version: it's cropped to a circle and wraps around, but it's very flat-looking.īy tweaking px and py where it says " TODO" we can get different bending effects. look up the corresponding colour from the map texture & plot it wrap the horizontal coordinate around our map when it goes off the edge U = time * rotationSpeed + (px + 1) * (mapHeight/2) convert our local offsets into lookup coordinates into our map texture TODO: warp our local offset vector px py to imitate 3D bulge ![]() if we're outside the circle, draw black/background and skip ahead get the squared magnitude of this vector convert pixel position into a vector relative to the center, iterate over each pixel in the discSize x discSize bounding square Since I'm not deeply familiar with Pico-8 syntax & conventions, I'll try to present these as pseudo-code that should be reasonably straightforward to translate / token-reduce as needed. Here's a rundown of a few different ways we can sample a panning texture to make it look like a globe.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |