ChatGPT
#1
I've been playing with ChatGPT. I asked it this question:

"write qb64 code that converts 3d coordinates to 2d screen coordinates"

This is what it produced:

Code: (Select All)
SCREEN 12 'Set the screen mode to 640x480 16-color mode
CLS 'Clear the screen

' Set up the 3D coordinates of a cube
DIM x(8), y(8), z(8)
x(1) = -1: y(1) = -1: z(1) = 1
x(2) = 1: y(2) = -1: z(2) = 1
x(3) = 1: y(3) = 1: z(3) = 1
x(4) = -1: y(4) = 1: z(4) = 1
x(5) = -1: y(5) = -1: z(5) = -1
x(6) = 1: y(6) = -1: z(6) = -1
x(7) = 1: y(7) = 1: z(7) = -1
x(8) = -1: y(8) = 1: z(8) = -1

' Set up the camera position
cx = 0 ' Camera X coordinate
cy = 0 ' Camera Y coordinate
cz = -10 ' Camera Z coordinate

' Set up the projection parameters
near_plane = 1 ' Distance to near plane
far_plane = 100 ' Distance to far plane
fov = 90 ' Field of view in degrees

' Calculate the projection matrix
f = 1 / TAN(fov / 2 * PI / 180) ' Calculate focal length
a = f * 640 / 480 ' Calculate aspect ratio
proj_matrix(1, 1) = a: proj_matrix(2, 2) = f
proj_matrix(3, 3) = far_plane / (far_plane - near_plane)
proj_matrix(3, 4) = -far_plane * near_plane / (far_plane - near_plane)
proj_matrix(4, 3) = 1

' Apply the projection matrix to the 3D coordinates and convert to 2D screen coordinates
FOR i = 1 TO 8
    ' Apply the projection matrix
    x_proj = x(i) * proj_matrix(1, 1) + y(i) * proj_matrix(2, 1) + z(i) * proj_matrix(3, 1) + proj_matrix(4, 1)
    y_proj = x(i) * proj_matrix(1, 2) + y(i) * proj_matrix(2, 2) + z(i) * proj_matrix(3, 2) + proj_matrix(4, 2)
    w_proj = x(i) * proj_matrix(1, 4) + y(i) * proj_matrix(2, 4) + z(i) * proj_matrix(3, 4) + proj_matrix(4, 4)

    ' Convert to 2D screen coordinates
    x_screen = 320 + x_proj / w_proj * 320 ' Center the X coordinate and scale to screen size
    y_screen = 240 - y_proj / w_proj * 240 ' Center the Y coordinate and flip the Y axis

    ' Draw a point on the screen at the converted coordinates
    PSET (x_screen, y_screen), 15
NEXT i

' Wait for the user to press a key
DO
    SLEEP
LOOP UNTIL INKEY$ <> ""

END

Any thoughts?
Software and cathedrals are much the same — first we build them, then we pray.
QB64 Tutorial
Reply
#2
Does this program make anything but a black screen on anyone else's machine?

ChatLGBT is nothing but fancy autocomplete. There, you heard my side first, ha.
Reply
#3
Well all we need is to _underline PI and move the near not so much and it makes sense:
Code: (Select All)
Screen 12 'Set the screen mode to 640x480 16-color mode
Cls 'Clear the screen

' Set up the 3D coordinates of a cube
Dim x(8), y(8), z(8)
x(1) = -1: y(1) = -1: z(1) = 1
x(2) = 1: y(2) = -1: z(2) = 1
x(3) = 1: y(3) = 1: z(3) = 1
x(4) = -1: y(4) = 1: z(4) = 1
x(5) = -1: y(5) = -1: z(5) = -1
x(6) = 1: y(6) = -1: z(6) = -1
x(7) = 1: y(7) = 1: z(7) = -1
x(8) = -1: y(8) = 1: z(8) = -1

' Set up the camera position
cx = 0 ' Camera X coordinate
cy = 0 ' Camera Y coordinate
cz = -10 ' Camera Z coordinate

' Set up the projection parameters
near_plane = 2 ' Distance to near plane
far_plane = 100 ' Distance to far plane
fov = 90 ' Field of view in degrees

' Calculate the projection matrix
f = 1 / Tan(fov / 2 * _Pi / 180) ' Calculate focal length
a = f * 640 / 480 ' Calculate aspect ratio
proj_matrix(1, 1) = a: proj_matrix(2, 2) = f
proj_matrix(3, 3) = far_plane / (far_plane - near_plane)
proj_matrix(3, 4) = -far_plane * near_plane / (far_plane - near_plane)
proj_matrix(4, 3) = 1

' Apply the projection matrix to the 3D coordinates and convert to 2D screen coordinates
For i = 1 To 8
    ' Apply the projection matrix
    x_proj = x(i) * proj_matrix(1, 1) + y(i) * proj_matrix(2, 1) + z(i) * proj_matrix(3, 1) + proj_matrix(4, 1)
    y_proj = x(i) * proj_matrix(1, 2) + y(i) * proj_matrix(2, 2) + z(i) * proj_matrix(3, 2) + proj_matrix(4, 2)
    w_proj = x(i) * proj_matrix(1, 4) + y(i) * proj_matrix(2, 4) + z(i) * proj_matrix(3, 4) + proj_matrix(4, 4)

    ' Convert to 2D screen coordinates
    x_screen = 320 + x_proj / w_proj * 320 ' Center the X coordinate and scale to screen size
    y_screen = 240 - y_proj / w_proj * 240 ' Center the Y coordinate and flip the Y axis

    ' Draw a point on the screen at the converted coordinates
    PSet (x_screen, y_screen), 15
