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


Messages In This Thread
ChatGPT - by TerryRitchie - 02-21-2023, 11:51 PM
RE: ChatGPT - by Sprezzo - 02-22-2023, 12:38 AM
RE: ChatGPT - by TerryRitchie - 02-22-2023, 01:47 AM
RE: ChatGPT - by bplus - 02-22-2023, 01:27 AM
RE: ChatGPT - by TerryRitchie - 02-22-2023, 01:52 AM
RE: ChatGPT - by mnrvovrfc - 02-22-2023, 02:57 AM
RE: ChatGPT - by TerryRitchie - 02-22-2023, 04:09 AM
RE: ChatGPT - by bplus - 02-22-2023, 03:16 AM
RE: ChatGPT - by PhilOfPerth - 07-12-2023, 06:15 AM
RE: ChatGPT - by mnrvovrfc - 02-22-2023, 05:26 AM
RE: ChatGPT - by madscijr - 02-23-2023, 10:36 PM
RE: ChatGPT - by Dimster - 02-22-2023, 05:16 PM
RE: ChatGPT - by mnrvovrfc - 02-23-2023, 02:35 AM
RE: ChatGPT - by aurel - 02-23-2023, 05:16 PM
RE: ChatGPT - by bplus - 02-23-2023, 08:19 PM
RE: ChatGPT - by SpriggsySpriggs - 02-23-2023, 08:37 PM
RE: ChatGPT - by TerryRitchie - 02-23-2023, 08:56 PM
RE: ChatGPT - by madscijr - 02-23-2023, 10:39 PM
RE: ChatGPT - by TerryRitchie - 02-23-2023, 10:54 PM
RE: ChatGPT - by madscijr - 02-23-2023, 11:06 PM
RE: ChatGPT - by mnrvovrfc - 02-23-2023, 11:53 PM
RE: ChatGPT - by madscijr - 02-24-2023, 12:37 AM
RE: ChatGPT - by bplus - 02-24-2023, 01:22 AM
RE: ChatGPT - by mnrvovrfc - 02-23-2023, 11:49 PM
RE: ChatGPT - by James D Jarvis - 02-23-2023, 08:49 PM
RE: ChatGPT - by DANILIN - 04-29-2023, 06:35 PM
RE: ChatGPT - by madscijr - 04-29-2023, 07:07 PM
RE: ChatGPT - by mnrvovrfc - 04-29-2023, 10:41 PM
RE: ChatGPT - by mnrvovrfc - 05-02-2023, 07:38 PM
RE: ChatGPT - by Dimster - 05-03-2023, 01:31 PM
RE: ChatGPT - by madscijr - 05-03-2023, 02:25 PM
RE: ChatGPT - by Dimster - 05-03-2023, 03:53 PM
RE: ChatGPT - by madscijr - 05-03-2023, 05:02 PM
RE: ChatGPT - by mnrvovrfc - 05-03-2023, 05:55 PM
RE: ChatGPT - by Ultraman - 05-03-2023, 05:41 PM
RE: ChatGPT - by madscijr - 05-03-2023, 06:07 PM
RE: ChatGPT - by TerryRitchie - 05-03-2023, 08:43 PM
RE: ChatGPT - by madscijr - 07-11-2023, 08:44 PM
RE: ChatGPT - by SMcNeill - 07-11-2023, 09:45 PM
RE: ChatGPT - by SpriggsySpriggs - 07-12-2023, 11:57 AM
RE: ChatGPT - by madscijr - 07-12-2023, 12:17 PM
RE: ChatGPT - by Kernelpanic - 07-15-2023, 08:46 PM
RE: ChatGPT - by madscijr - 07-15-2023, 11:24 PM
RE: ChatGPT - by SpriggsySpriggs - 07-16-2023, 12:34 AM
RE: ChatGPT - by madscijr - 07-16-2023, 06:40 PM
RE: ChatGPT - by mnrvovrfc - 07-16-2023, 07:37 PM
RE: ChatGPT - by madscijr - 07-17-2023, 02:44 AM
RE: ChatGPT - by SpriggsySpriggs - 07-17-2023, 02:33 PM



Users browsing this thread: 16 Guest(s)