Author Topic: Isometric Mapping Demo  (Read 10664 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Isometric Mapping Demo
« Reply #15 on: November 20, 2019, 02:58:49 pm »
Problem gridsize of 10 fixed:
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(1024, 720, 32)
  2.  
  3. DIM SHARED GridSize AS INTEGER
  4. CONST Red = &HFFFFAACC, Green = &HFF00FF00
  5. GridSize = 10 ' < 10 is causing problems with PAINT
  6.  
  7.  
  8. DIM grid(9, 9) AS _BYTE 'create a grid to layout our map
  9.  
  10. FOR i = 0 TO 9 'and let's create that map.  It's just going to be 4 walls and a floor...
  11.     grid(i, 0) = 1 'wall
  12.     grid(i, 9) = 1
  13.     grid(0, i) = 1
  14.     grid(9, i) = 1
  15.  
  16. FOR y = 1 TO 8
  17.     FOR x = 1 TO 8
  18.         grid(x, y) = 2 'floor
  19.     NEXT
  20.  
  21.  
  22. 'Now, let's just draw grids one at a time to compare.
  23. _PRINTSTRING (100, 80), "Normal 2D grid"
  24. FOR y = 0 TO 9
  25.     FOR x = 0 TO 9
  26.         'normal grid first
  27.         IF grid(x, y) = 1 THEN Kolor = Red ELSE Kolor = Green
  28.         xpos = x * GridSize + 100: ypos = y * GridSize + 100
  29.         xpos2 = xpos + GridSize: ypos2 = ypos + GridSize
  30.         LINE (xpos, ypos)-(xpos2, ypos2), Kolor, BF
  31.         LINE (xpos, ypos)-(xpos2, ypos2), &HFFFFFFFF, B
  32.         'and that's all it takes for the normal grid.  Can't get any simpler for 2d maps!
  33.     NEXT
  34.  
  35.  
  36. _PRINTSTRING (350, 80), "Normal 2D grid in Isometic Perspective"
  37. FOR y = 0 TO 9
  38.     FOR x = 0 TO 9
  39.         'And now, let's do the same thing with our isometic map.
  40.         IF grid(x, y) = 1 THEN Kolor = Red ELSE Kolor = Green
  41.         xpos = x * GridSize + 100: ypos = y * GridSize + 100
  42.         xpos2 = xpos + GridSize: ypos2 = ypos + GridSize
  43.         IsoLine xpos, ypos, xpos2, ypos2, 500, 0, Kolor
  44.         'And that's basically all the takes to rotate our map to make it a 2D isometic perspective
  45.     NEXT
  46.  
  47.  
  48. _PRINTSTRING (350, 360), "Normal 2D grid in 3D Isometic Perspective"
  49. FOR y = 0 TO 9
  50.     FOR x = 0 TO 9
  51.         'And here, I'm going to make it a 3D isometic map
  52.         IF grid(x, y) = 1 THEN Kolor = Red ELSE Kolor = Green
  53.         IF grid(x, y) = 1 THEN z = 16 ELSE z = 0 'Give my walls a height of 16, for a cube
  54.  
  55.         xpos = x * GridSize + 100: ypos = y * GridSize + 100
  56.         xpos2 = xpos + GridSize: ypos2 = ypos + GridSize
  57.         IsoLine3D xpos, ypos, xpos2, ypos2, z, 500, 300, Kolor
  58.     NEXT
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68. FUNCTION CX2I (x AS LONG, y AS LONG) 'Convert Cartesian X To Isometic coordinates
  69.     CX2I = x - y
  70.  
  71. FUNCTION CY2I (x AS LONG, y AS LONG) 'Convert Cartesian Y To Isometic coordinates
  72.     CY2I = (x + y) / 2
  73.  
  74. SUB IsoLine (x, y, x2, y2, xoffset, yoffset, kolor AS _UNSIGNED LONG)
  75.     'since we're drawing a diamond and not a square box, we can't use Line BF.
  76.     'We have to manually down the 4 points of the line.
  77.     LINE (CX2I(x, y) + xoffset, CY2I(x, y) + yoffset)-(CX2I(x2, y) + xoffset, CY2I(x2, y) + yoffset), kolor
  78.     LINE -(CX2I(x2, y2) + xoffset, CY2I(x2, y2) + yoffset), kolor
  79.     LINE -(CX2I(x, y2) + xoffset, CY2I(x, y2) + yoffset), kolor
  80.     LINE -(CX2I(x, y) + xoffset, CY2I(x, y) + yoffset), kolor
  81.     PAINT (CX2I(x, y) + xoffset, CY2I(x, y) + 4), kolor 'and fill the diamond solid
  82.     LINE (CX2I(x, y) + xoffset, CY2I(x, y) + yoffset)-(CX2I(x2, y) + xoffset, CY2I(x2, y) + yoffset), &HFFFFFFFF
  83.     LINE -(CX2I(x2, y2) + xoffset, CY2I(x2, y2) + yoffset), &HFFFFFFFF
  84.     LINE -(CX2I(x, y2) + xoffset, CY2I(x, y2) + yoffset), &HFFFFFFFF
  85.     LINE -(CX2I(x, y) + xoffset, CY2I(x, y) + yoffset), &HFFFFFFFF
  86.  
  87. SUB IsoLine3D (x, y, x2, y2, z, xoffset, yoffset, kolor AS _UNSIGNED LONG)
  88.     'Like IsoLine, we're going to have to draw our lines manually.
  89.     'only in this case, we also need a Z coordinate to tell us how THICK/TALL/HIGH to make our tile
  90.     r = _RED32(kolor): g = _GREEN32(kolor): b = _BLUE32(kolor)
  91.     'Let's just do all the math first this time.
  92.     'We need to turn those 4 normal points into 4 isometric points (x, y, x1, y1)
  93.  
  94.     TempX1 = CX2I(x, y) + xoffset: TempY1 = CY2I(x, y) + yoffset
  95.     TempX2 = CX2I(x2, y) + xoffset: TempY2 = CY2I(x2, y) + yoffset
  96.     TempX3 = CX2I(x2, y2) + xoffset: TempY3 = CY2I(x2, y2) + yoffset
  97.     TempX4 = CX2I(x, y2) + xoffset: TempY4 = CY2I(x, y2) + yoffset
  98.  
  99.     'The top
  100.     'LINE (TempX1, TempY1 - z)-(TempX2, TempY2 - z), kolor 'draw the diamond
  101.     'LINE -(TempX3, TempY3 - z), kolor
  102.     'LINE -(TempX4, TempY4 - z), kolor
  103.     'LINE -(TempX1, TempY1 - z), kolor
  104.     'PAINT (TempX1, TempY1 - z + 4), kolor 'and fill the diamond solid
  105.     fquad TempX1, TempY1 - z, TempX2, TempY2 - z, TempX3, TempY3 - z, TempX4, TempY4 - z, kolor
  106.     '
  107.     'LINE (TempX1, TempY1 - z)-(TempX2, TempY2 - z), -1 'and redraw the grid
  108.     'LINE -(TempX3, TempY3 - z), -1
  109.     'LINE -(TempX4, TempY4 - z), -1
  110.     'LINE -(TempX1, TempY1 - z), -1
  111.  
  112.     IF z <> 0 THEN 'no need to draw any height, if there isn't any.
  113.         'the left side
  114.         'LINE (TempX4, TempY4 - z)-(TempX4, TempY4), kolor 'draw it
  115.         'LINE -(TempX3, TempY3), kolor
  116.         'LINE -(TempX3, TempY3 - z), kolor
  117.         'LINE -(TempX4, TempY4 - z), kolor
  118.         'PAINT (TempX3 - 2, TempY3 - z + 2), kolor 'fill it
  119.         fquad TempX4, TempY4 - z, TempX4, TempY4, TempX3, TempY3, TempX3, TempY3 - z, _RGB32(.25 * r, .5 * g, .75 * b)
  120.         '
  121.         'LINE (TempX4, TempY4 - z)-(TempX4, TempY4), -1 'redraw the grid lines
  122.         'LINE -(TempX3, TempY3), -1
  123.         'LINE -(TempX3, TempY3 - z), -1
  124.         'LINE -(TempX4, TempY4 - z), -1
  125.         'and then for the right side
  126.         'LINE (TempX3, TempY3 - z)-(TempX3, TempY3), kolor 'draw it
  127.         'LINE -(TempX2, TempY2), kolor
  128.         'LINE -(TempX2, TempY2 - z), kolor
  129.         'LINE -(TempX3, TempY3 - z), kolor
  130.         'PAINT (TempX3 + 2, TempY3 - z + 2), kolor 'fill it
  131.         fquad TempX3, TempY3 - z, TempX3, TempY3, TempX2, TempY2, TempX2, TempY2 - z, _RGB32(.75 * r, .3 * g, .3 * b)
  132.  
  133.         'LINE (TempX3, TempY3 - z)-(TempX3, TempY3), -1 'redraw the grid lines
  134.         'LINE -(TempX2, TempY2), -1
  135.         'LINE -(TempX2, TempY2 - z), -1
  136.         'LINE -(TempX3, TempY3 - z), -1
  137.     END IF
  138.  
  139.  
  140.  
  141.  
  142. 'this text was fetched
  143. SUB ftri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  144.     DIM a&
  145.     a& = _NEWIMAGE(1, 1, 32)
  146.     _DEST a&
  147.     PSET (0, 0), K
  148.     _DEST 0
  149.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  150.     _FREEIMAGE a& '<<< this is important!
  151.  
  152. 'need 4 non linear points (not all on 1 line) list them clockwise so x2, y2 is diagonal of x4, y4
  153. SUB fquad (x1, y1, x2, y2, x3, y3, x4, y4, K AS _UNSIGNED LONG)
  154.     ftri x1, y1, x2, y2, x4, y4, K
  155.     ftri x3, y3, x2, y2, x4, y4, K
  156.  
  157.  
  158.  

I also removed all the line drawing for edges and made slight change to red color
Gridsize 10 fixed.PNG
* Gridsize 10 fixed.PNG (Filesize: 3.52 KB, Dimensions: 354x167, Views: 201)

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Isometric Mapping Demo
« Reply #16 on: November 20, 2019, 03:14:25 pm »
Code: [Select]
SUB ftri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
    STATIC a&
    D = _DEST
    IF a& = 0 THEN a& = _NEWIMAGE(1, 1, 32)
     _DEST a&
    PSET (0, 0), K
    _DEST D
    _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
END SUB

A few quick changes to the routine which should speed it up just a wee bit.  Speed is one of the primary concerns with any sort of fill routine.  ;)

