QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: MasterGy on January 09, 2021, 03:22:28 pm

Title: Earth-browser in maptriangle
Post by: MasterGy on January 09, 2021, 03:22:28 pm
Hi !
I was curious about the math of how to draw a rectangular texture onto a sphere.
The video tells everything. I searched Google for the best quality "worldmap". Unfortunately, I noticed that they like to cut off the North Pole. Even though I find it in HD quality, sometimes the top and bottom are cut off (this can be seen from the degrees). I don’t think the proportions of any of the textures are authentic, but it’s still good for fun.



download (bas and exe)
https://drive.google.com/file/d/14XiPjwN8vBySSdFOE-eEcz0sBNaIIZMA/view?usp=sharing
Title: Re: Earth-browser in maptriangle
Post by: STxAxTIC on January 09, 2021, 03:43:16 pm
This is awesome.
Title: Re: Earth-browser in maptriangle
Post by: Petr on January 09, 2021, 03:54:06 pm
Really perfect work.
Title: Re: Earth-browser in maptriangle
Post by: SpriggsySpriggs on January 09, 2021, 04:42:32 pm
Now make a Universe Sandbox clone in QB64 :)

No, but seriously, this looks great. Thanks for sharing
Title: Re: Earth-browser in maptriangle
Post by: johnno56 on January 09, 2021, 10:59:50 pm
What? No aliens? I was expecting at least ONE alien... lol  Kidding!  Great work!!
Title: Re: Earth-browser in maptriangle
Post by: SMcNeill on January 09, 2021, 11:08:01 pm
What? No aliens? I was expecting at least ONE alien... lol  Kidding!  Great work!!

There might not be any aliens, but there are ghosts.  Look close at the start of the video and you can spot one spirit near the center-left of the screen.
Title: Re: Earth-browser in maptriangle
Post by: TempodiBasic on January 10, 2021, 10:52:30 am
Yes Well Done!

about this
Quote
, I noticed that they like to cut off the North Pole
but do you say that Google collaborates with Area 52 to cover the hole at the 2 poles of earth?

Cool!
Title: Re: Earth-browser in maptriangle
Post by: OldMoses on January 10, 2021, 12:26:05 pm
Anyone know how to control it? It just flies past the screen and I can't seem to control it.
Title: Re: Earth-browser in maptriangle
Post by: bplus on January 10, 2021, 12:38:35 pm
Anyone know how to control it? It just flies past the screen and I can't seem to control it.

Ah this reminds so much of my tunneling work which ended up in a Satellite!
https://qb64.freeforums.net/thread/123/tunnel

Maybe you can find hints there, for how to build something like this or back when we were doing Mars projections.

Took awhile go dig up, here tis from Oct 2018
https://www.qb64.org/forum/index.php?topic=250.msg6345#msg6345
Title: Re: Earth-browser in maptriangle
Post by: OldMoses on January 10, 2021, 12:58:49 pm
Did a test program and figured out that for some reason _MOUSEMOVEMENTX does not work on my machine, and _MOUSEMOVEMENTY only goes up and never down. It does so whether I'm moving in x or y. I'm using 1.4 but I never caught it before, because I've never had occasion to use the mouse movement commands.

Edit: I recently slowed down my CPU to stop fan noise and noticed it took a hit on performance, also the mouse battery is rather old, so I'll try that first.

Code: QB64: [Select]
  1. a& = _NEWIMAGE(600, 600, 32)
  2.  
  3. x = 300
  4. y = 300
  5.     CLS
  6.         x = x + _MOUSEMOVEMENTX
  7.         y = y + _MOUSEMOVEMENTY
  8.     WEND
  9.     PRINT x
  10.     PRINT y
  11.     _DISPLAY
  12.     _LIMIT 30
Title: Re: Earth-browser in maptriangle
Post by: Petr on January 10, 2021, 01:25:07 pm
@OldMoses

