Author Topic: MAPTRIANGLE in 3D  (Read 321 times)

Offline Petr

  • I am instructed.
MAPTRIANGLE in 3D
« on: June 25, 2018, 05:08:57 PM »
Code: [Select]
SCREEN _NEWIMAGE(1024, 768, 32)
im& = _SCREENIMAGE
img& = _COPYIMAGE(im&, 33)
_FREEIMAGE im&
SX0 = 0: SY0 = 0: SX1 = 0: SY1 = _HEIGHT: sx2 = _WIDTH: sy2 = 0: sx3 = _WIDTH: sy3 = _HEIGHT
DX0 = -2: DY0 = 2: DX1 = -2: DY1 = -2: DX2 = 2: DY2 = 2: DX3 = 2: DY3 = -2

tt = .01: t = .1
DO
    e& = ell&
    WHILE _MOUSEINPUT: WEND
    Mx = _MOUSEX: My = _MOUSEY
    StredX = Mx
    t = t + tt: IF t > _PI(2) OR t < -_PI(2) THEN tt = tt * -1
    RR = SIN(t) - 4
    SS = COS(t) - 10
    R = -SIN(t) * -2
    s = -COS(t) * 2

    _MAPTRIANGLE (SX0, SY0)-(sx3, sy3)-(SX1, SY1), e& TO(DX0 * R, DY0 * s, RR)-(DX3 * R, DY3 * s, SS)-(DX1 * R, DY1 * s, RR), 0, _SMOOTH
    _MAPTRIANGLE (SX0, SY0)-(sx3, sy3)-(sx2, sy2), e& TO(DX0 * R, DY0 * s, RR)-(DX3 * R, DY3 * s, SS)-(DX2 * R, DY2 * s, SS), 0, _SMOOTH
    _DISPLAY
    _FREEIMAGE e&     
    _LIMIT 30
LOOP



FUNCTION ell&

    SHARED vx, vy, Mxx, Myy
    LOCATE 1, 1: PRINT "This is Software Screen."
    V& = _NEWIMAGE(1024, 768, 32)
    _DEST V&
    W = 1024: H = 768
    IF Mxx = 0 THEN Mxx = 10: Myy = 10
    vx = vx + Mxx: IF vx > W OR vx < 0 THEN Mxx = Mxx * -1
    vy = vy + Myy: IF vy > H OR vy < 0 THEN Myy = Myy * -1
    CLS , _RGB32(1, 55, 132)
    _PRINTMODE _KEEPBACKGROUND
    LOCATE 11, 30: PRINT "This is Hardware Screen"
    FOR d = 0 TO _PI / 2 STEP .2
        LINE (vx - SIN(d) * 50, vy - COS(d) * 50)-(vx + SIN(d) * 50, vy + COS(d) * 50), , BF
    NEXT d
    _DEST 0
    ell& = _COPYIMAGE(V&, 33)
    _FREEIMAGE V&
END FUNCTION
« Last Edit: November 03, 2018, 04:24:49 PM by Petr »

Offline Petr

  • I am instructed.
Re: MAPTRIANGLE in 3D
« Reply #1 on: June 25, 2018, 05:14:07 PM »
Previous source code repaired, because now is this possible :-D
« Last Edit: November 03, 2018, 04:25:54 PM by Petr »

Offline Petr

  • I am instructed.
Re: MAPTRIANGLE in 3D
« Reply #2 on: November 03, 2018, 04:32:50 PM »
I working on another program for a long time. It has been literally worm by my neck, so I needed to relax. So, What about, projected a normal 2D image in the form of a pyramid in 3D?

Code: [Select]
image = _LOADIMAGE("dyne01.jpg", 32)
imag = _NEWIMAGE(1024, 768, 32)
_PUTIMAGE (_WIDTH(image), _HEIGHT(image))-(0, 0), image, imag ' downsizing image to one size

imh& = _COPYIMAGE(imag, 33) '      hardware image are need for real 3D maptriangle use
TYPE V
    X AS SINGLE
    Y AS SINGLE
    Z AS SINGLE
END TYPE


W = _WIDTH(imag)
H = _HEIGHT(imag)

prvkuX = 60 '                       image "compression" ratio (do quads in this steps)
prvkuY = 80

