1

**Off Topic / 2d background parallax combined with planetoid curvature**

« **on:**August 20, 2022, 01:08:33 AM »

this is a really strange general math question im putting here before i post to stack exchange. this doesn't belong in mod discussion because it is not for blockland, it is just a general problem that i've been trying to wrap my head around.

i am trying to combine two different visual effects into one which i can mentally picture but on paper seems physically impossible. the two effects are as follows:

this one is simple. its multiple layers that use coordinates relative to the player but move at different scales to give the illusion of depth. layers that move slower (ie 1/2th the coordinates of the player) appear farther, while those that move faster fit well in a foreground.

this one is a little more complicated. it usually involves deforming/texturing a circle/sphere procedurally and it uses a radial coordinate system (coordinates can repeat and are maximum 360 degrees)

typical parallax uses a 2d cartesian x-y coordinate system, while planetoids/circles use 2d polar r-θ coordinate system. although they can be converted between each other, a polar parallax has several problems. first, all background layers of a planet must be the same or larger in radius in order to be visible to the camera (bigger than the planet). second, they must rotate slower than the camera rotates around the planet. the 'slower rotation' of the background circle is what is stumping me up. this is only for backgrounds, while foregrounds suffer from a similar but opposite spectrum of problems.

a slower circular background will have more data than required to display, as it will take more relative rotations of the planet to fully view all its data. this data (the 'dark side' of the planet) will never actually be viewed or used by the game because it isn't physically sound and is irrelevant. a faster circular background (foreground) will have less data than can be displayed on one rotation, leading to a problem of packing more than one rotation's worth of background into one rotation.

i drew a diagram to help communicate the ideas.

green circle - outer background circle (rotates at 0.5x speed)

red circle - inner planet circle (rotates at 1x speed)

if you superimpose two circles on each other and have the outer one rotate at 0.5 speed the inner one, by the time you traverse half the planet you would've traversed a quarter of the outer circle's background

this works fine until you traverse the whole planet once, after which you've only traversed half of the outer circle. this means, your second run around the red circle, you'd have an entirely different side of the outer circle. one hacky handicapped solution i found was to just cut the outer circle in half. since only half of the outer background can be viewed in one full planetary rotation, there is no need to display/store the other half. this half could be cloned on the opposite side of the planet and the seams connected to give the illusion of one continuous circular parallax background

this solution is far from ideal and i'm still looking for a more sound, mathematical solution. for example, this method is a mind forget on foreground (backgrounds that parallax faster than the planet) because it requires packing two circles' worth of data into one. if anyone has ever encountered a mathematically similar problem in the field of trigonometry and has some insight i'd love to hear it. this problem has been driving me partially insane for the last 5 months and has been a major holdup for one of my game design projects.

i am trying to combine two different visual effects into one which i can mentally picture but on paper seems physically impossible. the two effects are as follows:

**2d parallax**this one is simple. its multiple layers that use coordinates relative to the player but move at different scales to give the illusion of depth. layers that move slower (ie 1/2th the coordinates of the player) appear farther, while those that move faster fit well in a foreground.

**2d planetoid with curvature**this one is a little more complicated. it usually involves deforming/texturing a circle/sphere procedurally and it uses a radial coordinate system (coordinates can repeat and are maximum 360 degrees)

**the problem: combining the two.**typical parallax uses a 2d cartesian x-y coordinate system, while planetoids/circles use 2d polar r-θ coordinate system. although they can be converted between each other, a polar parallax has several problems. first, all background layers of a planet must be the same or larger in radius in order to be visible to the camera (bigger than the planet). second, they must rotate slower than the camera rotates around the planet. the 'slower rotation' of the background circle is what is stumping me up. this is only for backgrounds, while foregrounds suffer from a similar but opposite spectrum of problems.

a slower circular background will have more data than required to display, as it will take more relative rotations of the planet to fully view all its data. this data (the 'dark side' of the planet) will never actually be viewed or used by the game because it isn't physically sound and is irrelevant. a faster circular background (foreground) will have less data than can be displayed on one rotation, leading to a problem of packing more than one rotation's worth of background into one rotation.

i drew a diagram to help communicate the ideas.

green circle - outer background circle (rotates at 0.5x speed)

red circle - inner planet circle (rotates at 1x speed)

if you superimpose two circles on each other and have the outer one rotate at 0.5 speed the inner one, by the time you traverse half the planet you would've traversed a quarter of the outer circle's background

this works fine until you traverse the whole planet once, after which you've only traversed half of the outer circle. this means, your second run around the red circle, you'd have an entirely different side of the outer circle. one hacky handicapped solution i found was to just cut the outer circle in half. since only half of the outer background can be viewed in one full planetary rotation, there is no need to display/store the other half. this half could be cloned on the opposite side of the planet and the seams connected to give the illusion of one continuous circular parallax background

this solution is far from ideal and i'm still looking for a more sound, mathematical solution. for example, this method is a mind forget on foreground (backgrounds that parallax faster than the planet) because it requires packing two circles' worth of data into one. if anyone has ever encountered a mathematically similar problem in the field of trigonometry and has some insight i'd love to hear it. this problem has been driving me partially insane for the last 5 months and has been a major holdup for one of my game design projects.