# Triangles BRRRRT

6

SP4CEBAR 2022-12-21 22:44

You know what this means

2022-12-23 10:03
2022-12-23 09:21
2022-12-22 21:15
2022-12-22 11:28
2022-12-21 22:44

SP4CEBAR 2022-12-21 22:59

3D graphics here we come!

SP4CEBAR 2022-12-21 23:04 (Edited)

This is achieved with an optimized horizontal line drawer on the character data

SP4CEBAR 2022-12-22 08:50

It still isn't fast enough as it almost draws one triangle per frame, a 3D game with 0.5 frames per second isn't very playable

SP4CEBAR 2022-12-22 11:29

Update: slightly faster, but still less than a triangle per frame

nathanielbabiak 2022-12-22 12:37

I couldn't get my triangle drawer to get much faster either - the only thing that's really helped is drawing them smaller or changing the display system.

Also, for 3D, you may want to look at the triangle algorithm in the sprite expansion library. It follows the rasterization right-hand rule so pixels aren't overdrawn. It won't save much speed, but it'll stop the display from flickering at the borders of the triangles.

SP4CEBAR 2022-12-22 21:17

Update: some triangles were bugged, that's now fixed

SP4CEBAR 2022-12-22 21:19 (Edited)

@nathanielbabiak
The flickering is caused by VBL interrupts, the only way to fix that is to draw the whole triangle in a frame

SP4CEBAR 2022-12-22 21:26 (Edited)

(edit: replying to a deleted comment) That looked like this:

GAMELEGEND (not actually him, it's a replica)

What was wrong with the triangles?

SP4CEBAR (still the same post)

@GAMELEGEND They were hourglass-shaped
My triangle system works like this:

• Input: three sets of coordinates and a 2-bit color
• Sorting: the coordinates are sorted based on their Y values (this was bugged)
• Line math: calculate the steepness and starting values for each line between the coordinates
• first half: loop from Y0 to Y1, generate the line X coordinates by repeatedly adding the steepness to the starting values, and draw a horizontal line on the X coordinates using my fast horizontal line drawing algorithm (based on the fact that most character bytes are 255)
• second half: same as the first half except it loops from Y1 to Y2

GAMELEGEND 2022-12-22 22:12

huh my comment showed back up after it disappeared

that's cool

SP4CEBAR 2022-12-23 09:20

Not actually: it's a markdown line with a markdown hyperlink, which as I just learned looks the same as a comment
I'm sorry Timo

SP4CEBAR 2022-12-23 09:22

Update: the line drawing algorithm is slightly faster and more organized

SP4CEBAR 2022-12-23 10:04

Update: again, slightly faster and more organized

SP4CEBAR 2022-12-23 10:23 (Edited)

By moving the safety and preparation calculations (ROM) away from the line and into the triangle I could get a somewhat significant improvement: maybe 2x as fast

@nathanielbabiak you could skip every second row (align all the triangles to use the same rows (rasters))
And then you could use this raster effect to duplicate each raster to cover the skipped ones:
SCROLL 0,0,RASTER MOD 2

GAMELEGEND 2022-12-23 14:17 (Edited)

I was wondering why I could not edit it

SP4CEBAR 2022-12-31 11:15

Apparently I spelled the subprogram name "triangle" as "triange" and it somehow didn't lead to any errors, I guess I'm keeping it now