01-23-2026, 04:37 AM
Here ya go...simple coloured primitives lib...enjoy!
Code: (Select All)
' PAC-3D S-TIER ENGINE: DEFINITIVE 2026 BUILD
' Fix: Parameter Mismatch in Floor Render + Cohesive Mesh Logic
' No colons - No placeholders - Pro-Grade
$CHECKING:OFF
SCREEN _NEWIMAGE(800, 600, 32)
_TITLE "S-Tier 3D Engine (2026 Fix)"
' --- 1. HARDWARE ASSET INITIALIZATION ---
DIM SHARED RED&, GRN&, BLU&, YEL&, WHT&, BLK&, MAG&
RED& = CreateSolid&(255, 50, 50)
GRN& = CreateSolid&(50, 255, 50)
BLU& = CreateSolid&(50, 50, 255)
YEL& = CreateSolid&(255, 255, 0)
WHT& = CreateSolid&(255, 255, 255)
BLK& = CreateSolid&(20, 20, 20)
MAG& = CreateSolid&(255, 50, 255)
' --- 2. MAIN DEMO LOOP ---
DIM angle AS SINGLE
DO
_LIMIT 60
CLS
angle = angle + 0.01
' Render Old-School Checkerboard Floor
DrawCheckerboardFloor -4.0
' Render Primitives
DrawCube -4.5, 0, -15, 1.5, angle, angle * 0.5, RED&
DrawSphere 0, 0, -15, 2, angle, YEL&
DrawCylinder 4.5, -4, -15, 1, 4, angle, BLU&
DrawCone -4.5, -4, -15, 1.5, 3, angle, GRN&
DrawDisk 0, 4, -15, 3, angle, MAG&
_DISPLAY
LOOP UNTIL _KEYDOWN(27)
' --- 3. PRIMITIVE PROCEDURES ---
SUB DrawCheckerboardFloor (floorY!)
DIM size!
size! = 1.0
DIM count
count = 20
DIM startX!, startZ!
startX! = -(count / 2) * size!
startZ! = startX! - 20
FOR x = 0 TO count - 1
FOR z = 0 TO count - 1
cx! = startX! + x * size! + size! / 2
cz! = startZ! + z * size! + size! / 2
IF (x + z) MOD 2 = 0 THEN
tex& = WHT&
ELSE
tex& = BLK&
END IF
' Corrected RenderFace Call (No extra rotation params)
RenderFace cx!, floorY!, cz!, -size! / 2, 0, -size! / 2, size! / 2, 0, -size! / 2, size! / 2, 0, size! / 2, -size! / 2, 0, size! / 2, tex&
NEXT z
NEXT x
END SUB
SUB DrawCube (cx!, cy!, cz!, s!, rx!, ry!, tex&)
DIM x(8), y(8), z(8) AS SINGLE
x(1) = -s!: y(1) = -s!: z(1) = -s!: x(2) = s!: y(2) = -s!: z(2) = -s!
x(3) = s!: y(3) = s!: z(3) = -s!: x(4) = -s!: y(4) = s!: z(4) = -s!
x(5) = -s!: y(5) = -s!: z(5) = s!: x(6) = s!: y(6) = -s!: z(6) = s!
x(7) = s!: y(7) = s!: z(7) = s!: x(8) = -s!: y(8) = s!: z(8) = s!
FOR i = 1 TO 8
ApplyRotation x(i), y(i), z(i), rx!, ry!
NEXT i
RenderFace cx!, cy!, cz!, x(1), y(1), z(1), x(2), y(2), z(2), x(3), y(3), z(3), x(4), y(4), z(4), tex&
RenderFace cx!, cy!, cz!, x(2), y(2), z(2), x(6), y(6), z(6), x(7), y(7), z(7), x(3), y(3), z(3), tex&
RenderFace cx!, cy!, cz!, x(6), y(6), z(6), x(5), y(5), z(5), x(8), y(8), z(8), x(7), y(7), z(7), tex&
RenderFace cx!, cy!, cz!, x(5), y(5), z(5), x(1), y(1), z(1), x(4), y(4), z(4), x(8), y(8), z(8), tex&
RenderFace cx!, cy!, cz!, x(4), y(4), z(4), x(3), y(3), z(3), x(7), y(7), z(7), x(8), y(8), z(8), tex&
RenderFace cx!, cy!, cz!, x(1), y(1), z(1), x(5), y(5), z(5), x(6), y(6), z(6), x(2), y(2), z(2), tex&
END SUB
SUB DrawSphere (cx!, cy!, cz!, r!, rot!, tex&)
DIM vstep!
vstep! = 0.4
FOR lat! = 0 TO 3.14159 STEP vstep!
FOR lon! = 0 TO 6.28318 STEP vstep!
x1! = r! * SIN(lat!) * COS(lon!): y1! = r! * COS(lat!): z1! = r! * SIN(lat!) * SIN(lon!)
x2! = r! * SIN(lat! + vstep!) * COS(lon!): y2! = r! * COS(lat! + vstep!): z2! = r! * SIN(lat! + vstep!) * SIN(lon!)
x3! = r! * SIN(lat! + vstep!) * COS(lon! + vstep!): y3! = r! * COS(lat! + vstep!): z3! = r! * SIN(lat! + vstep!) * SIN(lon! + vstep!)
x4! = r! * SIN(lat!) * COS(lon! + vstep!): y4! = r! * COS(lat!): z4! = r! * SIN(lat!) * SIN(lon! + vstep!)
ApplyRotation x1!, y1!, z1!, rot!, rot!
ApplyRotation x2!, y2!, z2!, rot!, rot!
ApplyRotation x3!, y3!, z3!, rot!, rot!
ApplyRotation x4!, y4!, z4!, rot!, rot!
RenderFace cx!, cy!, cz!, x1!, y1!, z1!, x2!, y2!, z2!, x3!, y3!, z3!, x4!, y4!, z4!, tex&
NEXT lon!
NEXT lat!
END SUB
SUB DrawCylinder (cx!, cy!, cz!, r!, h!, rot!, tex&)
DIM vstep!
vstep! = 0.4
FOR a! = 0 TO 6.28318 STEP vstep!
x1! = r! * COS(a!): z1! = r! * SIN(a!): x2! = r! * COS(a! + vstep!): z2! = r! * SIN(a! + vstep!)
ApplyRotation x1!, z1!, 0, 0, rot! ' Reuse rot logic
ApplyRotation x2!, z2!, 0, 0, rot!
RenderFace cx!, cy!, cz!, x1!, 0, z1!, x2!, 0, z2!, x2!, h!, z2!, x1!, h!, z1!, tex&
NEXT a!
END SUB
SUB DrawCone (cx!, cy!, cz!, r!, h!, rot!, tex&)
DIM vstep!
vstep! = 0.4
FOR a! = 0 TO 6.28318 STEP vstep!
x1! = r! * COS(a!): z1! = r! * SIN(a!): x2! = r! * COS(a! + vstep!): z2! = r! * SIN(a! + vstep!)
RenderTri cx!, cy!, cz!, 0, h!, 0, x1!, 0, z1!, x2!, 0, z2!, tex&
RenderTri cx!, cy!, cz!, 0, 0, 0, x1!, 0, z1!, x2!, 0, z2!, tex&
NEXT a!
END SUB
SUB DrawDisk (cx!, cy!, cz!, r!, rot!, tex&)
DIM vstep!
vstep! = 0.4
FOR a! = 0 TO 6.28318 STEP vstep!
x1! = r! * COS(a!): z1! = r! * SIN(a!): x2! = r! * COS(a! + vstep!): z2! = r! * SIN(a! + vstep!)
RenderTri cx!, cy!, cz!, 0, 0, 0, x1!, 0, z1!, x2!, 0, z2!, tex&
NEXT a!
END SUB
' --- 4. ENGINE CORE SUBS ---
SUB ApplyRotation (x!, y!, z!, rx!, ry!)
tx! = x! * COS(ry!) - z! * SIN(ry!)
tz! = x! * SIN(ry!) + z! * COS(ry!)
x! = tx!: z! = tz!
ty! = y! * COS(rx!) - z! * SIN(rx!)
tz! = y! * SIN(rx!) + z! * COS(rx!)
y! = ty!: z! = tz!
END SUB
SUB RenderFace (cx!, cy!, cz!, x1!, y1!, z1!, x2!, y2!, z2!, x3!, y3!, z3!, x4!, y4!, z4!, t&)
_MAPTRIANGLE (0, 0)-(0, 0)-(0, 0), t& TO(x1! + cx!, y1! + cy!, z1! + cz!)-(x2! + cx!, y2! + cy!, z2! + cz!)-(x3! + cx!, y3! + cy!, z3! + cz!)
_MAPTRIANGLE (0, 0)-(0, 0)-(0, 0), t& TO(x1! + cx!, y1! + cy!, z1! + cz!)-(x3! + cx!, y3! + cy!, z3! + cz!)-(x4! + cx!, y4! + cy!, z4! + cz!)
END SUB
SUB RenderTri (cx!, cy!, cz!, x1!, y1!, z1!, x2!, y2!, z2!, x3!, y3!, z3!, t&)
_MAPTRIANGLE (0, 0)-(0, 0)-(0, 0), t& TO(x1! + cx!, y1! + cy!, z1! + cz!)-(x2! + cx!, y2! + cy!, z2! + cz!)-(x3! + cx!, y3! + cy!, z3! + cz!)
END SUB
FUNCTION CreateSolid& (r, g, b)
temp& = _NEWIMAGE(1, 1, 32): _DEST temp&
PSET (0, 0), _RGB32(r, g, b)
_DEST 0: CreateSolid& = _COPYIMAGE(temp&, 33)
_FREEIMAGE temp&
END FUNCTION