Next i

' Wait for the user to press a key
Do
    Sleep
Loop Until InKey$ <> ""

End

A more interesting question might be the reverse.
b = b + ...
Reply
#4
(02-22-2023, 12:38 AM)Sprezzo Wrote: Does this program make anything but a black screen on anyone else's machine?

ChatLGBT is nothing but fancy autocomplete. There, you heard my side first, ha.

Yep, it makes a few mistakes here and there but it's quite interesting that it can do this. I also asked it to generate a subroutine to rotate an image and another function to perform a rotozoom. Each needed slight modifications that needed to be made but the answers were otherwise solid.

Here is the image rotation it came up with:

Code: (Select All)
' Subroutine to rotate an image in QB64
SUB RotateImage(img AS _UNSIGNED _BYTE Ptr, width AS _INTEGER, height AS _INTEGER, degrees AS _INTEGER)
    ' Calculate the sine and cosine of the rotation angle
    rad = degrees * 3.14159 / 180
    cosA = COS(rad)
    sinA = SIN(rad)

    ' Create a new temporary image buffer
    newImg AS _UNSIGNED _BYTE Ptr = _NEWIMAGE(width, height)

    ' Loop through each pixel in the original image
    FOR x = 0 TO width - 1
        FOR y = 0 TO height - 1
            ' Calculate the new position of the pixel after rotation
            newX = x * cosA - y * sinA
            newY = x * sinA + y * cosA

            ' Check if the new position is within the bounds of the image
            IF newX >= 0 AND newX < width AND newY >= 0 AND newY < height THEN
                ' Get the color of the pixel at the new position
                color = _GETIMAGE(img, newX, newY)

                ' Set the color of the corresponding pixel in the new image buffer
                _PUTIMAGE(newImg, x, y, color)
            END IF
        NEXT y
    NEXT x

    ' Copy the rotated image back into the original image buffer
    _PUTIMAGE(img, 0, 0, newImg)

    ' Free the temporary image buffer
    _FREEIMAGE(newImg)
END SUB

And its explanation:

To use this subroutine, you would pass in a pointer to the image buffer, as well as the width and height of the image and the number of degrees to rotate the image by. The subroutine would create a new temporary image buffer, loop through each pixel in the original image, calculate its new position after rotation, and set the color of the corresponding pixel in the new image buffer. Finally, the subroutine would copy the rotated image back into the original image buffer and free the temporary image buffer.

Do you see "AI" models like this a threat or enhancement for programmers? I can see both sides. For an experienced programmer this may generate new ideas. For a beginner this could become a crutch and a path that never leads to actually mastering a language.
Software and cathedrals are much the same — first we build them, then we pray.
QB64 Tutorial
Reply
#5
(02-22-2023, 01:27 AM)bplus Wrote: A more interesting question might be the reverse.

Well, I did that per your suggestion and crashed it! LOL, a chicken and egg scenario perhaps or divide by 0 type of question.


Attached Files Image(s)
   
Software and cathedrals are much the same — first we build them, then we pray.
QB64 Tutorial
Reply
#6
Need to create an account to use the blamed thing. Nope.

Somebody is using it as "alternative psychologist" in another forum I belong to. Make it stop!

I hope it keeps failing to produce useful replies and it just bumps back down to oblivion where it came from. Either it could be a threat, or it could be yet another technological fad. I'm an enemy of this, it's not chat it's garbage.
Reply
#7
Yeah I balked too at signing up having paranoid thoughts about the powers of AI.

Just don't ask if it can make a better copy of itself.
b = b + ...
Reply
#8
(02-22-2023, 02:57 AM)mnrvovrfc Wrote: Need to create an account to use the blamed thing. Nope.

Somebody is using it as "alternative psychologist" in another forum I belong to. Make it stop!

I hope it keeps failing to produce useful replies and it just bumps back down to oblivion where it came from. Either it could be a threat, or it could be yet another technological fad. I'm an enemy of this, it's not chat it's garbage.

Just make a throw away email address, that's all it needs to create an account. (the only reason an account is needed is because it remembers your past conversations and builds off of them, such as Eliza did back in the 80's)

It's really interesting to play with. One of the example code it created for me included a library made for FreeBASIC. When I pointed this out it apologized, acknowledged I was correct, and then proceeded to produce the code I requested using only native QB64 commands.

I can see this as a useful tool to throw ideas around and maybe in the future it can be fed code to analyze for suggestions. In fact, ChatGPT told me that the plus versions (ChatGPT+) can be tailored to specific tasks, such as programming (it told me that was the reason it was making programming mistakes, because the general public version is just general knowledge).

It's not "AI", I get that, it's just a very cleverly written relational database, but something that given time might be a helpful tool. I don't know, time will tell I suppose.
Software and cathedrals are much the same — first we build them, then we pray.
QB64 Tutorial
Reply
#9
Despite what I said earlier, I was a bit amused with how a couple of other members of this forum interacted with it. Like the first thread by madscijr that I read about it, to build some text-only adventure LOL.

But it should be only for entertainment, not to be taken more seriously so people begin to fear losing their employments and/or looking dumb writing things on a forum such as this one. Blush
Reply
#10
I understand ChapGPT's knowledge data base is limited to data up to the year 2021. If QB64PE expands commands and syntax (as most computer languages will do) will the plus version of ChapGPT keep updating it's knowledge base?
Reply




Users browsing this thread: 24 Guest(s)