Author Topic: 3D Object Editor: Start  (Read 5849 times)

0 Members and 1 Guest are viewing this topic.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
3D Object Editor: Start
« on: July 10, 2019, 06:02:11 pm »
Hi. This is my first 3D object editor, this time from 2D to 3D editor. It is maximal easy, i will develop it in this days. As next step i will add next windows with next view (from left, from right, from bottom, from above, and from back). Thanks to today discussion with SierraKen finally, after a long time, it turned on in my head and finally I think I know how to do this object editor. This is the first version, the foundation. I'll add higher versions here as I develop them. Of course, I will also choose textures. If you want to make a cube easily in space, run the program. There is a yellow rectangle in the center of the grid. This is the center of rotation (currently immobile). Create  three points and click to make a triangle. Then roll back to two vertices and click again to mark them. Click the fourth peak to draw a square created from two triangles. So. See how far apart the vertices in a square (described as OpenGL coordinates on the screen).
Press ESC. Because this is the first version, it does not offer a graphical environment of depth, but it will ask you. If you have vertices of a square that is 0.6, enter a depth of -5, -5.6, for example. This will result in a symmetrical body. Press enter. If you did everything right, a red cube rotates on your monitor. I think it might be interesting, so I'm releasing the early version. Look at the attachment I created :-D

Code: QB64: [Select]
  1.  
  2. SCREEN _NEWIMAGE(1024, 768, 32)
  3. FOR x = 0 TO 1023 STEP 16
  4.     FOR y = 0 TO 767 STEP 16
  5.         LINE (x, y)-(x + 15, y + 15), &H88FFFFFF, B
  6. NEXT y, x
  7. 'middle point
  8. FOR x = 0 TO 1023 STEP 16
  9.     LINE (x, 768 / 2)-(x + 15, (768 / 2) + 15), &H77FFFF00, B
  10.  
  11. FOR y = 0 TO 767 STEP 16
  12.     LINE (512, y)-(527, y + 15), &H77FFFF00, B
  13. LINE (512, 384)-(528, 398), &HFFFFFF00, BF
  14.  
  15. TYPE P2D
  16.     X AS INTEGER
  17.     Y AS INTEGER
  18.     X3D AS SINGLE
  19.     Y3D AS SINGLE
  20.  
  21. REDIM SHARED V(1) AS P2D, ua
  22.  
  23.  
  24.     'grid coordinates:
  25.     Xg = -1 + _CEIL(_MOUSEX / 16)
  26.     Yg = -1 + _CEIL(_MOUSEY / 16)
  27.  
  28.     PrvkuX = 1024 / 16
  29.     PrvkuY = 768 / 16
  30.  
  31.     X3D = (-PrvkuX / 2 + Xg) / 10
  32.     Y3D = (PrvkuY / 2 - Yg) / 10
  33.  
  34.         u = UBOUND(V)
  35.  
  36.  
  37.         LINE (Xg * 16, Yg * 16)-(Xg * 16 + 15, Yg * 16 + 15), &H55FF0000, BF
  38.  
  39.         V(u).X3D = X3D
  40.         V(u).Y3D = Y3D
  41.         V(u).X = Xg * 16
  42.         V(u).Y = Yg * 16
  43.         Reset_Mouse
  44.         IF u MOD 3 = 0 THEN DrawContent
  45.         u = u + 1
  46.         REDIM _PRESERVE V(u) AS P2D
  47.     END IF
  48.  
  49.  
  50.     LOCATE 1
  51.     PRINT "OpenGL coordinates: "; X3D, Y3D
  52.     PRINT "Grid 2D coordinates:"; Xg, Yg
  53.  
  54.  
  55.  
  56. IF UBOUND(v) >= 3 THEN
  57.     INPUT "Input Foreground Depth, Background Depth. Muss be both negative, otherwise is behind the monitor (unvisible):"; z0!, z1!
  58.     PRINT "Ok. Wait, creating 3D..."
  59.     SLEEP 1
  60.     CLS , &H00000000
  61.     '    _DISPLAYORDER _HARDWARE
  62.     H& = DoTexture
  63.     DO
  64.         Do3D z0!, z1!, H&
  65.         _DISPLAY
  66.         in$ = INKEY$
  67.         ua = ua + .1
  68.         _LIMIT 20
  69.     LOOP UNTIL in$ = CHR$(27)
  70.  
  71.     PRINT "Not enought coordinates. 3D can not be created.": SLEEP 3: END
  72.  
  73.  
  74.  
  75. SUB Do3D (sZ1 AS SINGLE, sZ2 AS SINGLE, H&)
  76.  
  77.  
  78.  
  79.     FOR C = 1 TO UBOUND(v) - 1 STEP 3
  80.         x1o = V(C).X3D
  81.         y1 = V(C).Y3D
  82.         z1o = sZ1
  83.  
  84.         x2o = V(C + 1).X3D
  85.         y2 = V(C + 1).Y3D
  86.         z2o = sZ1
  87.  
  88.         x3o = V(C + 2).X3D
  89.         y3 = V(C + 2).Y3D
  90.         z3o = sZ1
  91.  
  92.         x4o = V(C).X3D
  93.         y4 = V(C).Y3D
  94.         z4o = sZ2
  95.  
  96.         x5o = V(C + 1).X3D
  97.         y5 = V(C + 1).Y3D
  98.         z5o = sZ2
  99.  
  100.         x6o = V(C + 2).X3D
  101.         y6 = V(C + 2).Y3D
  102.         z6o = sZ2
  103.  
  104.  
  105.  
  106.  
  107.         'pokus o otocku XZ
  108.         CZ = (sZ1 + sZ2) / 2
  109.  
  110.  
  111.         R1 = SQR(x1o ^ 2 + (CZ - z1o) ^ 2)
  112.         R2 = SQR(x2o ^ 2 + (CZ - z2o) ^ 2)
  113.         R3 = SQR(x3o ^ 2 + (CZ - z3o) ^ 2)
  114.         R4 = SQR(x4o ^ 2 + (CZ - z4o) ^ 2)
  115.         R5 = SQR(x5o ^ 2 + (CZ - z5o) ^ 2)
  116.         R6 = SQR(x6o ^ 2 + (CZ - z6o) ^ 2)
  117.  
  118.         pi1 = JK(0.01, (sZ1 + sZ2) / 2, x1o, z1o, R1)
  119.         pi2 = JK(0.01, (sZ1 + sZ2) / 2, x2o, z2o, R2)
  120.         pi3 = JK(0.01, (sZ1 + sZ2) / 2, x3o, z3o, R3)
  121.         pi4 = JK(0.01, (sZ1 + sZ2) / 2, x4o, z4o, R4)
  122.         pi5 = JK(0.01, (sZ1 + sZ2) / 2, x5o, z5o, R5)
  123.         pi6 = JK(0.01, (sZ1 + sZ2) / 2, x6o, z6o, R6)
  124.  
  125.         x1 = SIN(ua + pi1) * R1
  126.         z1 = CZ + COS(ua + pi1) * R1
  127.  
  128.         x2 = SIN(ua + pi2) * R2
  129.         z2 = CZ + COS(ua + pi2) * R2
  130.  
  131.         x3 = SIN(ua + pi3) * R3
  132.         z3 = CZ + COS(ua + pi3) * R3
  133.  
  134.         x4 = SIN(ua + pi4) * R4
  135.         z4 = CZ + COS(ua + pi4) * R4
  136.  
  137.         x5 = SIN(ua + pi5) * R5
  138.         z5 = CZ + COS(ua + pi5) * R5
  139.  
  140.         x6 = SIN(ua + pi6) * R6
  141.         z6 = CZ + COS(ua + pi6) * R6
  142.  
  143.         '  PRINT z1; z2, z3, z4; z5; z6: SLEEP
  144.         'this is universal 3D draw SUB, in real programs muss be textured just what is really needed.                 6
  145.         W = 99: H = 99 'texture width and height                                                                      / \
  146.         '                                                                                                           / I   \
  147.         'predek   foreground                                                                                      /   I     \
  148.         _MAPTRIANGLE (0, 0)-(W, 0)-(0, H), H& TO(x1, y1, z1)-(x2, y2, z2)-(x3, y3, z3) '                        /     I      /3
  149.         'zadek    back                                                                                    Z2  /       I    /  I
  150.         _MAPTRIANGLE (0, 0)-(W, 0)-(0, H), H& TO(x4, y4, z4)-(x5, y5, z5)-(x6, y6, z6) '                    /         I  /    I
  151.         'levy bok    left side                                                                            /           I/      I
  152.         _MAPTRIANGLE (0, 0)-(W, 0)-(0, H), H& TO(x1, y1, z1)-(x4, y4, z4)-(x3, y3, z3) '                /            /I       I
  153.         _MAPTRIANGLE (0, 0)-(W, 0)-(0, H), H& TO(x4, y4, z4)-(x3, y3, z3)-(x6, y6, z6) '              /            /  I       I
  154.         'dno         bottom                                                                         /            /    I       I
  155.         _MAPTRIANGLE (0, 0)-(W, 0)-(0, H), H& TO(x4, y4, z4)-(x5, y5, z5)-(x1, y1, z1) '            4\----------+------5      I
  156.         _MAPTRIANGLE (0, 0)-(W, 0)-(0, H), H& TO(x5, y5, z5)-(x1, y1, z1)-(x2, y2, z2) '               \     /           \    I
  157.         'pravy bok   right side                                                                          \ /                \ I
  158.         _MAPTRIANGLE (0, 0)-(W, 0)-(0, H), H& TO(x5, y5, z5)-(x6, y6, z6)-(x2, y2, z2) '                  1-------------------2
  159.         _MAPTRIANGLE (0, 0)-(W, 0)-(0, H), H& TO(x5, y5, z5)-(x2, y2, z2)-(x3, y3, z3) '                           Z1
  160.     NEXT C
  161.  
  162.  
  163. SUB DrawContent
  164.     U = UBOUND(V) - 2
  165.  
  166.     LINE (V(U).X + 8, V(U).Y + 8)-(V(U + 1).X + 8, V(U + 1).Y + 8), &HFFFFFFFF
  167.     LINE (V(U + 1).X + 8, V(U + 1).Y + 8)-(V(U + 2).X + 8, V(U + 2).Y + 8), &HFFFFFFFF
  168.     LINE (V(U).X + 8, V(U).Y + 8)-(V(U + 2).X + 8, V(U + 2).Y + 8), &HFFFFFFFF
  169.  
  170.  
  171. SUB Reset_Mouse
  172.     DO UNTIL _MOUSEBUTTON(1) = 0
  173.         WHILE _MOUSEINPUT: WEND
  174.     LOOP
  175.  
  176. FUNCTION DoTexture&
  177.     a = _DEST
  178.     dt& = _NEWIMAGE(100, 100, 32)
  179.     _DEST dt&
  180.     CLS , &H99FF0000
  181.     '    FOR f = 0 TO 4
  182.     '    LINE (f, f)-(95 + f, 95 + f), &HFFFFFFFF, B
  183.     '    LINE (95 + f, 95 + f)-(f, 99)
  184.     '    NEXT f
  185.     DoTexture& = _COPYIMAGE(dt&, 33)
  186.     _DEST a
  187.     _FREEIMAGE dt&
  188.  
  189.  
  190.  
  191. FUNCTION JK! (cx, cy, px, py, R!)
  192.     '  podle definice jednotkove kruznice musim nejprve hodnoty prevest na rozsah od -1 do 1 pro x i pro y.
  193.     '  R urcuje velikost kruznice, cili jR bude 1/R
  194.     LenX! = cx - px
  195.     LenY! = cy - py
  196.     jR! = 1 / R!
  197.  
  198.     jX! = LenX! * jR!
  199.     jY! = LenY! * jR!
  200.  
  201.     sinusAlfa! = jX!
  202.     Alfa! = ABS(_ASIN(sinusAlfa!))
  203.  
  204.     Q = 1
  205.     IF px >= cx AND py >= cy THEN Q = 1 ' select angle to quadrant
  206.     IF px >= cx AND py <= cy THEN Q = 2
  207.     IF px <= cx AND py <= cy THEN Q = 3
  208.     IF px <= cx AND py >= cy THEN Q = 4
  209.     SELECT CASE Q
  210.         CASE 1: alfaB! = Alfa!
  211.         CASE 2: alfaB! = _PI / 2 + (_PI / 2 - Alfa!)
  212.         CASE 3: alfaB! = _PI + Alfa!
  213.         CASE 4: alfaB! = _PI(1.5) + (_PI / 2 - Alfa!)
  214.     END SELECT
  215.     JK! = alfaB!
  216.     IF JK! = 0 THEN BEEP
  217.  
