Author Topic: Earth-browser in maptriangle  (Read 5825 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Earth-browser in maptriangle
« Reply #15 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". ;-))
« Last Edit: January 10, 2021, 02:06:11 pm by bplus »

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: Earth-browser in maptriangle
« Reply #16 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

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Earth-browser in maptriangle
« Reply #17 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.

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: Earth-browser in maptriangle
« Reply #18 on: January 10, 2021, 02:14:50 pm »
the two things have nothing to do with each other

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: Earth-browser in maptriangle
« Reply #19 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.  

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Earth-browser in maptriangle
« Reply #20 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.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Earth-browser in maptriangle
« Reply #21 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?
« Last Edit: January 10, 2021, 03:03:41 pm by bplus »

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: Earth-browser in maptriangle
« Reply #22 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.

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Earth-browser in maptriangle
« Reply #23 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.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Earth-browser in maptriangle
« Reply #24 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.

Offline Galleon

  • QB64 Developer
  • Newbie
  • Posts: 25
    • View Profile
Re: Earth-browser in maptriangle
« Reply #25 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.

Offline luke

  • Administrator
  • Seasoned Forum Regular
  • Posts: 324
    • View Profile
Re: Earth-browser in maptriangle
« Reply #26 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.
« Last Edit: January 11, 2021, 07:39:36 am by luke »

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: Earth-browser in maptriangle
« Reply #27 on: January 11, 2021, 12:56:15 pm »
it doesn't bother me, just feel free! educational thoughts are voiced. interesting to me too.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Earth-browser in maptriangle
« Reply #28 on: January 11, 2021, 04:53:07 pm »
And we got it fixed! :)

Offline MasterGy

  • Seasoned Forum Regular
  • Posts: 327
  • people lie, math never lies
    • View Profile
Re: Earth-browser in maptriangle
« Reply #29 on: January 12, 2021, 06:54:20 am »
I am very happy with the fix, thank you for the fix on my behalf!