pX = W / prvkuX
pY = H / prvkuY
DIM V(4) AS V '                              SOFTWARE IMAGE ARRAY

SCREEN _NEWIMAGE(W * 2, H * 2, 32)
_FULLSCREEN

camX = 0
camY = -300
camZ = -3000


DO UNTIL camZ > 5
    camZ = camZ + 2

    FOR y = 0 TO H - 1 STEP pY
        FOR x = 0 TO W - 1 STEP pX

            vyska = 115 '                   upper vertex for pyramide
            dno = 100 '                     bottom vertexes for pyramide

            '                               2D Sources
            V(0).X = x - (pX / 2) '         middle
            V(0).Y = y - (pY / 2)

            V(1).X = x - pX '               left upper vertex '           1+--------------+2
            V(1).Y = y - pY '                                              |\     d     / |
            '                                                              |   \  0  /    |
            V(2).X = x '                    right upper vertex  '          | a    +    c  |
            V(2).Y = y - pY '                                              |   /    \     |
            '                                                              |/     b    \  |
            V(3).X = x '                    right bottom vertex           4+--------------+3
            V(3).Y = y

            V(4).X = x - pX '               left bottom vertex
            V(4).Y = y


            'recalculating for 3D _MAPTRIANGLE use

            DIM VV(4) AS V '                 HARDWARE IMAGE ARRAY

            VV(0).X = W / 2 - V(0).X + camX '   middle vertex
            VV(0).Z = H / 2 - V(0).Y + camZ
            VV(0).Y = vyska + camY


            VV(1).X = W / 2 - V(1).X + camX '   left upper vertex
            VV(1).Z = H / 2 - V(1).Y + camZ
            VV(1).Y = dno + camY

            VV(2).X = W / 2 - V(2).X + camX '   right upper vertex
            VV(2).Z = H / 2 - V(2).Y + camZ
            VV(2).Y = dno + camY

            VV(3).X = W / 2 - V(3).X + camX '   right bottom vertex
            VV(3).Z = H / 2 - V(3).Y + camZ
            VV(3).Y = dno + camY

            VV(4).X = W / 2 - V(4).X + camX '   left bottom vertex
            VV(4).Z = H / 2 - V(4).Y + camZ
            VV(4).Y = dno + camY


            '3D with _MAPTRIANGLE is based on OpenGL, so coordinates here are 0,0,-1 in middle screen, to left is X negative, to right is X positive, for up is Y positive, for down is Y negative,
            'for inward is Z negative (to -10000) and for outward is bigger to -1. If is Z higher than -1, is unvisible, is out of the screen.




            _MAPTRIANGLE (V(1).X, V(1).Y)-(V(4).X, V(4).Y)-(V(0).X, V(0).Y), imh& TO(VV(1).X, VV(1).Y, VV(1).Z)-(VV(4).X, VV(4).Y, VV(4).Z)-(VV(0).X, VV(0).Y, VV(0).Z) 'a
            _MAPTRIANGLE (V(4).X, V(4).Y)-(V(3).X, V(3).Y)-(V(0).X, V(0).Y), imh& TO(VV(4).X, VV(4).Y, VV(4).Z)-(VV(3).X, VV(3).Y, VV(3).Z)-(VV(0).X, VV(0).Y, VV(0).Z) 'b
            _MAPTRIANGLE (V(3).X, V(3).Y)-(V(2).X, V(2).Y)-(V(0).X, V(0).Y), imh& TO(VV(3).X, VV(3).Y, VV(3).Z)-(VV(2).X, VV(2).Y, VV(2).Z)-(VV(0).X, VV(0).Y, VV(0).Z) 'c
            _MAPTRIANGLE (V(1).X, V(1).Y)-(V(2).X, V(2).Y)-(V(0).X, V(0).Y), imh& TO(VV(1).X, VV(1).Y, VV(1).Z)-(VV(2).X, VV(2).Y, VV(2).Z)-(VV(0).X, VV(0).Y, VV(0).Z) 'd
        NEXT x
    NEXT y
    _DISPLAY
    _LIMIT 50 'if you use higher resolution (more quads) in lines 19, 20, maybe delete or overwrite this limit.
LOOP

Re: MAPTRIANGLE in 3D
« Reply #3 on: November 03, 2018, 05:26:56 PM »
Petr, this is interesting, is there a way to tilt top end toward viewer leaving bottom edge the same?

