Global MaruFight

I’ve attempted to draw MaruFight onto @dave1707’s globe/icosphere.

I feel good that I got it working in some way, but it looks pretty gooby, I think it needs a Mercator projection or something like that and I don’t think I can figure it out.

It would be pretty cool if it worked though right? I would greatly appreciate if anyone could tell me how to fix it. You can see the flaws clearly in the video.

https://youtu.be/KVCHcYt9g2E

Added video

Reminds me of agar.io :slight_smile:

In terms of projection I assume you mean the stretching at the poles? Technically a 2D wrapping space like that would map directly to a torus rather than a sphere.

The only thing I can think of that would map cleanly would be some kind of cube-map: https://en.wikipedia.org/wiki/Cube_mapping

Not sure how that would look though?

@John I agree, a cube map seems like it might be easiest in terms of visuals, but coding-wise it’s difficult for me to get my head around how I’d do the math for when little circle dudes (marus, I guess) move off the side of one part of the cube map.

It seems like it has to be possible to reverse the math on a Mercator projection, which would eliminate the movement problem, but I can’t get my brain around that either.

@UberGoober You’re not going to map a rectangle onto a sphere without some sort of distortion at the poles. Why you’re getting that black star at the top and bottom I don’t know. When I wrote the sphere code, instead of there being one pole at the top and bottom of the rectangle to map to it, I created 6 poles evenly spaced across the top and bottom to better map it and reduce the pole distortion. When I use a map of the Earth, there aren’t any dark star shapes at the top or bottom poles of the globe. See the Earth zip code below.

One thing that surprised me was looking at the Pacific Ocean. You can rotate the Earth so the ocean covers the whole view with some land just around the edges.

You can also zoom into the Earth and see the continents from inside.

@dave1707 okay I’m trying to think this through, because I think your grid map in your original project gives good clues, so let me sketch out how I think it would work…

So let’s say the bottom of a square at the equator is 18 pixels wide, and the bottom of a topmost square (whose top converges to a single point at the pole) is 4 pixels wide, that means for a maru 7 pixels wide to look the same size at the top as it does at the equator would require it to scale by 18/4 or 4.5.

So for a maru to travel from the equator to the top of the globe and look like it stayed the same size, I would need to somehow enlarge the image at basically every row of pixels using an algorithm that provided a smooth scaling from 18 to 4… and at the same time reduce the amount of space marus have to move around in as they near the top… and there’s where my brain breaks.

…or is there maybe some simpler way to get the marus moving around on the globe? If they were actual 3D objects it wouldn’t require any of this, but then I couldn’t use almost any of the original code… not sure which is harder… seems like the Mercator projection issue should be solvable…

@UberGoober Would this help any.

@UberGoober I figured that problem out at some point and wrote code that would solve the problem. The only problem is, I don’t remember what I wrote it for and I probably deleted it. The code was what kind of a circle/ellipse would I have to draw on the rectangle so when it was projected on the sphere it would still look like a circle at the equator and as it got closer to the pole.

@dave1707 that would certainly help, but the projection is only half the problem, the other half is figuring out how to make the marus move and detect each other as they near the poles.

So if we go the reverse-Mercator route, there will need to be both complicated math and complicated environment-detecting adjustments.

It’s beginning to look like a cube map might be best course after all, because while the math is still complicated, I can at least conceptually get my head around it.

@UberGoober Instead of a cube, you need a larger sided figure. You still have the flat surfaces for movement and collisions, but as you increase the number of sides, it approaches a sphere.

@dave1707 that would indeed be ideal but I don’t think I could ever do the math.

When it’s just a simple flat image, for example, I have to calculate what happens when a maru goes off the top, for instance, and when it goes across a corner, and that’s all very simple up-and-down math.

But with a cube map I’m going to have to figure out which edge leads to which edge, and it’s going to involve doing some rotations and right angles and all that—it’s going to be complicated but at least it’s all right angles or multiples of them, and I think it’s just right at the edge of my math ability.

But with any more than 6 sides all the calculation gets harder by orders of degrees, literally, and I just can’t do it. If you can though I’d love the help!

@UberGoober It’s not something I want to get into. I haven’t played with the flat version, so I’m not sure about the purpose of the round version other than you wanting to do it. I do a lot of things like that too, where it’s more about the challenge of doing it than what the final results give.

@dave1707 ultimately I think it would be cool to get little critters running around and fighting each other on the surface of @John’s planet generator. This seems like a baby step towards that. And that uses a cube map anyway so maybe that’s another good reason to do that way

My guess is, to look right on a sphere, your best bet is to do the sphere math. I’ d have to look it up and read to be sure, but the guys would have constant angular change over time. We’re i to do it, I’d start with one dot wandering the sphere, I think. I’ll try to get interested enough to do it, but I’m not optimistic.

@UberGoober Have you thought about drawing the marus as 3D objects on the surface of the sphere? It makes some of the maths a bit more complicated (tangents instead of up/down/left/right and distances become the shortest distance along the sphere’s surface - http://www.miguelcasillas.com/?p=107) but technically should work roughly the same.

@John I thought about that and there are two arguments against it: one, I’d have to completely rewrite the maru code, and part of the fun here, for me, is going fast by using existing code; and two, Since ultimately I would like to get the marus running around on the surface of your planet generator, and your planet generator uses a cube map for terrain generation, if someone ever wanted to make the marus react to specific terrain features, like height for instance, it would make the most sense for them to also be plotting their motions on that cube map.

… unless I’m misunderstanding what you mean…

@John can you provide any information on the properties of a cubeTexture? This looks like an undocumented feature that is used in your planet generator. I think I will need to know this to draw marus to a planet’s surface.

https://youtu.be/da5qW-FJmhE

@John—this is a demo of what a MaruPlanet would look like—it runs very slowly because, to change the planet map, on line 184 in Main I have to rebuild the colorMap cubetexture every frame.

Is there any way to write directly to the images inside a cubetexture so the simulation can run at a better rate?

Fixed video link.