MapTriangle (3D) demos
#8
The following example (3D) doesn't work quite well, so if anyone can fix it, I'd greatly appreciate it. First, a 2D program that, using the normal LINE command, shows the intention that the 3D program was supposed to carry out (how many times is it better to model it in 2D first, it is better to orientate yourself later, when it is in 3D)

Code: (Select All)
Screen _NewImage(1024, 768, 256)
krok = _Pi / 400 'sine draw 200 pixels before and 200 pixels after mouseX

Do
    While _MouseInput: Wend
    mx = _MouseX

    If x > 1024 Then x = 0
    x = x + 10

    If x < mx - 200 Or x > mx + 200 Then
        y1 = 350
        y2 = 350
        If mx > 200 Then sinP = 0 Else sinP = (200 - mx) * krok
    Else
        y1 = 350 + Sin(sinP) * 250
        y2 = 350 + Sin(sinP + krok * 10) * 250
        sinP = sinP + krok * 10
    End If
    Line (x, 0)-(x + 10, 767), 0, BF
    Line (x, y1)-(x + 10, y2)
Loop

Move the mouse in the X-axis. The deflection shows the intended intention. Just turn it around in your head as if the downward deflection is the direction in the Z axis, into the distance. This is the intended deformation of the image - zooming in the form of a wave (relative to the mouse) or zooming out, it doesn't matter, it's just a sign.

The 3D implementation follows, but it works - incorrectly. First, you need to be aware of the limitations of hardware images. It depends on your computer's graphics card, my computer is just weak, so I had to split the image into 2500 hardware images. These are then rendered. It is necessary to recalculate the mouse coordinates and there is a problem. 3D Maptriangle is not very suitable for normal 2D rendering, notice after launch that the mouse reacts across the width of the screen, but the 3D view is rendered depending on the distance. Try it yourself by changing the Z-axis coordinates on lines 41, 42 and 46, 47, just change the number -4 to another negative number. A negative number indicates the distance in depth, a positive number would mean that the object is in front of the monitor (behind your back) and therefore will not be rendered.

Move the mouse over the image in the X-axis, a wave will be formed with the image, as the intention showed in the previous case - but not quite accurate. And that is the question. Why is the wave not accurate?


Code: (Select All)
S = _ScreenImage
dW = Fix(_DesktopWidth / 50)
dH = Fix(_DesktopHeight / 50)

Screen _NewImage(_DesktopWidth, _DesktopHeight, 32)

Dim T(49, 49) As Long
For y = 0 To 49
    For x = 0 To 49
        V = _NewImage(dW, dH, 32)
        _PutImage (0, 0), S, V, (x * dW - 1, y * dH - 1)-(x * dW + dW - 1, y * dH + dH - 1)
        T(x, y) = _CopyImage(V, 33)
        _FreeImage V
    Next x
Next y
'above we converting screen image to small hardware images, 50 in X axis, 50 in Y axis, total 2500 textures


'let set 3DX from -3 to 3:
X3Dstp = 6 / 50 ' step for 3D drawing in X (we are here in OpenGL coordinate system)
krok = _Pi / 10 ' step for SINUS, it draws depth in this example

'let set 3DY from -3 to 3:
Y3Dstp = 6 / 50 ' step for Y drawing for 3D

x3d = -3 'default values
Y3D = -3

Do
    For yy = 0 To 49 'both FOR loops are here use for array T, not for drawing!
        SinP = 0
        For xx = 0 To 49
            While _MouseInput: Wend

            mxo = -_DesktopWidth / 2 + _MouseX 'because MapTriangle 3D use Open GL coordinate system, mouse coordinates must be recalculated
            mx = mxo / 6 / 50

            x3d = x3d + X3Dstp '                Variable for drawing in X axis

            If x3d < mx - X3Dstp * 5 Or x3d > mx + X3Dstp * 5 Then 'condition for mouse effect
                Z = -4
                Z2 = -4
                If mx < X3Dstp * 5 Then SinP = 0 Else SinP = (X3Dstp * 5 - mx) * krok
                If mx > X3Dstp * 5 Then SinP = 0 Else SinP = (X3Dstp * 5 + mx) * krok
            Else
                Z = -4 + Sin(SinP) / 2
                Z2 = -4 + Sin(SinP + krok) / 2
                SinP = SinP + krok
            End If

            _MapTriangle (0, dH)-(dW, dH)-(0, 0), T(xx, 49 - yy) To(x3d, Y3D, Z)-(x3d + X3Dstp, Y3D, Z2)-(x3d, Y3D + Y3Dstp, Z), 0 'draw hardware images to screen (note the swapping of coordinates, as OpenGL renders in reverse)
            _MapTriangle (dW, dH)-(0, 0)-(dW, 0), T(xx, 49 - yy) To(x3d + X3Dstp, Y3D, Z2)-(x3d, Y3D + Y3Dstp, Z)-(x3d + X3Dstp, Y3D + Y3Dstp, Z2), 0

        Next xx
        x3d = -3 '           reset X3D variable used for drawing to default value
        Y3D = Y3D + Y3Dstp '  Y3D is used for drawing in 3D
    Next yy
    Y3D = -3 '                reset Y3D to default value
    _Display '                show it all
    _Limit 20
Loop


Reply


Messages In This Thread
MapTriangle (3D) demos - by Petr - 03-21-2023, 03:58 PM
RE: MapTriangle (3D) demos - by Petr - 03-21-2023, 05:47 PM
RE: MapTriangle (3D) demos - by mnrvovrfc - 03-24-2023, 04:33 AM
RE: MapTriangle (3D) demos - by bplus - 03-24-2023, 05:16 AM
RE: MapTriangle (3D) demos - by Petr - 03-24-2023, 10:58 PM
RE: MapTriangle (3D) demos - by mnrvovrfc - 03-24-2023, 11:32 PM
RE: MapTriangle (3D) demos - by bplus - 03-24-2023, 11:54 PM
RE: MapTriangle (3D) demos - by Petr - 03-26-2023, 04:53 PM
RE: MapTriangle (3D) demos - by MasterGy - 03-28-2023, 05:05 PM
RE: MapTriangle (3D) demos - by Petr - 03-28-2023, 07:42 PM



Users browsing this thread: 2 Guest(s)