polygon_z_normal(3)
π polygon_z_normal(3) β the Allegro manual, but make it make sense
okay bestie, so this is a page straight outta the Allegro game programming library manual, and it's about two little functions that do the exact same vibe check on your polygons: polygon_z_normal and polygon_z_normal_f. They find the Z component of the normal vector to three vertices. That's the whole job. Iconic, honestly.
β¨ SYNOPSIS β¨
#include <allegro.h>
fixed polygon_z_normal(const V3D *v1, const V3D *v2, const V3D *v3);
float polygon_z_normal_f(const V3D_f *v1, const V3D_f *v2, const V3D_f *v3);
no cap, that's the whole signature. one for fixed, one for float, and both of them want three vertex pointers. π«Ά
πΈ DESCRIPTION πΈ
So here's the tea: this function finds the Z component of the normal vector to the three vertices you hand it β and those three vertices must be part of a convex polygon. that's not a suggestion, that's the rules. π
The main character use case here is back-face culling. Let me explain, because it's giving genius:
The back-faces of closed polyhedra are never visible to the viewer. like, never ever. so why are you drawing them?? exactly. you're not. This can cull on average half the polygons from a scene, which is a whole lot of free performance, periodt. π
How do you read the result? Simple:
- if the normal is negative, the polygon can safely be culled β bye bestie, don't let the door hit you β¨
- if it is zero, the polygon is perpendicular to the screen β it's literally edge-on, living its side-profile life
β οΈ okay but this is the important part, don't skip it: this back-face culling method must only be used once the X and Y coordinates have been projected into screen space using persp_project() (or if an orthographic (isometric) projection is being used). do it too early and it's just wrong. no notes.
π also, heads up: this function will fail if the three vertices are co-linear (they lie on the same line) in 3D space. co-linear vertices are not a vibe. give it an actual triangle, bestie.
π SEE ALSO π
alright that's the whole page, you ate it, you understood it, I'm obsessed with you. this was the polygon_z_normal(3) page from the Allegro manual, version 4.4.3 π¦ β go cull some back-faces, main character. ππβ¨
π¦ where this page comes from
- fedora 43: allegro-devel 4.4.3.1-18.fc43 Β· Giftware
- fedora 43: allegro-devel 4.4.3.1-18.fc43 Β· Giftware
- fedora 44: allegro-devel 4.4.3.1-20.fc44 Β· Giftware
- fedora 44: allegro-devel 4.4.3.1-20.fc44 Β· Giftware
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms