3DENGINE ● SmileBASIC Source

Register
This website has been moved, please see this post

# 3DENGINE

Submitted
Updated
Author
triangle
Public Key
43KNQEA6
Min. Compat.
All
Size
27.6 KB
Rating
Description A 3D engine programmed with easy use in mind. Also includes 4D and MODE7. Instructions ```'--------- '3D ENGINE '--------- 'TO USE IN YOUR OWN PROGRAM, COPY UP TO THE '"END 3D ENGINE" COMMENT INTO THE BEGINNING 'OF YOUR CODE. 'OR YOU CAN USE IT LIKE A LIBRARY BY 'CHANGING THE LINE ' GOTO @START 'TO ' END 'AND PUTTING ' SYSBEEP=0 ' LOAD"PRG1:3DENGINE",FALSE ' USE 1:EXEC 1 ' SYSBEEP=1 'INTO THE BEGINNING OF YOUR CODE. 'THINGS IN THIS ENGINE: 'MODULUS(VALUE1,VALUE2) 'SUBSTITUTE MODULUS FUNCTION 'IT IS THE SAME AS "VALUE1 MOD VALUE2", EXCEPT 'IT CAN RETURN DECIMAL NUMBERS, NOT JUST INTEGERS 'CAMERA CX,CY,CZ,ANGX,ANGY,ANGZ 'CHANGES CAMERA LOCATION AND ANGLE 'CX,CY, AND CZ ARE THE CAMERA'S COORDINATES 'ANGX,ANGY, AND ANGZ ARE THE CAMERA'S ANGLES 'PARALLAX ZOOM,EYEDIST,FOCUS,LEVEL3D 'ZOOM IS THE ZOOM LEVEL(HIGHER NUMBERS=LESS PERSPECTIVE DISTORTION) 'EYEDIST IS THE DISTANCE BETWEEN THE CAMERA'S "EYES." 'FOCUS IS THE Z COORDINATE OF THE FOCAL POINT. 'THE FOCAL POINT APPEARS AT THE SAME DEPTH 'AS THE SCREEN. ' 0 MAKES THE HORIZON THE FOCAL POINT. 'LEVEL3D IS LIKE A 3D SLIDER. IT RANGES FROM 0-1. 'IF LEVEL3D IS 0 THEN THE PARALLAX BARRIER WILL TURN OFF 'AND FRAMERATE MAY INCREASE. 'LIGHT LX,LY,LZ,INTENSITY,MINIMUM,MIDDLE 'CONTROLS THE LIGHTING 'LX, LY, AND LZ ARE THE COORDINATES OF THE 'LIGHT SOURCE 'INTENSITY, MINIMUM, AND MIDDLE ADJUST THE 'LIGHTING EFFECT '-INTENSITY MAKES THE LIGHT MORE OR LESS ' HARSH '-MINIMUM SETS A MINIMUM BRIGHTNESS A TRIANGLE ' CAN HAVE '-MIDDLE GOES FROM 0 TO INTENSITY*2 AND ' SPECIFIES THE "MIDDLE" BRIGHTNESS '-SOME INTENSITY,MINIMUM,MIDDLE SETS: ' REGULAR SHADING: 1,0.2,1 ' CEL SHADING: 10,0.5,7 ' SOFTER LIGHT: 0.5,0.2,1 ' SOFT BRIGHT LIGHT: 0.5,0.2,1.5 ' NO LIGHTING EFFECTS: 0,0,2 'PROJMODE MODE 'SETS THE PROJECTION METHOD '0 IS PERSPECTIVE AND 1 IS ORTHOGRAPHIC 'PERSPECTIVE IS THE DEFAULT 'CULL VALUE 'SETS BACKCULLING TO ON OR OFF 'CULLING ONLY DRAWS POLYGONS FACING TOWARDS 'THE CAMERA. IT CAN INCREASE SPEED, BUT IF YOU 'DON'T WANT TO CARE ABOUT ORDERING YOUR 'VERTICES OR WANT YOUR TRIANGLES TO BE 'VISIBLE FROM BOTH SIDES, TURN IT OFF. 'ALSO, IT'S BROKEN IN ORTHOGRAPHIC MODE. 'ON BY DEFAULT 'CURRBUFF() 'GETS THE GRAPHIC PAGE BEING WRITTEN TO 'EITHER 2 OR 3 'ADDTRI X1,Y1,Z1,X2,Y2,Z2,X3,Y3,Z3,OBJ,R,G,B 'ADDS A TRIANGLE TO THE SCENE 'THE FIRST 9 PARAMETERS ARE THE COORDINATES FOR THE THREE POINTS OF THE TRIANGLE 'OBJ IS THE NUMBER ID OF THE OBJECT TO ADD THIS TRIANGLE TO '-OBJECTS ARE LINKED TRIANGLES. YOU CAN OFFSET AND ANGLE AN ENTIRE OBJECT, '-AND ALL THE TRIANGLES THAT MAKE UP THE OBJECT WILL BE OFFSETTED AND ANGLED. 'R, G, AND B ARE THE COLOR CODES FOR THE TRIANGLE 'ADDLINE X1,Y1,Z1,X2,Y2,Z2,OBJ,R,G,B 'ADDS A LINE TO THE SCENE 'THE FIRST 6 PARAMETERS ARE THE COORDINATES FOR THE TWO POINTS OF THE LINE 'OBJ IS THE NUMBER ID OF THE OBJECT TO ADD THIS TRIANGLE TO 'R, G, AND B ARE THE COLOR CODES FOR THE TRIANGLE 'ADDSPRITE X,Y,Z,U,V,W,H,SCALE,OBJ 'ADDS A SPRITE TO THE SCENE 'X,Y, AND Z ARE THE COORDINATES OF THE CENTER OF THE SPRITE 'U AND V ARE THE COORDINATES ON THE SPRITESHEET TO USE 'W AND H ARE THE DIMENSIONS ON THE SPRITESHEET 'SCALE IS THE SIZE OF THE SPRITE IN 3D SPACE 'OBJ IS THE OBJECT TO ADD THE SPRITE TO 'SPRITES ARE KIND OF LAGGY BECAUSE IT'S MANUALLY RENDERING EACH PIXEL. 'OBJOFS OBJ,X,Y,Z,ANGX,ANGY,ANGZ 'SETS AN OFFSET AND ANGLE FOR AN OBJECT 'OBJ IS THE OBJECT ID 'X, Y, AND Z ARE THE OFFSET COORDINATES 'ANGX, ANGY, AND ANGZ ARE THE ANGLES FOR THE OBJECT 'TO GET CURRENT OBJECT VARIABLES USE: 'OBJX(OBJ), OBJY(OBJ), OBJZ(OBJ), OBJANGX(OBJ), OBJANGY(OBJ), AND OBJANGZ(OBJ) 'CHECKOBJ(OBJ) 'CHECKS IF AN OBJECT EXISTS 'RETURNS 0 IF OBJECT DOESN'T EXIST 'RETURNS 1 IF OBJECT EXISTS 'DESTROYOBJ OBJ 'REMOVES AN OBJECT 'OBJ IS THE OBJECT NUMBER TO DESTROY 'OTHER OBJECT NUMBERS WILL NOT BE AFFECTED 'ROTMODE "AXIS","AXIS","AXIS" 'SETS ORDER OF ROTATION '"AXIS" IS A STRING THAT CAN BE "X","Y", OR "Z" '@RENDER3D 'RENDERS THE SCENE 'MEANT TO BE EXECUTED ONCE EVERY FRAME 'NOTE: '-THIS ENGINE USES CARTESIAN COORDINATES, SO ' Y INCREASES UPWARDS INSTEAD OF DOWNWARDS ' LIKE IN SCREEN COORDINATES. '-Z INCREAS AWAY FROM THE CAMERA. '-ANGLES ARE IN DEGREES.```