Ha! So this is another great thing that is fixed in version 1.5! Now I tried it, in 1.4 your program doesn't really work, but in the upcoming version 1.5 it does! That's great. Really absolutely great!
Title: Re: Earth-browser in maptriangle
Post by: OldMoses on January 10, 2021, 01:34:04 pm
@OldMoses

Ha! So this is another great thing that is fixed in version 1.5! Now I tried it, in 1.4 your program doesn't really work, but in the upcoming version 1.5 it does! That's great. Really absolutely great!

I just gave the dev build a try and it still doesn't work for me, though it may not be the latest build... I changed mouse battery, tried changing mouse for another I have, tried restarting. Nothing so far has worked. My system just won't recognize a change in Y direction and won't recognize X movement at all. I guess I'll turn my CPU back up and see if that does anything.

EDIT: Nope! no dice on the CPU change. I'll have to label this one a mystery for now.
Title: Re: Earth-browser in maptriangle
Post by: Petr on January 10, 2021, 01:35:57 pm
Version under which it works is 1.5 488c4a1 from git.  HA! In 32 bit version it works, but in 64 bit version with the same version number it works not! Now tested!
Title: Re: Earth-browser in maptriangle
Post by: OldMoses on January 10, 2021, 01:42:44 pm
Version under which it works is 1.5 488c4a1 from git.  HA! In 32 bit version it works, but in 64 bit version with the same version number it works not! Now tested!

My dev copy is 1.5 5acd166, I'm pretty sure it's a 64 bit since I never download 32s.
Title: Re: Earth-browser in maptriangle
Post by: Petr on January 10, 2021, 01:52:35 pm
I also use the 32-bit version, because I am writing a program where I will also use the libxmp library for playing S3M, MOD, IT and XM formats and this is for 32 bit only. Thanks to that I can always test it in both versions. Finally, I have a 4 TB hard drive reserved for QB64 only ...
Title: Re: Earth-browser in maptriangle
Post by: bplus on January 10, 2021, 02:03:41 pm
Just out of curiosity, why can't standard mouse detection work for this program?

Ah maybe I should say "standard QB64 mouse detection". ;-))
Title: Re: Earth-browser in maptriangle
Post by: MasterGy on January 10, 2021, 02:13:23 pm

to this day i write in qb 1.3 because it makes exe faster. _MOUSEMOVEMENT still works fine here, but not in later versions. _Mousemoment detects when you leave the screen, but _MOUSEX does not. this can be confusing. I'm about to rewrite the source code to use _MOUSEX instead of _MOUSEMOVEMENTX. Or: start in 1.3
Title: Re: Earth-browser in maptriangle
Post by: Petr on January 10, 2021, 02:13:43 pm
@bplus wrote:
Quote
Just out of curiosity, why can't standard mouse detection work for this program?

Because _MOUSEMOVEMENT is far more convenient for the OpenGL coordinate system that uses _MAPTRIANGLE 3D. This does not mean that it cannot be written with _MOUSEX and _MOUSEY, but simply the _MOUSEMOVEMENT solution takes into account the OpenGL coordinate system.
Title: Re: Earth-browser in maptriangle
Post by: MasterGy on January 10, 2021, 02:14:50 pm
the two things have nothing to do with each other
Title: Re: Earth-browser in maptriangle
Post by: MasterGy on January 10, 2021, 02:38:47 pm

in principle, this will work for everyone