(Also returned the _DEST to whatever it was previously, and not just the display screen by default.)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Isometric Mapping Demo
« Reply #17 on: November 20, 2019, 03:23:38 pm »
Code: [Select]
SUB ftri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
    STATIC a&
    D = _DEST
    IF a& = 0 THEN a& = _NEWIMAGE(1, 1, 32)
     _DEST a&
    PSET (0, 0), K
    _DEST D
    _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
END SUB

A few quick changes to the routine which should speed it up just a wee bit.  Speed is one of the primary concerns with any sort of fill routine.  ;)

(Also returned the _DEST to whatever it was previously, and not just the display screen by default.)

With STATIC a&, you don't have to _FREEIMAGE a& ?

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Isometric Mapping Demo
« Reply #18 on: November 20, 2019, 03:47:25 pm »
With STATIC a&, you don't have to _FREEIMAGE a& ?

Nope.  You just make it once, leave it always available, and forget about it.  At its size, what is it?  4 bytes in memory + whatever the internal header structure uses?  Why reserve it, use it, free it, over and over, at that size?
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: Isometric Mapping Demo
« Reply #19 on: November 20, 2019, 04:35:02 pm »
Looking good, Steve!

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Isometric Mapping Demo
« Reply #20 on: November 21, 2019, 12:27:49 pm »
Would it be possible to make a routine that would make each individual iso-box 1 at a time. like SUB ISOBOX(X,Y,SIZE,HEIGHT) and then you just have to call that over and over to create a grid. No that I think about that might as well name it CUBE.