press esc to quit:
Code: [Select]
image = _LOADIMAGE("dyne01.jpg", 32)
imag = _NEWIMAGE(1024, 768, 32)
_PUTIMAGE (_WIDTH(image), _HEIGHT(image))-(0, 0), image, imag ' downsizing image to one size

imh& = _COPYIMAGE(imag, 33) '      hardware image are need for real 3D maptriangle use
TYPE V
    X AS SINGLE
    Y AS SINGLE
    Z AS SINGLE
END TYPE


W = _WIDTH(imag)
H = _HEIGHT(imag)

prvkuX = 60 '                       image "compression" ratio (do quads in this steps)
prvkuY = 80

pX = W / prvkuX
pY = H / prvkuY
DIM V(4) AS V '                              SOFTWARE IMAGE ARRAY

SCREEN _NEWIMAGE(W * 2, H * 2, 32)
_FULLSCREEN

camX = -180
camY = -200
camZ = -500

dir = 1
DO UNTIL _KEYDOWN(27) <> 0
    camZ = camZ + 2 * dir
    IF camZ > -400 THEN dir = -dir: camZ = -400: camX = camX - 4
    IF camZ < -500 THEN dir = -dir: camZ = -500: camY = camY - 4


    FOR y = 0 TO H - 1 STEP pY
        FOR x = 0 TO W - 1 STEP pX

            vyska = 118 '                   upper vertex for pyramide  115
            dno = 110 '                     bottom vertexes for pyramide 100

            '                               2D Sources
            V(0).X = x - (pX / 2) '         middle
            V(0).Y = y - (pY / 2)

            V(1).X = x - pX '               left upper vertex '           1+--------------+2
            V(1).Y = y - pY '                                              |\     d     / |
            '                                                              |   \  0  /    |
            V(2).X = x '                    right upper vertex  '          | a    +    c  |
            V(2).Y = y - pY '                                              |   /    \     |
            '                                                              |/     b    \  |
            V(3).X = x '                    right bottom vertex           4+--------------+3
            V(3).Y = y

            V(4).X = x - pX '               left bottom vertex
            V(4).Y = y


            'recalculating for 3D _MAPTRIANGLE use

            DIM VV(4) AS V '                 HARDWARE IMAGE ARRAY

            VV(0).X = W / 2 - V(0).X + camX '   middle vertex
            VV(0).Z = H / 2 - V(0).Y + camZ
            VV(0).Y = vyska + camY


            VV(1).X = W / 2 - V(1).X + camX '   left upper vertex
            VV(1).Z = H / 2 - V(1).Y + camZ
            VV(1).Y = dno + camY

            VV(2).X = W / 2 - V(2).X + camX '   right upper vertex
            VV(2).Z = H / 2 - V(2).Y + camZ
            VV(2).Y = dno + camY

            VV(3).X = W / 2 - V(3).X + camX '   right bottom vertex
            VV(3).Z = H / 2 - V(3).Y + camZ
            VV(3).Y = dno + camY

            VV(4).X = W / 2 - V(4).X + camX '   left bottom vertex
            VV(4).Z = H / 2 - V(4).Y + camZ
            VV(4).Y = dno + camY


            '3D with _MAPTRIANGLE is based on OpenGL, so coordinates here are 0,0,-1 in middle screen, to left is X negative, to right is X positive, for up is Y positive, for down is Y negative,
            'for inward is Z negative (to -10000) and for outward is bigger to -1. If is Z higher than -1, is unvisible, is out of the screen.




            _MAPTRIANGLE (V(1).X, V(1).Y)-(V(4).X, V(4).Y)-(V(0).X, V(0).Y), imh& TO(VV(1).X, VV(1).Y, VV(1).Z)-(VV(4).X, VV(4).Y, VV(4).Z)-(VV(0).X, VV(0).Y, VV(0).Z) 'a
            _MAPTRIANGLE (V(4).X, V(4).Y)-(V(3).X, V(3).Y)-(V(0).X, V(0).Y), imh& TO(VV(4).X, VV(4).Y, VV(4).Z)-(VV(3).X, VV(3).Y, VV(3).Z)-(VV(0).X, VV(0).Y, VV(0).Z) 'b
            _MAPTRIANGLE (V(3).X, V(3).Y)-(V(2).X, V(2).Y)-(V(0).X, V(0).Y), imh& TO(VV(3).X, VV(3).Y, VV(3).Z)-(VV(2).X, VV(2).Y, VV(2).Z)-(VV(0).X, VV(0).Y, VV(0).Z) 'c
            _MAPTRIANGLE (V(1).X, V(1).Y)-(V(2).X, V(2).Y)-(V(0).X, V(0).Y), imh& TO(VV(1).X, VV(1).Y, VV(1).Z)-(VV(2).X, VV(2).Y, VV(2).Z)-(VV(0).X, VV(0).Y, VV(0).Z) 'd
        NEXT x
    NEXT y
    _DISPLAY
    _LIMIT 50 'if you use higher resolution (more quads) in lines 19, 20, maybe delete or overwrite this limit.