3D objects.jpg

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: 3D Object Editor: Start
« Reply #1 on: July 10, 2019, 06:52:12 pm »
Cool!
Very very interesting!
Thanks to share it
Programming isn't difficult, only it's  consuming time and coffee

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: 3D Object Editor: Start
« Reply #2 on: July 13, 2019, 05:35:03 am »
Hi. I'm do this hard, thank you Tempo. The windows are four. X / Z, X / Y, and Y / Z, and one with a 3D preview (although the program is intended for _MAPTRIANGLE 3D, the fourth window will be drawn using OpenGL using the OpenGL screen conversion function to the Software screen by Ashish).

To imagine - how do you paint something to 2 axis,  when you have only a 2D monitor and X, Y coordinates on it? You simply move this X / Y at depth (in the array) to depth 2. Then draw a different shape at the same X / Y coordinates at another depth, lets say 5. You connect it and you have the front and back of the 3D body. The Same principle for left / right side (X / Z), where you move this style Y and for top / bottom where you move X in depth. So it will work. Upgrade 1 will be released right after the grid application. Here is preview, all window are full movable. I start program logic to do.

 
preview0.jpg

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: 3D Object Editor: First steps
« Reply #3 on: July 13, 2019, 03:54:27 pm »
Hi guys. Today is really successful. Electronics  in my monitor is before death, so I have the whole image in yellow and now waiting for a new monitor. And the following problem. This source code knows why it behaves differently every time you run it. I tried to find the cause, I didn't find it. The thing is that the top two windows and the bottom left window should have a grid when you start. 5 times I start it, 4 times the grid is there and then suddenly there is not. Or is in two windows, but the third window is blank. All windows and all grids do the same SUB. Every advice would really help me a lot. Thank you.