would It be able to processes the cubes in stages? draw the outer shell, then fill then draw the inner lines? I added an Image of what I mean, as I am terrible at explaining!

thought if it was handled this way using paint might still be an easier and viable solution. might beable to add an option as to if the "back side" lines are drawn or not. (so the cube looks solid not semi transparent)

example.bmp
* example.bmp (Filesize: 33.52 KB, Dimensions: 168x68, Views: 266)
Granted after becoming radioactive I only have a half-life!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Isometric Mapping Demo
« Reply #21 on: November 21, 2019, 12:32:14 pm »
Would it be possible to make a routine that would make each individual iso-box 1 at a time. like SUB ISOBOX(X,Y,SIZE,HEIGHT) and then you just have to call that over and over to create a grid. No that I think about that might as well name it CUBE.

would It be able to processes the cubes in stages? draw the outer shell, then fill then draw the inner lines? I added an Image of what I mean, as I am terrible at explaining!

thought if it was handled this way using paint might still be an easier and viable solution. might beable to add an option as to if the "back side" lines are drawn or not. (so the cube looks solid not semi transparent)

You can, as long as the colors are all the same on each side, but what do you do if they’re different?  (Brown dirt sides for a cliff, green grass on top, as an example.)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Isometric Mapping Demo
« Reply #22 on: November 21, 2019, 12:39:57 pm »
Would it be possible to make a routine that would make each individual iso-box 1 at a time. like SUB ISOBOX(X,Y,SIZE,HEIGHT) and then you just have to call that over and over to create a grid. No that I think about that might as well name it CUBE.