Code: QB64: [Select]
  1. ' settings ---------------------------------
  2.  
  3. map_pic_c = 8 'how many maps available ?
  4. map_pic$(0) = "need/physical-world-map.jpg": mp_t$(0) = "earth"
  5. map_pic$(1) = "need/outline-world-map.jpg": mp_t$(1) = "earth"
  6. map_pic$(2) = "need/map_hd.bmp": mp_t$(2) = "earth"
  7. map_pic$(3) = "need/geological-world-map.jpg": mp_t$(3) = "earth"
  8. map_pic$(4) = "need/continental-world-map.jpg": mp_t$(4) = "earth"
  9. map_pic$(5) = "need/moon_map_mercator.jpg": mp_t$(5) = "moon"
  10. map_pic$(6) = "need/mars_map.jpg": mp_t$(6) = "mars"
  11. map_pic$(7) = "need/squares.bmp": mp_t$(7) = ""
  12.  
  13. da = 70 'resolution 360/da degree horisontal
  14. db = 70 'resolution 360/db degree vertical
  15.  
  16. zoom_xy = 100
  17. zoom_distance = 50
  18. stepping = .08
  19. msenx = .05
  20. msenz = .05
  21. max_couch = 70
  22.  
  23. 'pre ---------------------------------------
  24. fnt = _LOADFONT("need/cyberbit.ttf", monx / 50)
  25. pip180 = _PI / 180: points = da * db: sqs = points
  26. DIM points(points - 1, 9), sq(sqs - 1, 7, map_pic_c - 1), cam(9), me(19)
  27. FOR t = 0 TO map_pic_c - 1: wmap(t) = _LOADIMAGE(map_pic$(t), 33): NEXT t
  28.  
  29. 'creating 3d points
  30. FOR da2 = 0 TO da - 1: dega = 360 / (da - 1) * da2 * pip180: FOR db2 = 0 TO db - 1: degb = 180 / (db - 1) * db2 * pip180
  31. ap = da2 * db + db2: points(ap, 0) = SIN(degb) * COS(dega): points(ap, 1) = SIN(degb) * SIN(dega): points(ap, 2) = COS(degb): NEXT db2, da2
  32.  
  33. 'creating squares
  34. FOR map = 0 TO map_pic_c - 1: FOR da2 = 0 TO da - 2: FOR db2 = 0 TO db - 2: sqa = da2 * db + db2 'actual square
  35.             sq(sqa, 0, map) = sqa: sq(sqa, 1, map) = sq(sqa, 0, map) + 1: sq(sqa, 2, map) = sq(sqa, 0, map) + db: sq(sqa, 3, map) = sq(sqa, 2, map) + 1 '3d points ser
  36.             sq(sqa, 4, map) = _WIDTH(wmap(map)) - (_WIDTH(wmap(map)) / (da - 1) * da2) - 1
  37.             sq(sqa, 5, map) = _WIDTH(wmap(map)) - (_WIDTH(wmap(map)) / (da - 1) * (da2 + 1)) - 1
  38.             sq(sqa, 6, map) = INT(_HEIGHT(wmap(map)) / (db - 1) * db2): sq(sqa, 7, map) = INT(_HEIGHT(wmap(map)) / (db - 1) * (db2 + 1))
  39. NEXT db2, da2, map
  40.  
  41. me(0) = -1.31: me(1) = .575: me(2) = 1.5: me(10) = 1.94: me(11) = 2.05 'start position
  42.  
  43. 'boss cycle -----------------------------------------------
  44.  
  45.     IF INKEY$ = " " THEN act_map = act_map + 1: IF act_map > map_pic_c - 1 THEN act_map = 0
  46.  
  47.     'control
  48.     kw = _KEYDOWN(119) OR _MOUSEBUTTON(1): ks = _KEYDOWN(115) OR _MOUSEBUTTON(2): ka = _KEYDOWN(97): kd = _KEYDOWN(100): et_ir = (ABS(ka OR kd OR kw) OR -ABS(ks))
  49.     ir = 0: IF inv_me10 = -1 THEN SWAP ka, kd
  50.     FOR elt1 = 0 TO max_couch STEP 2: FOR elt2 = 0 TO 360 STEP 12: IF ir = 0 THEN
  51.                 elt_xy = SIN(elt2 * pip180) * elt1: elt_z = COS(elt2 * pip180) * elt1
  52.                 szog_xy_elt = -90 * ABS(ka) + 90 * ABS(kd): szog_xy = me(10) + (szog_xy_elt + elt_xy) * pip180: szog_z = me(11) + pip180 * (90 + elt_z)
  53.                 irx = -SIN(szog_xy) * COS(szog_z): iry = -COS(szog_xy) * COS(szog_z): irz = SIN(szog_z): ir = et_ir: multi = stepping * ir * pre_calc * 2
  54.                 multi = stepping * ir / max_couch * (max_couch - elt1): me(0) = me(0) + irx * multi: me(1) = me(1) + iry * multi
  55.     me(2) = me(2) + irz * multi: END IF: NEXT elt2, elt1
  56.     'mousex = 0: mousey = 0
  57.     me(11) = me(11) + mousey / 7 * msenz
  58.     mousex = _MOUSEX - mousex_last
  59.     mousey = _MOUSEY - mousey_last
  60.     mousex_last = _MOUSEX: mousey_last = _MOUSEY
  61.  
  62.     me(11) = me(11) - 2 * _PI * ABS(me(11) > 2 * _PI): me(11) = me(11) + 2 * _PI * ABS(me(11) < 0): inv_me10 = 1: IF me(11) < _PI THEN inv_me10 = -1
  63.     me(10) = me(10) + mousex / 5 * msenx * inv_me10
  64.  
  65.     'calculating points
  66.     cam(0) = me(0) - SIN(me(10) - 180 * pip180) * me(3) / 2: cam(1) = me(1) - COS(me(10) - 180 * pip180) * me(3) / 2
  67.     cam(2) = me(2) + me(5) / 4: cam(3) = me(10): cam(4) = me(11): cosrotz = COS(cam(3)): sinrotz = SIN(cam(3)): cosrotx = COS(cam(4)): sinrotx = SIN(cam(4))
  68.     FOR actual_point = 0 TO points - 1
  69.         px = points(actual_point, 0) - cam(0): py = points(actual_point, 1) - cam(1): pz2 = points(actual_point, 2) - cam(2)
  70.         px3 = px * cosrotz - py * sinrotz: py2 = px * sinrotz + py * cosrotz: py3 = py2 * cosrotx - pz2 * sinrotx: pz3 = py2 * sinrotx + pz2 * cosrotx
  71.         points(actual_point, 4) = -px3 * zoom_xy: points(actual_point, 5) = -py3 * zoom_xy: points(actual_point, 6) = -pz3 * zoom_distance
  72.     NEXT actual_point
  73.  
  74.     'draw
  75.     FOR asq = 0 TO sqs - 1
  76.         wx0 = points(sq(asq, 0, act_map), 4): wy0 = points(sq(asq, 0, act_map), 5): wz0 = points(sq(asq, 0, act_map), 6)
  77.         wx1 = points(sq(asq, 1, act_map), 4): wy1 = points(sq(asq, 1, act_map), 5): wz1 = points(sq(asq, 1, act_map), 6)
  78.         wx2 = points(sq(asq, 2, act_map), 4): wy2 = points(sq(asq, 2, act_map), 5): wz2 = points(sq(asq, 2, act_map), 6)
  79.         wx3 = points(sq(asq, 3, act_map), 4): wy3 = points(sq(asq, 3, act_map), 5): wz3 = points(sq(asq, 3, act_map), 6)
  80.         sy0 = sq(asq, 6, act_map): sx0 = sq(asq, 4, act_map): sy1 = sq(asq, 7, act_map): sx1 = sq(asq, 4, act_map)
  81.         sy2 = sq(asq, 6, act_map): sx2 = sq(asq, 5, act_map): sy3 = sq(asq, 7, act_map): sx3 = sq(asq, 5, act_map)
  82.         _MAPTRIANGLE (sx0, sy0)-(sx1, sy1)-(sx2, sy2), wmap(act_map) TO(wx0, wy0, wz0)-(wx1, wy1, wz1)-(wx2, wy2, wz2), , _SMOOTH
  83.         _MAPTRIANGLE (sx3, sy3)-(sx1, sy1)-(sx2, sy2), wmap(act_map) TO(wx3, wy3, wz3)-(wx1, wy1, wz1)-(wx2, wy2, wz2), , _SMOOTH
  84.     NEXT asq
  85.  
  86.     'view
  87.     _DISPLAY: _PUTIMAGE , wmap(act_map)
  88.     rdis = _FONTHEIGHT * 1.2
  89.     _PRINTSTRING (0, 0), "MOVING:WASD+mouse         NEXT MAP:space key           "
  90.     _PRINTSTRING (0, rdis), "Type:  " + UCASE$(mp_t$(act_map)) + "  " + map_pic$(act_map) + "             "
  91.     distance = SQR(me(0) * me(0) + me(1) * me(1) + me(2) * me(2)): diam = 0
  92.     SELECT CASE mp_t$(act_map)
  93.         CASE "earth": diam = 12742
  94.         CASE "moon": diam = 3474
  95.         CASE "mars": diam = 6779
  96.     END SELECT
  97.     distance_km = -(1 - distance) * diam / 2
  98.     IF diam THEN _PRINTSTRING (0, rdis * 2), "distance from the surface " + STR$(INT(distance_km)) + "km   ," + STR$(INT(distance_km / 1.6)) + "mp                    "
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
Title: Re: Earth-browser in maptriangle
Post by: OldMoses on January 10, 2021, 02:41:01 pm
As Petr indicated, I downloaded the 32 bit build and it will work with 32 bit version, on my system. Is everyone else running 32, or does my rig just not play nice with 64? Can't say I've ever had other issues with it.
Title: Re: Earth-browser in maptriangle
Post by: bplus on January 10, 2021, 02:58:36 pm
Code: QB64: [Select]
  1. _Mousemoment detects when you leave the screen, but _MOUSEX does not.