Code: QB64: [Select]
  1.  
  2. _TITLE "3D Object editor V 0.1 Alfa"
  3. TYPE V '                informace v mrizce
  4.     X AS SINGLE '      OpenGL souradnice obsazeneho bodu v X                                                      not used, will be used later
  5.     Y AS SINGLE '      OpenGL souradnice obsazeneho bodu v Y
  6.     Z AS SINGLE '      OpenGL souradnice obsazeneho bodu v Z
  7.  
  8. TYPE Triangle ' Souhrn o bodech z pole Grid - proste body ty a ty tvori tento trojuhelnik s touto texturou        not used, will be used later
  9.     TriangleS AS LONG 'odkud v poli V jsou vrcholy tohoto trojuhelnika
  10.     TriangleE AS LONG ' kam v poli V jsou vrcholy tohoto trojuhelnika
  11.     Texture AS LONG 'cislo textury z pole textur pro tento trojuhelnik
  12.  
  13. TYPE texture
  14.     name AS STRING '                                                                                               not used
  15.  
  16.  
  17. TYPE W 'pro okna                                                                                                'used for program windows
  18.     X1 AS INTEGER '
  19.     Y1 AS INTEGER '
  20.     X2 AS INTEGER '
  21.     Y2 AS INTEGER '                                                                                              current window position X1,Y1,X2,Y2
  22.     oX1 AS INTEGER
  23.     oY1 AS INTEGER
  24.     oX2 AS INTEGER
  25.     oY2 AS INTEGER '                                                                                             previous window position oX1, oY1, oX2, oY2
  26.     Status AS _BYTE '                                                                                            0 = standarnd, somewhere on the screen, -1 = closed, 1 = minimized, 2 = maximalized
  27.     WName AS STRING '                                                                                            window name
  28.     GActive AS INTEGER
  29.     GXs AS INTEGER
  30.     GXe AS INTEGER '
  31.     GYs AS INTEGER '                                                                                             GXs, GYs, GXe, GYe = Grid X Start, Grid Y Start, Grid X end.... for grid
  32.     GYe AS INTEGER '
  33.     Gc AS _UNSIGNED LONG '                                                                                       Grid foreground color
  34.     GBc AS _UNSIGNED LONG '                                                                                      Grid background color
  35.     Gsize AS INTEGER '                                                                                           Grid size
  36.     Draw_Pos AS _BYTE '                                                                            .
  37. REDIM SHARED W(0) AS W '
  38. REDIM SHARED W2(0) AS LONG '                                                                                     'Contains records number from array W (for windows) and set foreground window. Foreground window is always ubound W2.
  39. DIM SHARED Arr3D(100, 100, 100) AS SINGLE, ScreenBackGroundColor AS _UNSIGNED LONG, IconBack AS LONG
  40. DIM SHARED ICOLeft, ICORight, ICOUp, ICODn, ICOClose, ICOMaximize, ICOMinimize, ICOSetup
  41.  
  42. IconBack = IconBackground
  43.  
  44.  
  45. ScreenBackGroundColor = &HFF55AA99
  46. CONST GridSizeX = 100 'later this all constants will be optional
  47. CONST GridSizeY = 100
  48. CONST GridSizeZ = 100
  49. CONST GridSize = 60
  50.  
  51.  
  52.  
  53. SCREEN _NEWIMAGE(W, H, 32)
  54. CLS , ScreenBackGroundColor~&
  55. wdth = _DESKTOPWIDTH / 2
  56. hght = _DESKTOPHEIGHT / 2
  57.  
  58.  
  59.  
  60.  
  61. W1 = Init_Window("Front View XY", 1, 71, wdth - 1, hght - 1, &HFFFFFFFF, &HFF888888, GridSize, 0)
  62. W2 = Init_Window("Side View XZ", wdth + 1, 71, wdth * 2 - 1, hght, &HFF00FFFF, &HFF999999, GridSize, 0)
  63. W3 = Init_Window("Bottom View YZ", 1, hght + 1, wdth, hght * 2 - 1, &HFFFFFFFF, &HFF7A7A7A, GridSize, 0)
  64. W4 = Init_Window("3D Preview window", wdth + 1, hght + 1, wdth * 2 - 1, hght * 2 - 1, &HFF00CCFF, &HFF808080, GridSize, 0)
  65.  
  66.  
  67. LoadIcons 'my old program - editor.bm file
  68. gte = 0
  69.     _MOUSESHOW "default"
  70.     Draw_Window W1
  71.     Draw_Window W2
  72.     Draw_Window W3
  73.     Draw_Window W4
  74.  
  75.  
  76.     _DISPLAY
  77.     _LIMIT 20
  78.  
  79.  
  80.  
  81.  
  82. SUB Grid (R AS INTEGER) 'i think, somewhere in this sub is bug, but i see it not.
  83.  
  84.     X1 = W(R).X1
  85.     Y1 = W(R).Y1
  86.     X2 = W(R).X2
  87.     Y2 = W(R).Y2
  88.  
  89.     'vlozi ovladaci prvky okna
  90.     _PUTIMAGE (X2 - 25, Y1 + 4), ICOClose
  91.     _PUTIMAGE (X2 - 42, Y1 + 4), ICOMaximize
  92.     _PUTIMAGE (X2 - 59, Y1 + 4), ICOMinimize
  93.  
  94.  
  95.     _PUTIMAGE (X2 - 20, Y2 - 20), ICORight
  96.     _PUTIMAGE (X1 + 5, Y2 - 20), ICOLeft
  97.     _PUTIMAGE (X2 - 20, Y1 + 24), ICOUp
  98.     _PUTIMAGE (X2 - 20, Y2 - 37), ICODn
  99.  
  100.     LINE (X1 + 20, Y2 - 19)-(X2 - 20, Y2 - 7), &HFF88F888, B 'X rectangle
  101.     LINE (X2 - 19, Y1 + 40)-(X2 - 7, Y2 - 38), &HFF88F888, B 'Y rectangle
  102.  
  103.     MX = _MOUSEX: MY = _MOUSEY: MB1 = _MOUSEBUTTON(1)
  104.  
  105.  
  106.  
  107.     FOR U = LBOUND(w) TO UBOUND(w)
  108.         IF MB1 THEN
  109.             IF MX >= W(U).X1 AND MX <= W(U).X2 AND MY >= W(U).Y1 AND MY <= W(U).Y2 THEN 'if user is in some window area and click, set it as active. Window shift is possible by clicking and moving window header.
  110.                 IF UBOUND(w2) = U THEN EXIT FOR '
  111.                 Set_Active_Window U
  112.                 EXIT FOR
  113.             END IF
  114.         END IF
  115.     NEXT U
  116.  
  117.     IF MX < X2 AND MX > X2 - 70 THEN
  118.         IF MY >= Y1 AND MY <= Y1 + 19 THEN
  119.             SELECT CASE MX
  120.                 CASE X2 - 25 TO X2 - 10
  121.                     LINE (X2 - 10, Y1 + 4)-(X2 - 25, Y1 + 19), &H99FF0000, BF 'icon CLOSE
  122.                     IF MB1 THEN
  123.                         W(R).Status = -1 '                                     minimalize
  124.                         LINE (X1, Y1)-(X2, Y2), ScreenBackGroundColor, BF
  125.                     END IF
  126.  
  127.  
  128.                 CASE X2 - 59 TO X2 - 44
  129.                     LINE (X2 - 59, Y1 + 4)-(X2 - 44, Y1 + 19), &H99FF0000, BF 'maximalize
  130.                     IF MB1 THEN
  131.                         IF W(R).Status = 0 THEN
  132.                             W(R).oX1 = X1
  133.                             W(R).oY1 = Y1
  134.                             W(R).oX2 = X2
  135.                             W(R).oY2 = Y2
  136.  
  137.                             W(R).X1 = R * 70
  138.                             W(R).X2 = W(R).X1 + 70
  139.                             W(R).Y2 = _DESKTOPHEIGHT
  140.                             W(R).Y1 = _DESKTOPHEIGHT - 70
  141.                             W(R).Status = 1
  142.  
  143.                             Set_Active_Window R
  144.                             Reset_Mouse
  145.                             GOTO eif
  146.                         END IF
  147.  
  148.                         IF W(R).Status = 2 THEN 'return previous state
  149.                             W(R).X1 = W(R).oX1
  150.                             W(R).Y1 = W(R).oY1
  151.                             W(R).X2 = W(R).oX2
  152.                             W(R).Y2 = W(R).oY2
  153.                             W(R).Status = 0
  154.  
  155.                             X1 = W(R).oX1
  156.                             Y1 = W(R).oY1
  157.                             X2 = W(R).oX2
  158.                             Y2 = W(R).oY2
  159.  
  160.                             Set_Active_Window R
  161.                         END IF
  162.                         eif:
  163.                         LINE (0, 71)-(_DESKTOPWIDTH, _DESKTOPHEIGHT), ScreenBackGroundColor, BF
  164.                     END IF
  165.  
  166.  
  167.                 CASE X2 - 41 TO X2 - 27
  168.                     LINE (X2 - 41, Y1 + 4)-(X2 - 27, Y1 + 19), &H99FF0000, BF 'icon minimalize
  169.                     IF MB1 THEN
  170.                         LINE (X1, Y1)-(X2, Y2), ScreenBackGroundColor, BF
  171.                         IF W(R).Status = 1 THEN '        return previous state from minimalize
  172.                             W(R).X1 = W(R).oX1
  173.                             W(R).Y1 = W(R).oY1
  174.                             W(R).X2 = W(R).oX2
  175.                             W(R).Y2 = W(R).oY2
  176.                             W(R).Status = 0
  177.                             X1 = W(R).oX1
  178.                             Y1 = W(R).oY1
  179.                             X2 = W(R).oX2
  180.                             Y2 = W(R).oY2
  181.  
  182.                             Set_Active_Window R
  183.                             GOTO eif2
  184.                         END IF
  185.  
  186.  
  187.  
  188.                         IF W(R).Status = 0 THEN 'Maximalize. First write current coordinates.
  189.                             W(R).oX1 = X1
  190.                             W(R).oY1 = Y1
  191.                             W(R).oX2 = X2
  192.                             W(R).oY2 = Y2
  193.  
  194.                             W(R).X1 = 3
  195.                             W(R).X2 = _DESKTOPWIDTH - 3
  196.                             W(R).Y2 = _DESKTOPHEIGHT - 5
  197.                             W(R).Y1 = 71
  198.                             W(R).Status = 2
  199.                             Set_Active_Window R
  200.                         END IF
  201.                         eif2:
  202.                     END IF
  203.             END SELECT
  204.         END IF
  205.     END IF
  206.  
  207.     'DRAW GRID IN WINDOWS
  208.  
  209.     'Load previous grid coordinates (on grid positions)
  210.  
  211.     MrY1 = W(R).GYs
  212.     MrY2 = W(R).GYe
  213.     MrX1 = W(R).GXs '                                   Positions on grid
  214.     MrX2 = W(R).GXe
  215.  
  216.     'arrow up in windows
  217.     IF MX >= X2 - 19 AND MX <= X2 - 7 THEN
  218.         IF MY >= Y1 + 26 AND MY <= Y1 + 38 THEN
  219.             LINE (X2 - 19, Y1 + 26)-(X2 - 7, Y1 + 38), &H33FF0000, BF
  220.             IF MB1 THEN MrY1 = MrY1 - 1
  221.         END IF
  222.     END IF
  223.  
  224.     'rrow down in windows
  225.     IF MX >= X2 - 19 AND MX <= X2 - 7 THEN
  226.         IF MY >= Y2 - 38 AND MY <= Y2 - 26 THEN
  227.             LINE (X2 - 19, Y2 - 26)-(X2 - 7, Y2 - 38), &H33FF0000, BF
  228.             IF MB1 THEN MrY1 = MrY1 + 1
  229.         END IF
  230.     END IF
  231.  
  232.     'arrow left
  233.     IF MX >= X1 + 6 AND MX <= X1 + 18 THEN
  234.         IF MY >= Y2 - 20 AND MY <= Y2 - 5 THEN
  235.             LINE (X1 + 18, Y2 - 20)-(X1 + 6, Y2 - 5), &H33FF0000, BF
  236.             IF MB1 THEN MrX1 = MrX1 - 1
  237.         END IF
  238.     END IF
  239.  
  240.     'arrow right
  241.     IF MX >= X2 - 18 AND MX <= X2 - 6 THEN
  242.         IF MY >= Y2 - 20 AND MY <= Y2 - 5 THEN
  243.             LINE (X2 - 18, Y2 - 20)-(X2 - 6, Y2 - 5), &H33FF0000, BF
  244.             IF MB1 THEN MrX1 = MrX1 + 1
  245.         END IF
  246.     END IF
  247.     'if is here inserted: PRINT R: _DISPLAY: SLEEP, problem not occur. WHY?
  248.  
  249.  
  250.  
  251.     IF R <= 2 THEN '                                I need view grid in window nr. 0,1,2. Window 3 use none grid. It is window for future OpenGL view.
  252.         rrr = rrr + 1
  253.         IF W(R).Status = 0 OR W(R).Status = 2 THEN
  254.  
  255.  
  256.             GX1 = X1 + 10 '                        reset start coordinates for grid. It is different, if is window minimized or use other width, height, or is maximalized.
  257.             GY1 = Y1 + 28 '                        this are relative coordinates.
  258.             GX2 = X2 - 25 '
  259.             GY2 = Y2 - 23 '
  260.             Gsize = W(R).Gsize
  261.  
  262.  
  263.             DO UNTIL (GX2 - GX1) MOD Gsize = 0 'reset grid size to value best for use in window for full fill.
  264.                 Gsize = Gsize - 1
  265.             LOOP
  266.  
  267.  
  268.             'Every window show one piece in space (currently all show just X/Y)
  269.             MinX = 0: MinY = 0: MinZ = 0
  270.             SELECT CASE R
  271.                 CASE 0: MaxX = GridSizeX: MaxY = GridSizeY: Z = CurrentZ 'View XY
  272.                 CASE 1: MaxX = GridSizeX: MaxY = GridSizeZ: Z = CurrentY 'View YZ
  273.                 CASE 2: MaxX = GridSizeY: MaxY = GridSizeZ: Z = CurrentX 'View XZ
  274.             END SELECT '               y                               x
  275.  
  276.  
  277.             'MrX1 and MrY1 are field coordinates, not graphical!
  278.  
  279.  
  280.             IF MrX1 < MinX THEN MrX1 = MinX 'LBOUND Overflow prevent
  281.             IF MrY1 < MinY THEN MrY1 = MinY
  282.  
  283.             'claculate how much points can be viewed
  284.             Xd = INT((GX2 - GX1 - Gsize) / Gsize)
  285.             Yd = INT((GY2 - GY1 - Gsize) / Gsize)
  286.  
  287.             MrX2 = MrX1 + Xd
  288.             MrY2 = MrY1 + Yd
  289.  
  290.  
  291.             IF MrX2 > MaxX THEN MrX2 = MaxX 'UBOUND Overflow prevent
  292.             IF MrY2 > MaxY THEN MrY2 = MaxY
  293.  
  294.  
  295.             Z = 2 'Alpha test - set X, Y to Z = 2
  296.             Arr3D(5, 7, 2) = 1
  297.  
  298.  
  299.             FOR DrawGridY = MrY1 TO MrY2
  300.                 FOR DrawGridX = MrX1 TO MrX2
  301.                     ArrayX = DrawGridX
  302.                     ArrayY = DrawGridY
  303.                     IF Arr3D(ArrayX, ArrayY, Z) = 0 THEN
  304.                         LINE (GX1 + (Gsize * DrawGridX) - (Gsize * MrX1), GY1 + (Gsize * DrawGridY) - (Gsize * MrY1))-(GX1 + (DrawGridX * Gsize) + Gsize - 1 - (Gsize * MrX1), GY1 + (DrawGridY * Gsize) + Gsize - 1 - (Gsize * MrY1)), W(R).Gc, B
  305.                     ELSE
  306.                         LINE (GX1 + (Gsize * DrawGridX) - (Gsize * MrX1), GY1 + (Gsize * DrawGridY) - (Gsize * MrY1))-(GX1 + (DrawGridX * Gsize) + Gsize - 1 - (Gsize * MrX1), GY1 + (DrawGridY * Gsize) + Gsize - 1 - (Gsize * MrY1)), &HFFFF0000, BF
  307.                     END IF
  308.                 NEXT
  309.             NEXT
  310.         END IF
  311.  
  312.  
  313.  
  314.  
  315.     END IF
  316.  
  317.  
  318.     'save grid positions to field
  319.     W(R).GYs = MrY1
  320.     W(R).GYe = MrY2
  321.     W(R).GXs = MrX1
  322.     W(R).GXe = MrX2
  323.  
  324.  
  325.  
  326.  
  327.     PCOPY _DISPLAY, 10
  328.  
  329.     'pokracovat ovladanim a plnenim + kresbou mrizky
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337. SUB Set_Active_Window (window_nr AS INTEGER)
  338.     ii = 0
  339.     IF W2(UBOUND(w2) - 1) <> window_nr THEN
  340.         DO UNTIL W2(ii) = window_nr
  341.             ii = ii + 1
  342.         LOOP
  343.         SWAP W2(UBOUND(w2) - 1), W2(ii)
  344.     END IF
  345.  
  346. SUB Reset_Mouse
  347.     DO UNTIL _MOUSEBUTTON(1) = 0
  348.         WHILE _MOUSEINPUT: WEND
  349.     LOOP
  350.  
  351. FUNCTION Init_Window (Wname AS STRING, X1 AS INTEGER, Y1 AS INTEGER, X2 AS INTEGER, Y2 AS INTEGER, GridColor AS _UNSIGNED LONG, BackgroundColor AS _UNSIGNED LONG, Size AS _BYTE, Status AS _BYTE) 'pri initu je mrizka na pocatku.
  352.     I = UBOUND(W)
  353.     W(I).X1 = X1: W(I).Y1 = Y1: W(I).X2 = X2: W(I).Y2 = Y2: W(I).Status = Status: W(I).Gc = GridColor: W(I).GBc = BackgroundColor: W(I).WName = Wname: W(I).Gsize = Size: W(I).GXe = GridSizeX: W(I).GYe = GridSizeY
  354.     W2(I) = I
  355.     REDIM _PRESERVE W(I + 1) AS W
  356.     REDIM _PRESERVE W2(I + 1) AS LONG
  357.     Init_Window = I
  358.  
  359.  
  360.  
  361. SUB Draw_Window (Window_NR AS LONG)
  362.     X1 = W(Window_NR).X1: Y1 = W(Window_NR).Y1: X2 = W(Window_NR).X2: Y2 = W(Window_NR).Y2: BackGroundColor~& = W(Window_NR).GBc: Wname$ = W(Window_NR).WName
  363.     Size = W(Window_NR).Gsize: GridColor~& = W(Window_NR).Gc
  364.  
  365.  
  366.  
  367.  
  368.     IF _MOUSEX >= X1 AND _MOUSEX <= X2 - 70 AND W(Window_NR).Status > -1 THEN 'omezeni kvuli ikonam ovladani okna
  369.         IF _MOUSEY >= Y1 AND _MOUSEY <= Y1 + 19 THEN
  370.             ' IF UBOUND(w2) - 1 = Window_NR THEN
  371.             IF Window_NR = W2(UBOUND(w2) - 1) THEN _MOUSESHOW "link"
  372.             IF _MOUSEBUTTON(1) THEN
  373.  
  374.                 IF Window_NR = W2(UBOUND(w2) - 1) THEN
  375.                     ox1 = X1: ox2 = X2: oy1 = Y1: oy2 = Y2
  376.  
  377.  
  378.  
  379.                     PCOPY _DISPLAY, 10
  380.                     DO UNTIL _MOUSEBUTTON(1) = 0
  381.                         DO WHILE _MOUSEINPUT: LOOP
  382.                         MMX = MOUSEMOVEMENTX * 3
  383.                         MMY = MOUSEMOVEMENTY * 3
  384.  
  385.  
  386.                         PCOPY 10, _DISPLAY
  387.                         ooX1 = X1
  388.                         X1 = X1 + MMX
  389.                         ooy1 = Y1
  390.                         Y1 = Y1 + MMY
  391.                         X2 = X2 + MMX
  392.                         ooy2 = Y2
  393.                         Y2 = Y2 + MMY
  394.  
  395.  
  396.                         IF Y1 < 70 THEN Y1 = 70: Y2 = ooy2
  397.                         IF Y1 > _DESKTOPHEIGHT - 70 THEN Y1 = _DESKTOPHEIGHT - 70: Y2 = ooy2
  398.                         IF X2 < 70 THEN X2 = 70
  399.                         IF X1 > _DESKTOPWIDTH - 70 THEN X1 = _DESKTOPWIDTH - 70
  400.                         '------------------------------------------
  401.  
  402.                         LINE (X1, Y1)-(X2, Y2), &HFFFFFFFF, B , 127
  403.                         _DISPLAY
  404.                     LOOP
  405.  
  406.                     PCOPY 10, _DISPLAY
  407.                 END IF
  408.  
  409.                 FOR r = LBOUND(W) TO UBOUND(W)
  410.                     W(r).Draw_Pos = 0
  411.                 NEXT r
  412.                 W(Window_NR).Draw_Pos = 1
  413.  
  414.                 W(Window_NR).X1 = X1: W(Window_NR).X2 = X2
  415.                 W(Window_NR).Y1 = Y1: W(Window_NR).Y2 = Y2
  416.  
  417.                 IF W2(UBOUND(w2) - 1) <> Window_NR THEN
  418.                     DO UNTIL W2(ii) = Window_NR
  419.                         ii = ii + 1
  420.                     LOOP
  421.                     SWAP W2(UBOUND(w2) - 1), W2(ii)
  422.                 END IF
  423.  
  424.  
  425.                 LINE (ox1, oy1)-(ox2, oy2), ScreenBackGroundColor~&, BF 'premaze cernou barvou puvodni pozici okna
  426.             END IF
  427.  
  428.         END IF
  429.         ' END IF
  430.     END IF
  431.     '----------------- PREDCHOZI BLOK RESI POSUN OKEN TAHEM ZA HORNI OKRAJ ----------------------------
  432.  
  433.     '----------------- NASLEDUJE BLOK PRO ROZTAHOVANI TAHEM ZA LEVY, PRAVY, NEBO SPODNI OKRAJ ---------
  434.  
  435.     IF W(Window_NR).Status > -1 THEN
  436.         IF Window_NR = W2(UBOUND(w2) - 1) THEN 'omezeni manipulace s oknem pouze pro aktivni okno
  437.             'levy okraj:
  438.             IF _MOUSEX >= W(Window_NR).X1 AND _MOUSEX < W(Window_NR).X1 + 15 THEN
  439.                 IF _MOUSEY >= W(Window_NR).Y1 AND _MOUSEY <= W(Window_NR).Y2 - 25 THEN '   omezeni kvuli sipkam posunu mrizky
  440.                     ShiftLeft = 1
  441.                 END IF
  442.             END IF
  443.  
  444.             'pravy okraj:
  445.             IF _MOUSEX >= W(Window_NR).X2 - 15 AND _MOUSEX < W(Window_NR).X2 THEN
  446.                 IF _MOUSEY >= W(Window_NR).Y1 + 40 AND _MOUSEY <= W(Window_NR).Y2 - 40 THEN '   omezeni kvuli sipkam posunu mrizky
  447.                     ShiftRight = 1
  448.                 END IF
  449.             END IF
  450.  
  451.             'spodni okraj
  452.  
  453.             IF _MOUSEX >= W(Window_NR).X1 + 20 AND _MOUSEX <= W(Window_NR).X2 - 20 THEN '   omezeni kvuli sipkam posunu mrizky
  454.                 IF _MOUSEY >= W(Window_NR).Y2 - 15 AND _MOUSEY <= W(Window_NR).Y2 THEN
  455.                     ShiftDown = 1
  456.                 END IF
  457.             END IF
  458.  
  459.             IF ShiftLeft OR ShiftRight THEN _MOUSESHOW "horizontal"
  460.             IF ShiftDown THEN _MOUSESHOW "vertical"
  461.             '------------- PREDCHOZI BLOK RESI ROZSVECENI SIPEK <-> ATD PRI NAJETI MYSI NA KRAJ OKNA -------------
  462.  
  463.             IF ShiftLeft AND _MOUSEBUTTON(1) THEN
  464.                 PCOPY _DISPLAY, 10
  465.                 IF _MOUSEX > 5 THEN
  466.                     DO UNTIL _MOUSEBUTTON(1) = 0
  467.                         IF W(Window_NR).X1 < W(Window_NR).X2 - 70 OR MMX = 1 THEN
  468.                             WHILE _MOUSEINPUT: WEND
  469.                             W(Window_NR).X1 = W(Window_NR).X1 + MOUSEMOVEMENTX * 3
  470.                             X1 = W(Window_NR).X1: Y1 = W(Window_NR).Y1: X2 = W(Window_NR).X2: Y2 = W(Window_NR).Y2
  471.                             PCOPY 10, _DISPLAY
  472.                             LINE (X1, Y1)-(X2, Y2), &HFFFFFFFF, B , 127
  473.                         ELSE
  474.                             W(Window_NR).X1 = W(Window_NR).X2 - 71
  475.                         END IF
  476.                         _DISPLAY
  477.                     LOOP
  478.                     CLS , ScreenBackGroundColor~&
  479.                 END IF
  480.             END IF
  481.  
  482.             IF ShiftRight AND _MOUSEBUTTON(1) THEN
  483.                 PCOPY _DISPLAY, 10
  484.                 IF _MOUSEX < _DESKTOPWIDTH - 5 THEN
  485.                     DO UNTIL _MOUSEBUTTON(1) = 0
  486.                         IF W(Window_NR).X2 > W(Window_NR).X1 + 70 OR MMX = -1 THEN
  487.                             WHILE _MOUSEINPUT: WEND
  488.                             W(Window_NR).X2 = W(Window_NR).X2 + MOUSEMOVEMENTX * 3
  489.                             X1 = W(Window_NR).X1: Y1 = W(Window_NR).Y1: X2 = W(Window_NR).X2: Y2 = W(Window_NR).Y2
  490.                             PCOPY 10, _DISPLAY
  491.                             LINE (X1, Y1)-(X2, Y2), &HFFFFFFFF, B , 127
  492.                         ELSE
  493.                             W(Window_NR).X2 = W(Window_NR).X1 + 71
  494.                         END IF
  495.                         _DISPLAY
  496.                     LOOP
  497.                     CLS , ScreenBackGroundColor~&
  498.                 END IF
  499.             END IF
  500.  
  501.             IF ShiftDown AND _MOUSEBUTTON(1) THEN
  502.                 PCOPY _DISPLAY, 10
  503.                 IF _MOUSEY < _DESKTOPHEIGHT THEN
  504.  
  505.                     DO UNTIL _MOUSEBUTTON(1) = 0
  506.                         IF W(Window_NR).Y2 > W(Window_NR).Y1 + 70 THEN
  507.                             WHILE _MOUSEINPUT: WEND
  508.                             W(Window_NR).Y2 = W(Window_NR).Y2 + MOUSEMOVEMENTY * 3
  509.                             X1 = W(Window_NR).X1: Y1 = W(Window_NR).Y1: X2 = W(Window_NR).X2: Y2 = W(Window_NR).Y2
  510.                             PCOPY 10, _DISPLAY
  511.                             LINE (X1, Y1)-(X2, Y2), &HFFFFFFFF, B , 127
  512.                         ELSE
  513.                             W(Window_NR).Y2 = W(Window_NR).Y1 + 71
  514.                         END IF
  515.  
  516.                         _DISPLAY
  517.                     LOOP
  518.                     CLS , ScreenBackGroundColor~&
  519.                 END IF
  520.             END IF
  521.  
  522.  
  523.         END IF 'konec kotroly STATUS > -1
  524.  
  525.  
  526.     END IF 'konec omezeni pohybu podle toho, jestli jde o aktivni okno.
  527.     '---------------------------------- next day -------------------------------------------------------------- 12-07-2019 ---------------------------------------------
  528.     'pridam tomu trochu na vzhledu. Jemny barevny prechod pro cast pod ikonami poresim funkci, aby se to stale nekreslilo.
  529.     'pozadi vlozim pred kresleni oken - radek 61, provedeny upravy a otestovani v Draw_Window
  530.  
  531.     _PUTIMAGE (0, 0), IconBack 'vklad pozadi pod hornim pasem pro ikony
  532.  
  533.  
  534.     'Pridan EDITOR.BM pro loadovani ICO souboru (sipky pro okna)
  535.     'Pro vyssi prehlednost necham vzdy mrizku vcetne posunu na subu GRID.
  536.     'Grid bude kreslit na hotove okenni pozadi, cili az na konci tohoto SUBu.
  537.  
  538.  
  539.  
  540.     'vykresleni oken v poradi tak, aby posledni aktivni okno bylo na vrchu.
  541.     FOR WW = LBOUND(w2) TO UBOUND(w2) - 1
  542.         Window_NR = (W2(WW))
  543.         IF W(Window_NR).Status = -1 THEN _CONTINUE 'VYPNE OKNO
  544.  
  545.         COLOR &HFFFFFFFF
  546.         '  PRINT Window_NR: _DISPLAY
  547.         X1 = W(Window_NR).X1: Y1 = W(Window_NR).Y1: X2 = W(Window_NR).X2: Y2 = W(Window_NR).Y2: BackGroundColor~& = W(Window_NR).GBc: Wname$ = W(Window_NR).WName
  548.         Size = W(Window_NR).Gsize: GridColor~& = W(Window_NR).Gc
  549.  
  550.  
  551.         LINE (X1, Y1)-(X2, Y2), BackGroundColor~&, BF
  552.         LINE (X1, Y1 + 20)-(X2, Y2), &HFFFFFFFF, B
  553.         LINE (X1 + 2, Y1 + 22)-(X2 - 2, Y2 - 2), &HFFFFFFFF, B
  554.  
  555.         LINE (X1 + 3, Y1)-(X2 - 3, Y1 + 19), _RGB32(183, 194, 200), BF
  556.  
  557.         LINE (X1, Y1)-(X2, Y2), &HFFFFFFFF, B
  558.         LINE (X1 + 2, Y1 + 2)-(X2 - 2, Y2 - 2), &HFFFFFFFF, B
  559.  
  560.  
  561.         COLOR &HFF000000
  562.  
  563.         IF X2 - X1 >= LEN(Wname$) * 16 + 50 THEN
  564.             _PRINTSTRING (X1 + 40, Y1 + 4), "[" + Wname$ + "]" + STR$(Window_NR)
  565.         ELSE
  566.             chrs = _CEIL(X2 - X1 - 90) / 16
  567.             IF chrs < 0 THEN chrs = 0
  568.             nWname$ = LEFT$("[" + Wname$ + "]", chrs)
  569.             _PRINTSTRING (X1 + 40, Y1 + 4), nWname$
  570.         END IF
  571.  
  572.  
  573.         Grid Window_NR
  574.  
  575.     NEXT
  576.  
  577.  
  578.  
  579.  
  580. FUNCTION MOUSEMOVEMENTX
  581.     SHARED memory_mousemovementx
  582.     MOUSEMOVEMENTX = 0
  583.     IF _MOUSEX > memory_mousemovementx THEN memory_mousemovementx = _MOUSEX: MOUSEMOVEMENTX = 1: EXIT FUNCTION
  584.     IF _MOUSEX < memory_mousemovementx THEN memory_mousemovementx = _MOUSEX: MOUSEMOVEMENTX = -1
  585.  
  586. FUNCTION MOUSEMOVEMENTY
  587.     SHARED memory_mousemovementy
  588.     MOUSEMOVEMENTY = 0
  589.     IF _MOUSEY > memory_mousemovementy THEN memory_mousemovementy = _MOUSEY: MOUSEMOVEMENTY = 1: EXIT FUNCTION
  590.     IF _MOUSEY < memory_mousemovementy THEN memory_mousemovementy = _MOUSEY: MOUSEMOVEMENTY = -1
  591.  
  592. FUNCTION IconBackground&
  593.     a = _DEST
  594.     IconBackground& = _NEWIMAGE(_DESKTOPWIDTH, 70, 32)
  595.     _DEST IconBackground&
  596.     D = 85 / 70
  597.     DRA = 255
  598.     FOR Dr = 0 TO 70
  599.         LINE (0, Dr)-(_DESKTOPWIDTH, Dr), _RGB32(DRA)
  600.         DRA = DRA - D
  601.     NEXT
  602.     c = 70 / _DESKTOPWIDTH
  603.     CC = 127
  604.     FOR r = 0 TO _DESKTOPWIDTH
  605.         PSET (r, 67), _RGB32(CC)
  606.         PSET (r, 69), _RGB32(CC)
  607.         CC = CC - c
  608.     NEXT
  609.  
  610.     _DEST a
  611.  
  612. SUB LoadIcons
  613.     ICOLeft = LOADICO("ico/left.ico", 9)
  614.     ICORight = LOADICO("ico/right.ico", 9)
  615.     ICOUp = LOADICO("ico/up.ico", 9)
  616.     ICODn = LOADICO("ico/down.ico", 9)
  617.     ICOClose = LOADICO("ico/close.ico", 9)
  618.     ICOMaximize = LOADICO("ico/maximize.ico", 9)
  619.     ICOMinimize = LOADICO("ico/minimize.ico", 9)
  620.     ICOSetup = LOADICO("ico/setup.ico", 7)
  621. '$include:'editor.bm'
  622.  