would It be able to processes the cubes in stages? draw the outer shell, then fill then draw the inner lines? I added an Image of what I mean, as I am terrible at explaining!

thought if it was handled this way using paint might still be an easier and viable solution. might beable to add an option as to if the "back side" lines are drawn or not. (so the cube looks solid not semi transparent)

I did just that with this: https://www.qb64.org/forum/index.php?topic=1905.0 and I even named it cube2 as cube was from other code I used for model.

There all sorts of cubes you can make. The one demo'd above fit in convenient square for front face 1 quarter of square for easy overlapping of psuedo 3D model, you can put the square face in any of 4 corners, or you can do regular hexagon shapes and grid them out like Hexagonal Life or Hexagonal Minesweeper.

You can use MAPTRIANGLE (2D) to add texture fills instead of ftri or fquad, which use MAPTRIANGLE too, and has to be much faster and more effective than PAINT eg transparent color fills!
« Last Edit: November 21, 2019, 12:42:47 pm by bplus »

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Isometric Mapping Demo
« Reply #23 on: November 21, 2019, 07:07:12 pm »
You can, as long as the colors are all the same on each side, but what do you do if they’re different?  (Brown dirt sides for a cliff, green grass on top, as an example.)

what about using iso-boxes? have a horizontal one for top and bottom and then vertical ones for the sides? then each side could be a different color, or even alpha shaded? granted you would have 6 calls for each cube. I don't know, just fartin ideas that could keep it simple line\paint based routines.

You can use MAPTRIANGLE (2D) to add texture fills instead of ftri or fquad, which use MAPTRIANGLE too, and has to be much faster and more effective than PAINT eg transparent color fills!

I mean Maptri would be great for applying textures to the faces, but at sizes <32(or maybe even 24-pushing though) a texture is going to be very limited. I've used DirectQB's maptri function to texture walls in a '3D'ish type dungeon crawl, but I was using full screen 13, textured tris up to 256px hor, and 192px vert. my source texture was 256x256 even for that.(had to be ^2 for DQB though so some of that was lost[if i remember correctly, was over 20y/a now.])
I should try to port that to QB64 actually. Use higher res textures for 640x400 or 800x600.
Granted after becoming radioactive I only have a half-life!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Isometric Mapping Demo
« Reply #24 on: December 16, 2019, 11:12:53 am »
Code: [Select]
SUB ftri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
    STATIC a&
    D = _DEST
    IF a& = 0 THEN a& = _NEWIMAGE(1, 1, 32)
     _DEST a&
    PSET (0, 0), K
    _DEST D
    _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
END SUB

A few quick changes to the routine which should speed it up just a wee bit.  Speed is one of the primary concerns with any sort of fill routine.  ;)

(Also returned the _DEST to whatever it was previously, and not just the display screen by default.)

Hi Steve,

