Added TEXT as a new object type! Check the documentation for more details! Game worlds can easily display messages as 3D objects.
CHESS.3D has been worked on, the AI is more intelligent and uses alpha-beta pruning to simulate ahead in the future to find how to maximize the minimum score. In the first few lines you can set the AI_VS_AI to watch it play against itself.
Every demo has been updated to make use of the new features.
Fixed the randomly-appearing-flickering-lines-bug for DLC users.
Fixed triangles-sometimes-not-rendering-glitch for non-DLC users.
Also non-DLC users run at a fairly higher framerate due to less function calls.
Perspective calculations and rendering have been worked on a lot, graphics are much smoother.
Added a new demo to showcase 3D randomized fractal tree generation.
Spheres now render without borders to improve the look of scenes.
Changed the way object tags work, instead of saving TAG$ to every triangle it saves it in the objects themselves. Also triangles no longer carry a second color (the sphere border color). Triangles only carry the most necessary data now.
FPS is more smooth/stabilized.
Added the ability to change the view distance to make programs run faster for o3DS users.
Added function APPLYSURFACEEQUATION to automatically set a SURFACE object to mimic a mathematical equation. This makes the code for the GRAPH_3D demo much simpler and gives users much more power to simulate terrain.
Added lots of new functions!
Added a fully functional 3D chess game against a real AI that looks a few moves ahead to determine the best way to move.
Added an first person shooter game demo.
Added support for 3D lines using ADDLINE(X1,Y1,Z1,X2,Y2,Z2,COLOR).
Added a surface object, which is a grid plane with multiple sections (used in the 3D grapher).
Fixed a few bugs when deleting an object.
Added some new functions.
BUFFERing only buffers the top screen, use BUFFERBOTTOM to buffer the lower screen.
Other small tweaks and optimizations.
Framerate has been doubled and possibly tripled, especially for DLC users. The engine runs incredibly fast for users that have purchased the SmileBASIC DLC!
SIM.3D no longer needs any other program slots other than 3. So this update makes it a lot more compact and simple.
Hue, saturation, and value are now optional by using HSV(H,S,V) just like RGB(R,G,B). Objects only need a single color value to be initialized. So #RED, #GREEN, #BLUE, etc... can work too.
Field of view (FOV), world scale constant (WSC), and the cutoff ratio (CUTOFF_RATIO) are modifiable.
Cutoff ratio is the ratio between the camera and the object of focus in which polygons will no longer be drawn. Default is 0.5.
Lots of new functions that give more power to the user, such as finding the closest/furthest objects to a point, and making an object rotate to face a given point in the world.
Behind the scenes optimizations for maximum performance.
DLC is fully implemented! The engine runs much smoother when the Advanced Sound DLC is purchased, the application now only needs to run a few ARYOP operations each frame.
Performance without DLC has also been improved, but DLC gives much higher performance.
Circles have been removed, and re-implemented as triangle objects. Now that there is complete consistency with objects, huge performance advancements have been made.
The flickering graphics bug has been targeted and removed. Graphics feel cleaner with modified algorithms.
Example programs have been modified a little bit. Please feel free to view the code for those, and use them to implement your own games. I do not require any credit. Everything is free for everybody.
Triangles are now sorted by the furthest away Z point.
CIRCLE functions are now called SPHERE functions.
All future updates from this point forward will minimize the modifications required for a game to run on the updated engine. Any modifications required will be listed down here for you.
Application is stable.
NotesThis application was designed specifically to teach the idea of 3D game design. While this engine was built with simplicity in mind, it was also built to maximize efficiency and minimize the computation required to display good looking graphics. With that said this is an excellent engine to make 3D games, I don't ask for any credit, and anyone can use this program for their own purposes.
Use the comment section below for help, or if you have any questions, I'll be glad to help!
To see the power of SIM.3D, I added some regular demos that will give a better idea on how to use SIM.3D. The files include:
3D.ENGINE - The engine in all it's glory.
BOX_O_GEMS - A demo to show all the different kinds of objects, and how fast they render.
CHESS.3D - A rather complex program to show what can be made with SIM.3D.
FPS_DEMO - A first-person-shooter-styled simulation, on a Perlin-noise-generated map.
GRAPH_3D - A powerful yet simple 3D equation grapher.
SIERPINSKI - Using simple code to generate a Sierpinski pyramid.
SIMPLE_CUBES - A short code demo to show how SIM.3D is used.
SPIRAL_SPHERE - Generate colorful sphere-spirals of spheres.
TREE_OF_WISDOM - Showcasing three dimensional fractal tree generation using simple recursion.
To use this engine, simply add this to the first line of your code
PRGEDIT 3 EXEC "PRG3:3D.ENGINE" ENDDoing so will load the 3D engine into program slot 3, then insert the code from program slot 0 into program slot 3, then execute itself.
The most basic application to rotate a cube in the center of the screen is as follows:
PRGEDIT 3 EXEC "PRG3:3D.ENGINE" END 'S1M.3D
'C CONTAINS A REFERENCE TO THE CUBE
VSYNC 'STABALIZE THE FRAMERATE
BUFFER 'SWITCH GPAGES TO PREVENT FLICKERING
GCLS 'CLEAR THE SCREEN
ROTOBJ C,0,1,0 'ROTATE THE CUBE AROUND THE Y AXIS
RENDER 'RENDER THE WORLD
GOTO @LOOP 'REPEAT
There are a few things to be aware of before diving into the 3D engine
One in-world unit is the equivalent of 50 pixels. Adding a scale definition like this makes the game feel more realistic.
When working with SIM.3D, you must work in the default program slot 0, you will need to save every time you run the code. Any errors can be traced to your code in program slot 3 where the actual engine is.
Or you could work directly in the 3D engine and avoid the use of the loader. There's a spot in the beginning of the code dedicated for user programs to go.
Every object is composed of triangles. If a triangle is defined clockwise then it will be visible from the outside of the object. There are preset objects to make this easier to work with.
So triangles can only be seen from one side (for higher performance), using STRETCHOBJ with negative values to stretch an object inside-out will let you see the object's back faces instead of front
Every object is given an index. This index will never change until the object is deleted, in which case the ID will be given to the next future object to be defined.
Engine variables:VAR CAMX,CAMY,CAMZ 'THE FOCUS POSITION OF THE CAMERA (DEFAULT: 0,0,0)
VAR CAMRX,CAMRY,CAMRZ 'ROTATION OF THE CAMERA (IN DEGREES) AROUND THE CAMERA FOCUS (DEFAULT: 0,20,0)
VAR CAMDIST 'DISTANCE AWAY FROM CAMERA'S FOCUS POINT (DEFAULT: 10)
VAR FOV 'FIELD OF VIEW (DEFAULT: 5)
VAR WSC 'WORLD SCALING CONSTANT IN PIXELS (DEFAULT: 50)
VAR CUTOFF_RATIO 'THE RATIO BETWEEN CAMERA AND FOCUS IN WHICH THINGS STOP RENDERING (DEFAULT: 0.7)
VAR BOUNDCAMANGLES 'TRUE/FALSE, TELL IF THE CAMERA SHOULD BE BOUNDED BETWEEN -180 AND 180 (DEFAULT: 1)
VAR RENDERDIST 'HOW FAR THE PLACER CAN SEE, 0=INFINITE (DEFAULT: 0)
VAR ACCELERATED_RENDERING 'TRUE/FALSE TO USE ADVANCED SOUND DLC (DEFAULT: 1 IF POSSIBLE)
VAR FPS 'FRAMES PER SECOND
Here are the preset object definitions:ADDCUBE(X,Y,Z,LENGTH,WIDTH,HEIGHT,COLOR)
'CREATES A RECTANGULAR PRISM, RETURNS ITS INDEX
'CREATES A SPHERE, RETURNS ITS INDEX IN THE WORLD
'CREATES A LINE, RETURNS ITS INDEX
'CREATES A PYRAMID, WHERE THE BASE OF THE BOTTOM IS X,Y,Z
'RETURNS THE OBJECT'S INDEX
'RETURNS THE OBJECT'S INDEX
'RETURNS THE OBJECT'S INDEX
'(AN INSIDE-OUT CUBE)
'RETURNS THE OBJECT'S INDEX
'CREATE A FLAT GRID PLANE, RETURNS ITS INDEX
'MAKE A TEXT OBJECT IN THE WORLD
'RETURNS THE OBJECT'S INDEX
You may also consider defining your own objectADDOBJ(TYPE$,X,Y,Z,COLOR)
'X,Y,Z DEFINE EACH TRIANGLE. THESE ARRAYS MUST BE IN SETS OF 3, SO LENGTH=3,6,9,12,15,18,...
Every object contains these variables:OBJX 'CENTER OF MASS X POSITION
OBJY 'CENTER OF MASS Y POSITION
OBJZ 'CENTER OF MASS Z POSITION
OBJTAG$ 'A STRING
ONJTYPE$ 'A STRING TELLING WHAT TYPE OF OBJECT IT IS
OBJINDEX 'THE INDEX POINTING TO WHICH TRIANGLES BELONG TO THIS OBJECT
OBJLENGTH 'THE LENGTH OF HOW MANY TRIANGLES BELONG TO THIS OBJECT
OBJRX 'GET (NO SET) THE OBJECT'S X ROTATION
OBJRY 'GET (NO SET) THE OBJECT'S Y ROTATION
OBJRZ 'GET (NO SET) THE OBJECT'S Z ROTATION
OBJMASK 'WHEN YOU DEFINE AN OBJECT YOU ARE GIVEN A MASK INDEX WHICH WILL NEVER
'CHANGE, SO YOU CAN ONLY ACCESS THE VARIABLES ABOVE BY GOING THROUGH THE OBJECT MASK
'BY USING THIS MASK, WE CAN GUARANTEE THAT AN OBJECT INDEX WILL NEVER CHANGE
'EVEN IF OBJECTS BEFORE IT ARE DELETED.
Here is a list of object functionsSTRETCHOBJ INDEX,SCALEX,SCALEY,SCALEZ
'SQUISHES OR STRETCHES AN OBJECT'S POINTS BY A GIVEN SCALE
'INCREMENT AN OBJECT'S POSITION
'TELEPORT AN OBJECT SOMEWHERE
'INCREMENT THE ROTATION OF AN OBJECT AROUND ITS CENTER OF MASS
'SET THE ROTATION OF AN OBJECT AROUND ITS CENTER OF MASS
'THIS WILL RESET THE OBJECT'S ROTATION TO ITS DEFAULT, THEN ROTATE IT AX,AY,AZ
'ROTATE AN OBJECT AROUND (X,Y,Z)
'ROTATE AN OBJECT AROUND ANOTHER OBJECT
'ROTATE AN OBJECT SO THAT IT FACES THE POINT X,Y,Z
DELOBJ INDEX : INDEX=-1
'DELETE AN OBJECT FROM THE WORLD
'SET AN OBJECT'S COLOR
'SET THE COLOR OF A SINGLE TRIANGLE ON AN OBJECT
'GIVE AN OBJECT A STRING, DEFAULT=""
'THIS CAN BE STRING, IT DOESN'T AFFECT THE 3D ENGINE
'GET THE TAG$ VALUE OF AN OBJECT
'QUICKLY FIND AN OBJECT WITH A SPECIFIC TAG$ VALUE
'RETURNS -1 IF NO OBJECT EXISTS WITH THIS TAG
'RETURNS THE STRING DEFINING WHAT TYPE OF OBJECT IT IS
'POSSIBLE RESULTS ARE:
'RETURNS A SORTED ARRAY OF OBJECT INDEXES SUCH THAT THE FIRST ITEM IS CLOSEST
'TO (X,Y,Z) AND THE LAST ITEM IS FURTHEST AWAY FROM (X,Y,Z)
'AND THE LAST ITEM IS FURTHEST AWAY FROM (X,Y,Z)
'APPLY A MATH EXPRESSION TO A SURFACE OBJECT
'EQU$ IS AN EQUATION WITH X,Y, AND Z IN IT
'EQU$="SIN(X)+COS(Z)" MAKES A WAVY SURFACE
'MINY AND MAXY DEFINE THE OBJECT'S Y BOUNDS
'SCX,SCY,SCZ ARE THE ZOOM FACTORS, 0.1=>10X ZOOM
'SAME AS SAYING OBJMASK[MASKEDINDEX]
'UPDATES THE CENTER OF MASS OF AN OBJECT (DONE AUTOMATICALLY)
And a few other functions, slightly unrelated, but implemented nonetheless:RENDER
'DRAWS THE CURRENT WORLD STATE, REQUIRED TO RUN ONCE EVERY FRAME
'PREVENTS FLICKERING BY SWAPPING GPAGES EACH FRAME, DRAWING TO THE ONE NOT
'BEING SHOWN. THIS SHOULD BE RAN ONCE EVERY FRAME, WITH A GCLS DIRECTLY AFTER IT
'THIS ONLY AFFECTS THE TOP SCREEN
'PREVENT FLICKERING ON THE LOWER SCREEN, PUT GCLS DIRECTLY AFTER IT
GETCAMRAY OUT X,Y,Z
'RETURNS THE NORMALIZED DIRECTION THE CAMERA IS FACING
GETCAMRAY2D OUT X,Y,Z
'RETURNS THE NORMALIZED DIRECTION THE CAMERA IS FACING EXCLUDING Y
NORMALIZE X,Y,Z OUT X,Y,Z
'SET THE DISTANCE OF AN X,Y,Z DISPLACEMENT EQUAL TO 1
'WHILE MAINTAINING THE ANGLE
'DELETES EVERYTHING IN THE WORLD
'TRIANGLE OPERATION FUNCTIONS
SETTRI INDEX,X1,Y1,Z1,X2,Y2,Z2,X3,Y3,Z3 'SET A TRIANGLES POSITION
DELTRI TRIANGLEINDEX 'DELETE A TRIANGLE
'3D POINT ROTATION FUNCTIONS
ROT X,Y,Z,ORIGINX,ORIGINY,ORIGINZ,ANGLEX,ANGLEY,ANGLEZ OUT X,Y,Z
ROTX X,Y,Z,ANGLE OUT X,Y,Z 'ROTATE A POINT JUST AROUND X AXIS
ROTY X,Y,Z,ANGLE OUT X,Y,Z 'ROTATE A POINT JUST AROUND Y AXIS
ROTZ X,Y,Z,ANGLE OUT X,Y,Z 'ROTATE A POINT JUST AROUND Z AXIS
INSERT ARRAY,INDEX,VALUE 'QUICKLY INSERT AN ELEMENT INTO AN ARRAY
REMOVE ARRAY,INDEX 'QUICKLY REMOVE AN ELEMENT FROM AN ARRAY
TRIM$(S$) 'REMOVE SPACES AND NEW LINES FROM THE FRONT AND END OF A STRING
HSV2RGB HUE,SATURATION,VALUE OUT RED,GREEN,BLUE
RGB2HSV RED,GREEN,BLUE OUT HUE,SATURATION,VALUE
'RETURNS THE COLOR AS A SINGLE NUMBER, JUST LIKE RGB(R,G,B) DOES
'DRAW A FILLED CIRCLE
'DRAW CENTERED TEXT ON THE SCREEN
PERSPECTIVE X,Y,Z OUT X,Y,Z
'CONVERT IN-WORLD COORDINATES TO SCREEN COORDINATES
'QUICKLY JUST CALCULATE THE Z VALUE AFTER PERSPECTIVE
ARYOP_PERSPECTIVE X,Y,Z OUT X,Y,Z
'CALCULATE FASTER PERSPECTIVE