Discussion

real time 3D graphics might be possible

2

SP4CEBAR 2023-11-02 15:51 (Edited)

A while ago I made a triangle algorithm that writes horizontal segments quickly by writing 8 pixels (one byte) at a time, but the algorithm could only draw one or two triangles per frame. So what if, instead of drawing triangles, I were to make a similar algorithm to draw objects?

Like for example a subprogram that takes an array of seven x-coordinates, an array of seven y-coordinates, and an array of three two-bit colors. to define three visible faces of a 3D object, which could be a cube, a beam, or any trapezohedron. By the way, I've never seen more fancy words being used in a sentence than on the wikipedia page of a cube.

Or even better, a subprogram that treats the whole scene as one object that takes a sorted array of y-coordinates, with an array of x-coordinates, an array that defines how many points each face in the scene has, and another array that defines the color of each face.

Any polygon is made out of lines, lines are defined here as a starting y-value that adds this line to the system, a starting x-value, a direction value that is added to the x-value on every loop, and an ending y-value that removes this line from the system.

The subprogram could then be:

This likely will be far from 60fps, but I think even 10FPS could be considered a win, and it will run quicker if there are few objects in the scene, because the for loop from N_COMPLETED to N_ACTIVE will not run on empty rasters because of the value of those two variables.

EDIT: here's a program version:

'The first line is the baseline and is a vertical line at zero
SUB DRAW_SCENE ( X(), DX(), YA(), YB(), C() )
  N_COMPLETED = 1
  N_ACTIVE    = 0
  FOR Y=0 TO 127
    FOR LINE=N_COMPLETED TO N_ACTIVE
      ADD X( LINE ), DX( LINE )
      CALL DRAW_H_SEGMENT ( X( LINE ), X( LINE-1 ), C( LINE ) )
    NEXT LINE
    IF Y>YA(N_ACTIVE) THEN INC N_ACTIVE
    IF Y>YB(N_COMPLETED) THEN INC N_COMPLETED
  NEXT Y
END SUB


SP4CEBAR 2023-11-02 17:06 (Edited)

This doesn't include the processing required to transform the 3D coordinates through a matrix and to ensure all coordinates are sorted by Y values, and indexed by x values before entering the described display function


nathanielbabiak 2023-11-02 23:39 (Edited)

It'll be pretty slow on this system. I've done it here if you want a basis for comparison.


Log in to reply.