After compiling just press F5 more times, after you close previous compiled program. This source need included files.

 
* 3DObjektEditor.zip (Filesize: 232.21 KB, Downloads: 238)
« Last Edit: July 13, 2019, 04:07:10 pm by Petr »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: 3D Object Editor: Start
« Reply #4 on: July 13, 2019, 06:16:40 pm »
Could this be a problem of not using _FREEIMAGE?

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: 3D Object Editor: Start
« Reply #5 on: July 14, 2019, 03:50:29 am »
Hi Pete. No, because is used just one undeleted virtual screen and is loaded just 1x before program loop, for icon background on row 46 and next undeleted newimages are  from LOADICO, but this are also loaded before program loop  -  it call row 73 extra SUB for loading it.  Because it use frame icon parameter (icon number), so it load just one concrete ico image. I think, here is not problem.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: 3D Object Editor: Start
« Reply #6 on: July 14, 2019, 04:23:09 am »
Oh my god. Bug indetified. I know not why, but again error on my place. So, please, if you are interrested, see to row 309 - 319. This block draw grid to window and sometimes are parameters for draw illegal, because sometimes is MrX2 < MrX1  or  MrY2 < MrY1. I muss find now why.

piece of code
 
 FOR DrawGridY = MrY1 TO MrY2
                FOR DrawGridX = MrX1 TO MrX2
                    ArrayX = DrawGridX
                    ArrayY = DrawGridY
                    IF Arr3D ( ArrayX , ArrayY , Z ) = 0 THEN