LOOP

B = B + ...
QB64 x 64 v1.2 2018 0228/86 git b30af92
QB64 v1.2 20180228/86 git 6fde149
QB64 v1.2 [dev build]_d84bb00

Offline Petr

  • I am instructed.
Re: MAPTRIANGLE in 3D
« Reply #4 on: November 03, 2018, 08:06:48 PM »
Hi Bplus. Thank for your interest. Is it so enough?

Code: [Select]
image = _LOADIMAGE("dyne01.jpg", 32)
imag = _NEWIMAGE(1024, 768, 32)
_PUTIMAGE (_WIDTH(image), _HEIGHT(image))-(0, 0), image, imag ' downsizing image to one size

imh& = _COPYIMAGE(imag, 33) '      hardware image are need for real 3D maptriangle use
TYPE V
    X AS SINGLE
    Y AS SINGLE
    Z AS SINGLE
END TYPE


W = _WIDTH(imag)
H = _HEIGHT(imag)

prvkuX = 150 '                       image "compression" ratio (do quads in this steps)
prvkuY = 150

pX = W / prvkuX
pY = H / prvkuY
DIM V(4) AS V '                              SOFTWARE IMAGE ARRAY
DIM px(4), O(4) AS V

SCREEN _NEWIMAGE(W * 2, H * 2, 32)
_FULLSCREEN

camX = -200
camY = -100
camZ = -800