I found problem with this modified routine of ftri plus a place where neither version of cSleep or your Pause worked.
Code: QB64: [Select]
  1. _TITLE "fTri Tests, click 4 points to draw transparent quad" 'b+ 2019-12-15 discovered a problem with fTri or using it with fQuad
  2.  
  3. CONST xmax = 800, ymax = 600
  4. SCREEN _NEWIMAGE(xmax, ymax, 32)
  5. _SCREENMOVE 300, 40
  6. DIM pi, oldMouse
  7. DIM mx(1 TO 4), my(1 TO 4)
  8.     CLS
  9.     WHILE pi < 4 'get 4 mouse clicks
  10.         _PRINTSTRING (5, 5), SPACE$(20)
  11.         _PRINTSTRING (5, 5), "Need 4 clicks, have" + STR$(pi)
  12.         WHILE _MOUSEINPUT: WEND
  13.         IF _MOUSEBUTTON(1) AND oldMouse = 0 THEN 'new mouse down
  14.             pi = pi + 1
  15.             mx(pi) = _MOUSEX: my(pi) = _MOUSEY
  16.             CIRCLE (mx(pi), my(pi)), 2
  17.         END IF
  18.         oldMouse = _MOUSEBUTTON(1)
  19.         _DISPLAY
  20.         _LIMIT 60
  21.     WEND
  22.     _PRINTSTRING (5, 5), "Sleeping, click or press key... or esc"
  23.     fquad1 mx(1), my(1), mx(2), my(2), mx(3), my(3), mx(4), my(4), &H880000FF
  24.     _DISPLAY
  25.     ' cSleep 45   '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< dang!! this is working either !!!!!!!!!!!!!!!!!!!!
  26.     ' Pause 30 ' <<<<<<<<<<<<<<<<<<<< well this isn't working either!!!!!!!!!!!!!!
  27.     SLEEP
  28.     pi = 0 'point index
  29.  
  30.  
  31. ' my original fTri that never had a problem with
  32. ' found at [abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]:    http://www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index.php?topic=14425.0
  33. SUB ftri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  34.     DIM D AS LONG, a&
  35.     D = _DEST
  36.     a& = _NEWIMAGE(1, 1, 32)
  37.     _DEST a&
  38.     PSET (0, 0), K
  39.     _DEST D
  40.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  41.     _FREEIMAGE a& '<<< this is important!
  42.  
  43. '2019-11-20 Steve saves some time with STATIC and saves and restores last dest
  44. SUB ftri1 (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  45.     DIM D AS LONG
  46.     STATIC a&
  47.     D = _DEST
  48.     IF a& = 0 THEN a& = _NEWIMAGE(1, 1, 32)
  49.     _DEST a&
  50.     PSET (0, 0), K
  51.     _DEST D
  52.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  53.  
  54. ' original fill quad that may be at fault using Steve's fTri version
  55. 'need 4 non linear points (not all on 1 line) list them clockwise so x2, y2 is opposite of x4, y4
  56. SUB fquad (x1, y1, x2, y2, x3, y3, x4, y4, K AS _UNSIGNED LONG)
  57.     ftri1 x1, y1, x2, y2, x4, y4, K
  58.     ftri1 x3, y3, x2, y2, x4, y4, K
  59.  
  60. 'try a new quad   OK works fine with original fTri but not fTr1 Steves mod
  61. SUB fquad1 (x1, y1, x2, y2, x3, y3, x4, y4, K AS _UNSIGNED LONG)
  62.     ftri1 x1, y1, x2, y2, x3, y3, K
  63.     ftri1 x3, y3, x4, y4, x1, y1, K
  64.  
  65. 'now this original code is not working!
  66. SUB cSleep (secsWait AS DOUBLE) 'wait for keypress or mouseclick, solves midnight problem nicely I think
  67.     DIM wayt AS INTEGER, oldMouse AS INTEGER, k AS LONG, startTime AS DOUBLE
  68.  
  69.     startTime = TIMER
  70.     wayt = 1
  71.     _KEYCLEAR
  72.     WHILE wayt
  73.         WHILE _MOUSEINPUT: WEND
  74.         IF _MOUSEBUTTON(1) AND oldMouse = 0 THEN wayt = 0
  75.         oldMouse = _MOUSEBUTTON(1) ' <<< this is Steve's cool way to get clear of mouse click
  76.         k = _KEYHIT: IF k > 0 THEN _KEYCLEAR: wayt = 0
  77.         IF TIMER - startTime < 0 THEN 'past midnight
  78.             IF TIMER + 24 * 60 * 60 - startTime > secsWait THEN wayt = 0
  79.         ELSE
  80.             IF TIMER - startTime >= secsWait THEN wayt = 0
  81.         END IF
  82.         _LIMIT 30
  83.     WEND
  84.  
  85. 'try Steve's Pause, nope doesn't work either!!!!
  86. SUB Pause (time AS _FLOAT)
  87.     DIM ExitTime AS _FLOAT, oldMouse AS INTEGER, k AS LONG
  88.     _KEYCLEAR 'clear the keyboard buffer so we don't automatically exit the routine
  89.     IF time <= 0 THEN ExitTime = 1.18E+1000 ELSE ExitTime = time + TIMER
  90.     DO
  91.         WHILE _MOUSEINPUT: WEND: IF _MOUSEBUTTON(1) AND NOT oldMouse THEN EXIT SUB
  92.         k = _KEYHIT: IF k > 0 THEN _KEYCLEAR: EXIT SUB 'clear any stray key events so they don't mess with code outside the Pause.
  93.         oldMouse = _MOUSEBUTTON(1)
  94.         _LIMIT 10
  95.     LOOP UNTIL ExitTime < TIMER
  96.  
  97.  
« Last Edit: December 16, 2019, 11:16:28 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Isometric Mapping Demo
« Reply #25 on: December 16, 2019, 11:50:45 am »
Hi Steve,

This line added to both cSleep and Pause seems to fix the problem in the code above:
Code: QB64: [Select]
where we use _KEYCLEAR, we have to clear old mouse clicks also?

I have not tested updated code elsewhere yet.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Isometric Mapping Demo
« Reply #26 on: December 16, 2019, 12:54:35 pm »
Hi Steve,

This line added to both cSleep and Pause seems to fix the problem in the code above:
Code: QB64: [Select]
where we use _KEYCLEAR, we have to clear old mouse clicks also?

I have not tested updated code elsewhere yet.

One thing I see is missing: oldmouse should be set to -1 before the loop starts.

WHILE _MOUSEINPUT: WEND
IF _MOUSEBUTTON(1) = -1 AND oldmouse = 0 THEN...

If we don’t set oldmouse to -1, we’d instantly kick out of the loop if the user had the button down to begin with.

By setting oldmouse to -1 at the start, we treat the routine as if the button was previously held down, and only accept a click once we get confirmation it’s been up, before being pressed down.

^There might be your error.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Isometric Mapping Demo
« Reply #27 on: December 16, 2019, 01:25:39 pm »
Hi Steve,

That Pause routine came from here:
https://www.qb64.org/forum/index.php?topic=1511.msg111606#msg111606
and was what I based cSleep on.


Setting oldMouse to -1 at start does seem better than my fix. I will test, thanks :)