Thank you for your interrest.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: 3D Object Editor: Start
« Reply #7 on: July 14, 2019, 05:27:30 am »
So. Again i test it. I Found this:

If the program is compiled in IDE version 1.1, ie 20170120/51, then there is no error! In IDE 1.3, sometimes absurd values occur in the memory field for unknown reasons. I tried to redefine the INTEGER type to LONG without a positive effect. I'm sure I came across a critical QB64 error. To make it easier for developers when the program encounters nonsensical values read from the array (which did not happen once in version 1.1), it whistles and prints out incoming values from memory. So - program development will continue with version 1.1, due to unreliability of version 1.3.

Developers, see row 335. This row find illegal values from memory and write it to screen.


Degraded version for use in IDE 1.1 (but full functional). Need the same attached files above.

Code: QB64: [Select]
  1.  
  2. '   Tato verze je na foru s dotazem na obcasne chybejici mrizku po startu.
  3. '
  4.  
  5.  
  6.  
  7. _TITLE "3D Object editor V 0.1 Alfa"
  8. TYPE V '                informace v mrizce
  9.     X AS SINGLE '      OpenGL souradnice obsazeneho bodu v X                                                      not used, will be used later
  10.     Y AS SINGLE '      OpenGL souradnice obsazeneho bodu v Y
  11.     Z AS SINGLE '      OpenGL souradnice obsazeneho bodu v Z
  12.  
  13. TYPE Triangle ' Souhrn o bodech z pole Grid - proste body ty a ty tvori tento trojuhelnik s touto texturou        not used, will be used later
  14.     TriangleS AS LONG 'odkud v poli V jsou vrcholy tohoto trojuhelnika
  15.     TriangleE AS LONG ' kam v poli V jsou vrcholy tohoto trojuhelnika
  16.     Texture AS LONG 'cislo textury z pole textur pro tento trojuhelnik
  17.  
  18. TYPE texture
  19.     name AS STRING * 12 '                                                                                               not used
  20.  
  21.  
  22. TYPE W 'pro okna                                                                                                'used for program windows
  23.     X1 AS LONG '
  24.     Y1 AS LONG '
  25.     X2 AS LONG '
  26.     Y2 AS LONG '                                                                                              current window position X1,Y1,X2,Y2
  27.     oX1 AS LONG
  28.     oY1 AS LONG
  29.     oX2 AS LONG
  30.     oY2 AS LONG '                                                                                             previous window position oX1, oY1, oX2, oY2
  31.     Status AS _BYTE '                                                                                            0 = standarnd, somewhere on the screen, -1 = closed, 1 = minimized, 2 = maximalized
  32.     WName AS STRING * 12 '                                                                                            window name
  33.     GActive AS INTEGER
  34.     GXs AS LONG
  35.     GXe AS LONG '
  36.     GYs AS LONG '                                                                                             GXs, GYs, GXe, GYe = Grid X Start, Grid Y Start, Grid X end.... for grid
  37.     GYe AS LONG '
  38.     Gc AS _UNSIGNED LONG '                                                                                       Grid foreground color
  39.     GBc AS _UNSIGNED LONG '                                                                                      Grid background color
  40.     Gsize AS LONG '                                                                                           Grid size
  41.     Draw_Pos AS _BYTE '                                                                                          Last click
  42. REDIM SHARED W(0) AS W '
  43. REDIM SHARED W2(0) AS LONG '                                                                                     'Contains records number from array W (for windows) and set foreground window. Foreground window is always ubound W2.
  44. DIM SHARED Arr3D(100, 100, 100) AS SINGLE, ScreenBackGroundColor AS _UNSIGNED LONG, IconBack AS LONG
  45. DIM SHARED ICOLeft, ICORight, ICOUp, ICODn, ICOClose, ICOMaximize, ICOMinimize, ICOSetup
  46.  
  47. IconBack = IconBackground
  48.  
  49.  
  50. ScreenBackGroundColor = &HFF55AA99
  51. CONST GridSizeX = 100 'later this all constants will be optional
  52. CONST GridSizeY = 100
  53. CONST GridSizeZ = 100
  54. CONST GridSize = 16
  55.  
  56.  
  57.  
  58. SCREEN _NEWIMAGE(W, H, 32)
  59. CLS , ScreenBackGroundColor~&
  60. wdth = _DESKTOPWIDTH / 2
  61. hght = _DESKTOPHEIGHT / 2
  62.  
  63.  
  64.  
  65.  
  66. W1 = Init_Window("Front View XY", 1, 71, wdth - 1, hght - 1, &HFFFFFFFF, &HFF888888, GridSize, 0)
  67. W2 = Init_Window("Side View XZ", wdth + 1, 71, wdth * 2 - 1, hght, &HFF00FFFF, &HFF999999, GridSize, 0)
  68. W3 = Init_Window("Bottom View YZ", 1, hght + 1, wdth, hght * 2 - 1, &HFFFFFFFF, &HFF7A7A7A, GridSize, 0)
  69. W4 = Init_Window("3D Preview window", wdth + 1, hght + 1, wdth * 2 - 1, hght * 2 - 1, &HFF00CCFF, &HFF808080, GridSize, 0)
  70.  
  71. my = _DEST
  72. LoadIcons 'my old program - editor.bm file
  73. _DEST my: _SOURCE my
  74.  
  75.  
  76.  
  77.  
  78. gte = 0
  79.     _MOUSESHOW "default"
  80.     Draw_Window W1
  81.     Draw_Window W2
  82.     Draw_Window W3
  83.     Draw_Window W4
  84.  
  85.  
  86.     _DISPLAY
  87.     _LIMIT 20
  88.  
  89.  
  90.  
  91.  
  92. SUB Grid (R AS INTEGER) 'i think, somewhere in this sub is bug, but i see it not.
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101. X1 = W(R).X1
  102. Y1 = W(R).Y1
  103. X2 = W(R).X2
  104. Y2 = W(R).Y2
  105.  
  106. 'vlozi ovladaci prvky okna
  107. _PUTIMAGE (X2 - 25, Y1 + 4), ICOClose
  108. _PUTIMAGE (X2 - 42, Y1 + 4), ICOMaximize
  109. _PUTIMAGE (X2 - 59, Y1 + 4), ICOMinimize
  110.  
  111.  
  112. _PUTIMAGE (X2 - 20, Y2 - 20), ICORight
  113. _PUTIMAGE (X1 + 5, Y2 - 20), ICOLeft
  114. _PUTIMAGE (X2 - 20, Y1 + 24), ICOUp
  115. _PUTIMAGE (X2 - 20, Y2 - 37), ICODn
  116.  
  117. LINE (X1 + 20, Y2 - 19)-(X2 - 20, Y2 - 7), &HFF88F888, B 'X rectangle
  118. LINE (X2 - 19, Y1 + 40)-(X2 - 7, Y2 - 38), &HFF88F888, B 'Y rectangle
  119.  
  120. MX = _MOUSEX: MY = _MOUSEY: MB1 = _MOUSEBUTTON(1)
  121.  
  122.  
  123.  
  124. FOR U = LBOUND(w) TO UBOUND(w)
  125.     IF MB1 THEN
  126.         IF MX >= W(U).X1 AND MX <= W(U).X2 AND MY >= W(U).Y1 AND MY <= W(U).Y2 THEN 'if user is in some window area and click, set it as active. Window shift is possible by clicking and moving window header.
  127.             IF UBOUND(w2) = U THEN EXIT FOR '
  128.             Set_Active_Window U
  129.             EXIT FOR
  130.         END IF
  131.     END IF
  132.  
  133. IF MX < X2 AND MX > X2 - 70 THEN
  134.     IF MY >= Y1 AND MY <= Y1 + 19 THEN
  135.         SELECT CASE MX
  136.             CASE X2 - 25 TO X2 - 10
  137.                 LINE (X2 - 10, Y1 + 4)-(X2 - 25, Y1 + 19), &H99FF0000, BF 'icon CLOSE
  138.                 IF MB1 THEN
  139.                     W(R).Status = -1 '                                     minimalize
  140.                     LINE (X1, Y1)-(X2, Y2), ScreenBackGroundColor, BF
  141.                 END IF
  142.  
  143.  
  144.             CASE X2 - 59 TO X2 - 44
  145.                 LINE (X2 - 59, Y1 + 4)-(X2 - 44, Y1 + 19), &H99FF0000, BF 'maximalize
  146.                 IF MB1 THEN
  147.                     IF W(R).Status = 0 THEN
  148.                         W(R).oX1 = X1
  149.                         W(R).oY1 = Y1
  150.                         W(R).oX2 = X2
  151.                         W(R).oY2 = Y2
  152.  
  153.                         W(R).X1 = R * 70
  154.                         W(R).X2 = W(R).X1 + 70
  155.                         W(R).Y2 = _DESKTOPHEIGHT
  156.                         W(R).Y1 = _DESKTOPHEIGHT - 70
  157.                         W(R).Status = 1
  158.  
  159.                         Set_Active_Window R
  160.                         Reset_Mouse
  161.                         GOTO eif
  162.                     END IF
  163.  
  164.                     IF W(R).Status = 2 THEN 'return previous state
  165.                         W(R).X1 = W(R).oX1
  166.                         W(R).Y1 = W(R).oY1
  167.                         W(R).X2 = W(R).oX2
  168.                         W(R).Y2 = W(R).oY2
  169.                         W(R).Status = 0
  170.  
  171.                         X1 = W(R).oX1
  172.                         Y1 = W(R).oY1
  173.                         X2 = W(R).oX2
  174.                         Y2 = W(R).oY2
  175.  
  176.                         Set_Active_Window R
  177.                     END IF
  178.                     eif:
  179.                     LINE (0, 71)-(_DESKTOPWIDTH, _DESKTOPHEIGHT), ScreenBackGroundColor, BF
  180.                 END IF
  181.  
  182.  
  183.             CASE X2 - 41 TO X2 - 27
  184.                 LINE (X2 - 41, Y1 + 4)-(X2 - 27, Y1 + 19), &H99FF0000, BF 'icon minimalize
  185.                 IF MB1 THEN
  186.                     LINE (X1, Y1)-(X2, Y2), ScreenBackGroundColor, BF
  187.                     IF W(R).Status = 1 THEN '        return previous state from minimalize
  188.                         W(R).X1 = W(R).oX1
  189.                         W(R).Y1 = W(R).oY1
  190.                         W(R).X2 = W(R).oX2
  191.                         W(R).Y2 = W(R).oY2
  192.                         W(R).Status = 0
  193.                         X1 = W(R).oX1
  194.                         Y1 = W(R).oY1
  195.                         X2 = W(R).oX2
  196.                         Y2 = W(R).oY2
  197.  
  198.                         Set_Active_Window R
  199.                         GOTO eif2
  200.                     END IF
  201.  
  202.  
  203.  
  204.                     IF W(R).Status = 0 THEN 'Maximalize. First write current coordinates.
  205.                         W(R).oX1 = X1
  206.                         W(R).oY1 = Y1
  207.                         W(R).oX2 = X2
  208.                         W(R).oY2 = Y2
  209.  
  210.                         W(R).X1 = 3
  211.                         W(R).X2 = _DESKTOPWIDTH - 3
  212.                         W(R).Y2 = _DESKTOPHEIGHT - 5
  213.                         W(R).Y1 = 71
  214.                         W(R).Status = 2
  215.                         Set_Active_Window R
  216.                     END IF
  217.                     eif2:
  218.                 END IF
  219.         END SELECT
  220.     END IF
  221.  
  222. 'DRAW GRID IN WINDOWS
  223.  
  224. 'Load previous grid coordinates (on grid positions)
  225.  
  226. MrY1 = W(R).GYs
  227. MrY2 = W(R).GYe
  228. MrX1 = W(R).GXs '                                   Positions on grid
  229. MrX2 = W(R).GXe
  230.  
  231. 'arrow up in windows
  232. IF MX >= X2 - 19 AND MX <= X2 - 7 THEN
  233.     IF MY >= Y1 + 26 AND MY <= Y1 + 38 THEN
  234.         LINE (X2 - 19, Y1 + 26)-(X2 - 7, Y1 + 38), &H33FF0000, BF
  235.         IF MB1 THEN MrY1 = MrY1 - 1
  236.     END IF
  237.  
  238. 'rrow down in windows
  239. IF MX >= X2 - 19 AND MX <= X2 - 7 THEN
  240.     IF MY >= Y2 - 38 AND MY <= Y2 - 26 THEN
  241.         LINE (X2 - 19, Y2 - 26)-(X2 - 7, Y2 - 38), &H33FF0000, BF
  242.         IF MB1 THEN MrY1 = MrY1 + 1
  243.     END IF
  244.  
  245. 'arrow left
  246. IF MX >= X1 + 6 AND MX <= X1 + 18 THEN
  247.     IF MY >= Y2 - 20 AND MY <= Y2 - 5 THEN
  248.         LINE (X1 + 18, Y2 - 20)-(X1 + 6, Y2 - 5), &H33FF0000, BF
  249.         IF MB1 THEN MrX1 = MrX1 - 1
  250.     END IF
  251.  
  252. 'arrow right
  253. IF MX >= X2 - 18 AND MX <= X2 - 6 THEN
  254.     IF MY >= Y2 - 20 AND MY <= Y2 - 5 THEN
  255.         LINE (X2 - 18, Y2 - 20)-(X2 - 6, Y2 - 5), &H33FF0000, BF
  256.         IF MB1 THEN MrX1 = MrX1 + 1 'tady mrX1 neblbne
  257.     END IF
  258. 'if is here inserted: PRINT R: _DISPLAY: SLEEP, problem not occur. WHY?
  259.  
  260.  
  261.  
  262. IF R <= 2 THEN '                                I need view grid in window nr. 0,1,2. Window 3 use none grid. It is window for future OpenGL view.
  263.     rrr = rrr + 1
  264.     IF W(R).Status = 0 OR W(R).Status = 2 THEN
  265.  
  266.  
  267.         GX1 = X1 + 10 '                        reset start coordinates for grid. It is different, if is window minimized or use other width, height, or is maximalized.
  268.         GY1 = Y1 + 28 '                        this are relative coordinates.
  269.         GX2 = X2 - 25 '
  270.         GY2 = Y2 - 23 '
  271.         Gsize = W(R).Gsize
  272.  
  273.  
  274.         '  DO UNTIL (GX2 - GX1) MOD Gsize = 0 'reset grid size to value best for use in window for full fill.
  275.         '  Gsize = Gsize - 1
  276.         ' LOOP
  277.         'musel sem to odstavit, protoze to nesmyslne menilo velikost mrizky za chodu (pri roztazeni okna z boku nebo zdola)
  278.  
  279.  
  280.         'Every window show one piece in space (currently all show just X/Y)
  281.         MinX = 0: MinY = 0: MinZ = 0
  282.         SELECT CASE R
  283.             CASE 0: MaxX = GridSizeX: MaxY = GridSizeY: Z = CurrentZ 'View XY
  284.             CASE 1: MaxX = GridSizeX: MaxY = GridSizeZ: Z = CurrentY 'View YZ
  285.             CASE 2: MaxX = GridSizeY: MaxY = GridSizeZ: Z = CurrentX 'View XZ
  286.         END SELECT '               y                               x
  287.  
  288.  
  289.         'MrX1 and MrY1 are field coordinates, not graphical!
  290.  
  291.  
  292.         IF MrX1 < MinX THEN MrX1 = MinX 'LBOUND Overflow prevent
  293.         IF MrY1 < MinY THEN MrY1 = MinY
  294.  
  295.         'claculate how much points can be viewed
  296.         Xd = INT((GX2 - GX1 - Gsize) / Gsize)
  297.         Yd = INT((GY2 - GY1 - Gsize) / Gsize)
  298.  
  299.         MrX2 = MrX1 + Xd
  300.         MrY2 = MrY1 + Yd
  301.  
  302.  
  303.         IF MrX2 > MaxX THEN MrX2 = MaxX 'UBOUND Overflow prevent
  304.         IF MrY2 > MaxY THEN MrY2 = MaxY
  305.  
  306.  
  307.         Z = 2 'Alpha test - set X, Y to Z = 2
  308.         Arr3D(5, 7, 2) = 1
  309.  
  310.  
  311.         IF MrX2 < MrX1 OR MrY2 < MrY1 THEN SOUND 350, .5: PRINT MrX2; MrX1, MrY2; MrY1: _DISPLAY: SLEEP
  312.  
  313.  
  314.  
  315.         FOR DrawGridY = MrY1 TO MrY2
  316.             FOR DrawGridX = MrX1 TO MrX2
  317.                 ArrayX = DrawGridX
  318.                 ArrayY = DrawGridY
  319.                 IF Arr3D(ArrayX, ArrayY, Z) = 0 THEN
  320.                     LINE (GX1 + (Gsize * DrawGridX) - (Gsize * MrX1), GY1 + (Gsize * DrawGridY) - (Gsize * MrY1))-(GX1 + (DrawGridX * Gsize) + Gsize - 1 - (Gsize * MrX1), GY1 + (DrawGridY * Gsize) + Gsize - 1 - (Gsize * MrY1)), &HFF0000FF, B
  321.                 ELSE
  322.                     LINE (GX1 + (Gsize * DrawGridX) - (Gsize * MrX1), GY1 + (Gsize * DrawGridY) - (Gsize * MrY1))-(GX1 + (DrawGridX * Gsize) + Gsize - 1 - (Gsize * MrX1), GY1 + (DrawGridY * Gsize) + Gsize - 1 - (Gsize * MrY1)), &HFFFF0000, BF
  323.                 END IF
  324.             NEXT
  325.         NEXT
  326.  
  327.  
  328.     END IF
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335. 'save grid positions to field
  336. W(R).GYs = MrY1
  337. W(R).GYe = MrY2
  338. W(R).GXs = MrX1
  339. W(R).GXe = MrX2
  340.  
  341.  
  342.  
  343.  
  344.  
  345. 'pokracovat ovladanim a plnenim + kresbou mrizky
  346.  
  347.  
  348.  
  349.  
  350.  
  351.  
  352.  
  353. SUB Set_Active_Window (window_nr AS INTEGER)
  354. ii = 0
  355. IF W2(UBOUND(w2) - 1) <> window_nr THEN
  356.     DO UNTIL W2(ii) = window_nr
  357.         ii = ii + 1
  358.     LOOP
  359.     SWAP W2(UBOUND(w2) - 1), W2(ii)
  360.  
  361. SUB Reset_Mouse
  362.  
  363. FUNCTION Init_Window (Wname AS STRING, X1 AS INTEGER, Y1 AS INTEGER, X2 AS INTEGER, Y2 AS INTEGER, GridColor AS _UNSIGNED LONG, BackgroundColor AS _UNSIGNED LONG, Size AS _BYTE, Status AS _BYTE) 'pri initu je mrizka na pocatku.
  364. I = UBOUND(W)
  365. W(I).X1 = X1: W(I).Y1 = Y1: W(I).X2 = X2: W(I).Y2 = Y2: W(I).Status = Status: W(I).Gc = GridColor: W(I).GBc = BackgroundColor: W(I).WName = Wname: W(I).Gsize = Size: W(I).GXe = GridSizeX: W(I).GYe = GridSizeY
  366. W2(I) = I
  367. REDIM _PRESERVE W(I + 1) AS W
  368. Init_Window = I
  369.  
  370.  
  371.  
  372. SUB Draw_Window (Window_NR AS LONG)
  373. X1 = W(Window_NR).X1: Y1 = W(Window_NR).Y1: X2 = W(Window_NR).X2: Y2 = W(Window_NR).Y2: BackGroundColor~& = W(Window_NR).GBc: Wname$ = W(Window_NR).WName
  374. Size = W(Window_NR).Gsize: GridColor~& = W(Window_NR).Gc
  375.  
  376.  
  377.  
  378.  
  379. IF _MOUSEX >= X1 AND _MOUSEX <= X2 - 70 AND W(Window_NR).Status > -1 THEN 'omezeni kvuli ikonam ovladani okna
  380.     IF _MOUSEY >= Y1 AND _MOUSEY <= Y1 + 19 THEN
  381.         ' IF UBOUND(w2) - 1 = Window_NR THEN
  382.         IF Window_NR = W2(UBOUND(w2) - 1) THEN _MOUSESHOW "link"
  383.         IF _MOUSEBUTTON(1) THEN
  384.  
  385.             IF Window_NR = W2(UBOUND(w2) - 1) THEN
  386.                 ox1 = X1: ox2 = X2: oy1 = Y1: oy2 = Y2
  387.  
  388.  
  389.  
  390.                 PCOPY _DISPLAY, 10
  391.                 DO UNTIL _MOUSEBUTTON(1) = 0
  392.                     DO WHILE _MOUSEINPUT: LOOP
  393.                     MMX = MOUSEMOVEMENTX * 3
  394.                     MMY = MOUSEMOVEMENTY * 3
  395.  
  396.  
  397.                     PCOPY 10, _DISPLAY
  398.                     ooX1 = X1
  399.                     X1 = X1 + MMX
  400.                     ooy1 = Y1
  401.                     Y1 = Y1 + MMY
  402.                     X2 = X2 + MMX
  403.                     ooy2 = Y2
  404.                     Y2 = Y2 + MMY
  405.  
  406.  
  407.                     IF Y1 < 70 THEN Y1 = 70: Y2 = ooy2
  408.                     IF Y1 > _DESKTOPHEIGHT - 70 THEN Y1 = _DESKTOPHEIGHT - 70: Y2 = ooy2
  409.                     IF X2 < 70 THEN X2 = 70
  410.                     IF X1 > _DESKTOPWIDTH - 70 THEN X1 = _DESKTOPWIDTH - 70
  411.                     '------------------------------------------
  412.  
  413.                     LINE (X1, Y1)-(X2, Y2), &HFFFFFFFF, B , 127
  414.                     _DISPLAY
  415.                 LOOP
  416.  
  417.                 PCOPY 10, _DISPLAY
  418.             END IF
  419.  
  420.             '               FOR r = LBOUND(W) TO UBOUND(W)
  421.             '              W(r).Draw_Pos = 0
  422.             '             NEXT r
  423.             '                W(Window_NR).Draw_Pos = 1
  424.  
  425.             W(Window_NR).X1 = X1: W(Window_NR).X2 = X2
  426.             W(Window_NR).Y1 = Y1: W(Window_NR).Y2 = Y2
  427.  
  428.             IF W2(UBOUND(w2) - 1) <> Window_NR THEN
  429.                 DO UNTIL W2(ii) = Window_NR
  430.                     ii = ii + 1
  431.                 LOOP
  432.                 SWAP W2(UBOUND(w2) - 1), W2(ii)
  433.             END IF
  434.  
  435.  
  436.             LINE (ox1, oy1)-(ox2, oy2), ScreenBackGroundColor~&, BF 'premaze cernou barvou puvodni pozici okna
  437.         END IF
  438.  
  439.     END IF
  440.     ' END IF
  441. '----------------- PREDCHOZI BLOK RESI POSUN OKEN TAHEM ZA HORNI OKRAJ ----------------------------
  442.  
  443. '----------------- NASLEDUJE BLOK PRO ROZTAHOVANI TAHEM ZA LEVY, PRAVY, NEBO SPODNI OKRAJ ---------
  444.  
  445. IF W(Window_NR).Status > -1 THEN
  446.     IF Window_NR = W2(UBOUND(w2) - 1) THEN 'omezeni manipulace s oknem pouze pro aktivni okno
  447.         'levy okraj:
  448.         IF _MOUSEX >= W(Window_NR).X1 AND _MOUSEX < W(Window_NR).X1 + 15 THEN
  449.             IF _MOUSEY >= W(Window_NR).Y1 AND _MOUSEY <= W(Window_NR).Y2 - 25 THEN '   omezeni kvuli sipkam posunu mrizky
  450.                 ShiftLeft = 1
  451.             END IF
  452.         END IF
  453.  
  454.         'pravy okraj:
  455.         IF _MOUSEX >= W(Window_NR).X2 - 15 AND _MOUSEX < W(Window_NR).X2 THEN
  456.             IF _MOUSEY >= W(Window_NR).Y1 + 40 AND _MOUSEY <= W(Window_NR).Y2 - 40 THEN '   omezeni kvuli sipkam posunu mrizky
  457.                 ShiftRight = 1
  458.             END IF
  459.         END IF
  460.  
  461.         'spodni okraj
  462.  
  463.         IF _MOUSEX >= W(Window_NR).X1 + 20 AND _MOUSEX <= W(Window_NR).X2 - 20 THEN '   omezeni kvuli sipkam posunu mrizky
  464.             IF _MOUSEY >= W(Window_NR).Y2 - 15 AND _MOUSEY <= W(Window_NR).Y2 THEN
  465.                 ShiftDown = 1
  466.             END IF
  467.         END IF
  468.  
  469.         IF ShiftLeft OR ShiftRight THEN _MOUSESHOW "horizontal"
  470.         IF ShiftDown THEN _MOUSESHOW "vertical"
  471.         '------------- PREDCHOZI BLOK RESI ROZSVECENI SIPEK <-> ATD PRI NAJETI MYSI NA KRAJ OKNA -------------
  472.  
  473.         IF ShiftLeft AND _MOUSEBUTTON(1) THEN
  474.             PCOPY _DISPLAY, 10
  475.             IF _MOUSEX > 5 THEN
  476.                 DO UNTIL _MOUSEBUTTON(1) = 0
  477.                     IF W(Window_NR).X1 < W(Window_NR).X2 - 70 OR MMX = 1 THEN
  478.                         WHILE _MOUSEINPUT: WEND
  479.                         W(Window_NR).X1 = W(Window_NR).X1 + MOUSEMOVEMENTX * 3
  480.                         X1 = W(Window_NR).X1: Y1 = W(Window_NR).Y1: X2 = W(Window_NR).X2: Y2 = W(Window_NR).Y2
  481.                         PCOPY 10, _DISPLAY
  482.                         LINE (X1, Y1)-(X2, Y2), &HFFFFFFFF, B , 127
  483.                     ELSE
  484.                         W(Window_NR).X1 = W(Window_NR).X2 - 71
  485.                     END IF
  486.                     _DISPLAY
  487.                 LOOP
  488.                 CLS , ScreenBackGroundColor~&
  489.             END IF
  490.         END IF
  491.  
  492.         IF ShiftRight AND _MOUSEBUTTON(1) THEN
  493.             PCOPY _DISPLAY, 10
  494.             IF _MOUSEX < _DESKTOPWIDTH - 5 THEN
  495.                 DO UNTIL _MOUSEBUTTON(1) = 0
  496.                     IF W(Window_NR).X2 > W(Window_NR).X1 + 70 OR MMX = -1 THEN
  497.                         WHILE _MOUSEINPUT: WEND
  498.                         W(Window_NR).X2 = W(Window_NR).X2 + MOUSEMOVEMENTX * 3
  499.                         X1 = W(Window_NR).X1: Y1 = W(Window_NR).Y1: X2 = W(Window_NR).X2: Y2 = W(Window_NR).Y2
  500.                         PCOPY 10, _DISPLAY
  501.                         LINE (X1, Y1)-(X2, Y2), &HFFFFFFFF, B , 127
  502.                     ELSE
  503.                         W(Window_NR).X2 = W(Window_NR).X1 + 71
  504.                     END IF
  505.                     _DISPLAY
  506.                 LOOP
  507.                 CLS , ScreenBackGroundColor~&
  508.             END IF
  509.         END IF
  510.  
  511.         IF ShiftDown AND _MOUSEBUTTON(1) THEN
  512.             PCOPY _DISPLAY, 10
  513.             IF _MOUSEY < _DESKTOPHEIGHT THEN
  514.  
  515.                 DO UNTIL _MOUSEBUTTON(1) = 0
  516.                     IF W(Window_NR).Y2 > W(Window_NR).Y1 + 70 THEN
  517.                         WHILE _MOUSEINPUT: WEND
  518.                         W(Window_NR).Y2 = W(Window_NR).Y2 + MOUSEMOVEMENTY * 3
  519.                         X1 = W(Window_NR).X1: Y1 = W(Window_NR).Y1: X2 = W(Window_NR).X2: Y2 = W(Window_NR).Y2
  520.                         PCOPY 10, _DISPLAY
  521.                         LINE (X1, Y1)-(X2, Y2), &HFFFFFFFF, B , 127
  522.                     ELSE
  523.                         W(Window_NR).Y2 = W(Window_NR).Y1 + 71
  524.                     END IF
  525.  
  526.                     _DISPLAY
  527.                 LOOP
  528.                 CLS , ScreenBackGroundColor~&
  529.             END IF
  530.         END IF
  531.  
  532.  
  533.     END IF 'konec kotroly STATUS > -1
  534.  
  535.  
  536. END IF 'konec omezeni pohybu podle toho, jestli jde o aktivni okno.
  537. '---------------------------------- next day -------------------------------------------------------------- 12-07-2019 ---------------------------------------------
  538. 'pridam tomu trochu na vzhledu. Jemny barevny prechod pro cast pod ikonami poresim funkci, aby se to stale nekreslilo.
  539. 'pozadi vlozim pred kresleni oken - radek 61, provedeny upravy a otestovani v Draw_Window
  540.  
  541. _PUTIMAGE (0, 0), IconBack 'vklad pozadi pod hornim pasem pro ikony
  542.  
  543.  
  544. 'Pridan EDITOR.BM pro loadovani ICO souboru (sipky pro okna)
  545. 'Pro vyssi prehlednost necham vzdy mrizku vcetne posunu na subu GRID.
  546. 'Grid bude kreslit na hotove okenni pozadi, cili az na konci tohoto SUBu.
  547.  
  548.  
  549.  
  550. 'vykresleni oken v poradi tak, aby posledni aktivni okno bylo na vrchu.
  551. FOR WW = LBOUND(w2) TO UBOUND(w2) - 1
  552.     Window_NR = (W2(WW))
  553.     IF W(Window_NR).Status = -1 THEN GOTO f 'VYPNE OKNO
  554.  
  555.     COLOR &HFFFFFFFF
  556.     '  PRINT Window_NR: _DISPLAY
  557.     X1 = W(Window_NR).X1: Y1 = W(Window_NR).Y1: X2 = W(Window_NR).X2: Y2 = W(Window_NR).Y2: BackGroundColor~& = W(Window_NR).GBc: Wname$ = W(Window_NR).WName
  558.     Size = W(Window_NR).Gsize: GridColor~& = W(Window_NR).Gc
  559.  
  560.  
  561.     LINE (X1, Y1)-(X2, Y2), BackGroundColor~&, BF
  562.     LINE (X1, Y1 + 20)-(X2, Y2), &HFFFFFFFF, B
  563.     LINE (X1 + 2, Y1 + 22)-(X2 - 2, Y2 - 2), &HFFFFFFFF, B
  564.  
  565.     LINE (X1 + 3, Y1)-(X2 - 3, Y1 + 19), _RGB32(183, 194, 200), BF
  566.  
  567.     LINE (X1, Y1)-(X2, Y2), &HFFFFFFFF, B
  568.     LINE (X1 + 2, Y1 + 2)-(X2 - 2, Y2 - 2), &HFFFFFFFF, B
  569.  
  570.  
  571.     COLOR &HFF000000
  572.  
  573.     IF X2 - X1 >= LEN(Wname$) * 16 + 50 THEN
  574.         _PRINTSTRING (X1 + 40, Y1 + 4), "[" + Wname$ + "]" + STR$(Window_NR)
  575.     ELSE
  576.         chrs = _CEIL(X2 - X1 - 90) / 16
  577.         IF chrs < 0 THEN chrs = 0
  578.         nWname$ = LEFT$("[" + Wname$ + "]", chrs)
  579.         _PRINTSTRING (X1 + 40, Y1 + 4), nWname$
  580.     END IF
  581.  
  582.  
  583.     Grid Window_NR
  584.     f:
  585.  
  586.  
  587.  
  588.  
  589. FUNCTION MOUSEMOVEMENTX
  590. SHARED memory_mousemovementx
  591. MOUSEMOVEMENTX = 0
  592. IF _MOUSEX > memory_mousemovementx THEN memory_mousemovementx = _MOUSEX: MOUSEMOVEMENTX = 1: EXIT FUNCTION
  593. IF _MOUSEX < memory_mousemovementx THEN memory_mousemovementx = _MOUSEX: MOUSEMOVEMENTX = -1
  594.  
  595. FUNCTION MOUSEMOVEMENTY
  596. SHARED memory_mousemovementy
  597. MOUSEMOVEMENTY = 0
  598. IF _MOUSEY > memory_mousemovementy THEN memory_mousemovementy = _MOUSEY: MOUSEMOVEMENTY = 1: EXIT FUNCTION
  599. IF _MOUSEY < memory_mousemovementy THEN memory_mousemovementy = _MOUSEY: MOUSEMOVEMENTY = -1
  600.  
  601. FUNCTION IconBackground&
  602. a = _DEST
  603. IconBackground& = _NEWIMAGE(_DESKTOPWIDTH, 70, 32)
  604. _DEST IconBackground&
  605. D = 85 / 70
  606. DRA = 255
  607. FOR Dr = 0 TO 70
  608.     LINE (0, Dr)-(_DESKTOPWIDTH, Dr), _RGB32(DRA, DRA, DRA)
  609.     DRA = DRA - D
  610. c = 70 / _DESKTOPWIDTH
  611. CC = 127
  612.     PSET (r, 67), _RGB32(CC, CC, CC)
  613.     PSET (r, 69), _RGB32(CC, CC, CC)
  614.     CC = CC - c
  615.  
  616.  
  617. SUB LoadIcons
  618. ICOLeft = LOADICO("ico/left.ico", 9)
  619. ICORight = LOADICO("ico/right.ico", 9)
  620. ICOUp = LOADICO("ico/up.ico", 9)
  621. ICODn = LOADICO("ico/down.ico", 9)
  622. ICOClose = LOADICO("ico/close.ico", 9)
  623. ICOMaximize = LOADICO("ico/maximize.ico", 9)
  624. ICOMinimize = LOADICO("ico/minimize.ico", 9)
  625. ICOSetup = LOADICO("ico/setup.ico", 7)
  626.  
  627. FUNCTION Window_Active (tX, tY, tX2, tY2)
  628. FOR T = 0 TO 3
  629.     S = W(T).Draw_Pos
  630.     X1 = W(T).X1
  631.     Y1 = W(T).Y1
  632.     X2 = W(T).X2
  633.     Y2 = W(T).Y2
  634.     'detekce bodu v ctverci. pokud jedina strana je v jinem okne a toto okno ma priznak S = 1, pak funkce vrati cislo okna, ktere je aktivni. Pokud tam neni shoda, vrati cislo okna, ktere je v teto pozici.
  635.  
  636.  
  637.  
  638.  
  639. '$include:'editor.bm'
  640.  

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: 3D Object Editor: Start
« Reply #8 on: July 14, 2019, 05:36:37 am »
Error localized specifically !!!! If you remove * 12 from STRING definitions in IDE 1.3  (which is necessary for IDE 1.1 but not 1.3) from the last source after the field definitions after the STRING field, then you will get the previous error. If you leave STRING * 12 there, then the error disappears.
« Last Edit: July 14, 2019, 05:52:58 am by Petr »

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: 3D Object Editor: Start
« Reply #9 on: July 14, 2019, 01:59:32 pm »
Hi Petr