DO UNTIL LEN(INKEY$)

    FOR y = 0 TO H - 1 STEP pY
        FOR x = 0 TO W - 1 STEP pX

            vyska = 125 '                   upper vertex for pyramide
            dno = 100 '                     bottom vertexes for pyramide

            '                               2D Sources
            V(0).X = x - (pX / 2) '         middle
            V(0).Y = y - (pY / 2)

            V(1).X = x - pX '               left upper vertex '           1+--------------+2
            V(1).Y = y - pY '                                              |\     d     / |
            '                                                              |   \  0  /    |
            V(2).X = x '                    right upper vertex  '          | a    +    c  |
            V(2).Y = y - pY '                                              |   /    \     |
            '                                                              |/     b    \  |
            V(3).X = x '                    right bottom vertex           4+--------------+3
            V(3).Y = y

            V(4).X = x - pX '               left bottom vertex
            V(4).Y = y


            'recalculating for 3D _MAPTRIANGLE use

            DIM VV(4) AS V '                 HARDWARE IMAGE ARRAY

            VV(0).X = W / 2 - V(0).X + camX '   middle vertex
            VV(0).Z = H / 2 - V(0).Y + camZ
            VV(0).Y = vyska + camY


            VV(1).X = W / 2 - V(1).X + camX '   left upper vertex
            VV(1).Z = H / 2 - V(1).Y + camZ
            VV(1).Y = dno + camY + 10

            VV(2).X = W / 2 - V(2).X + camX '   right upper vertex
            VV(2).Z = H / 2 - V(2).Y + camZ
            VV(2).Y = dno + camY + 10

            VV(3).X = W / 2 - V(3).X + camX '   right bottom vertex
            VV(3).Z = H / 2 - V(3).Y + camZ
            VV(3).Y = dno + camY

            VV(4).X = W / 2 - V(4).X + camX '   left bottom vertex
            VV(4).Z = H / 2 - V(4).Y + camZ
            VV(4).Y = dno + camY


            '3D with _MAPTRIANGLE is based on OpenGL, so coordinates here are 0,0,-1 in middle screen, to left is X negative, to right is X positive, for up is Y positive, for down is Y negative,
            'for inward is Z negative (to -10000) and for outward is bigger to -1. If is Z higher than -1, is unvisible, is out of the screen.

            rotation = rotation + .0001

            sinr! = SIN(-rotation / 57.2957795131): cosr! = COS(-rotation / 57.2957795131)
            FOR i& = 0 TO 4
                x2& = ((VV(i&).X * cosr!) + (sinr! * VV(i&).Z)) + VV(i&).X
                y2& = ((VV(i&).Z * cosr!) - (VV(i&).X * sinr!)) + VV(i&).Z

                O(i&).X = x2& + VV(i&).X
                O(i&).Z = VV(i&).Z + y2&
                O(i&).Y = VV(i&).Y - 200
            NEXT







            _MAPTRIANGLE (V(1).X, V(1).Y)-(V(4).X, V(4).Y)-(V(0).X, V(0).Y), imh& TO(O(1).X, O(1).Y, O(1).Z)-(O(4).X, O(4).Y, O(4).Z)-(O(0).X, O(0).Y, O(0).Z), _SMOOTH 'a
            _MAPTRIANGLE (V(4).X, V(4).Y)-(V(3).X, V(3).Y)-(V(0).X, V(0).Y), imh& TO(O(4).X, O(4).Y, O(4).Z)-(O(3).X, O(3).Y, O(3).Z)-(O(0).X, O(0).Y, O(0).Z), _SMOOTH 'b
            _MAPTRIANGLE (V(3).X, V(3).Y)-(V(2).X, V(2).Y)-(V(0).X, V(0).Y), imh& TO(O(3).X, O(3).Y, O(3).Z)-(O(2).X, O(2).Y, O(2).Z)-(O(0).X, O(0).Y, O(0).Z), _SMOOTH 'c
            _MAPTRIANGLE (V(1).X, V(1).Y)-(V(2).X, V(2).Y)-(V(0).X, V(0).Y), imh& TO(O(1).X, O(1).Y, O(1).Z)-(O(2).X, O(2).Y, O(2).Z)-(O(0).X, O(0).Y, O(0).Z), _SMOOTH 'd
        NEXT x
    NEXT y
    _DISPLAY
    _LIMIT 20 'if you use higher resolution (more quads) in lines 19, 20, maybe delete or overwrite this limit.
LOOP

Re: MAPTRIANGLE in 3D
« Reply #5 on: November 03, 2018, 09:53:37 PM »
It is moving fastest when it is largest and best chance to see details is lost.
B = B + ...
QB64 x 64 v1.2 2018 0228/86 git b30af92
QB64 v1.2 20180228/86 git 6fde149
QB64 v1.2 [dev build]_d84bb00

Offline Petr

  • I am instructed.
Re: MAPTRIANGLE in 3D
« Reply #6 on: November 04, 2018, 06:21:04 AM »
Yeah. With close proximity, the GPU has fewer computations and increases speed. Well, I will write something similar and try it better :-D

Re: MAPTRIANGLE in 3D
« Reply #7 on: November 04, 2018, 11:55:18 AM »
It is a good Halloween animation!
:-)

Offline Ashish

  • The joy of coding is endless.
Re: MAPTRIANGLE in 3D
« Reply #8 on: November 05, 2018, 04:12:21 AM »
Hi Petr!
Nice work on this!
For speed, you can try doing this in OpenGL (using array buffers).
if (Me.success) {Me.improve()} else {Me.tryAgain()}


aKFrameWork - http://bit.ly/aKFrameWork
Menu System - http://bit.ly/guiMenuBar
p5.js in QB64 - http://bit.ly/p5jsbas

@KingOfCoders

Offline Petr

  • I am instructed.
Re: MAPTRIANGLE in 3D
« Reply #9 on: November 05, 2018, 06:19:29 PM »
Hi Ashish. I like to see you here after a long time! Yes, with OpenGL the solution is here. I'm sure I'll go back to him, but I'll still be doing some attempts with _MAPTRIANGLE. I assume that QB64 problems with OpenGL will worsen over time (because OpenGL is no longer supported by some OS, instead of Vulkan) so we maybe may see Vulcan in QB64 :-D. Yeah, it's more like a dream.

