ChatGPT
#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


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: 13 Guest(s)