fantastic, you have found or a bug of parser or a empowerement that shifts QB64 far from QB45

see here
 
UDT stringa fissa2.jpg


in fact I remember that I learnt UDT while I's learning Random access to file for defining RECORD and as QB help seems to affirm
in TYPE definition  String must be fixed using *n
 
UDT stringa fissa.jpg


and in QB64 Wiki we have no mention of fixed string in TYPE page but all the examples show fixed strings
http://qb64.org/wiki/TYPE

but we have informations from STRING wiki page
http://qb64.org/wiki/STRING

Good, more we use QB64, more the developers' team gets back useful feedbacks.


« Last Edit: July 14, 2019, 02:02:17 pm by TempodiBasic »
Programming isn't difficult, only it's  consuming time and coffee

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: 3D Object Editor: Start
« Reply #10 on: July 14, 2019, 02:17:22 pm »
Hi Petr
about your creature...


WOW!
It's great to have 4 windows that are sizeable, moveable, can be minimized, maximizide and closed.

Two feedback that may be useful:
1. For now dragging a window make slow the flow of program
2. if I overlap 2 windows and I click on the portion of the window that overlaps the other window the clickStroke is given to the window that has the low order (0-1-2-3) so there is no Zorder for windowing... if I click on window 3 that overlaps window 1 I'll aspect to interact with window 3 and not to focus window 1 that is under.
Thanks to read
Programming isn't difficult, only it's  consuming time and coffee

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: 3D Object Editor: Start
« Reply #11 on: July 14, 2019, 02:28:14 pm »
Hi Tempo, I know about these problems, and I wanted to work on them... i run it and miss a grid in one window after running.... and start detective work why... :-D This is the version during development. I'm writing a feature now, that will solve the overlapping windows. Thank You :-D

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: 3D Object Editor: Continue
« Reply #12 on: September 03, 2019, 02:27:11 pm »
Hi.