Any thoughts about fTri? It seems to retain the last transparent color when we use STATIC a& and not _FREEIMAGE.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Isometric Mapping Demo
« Reply #28 on: December 16, 2019, 01:32:35 pm »
Hi Steve,

That Pause routine came from here:
https://www.qb64.org/forum/index.php?topic=1511.msg111606#msg111606
and was what I based cSleep on.


Setting oldMouse to -1 at start does seem better than my fix. I will test, thanks :)

Any thoughts about fTri? It seems to retain the last transparent color when we use STATIC a& and not _FREEIMAGE.

Several options; as I didn’t think about alpha blending with the static handle.

CLS, 0 could clear the old pixel first.
Or _DONTBLEND a& before using the PSET command (I’d probably just go this route, as DONTBLEND is a speed up over using blend.)

Edit: Went in and preset oldmouse to -1 in the Pause command so it shouldn’t have the previously down glitch anymore.  ;)

Code: [Select]
    IF a& = 0 THEN a& = _NEWIMAGE(1, 1, 32): _DONTBLEND a&
(The above should set a& to no blend mode and then leave it to that, fixing the alpha issue with it.)
« Last Edit: December 16, 2019, 01:52:36 pm by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Isometric Mapping Demo
« Reply #29 on: December 16, 2019, 02:16:04 pm »
Several options; as I didn’t think about alpha blending with the static handle.

CLS, 0 could clear the old pixel first.
Or _DONTBLEND a& before using the PSET command (I’d probably just go this route, as DONTBLEND is a speed up over using blend.)

Edit: Went in and preset oldmouse to -1 in the Pause command so it shouldn’t have the previously down glitch anymore.  ;)

Code: [Select]
    IF a& = 0 THEN a& = _NEWIMAGE(1, 1, 32): _DONTBLEND a&
(The above should set a& to no blend mode and then leave it to that, fixing the alpha issue with it.)

Hi Steve,

Reading about _DONTBLEND in help, it says that such will make the background opaque and block the background. When I use transparent colors with fTri, I usually want just a layer of see through color over what's behind. It's looking like I want to stick with original fTri that frees image to keep pure transparent layers going.

Update: confirmed the transparency is lost with _DONTBLEND

Thanks for your thoughts :)
« Last Edit: December 16, 2019, 02:26:29 pm by bplus »