Offline SMcNeill

  • QB64 Developer
Re: MAPTRIANGLE in 3D
« Reply #10 on: November 05, 2018, 06:53:06 PM »
Molten might be the way for us to go in the future:  https://moltengl.com

Quote
Molten GL provides the power to transform your graphics applications and games on iOS and macOS platforms. This premier product from the developers of MoltenVK will run your OpenGL ES 2.0 application or game on iOS or macOS using Metal — and faster!

No need to rewrite rendering logic and shaders for different platforms or abandon the familiar OpenGL ES 2.0 API. Applications built for OpenGL ES 2.0 can use MoltenGL to run on top of Metal, to gain the additional graphic performance of Metal today, and to protect your investments in OpenGL ES into the future!
« Last Edit: November 08, 2018, 11:33:10 AM by SMcNeill »

Offline Ashish

  • The joy of coding is endless.
Re: MAPTRIANGLE in 3D
« Reply #11 on: November 08, 2018, 11:21:02 AM »
Hi Ashish. I like to see you here after a long time! Yes, with OpenGL the solution is here. I'm sure I'll go back to him, but I'll still be doing some attempts with _MAPTRIANGLE. I assume that QB64 problems with OpenGL will worsen over time (because OpenGL is no longer supported by some OS, instead of Vulkan) so we maybe may see Vulcan in QB64 :-D. Yeah, it's more like a dream.
If OpenGL is going to be loose its support from some OS then, _MAPTRIANGLE will also not work, since _MAPTRIANGLE itself uses some GL commands internally.
if (Me.success) {Me.improve()} else {Me.tryAgain()}


aKFrameWork - http://bit.ly/aKFrameWork
Menu System - http://bit.ly/guiMenuBar
p5.js in QB64 - http://bit.ly/p5jsbas

@KingOfCoders

Online FellippeHeitor

  • QB64 Developer
  • LET IT = BE
    • QB64.org
Re: MAPTRIANGLE in 3D
« Reply #12 on: November 08, 2018, 11:24:58 AM »
We're not removing OpenGL support. Also, everything indicates we'll be back as normal in macOS in the upcoming 10.14.2 version of their OS.

Offline Ashish

  • The joy of coding is endless.
Re: MAPTRIANGLE in 3D
« Reply #13 on: November 08, 2018, 12:47:58 PM »
We're not removing OpenGL support. Also, everything indicates we'll be back as normal in macOS in the upcoming 10.14.2 version of their OS.
Thank God! :)
if (Me.success) {Me.improve()} else {Me.tryAgain()}


aKFrameWork - http://bit.ly/aKFrameWork
Menu System - http://bit.ly/guiMenuBar
p5.js in QB64 - http://bit.ly/p5jsbas

@KingOfCoders

Offline Petr

  • I am instructed.
Re: MAPTRIANGLE in 3D
« Reply #14 on: November 08, 2018, 03:55:33 PM »
I  also like restoring QB64 functionality to all supported systems. I will add to this thread the transcript of these OpenGL samples in the future. (so if we take Galleon's pattern, it will never be :-D) The display principle is the same (the OpenGL and 3D MAPTRIANGLE coordinate system), of course for 3D MAPTRIANGLE it is necessary to add a lot of already completed functions that OpenGL internally supports, such as a color transition from top to top, or _glrotatef (through modified ROTOZOOM), and I'm not talking about lighting. Again, using _MAPTRIANGLE, it is easier to perform texture than opens in OpenGL, where I have not yet come up with the reason why freeing texture work not right (with gl statement) and where I am very sorry for the miserable internal GLUT support. The tea pot, she sent me to the ground. The reason for her removal is..... and cause UNCOMPATIBILTY....  no, better no comment.

Problem with the buffer and speed, pointed out by BPlus, I assume that the _DEPTHBUFFER command should resolve this issue.

I do not want to hurt anyone here who is trying to support the flourishing QB64. I'm glad for it. Teapot is the only thing I do not take as a step forward. Well, gentlemen, I'm going to go into the depths of the code, I did not have time. I had to change the gutter on the roof. He was already very rusted Yeah. I sometimes do this too.
« Last Edit: November 08, 2018, 03:56:41 PM by Petr »