So after a very long time I decided to continue and release another development intermediate version of my 3D object editor. I improved the behavior of the windows, made real 3D viewable in the preview window, added some functions and several icons. The program is still far from complete.
A few words about the program function. The leftmost icon allows you to set
these things:
- Z offset for window 0 (X / Y). Moves the grid to the selected depth.
- Y offset for window 1 (X / Z). Moves the grid to the selected height in the body.
- X offset for window 2 (Y / Z). Moves the grid to the selected width in the body.

Just imagine having a book in your hand. Z is the page number in the book when looking at the book (that is, according to Z you can reach a specific depth inside the book).

The X offset is the same if you look at this book sideways, so the top-down axis is Y and the horizontal axis is Z, setting this to position the letter in a row on a specific page in the book,
(simply depth shift when looking at the body from the side)

The Y offset is again the same, if you visualize the bottom of the body. The Y offset determines the height at which a row is in a book, or otherwise, a depth shift when looking at a body so that its bottom is in front view.

the center point of the object. It is intended as the center around which the body will rotate.
 
Finally, set the ratio. This sets the total body size.
Since this is an early version of the program, I have only tested it on a rectangle in space.

Middle icon with pencil. Only works if the vertex field contains at least 4 records. It allows manual editing of the vertex field and their transcription. This is great for the spatial understanding of MAPTRIANGLE 3D. Notice how the drawing in Window 3 changes as you edit the coordinates.
The third icon allows you to delete the vertices to clear all windows.

I haven't worked on it at all for a while, because I had to prioritize more important and necessary things.

I plan to add (this is a must!) Option to select body textures, convert 2D to 3D, and interlayer copy. At the same time, the function one step back and other functions.

How to try it:
In the upper left window, use the arrows on the edge of the window to locate where the blue squares in the X and Y axes intersect. This is zero, the center of the body. Now, to maintain the proper texture of the inner texture, proceed as follows:

Click once left up above the blue crossing. Then to right up above the blue crossing. Then down left under the blue crossing and finally down right under the blue crossing. You have inserted 4 spatial points and you should see a rectangle or at least some white lines in window 3. You can now edit the 3D coordinates by clicking the center icon. To exit from the coordinates editor subroutine, press Esc. For erase all vertexes click to trash icon.

So far no great fame, but it will come someday :)


* 3Dedit.zip (Filesize: 366.9 KB, Downloads: 185)