Ah! good reason, thank you very much, MasterGy!

@Petr I hope you idea for fixing, works out for us.

Oh say, I just had thought, actually another question:
What does _Mousemovement return when the mouse is off screen?
Title: Re: Earth-browser in maptriangle
Post by: MasterGy on January 10, 2021, 03:21:52 pm
I may be wrong, but I noticed this:
_MOUSEMOVEMENT - it can also detect when you leave the window, but it doesn't work above 1.3, and there may be problems with non-windows
_MOUSEX - universal for all operating systems and qb - versions, but if you exit the window, it does not detect it.
To this day, I prefer qb 1.3 because of the compiler speed, and for that reason too.
Title: Re: Earth-browser in maptriangle
Post by: OldMoses on January 10, 2021, 03:23:46 pm
Oh say, I just had thought, actually another question:
What does _Mousemovement return when the mouse is off screen?

It just returns the relative offset from the last time the position was polled as far as I can tell.
Title: Re: Earth-browser in maptriangle
Post by: bplus on January 10, 2021, 07:50:56 pm
It just returns the relative offset from the last time the position was polled as far as I can tell.

This sounds the same as the regular QB64 mouse detection system, when you go off screen it just stops reporting mx my until you are back on again, nothing jumps to 0, 0 or disappears except mouse.
Title: Re: Earth-browser in maptriangle
Post by: Galleon on January 11, 2021, 07:30:24 am
FYI - I've been exclusively using the 32bit version just because of the bug in _MOUSEMOVEMENTX/Y on the 64bit version. It would be great if it got fixed at some point. No I'm not gonna fix it sorry.
Title: Re: Earth-browser in maptriangle
Post by: luke on January 11, 2021, 07:38:18 am
Version under which it works is 1.5 488c4a1 from git.  HA! In 32 bit version it works, but in 64 bit version with the same version number it works not! Now tested!
This is good to know!

Apologies to MasterGy for hijacking the thread.
Title: Re: Earth-browser in maptriangle
Post by: MasterGy on January 11, 2021, 12:56:15 pm
it doesn't bother me, just feel free! educational thoughts are voiced. interesting to me too.
Title: Re: Earth-browser in maptriangle
Post by: bplus on January 11, 2021, 04:53:07 pm
And we got it fixed! :)
Title: Re: Earth-browser in maptriangle
Post by: MasterGy on January 12, 2021, 06:54:20 am
I am very happy with the fix, thank you for the fix on my behalf!