' 3D Sinewave wibbly line thingy bob 'Hoppy's Fab 3D Camera - Target system 'CORRECTLY (at last) shows the 3D world from any place (Camera) looking to 'any place (Target). No Pukey angles required (except for roll should it be 'desired - avoid (sideways tilt); it is GRIM) DECLARE SUB RotateX (c AS ANY) DECLARE SUB RotateY (c AS ANY) DECLARE SUB RotateZ (c AS ANY) DECLARE SUB Screen3D (c AS ANY) SCREEN 12 FOR j% = 0 TO 15 PALETTE j%, (j% + 1) * 4 - 1 + ((j% + 1) * 4 - 1) * 256 + ((j% + 1) * 4 - 1) * 65536 NEXT j% RANDOMIZE TIMER Pi# = ATN(1) * 4 TYPE coord X AS SINGLE Y AS SINGLE Z AS SINGLE END TYPE TYPE pixel X AS INTEGER Y AS INTEGER Colour AS INTEGER END TYPE PRINT "Ignore the funny jagged lines when the thing gets close" PRINT "This is the 3D shape that is screwed up, not the 3d routines!" PRINT "Press space whilst running for a new one" PRINT INPUT "# Points"; n% DIM SHARED perspective, Rot AS coord, Pix AS pixel, PT(n%) AS pixel, p(n%) AS pixel DIM Target AS coord, Camera AS coord, Points(n%) AS coord, T(n%) AS coord perspective = 500 DIM SHARED CosX, SinX, CosY, SinY, CosZ, SinZ Target.X = 0 Target.Y = 0 Target.Z = 0 start: CLS s1 = (n% - 1) / (Pi# * 2 * INT(3 + RND * 4)) s2 = (n% - 1) / (Pi# * 2 * INT(3 + RND * 4)) s3 = (n% - 1) / (Pi# * 2 * INT(3 + RND * 4)) FOR a% = 1 TO n% Points(a%).X = 50 * COS(a% / s1) Points(a%).Y = 50 * COS(a% / s2) Points(a%).Z = 50 * SIN(a% / s3) NEXT a% top: i& = i& + 1 Camera.X = SIN(i& / 15.54) * 60 Camera.Y = COS(i& / 21.312) * 60 Camera.Z = SIN(i& / 63.45) * 200 DX = Target.X - Camera.X: IF ABS(DX) < .01 THEN DX = .01 DY = Target.Y - Camera.Y: IF ABS(DY) < .01 THEN DY = .01 DZ = Target.Z - Camera.Z: IF ABS(DZ) < .01 THEN DZ = .01 XRot = ATN(DY / SQR(DX * DX + DZ * DZ)) IF DZ > 0 THEN YRot = ATN(DX / DZ) ELSE YRot = Pi# - ATN(DX / -DZ) END IF 'ZRot=Waste of time except for vomity tilts i$ = INKEY$ IF i$ = " " THEN GOTO start IF i$ = CHR$(27) THEN END CosX = COS(XRot): SinX = SIN(XRot) CosY = COS(YRot): SinY = SIN(YRot) CosZ = COS(ZRot): SinZ = SIN(ZRot) FOR a% = 0 TO n% T(a%).X = Points(a%).X - Camera.X T(a%).Y = Points(a%).Y - Camera.Y T(a%).Z = Points(a%).Z - Camera.Z RotateY T(a%): T(a%) = Rot RotateX T(a%): T(a%) = Rot RotateZ T(a%) PT(a%) = p(a%) Screen3D Rot p(a%) = Pix IF Pix.Colour < 0 THEN p(a%).Colour = 0 NEXT a% FOR a% = 1 TO n% - 1 LINE (PT(a%).X, PT(a%).Y)-(PT(a% + 1).X, PT(a% + 1).Y), 0 LINE (p(a%).X, p(a%).Y)-(p(a% + 1).X, p(a% + 1).Y), p(a%).Colour NEXT a% LINE (PT(n%).X, PT(n%).Y)-(PT(1).X, PT(1).Y), 0 LINE (p(n%).X, p(n%).Y)-(p(1).X, p(1).Y), p(n%).Colour CIRCLE (PT(0).X, PT(0).Y), 2, 0 CIRCLE (p(0).X, p(0).Y), 2, 5 GOTO top SUB RotateX (c AS coord) Rot.X = c.X Rot.Y = c.Y * CosX - c.Z * SinX Rot.Z = c.Y * SinX + c.Z * CosX END SUB SUB RotateY (c AS coord) Rot.X = c.X * CosY - c.Z * SinY Rot.Y = c.Y Rot.Z = c.X * SinY + c.Z * CosY END SUB SUB RotateZ (c AS coord) Rot.X = c.X * CosZ - c.Y * SinZ Rot.Y = c.X * SinZ + c.Y * CosZ Rot.Z = c.Z END SUB SUB Screen3D (c AS coord) distance = SQR(c.X * c.X + c.Y * c.Y + c.Z * c.Z) mag = distance / perspective IF mag > .01 AND c.Z >= 0 THEN Pix.X = 320 + (c.X / mag) Pix.Y = 240 - (c.Y / mag) Pix.Colour = 500 / distance END IF END SUB