A fixed set parameter skybox added - which I will make this editor customizable.
// Project: 3D-Engine - by Programming is Ace
// Created: 2017-04-15
// show all errors
SetErrorMode(2)
#constant width=GetDeviceWidth()
#constant height=GetDeviceHeight()
// set window properties
SetWindowTitle( "3D-Engine" )
SetWindowSize( width, height, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( width, height ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
#constant textsizes#=14
// Buttons
type _buttons
ID as integer
name as string
x# as float
y# as float
sizex# as float
sizey# as float
checkbox as integer
color as integer
endtype
global buttons as _buttons[50]
// Game Objects
type _objects
id as integer
x# as float
y# as float
z# as float
rx# as float
ry# as float
rz# as float
transformrx# as float
transformry# as float
transformrz# as float
colr# as float
colg# as float
colb# as float
cola# as float
endtype
global objects as _objects[2000]
global currentobject=0
global maxobjects=0
// 3D World coordinates
global x#, y#, z#, cx#, cy#, cz#, rx#, ry#, rz#, crx#, cry#, crz#, cstep#, perspective=1
global oldx#, oldy#, oldz#, oldcx#, oldcy#, oldcz#, oldrx#, oldry#, oldrz#, oldcrx#, oldcry#, oldcrz#
// Sky box ints
global plane, planeleft, planeright, planefront, planeback,planetop, perspectivestring$,planetext
global worldsizex#=500
global worldsizey#=500
global wireframeon, wireframeoff, skyboxonoff
global wireframeonoff=0 // 1-on // 0-off
// Setup world
createworld(worldsizex#,worldsizey#)
create_wireframe()
// setup variables
planetext=CreateText("")
SetTextSize(planetext,textsizes#)
FPStext=createtext("FPS:")
SetTextSize(FPStext,textsizes#)
global infotext as integer[17]
for a=1 to infotext.length
infotext[a]=createtext("")
SetTextSize(infotext[a],17)
next
SetTextString(infotext[1], "Press 'Z' and cursors to change Z")
SetTextString(infotext[2], "Press 'X' and cursors to change X")
SetTextString(infotext[3], "Press 'Y' and cursors to change Y")
SetTextString(infotext[4], "Press 'C' and cursors to camera view")
SetTextString(infotext[5], "Press 'R' and cursors to rotate plane")
SetTextString(infotext[6], "Press 'T' to flip between Top Down / Perspective View")
SetTextString(infotext[7], "Press '1' to add a standard box and cursors to move")
SetTextString(infotext[8], "Press '2' to add a standard ball and cursors to move")
SetTextString(infotext[9], "Press '3' to add a standard Cylinder and cursors to move")
SetTextString(infotext[10], "Press '4' to add a standard Cone and cursors to move")
SetTextString(infotext[11], "Press 'A' add 1000 over the plane")
SetTextString(infotext[12], "Press 'M' to add a transform effect on each object")
SetTextString(infotext[13], "Press cursors on there own will move the new objects placed")
SetTextString(infotext[14], "Press 'W' to toggle Wireframe/Grid on and off to the plane")
SetTextString(infotext[15], "Press '<Space>' Reset the camera")
SetTextString(infotext[16], "Press '0' to show a SkyBox")
SetTextString(infotext[17], "Press 'Q' to Exit")
setup3dfield(1) // First create the field world coordinates
perspectivestring$="Perspective"
mouse=CreateObjectBox(.01,.01,.01)
do
SetObjectPosition(mouse, 0,.5,0)
SetObjectPosition(plane, x#,y#,z#)
SetObjectRotation(plane, rx#,ry#,rz#)
// Skybox
/*
SetObjectPosition(planetop, x#,y#+worldsizey#/2,z#-worldsizey#/2)
SetObjectRotation(planetop, rx#-180,ry#-270,rz#)
SetObjectPosition(planeleft, x#-worldsizey#,y#,z#-worldsizey#)
SetObjectRotation(planeleft, rx#-90,ry#-270,rz#-90)
SetObjectPosition(planeright, x#+worldsizey#,y#,z#-worldsizey#)
SetObjectRotation(planeright, rx#-90,ry#-270,rz#-90)
SetObjectPosition(planefront, x#,y#+5,z#+10)
SetObjectRotation(planefront, rx#-90,ry#,rz#-90)
SetObjectPosition(planeback, x#,y#+5,z#-10)
SetObjectRotation(planeback, rx#-90,ry#,rz#-90)
*/
// Display objects if created any
if maxobjects>0
for a=0 to maxobjects-1
SetObjectPosition(objects[a].id,objects[a].x#, objects[a].y#, objects[a].z#)
SetObjectRotation(objects[a].id,objects[a].rx#, objects[a].ry#, objects[a].rz#)
SetObjectColor(objects[a].id, objects[a].colr#, objects[a].colg#, objects[a].colb#, objects[a].cola#)
if GetRawKeyPressed(77) // M- to setup a transform to each object
objects[a].transformrx#=random2(-90,90) / 10
objects[a].transformry#=random2(-90,90) / 10
objects[a].transformrz#=random2(-90,90) / 10
endif
//Play the transforms
if objects[a].transformrx#<>0 or objects[a].transformry#<>0 or objects[a].transformrz# <> 0 then settransforms(a, objects[a].transformrx#,objects[a].transformry#,objects[a].transformrz#)
next
endif
// Check mouse collisons with the buttons on the system if nothing else is pressed (camera key / rotation key)
if maxobjects>0
if perspectivestring$="Perspective"
if GetRawKeyState(37) then dec objects[maxobjects-1].x#, cstep#
if GetRawKeyState(38) then inc objects[maxobjects-1].z#, cstep#
if GetRawKeyState(39) then inc objects[maxobjects-1].x#, cstep#
if GetRawKeyState(40) then dec objects[maxobjects-1].z#, cstep#
else
if GetRawKeyState(37) then dec objects[maxobjects-1].y#, cstep#
if GetRawKeyState(38) then dec objects[maxobjects-1].x#, cstep#
if GetRawKeyState(39) then inc objects[maxobjects-1].y#, cstep#
if GetRawKeyState(40) then inc objects[maxobjects-1].x#, cstep#
endif
endif
keypressed$=""
if GetRawKeyPressed(87) // W - add a wireframe
if (mod(wireframeonoff,2)=0)
SetObjectImage(plane, wireframeon,0)
else
SetObjectImage(plane, wireframeoff,0)
endif
inc wireframeonoff
endif
if GetRawKeyPressed(65) // A - Add a few objects
for l=maxobjects to 1000
sys_createobject(l,1,random2(-worldsizex#/2,worldsizex#/2),2,random2(-worldsizey#/2,worldsizey#/2),4,4,4) // 1 - Sphere / Ball
next
endif
if GetRawKeyPressed(49) then sys_createobject(maxobjects,1,0,2,0,4,4,4) // 1 - BOX/CUBE
if GetRawKeyPressed(50) then sys_createobject(maxobjects,2,0,2,0,4,50,50) // 2 - Sphere / Ball
if GetRawKeyPressed(51) then sys_createobject(maxobjects,3,0,2,0,4,4,50) // 3 - Cylinder
if GetRawKeyPressed(52) then sys_createobject(maxobjects,4,0,2,0,4,4,50) // 4 - CONE
if GetRawKeyPressed(84) // T = Top Down View Toggler
if perspective=2
setup3dfield(3)
perspectivestring$="Top down"
else
setup3dfield(2)
perspectivestring$="Perspective"
endif
endif
if GetRawKeyPressed(32) // Space
setup3dfield(1)
endif
if GetRawKeyPressed(48)
SetSkyBoxVisible(mod(skyboxonoff,2))
inc skyboxonoff
endif
if GetRawKeyState(187) // zoom in "-"
// cy#=cy#-cstep#
cz#=cz#+cstep#*2
endif
if GetRawKeyState(189) // zoom out "+"
// cy#=cy#+cstep#
cz#=cz#-cstep#*2
endif
if GetRawKeyPressed(81) // Q - Quit
exit
endif
if GetRawKeyState(67) // C - Camera
keypressed$="c"
endif
if GetRawKeyState(82) // R - Rotate Camera
keypressed$="r"
endif
if GetRawKeyState(88) // X
keypressed$="x"
endif
if GetRawKeyState(89) // X
keypressed$="y"
endif
if GetRawKeyState(90) // Z
keypressed$="z"
endif
if keypressed$="c"
if GetRawKeyState(37)
dec cx#,cstep#
endif
if GetRawKeystate(39)
inc cx#,cstep#
endif
if GetRawKeystate(38)
inc cz#,cstep#
endif
if GetRawKeystate(40)
dec cz#,cstep#
endif
SetCameraLookAt(1,cx#,cy#+5,cz#,0)
endif
if keypressed$="r"
if GetRawKeyState(37)
dec crx#,cstep#
dec crz#,cstep#
endif
if GetRawKeystate(39)
inc crx#,cstep#
inc crz#,cstep#
endif
if GetRawKeystate(38)
inc crz#,cstep#
inc cry#,cstep#
endif
if GetRawKeystate(40)
dec crz#,cstep#
dec cry#,cstep#
endif
endif
if keypressed$="x"
if GetRawKeyState(37)
dec cx#,cstep#
endif
if GetRawKeystate(39)
inc cx#,cstep#
endif
endif
if keypressed$="z"
if GetRawKeyState(38)
dec cz#,cstep#
endif
if GetRawKeystate(40)
inc cz#,cstep#
endif
endif
if keypressed$="y"
if GetRawKeyState(38)
dec cy#,cstep#
endif
if GetRawKeystate(40)
inc cy#,cstep#
endif
endif
if maxobjects=0 or keypressed$=""
// Move the camera to standard view
SetCameraPosition(1,cx#,cy#+10,cz#-10)
SetCameraRotation(1,crx#,cry#,crz#)
else
// Move the camera to the new place added
SetCameraPosition(1,objects[maxobjects-1].x#,objects[maxobjects-1].y#+10,objects[maxobjects-1].z#-50)
SetCameraRotation(1,crx#,cry#,crz#)
endif
UI_Diplay()
Render2Dfront()
Sync()
loop
function UI_Diplay()
// Build the UI interface
black=MakeColor(10,10,10)
DrawBox(0,0,300,height,black,black,black,black,1)
// Display UI
sys_buildbutton(1,"Perspective" ,30,30,150,60,MakeColor(100,100,100))
sys_buildbutton(2,"Add a Cube" ,30,60,150,100,MakeColor(100,100,100))
sys_buildbutton(3,"Add a Ball" ,30,100,150,140,MakeColor(100,100,100))
sys_buildbutton(4,"Add a Cone" ,30,140,150,180,MakeColor(100,100,100))
sys_buildbutton(5,"Add a Cylinder",30,180,150,220,MakeColor(100,100,100))
SetTextString(planetext,"Plane: X=" + str(x#) + " Y=" +str(y#) + " Z=" +str(z#) + " Camera X=" + str(cx#) + " Y=" + str(cy#)+" Z=" + str(cz#) + " Rotation X=" + str(crx#) + " Y=" + str(cry#) + " Z=" + str(cz#) + " Perspective=" + perspectivestring$ + " FPS-" + str(screenfps()) + " Key-" + str(GetRawLastKey()) + " Max Objects: " + str(maxobjects))
SetTextPosition(planetext, 10,10)
for a=1 to infotext.length / 2
SetTextPosition(infotext[a],200, 40+ (a*GetTextTotalHeight(infotext[a])))
SetTextDepth(infotext[a],0)
next
for a=(infotext.length/2)+1 to infotext.length
SetTextPosition(infotext[a],500, 40+ ((a-infotext.length/2)*GetTextTotalHeight(infotext[a])))
SetTextDepth(infotext[a],0)
next
SetObjectDepthWrite(plane,0)
endfunction
function sys_buildbutton(id, name$, x#, y#, sizex#, sizey#, color)
if GetTextExists(buttons[id].id)=0 then buttons[id].id=createtext(name$)
settextsize (buttons[id].id,textsizes#)
DrawBox(x#,y#,sizex#,sizey#,color<<2,color<<2,color,color,1)
SetTextPosition(buttons[id].id,(x#+(sizex#/2)-(GetTextTotalWidth(buttons[id].id))/2),y#+10)
endfunction
function settransforms(obj, trx#, try#, trz#)
inc objects[obj].rx#, trx#
inc objects[obj].ry#, try#
inc objects[obj].rz#, trz#
endfunction
function sys_createobject(obj,model, objx#, objy#, objz#, sizex#, sizey#, sizez#)
DeleteObject(obj)
select model
case 1: //Box
objects[obj].id=CreateObjectBox(sizex#,sizey#,sizez#)
endcase
case 2: //Sphere
objects[obj].id=CreateObjectSphere(sizex#,sizey#,sizez#)
endcase
case 3: //Cylinder
objects[obj].id=CreateObjectCylinder(sizex#,sizey#,sizez#)
endcase
case 4: //Cone
objects[obj].id=CreateObjectCone(sizex#,sizey#,sizez#)
endcase
endselect
objects[obj].x#=objx#
objects[obj].y#=objy#
objects[obj].z#=objz#
objects[obj].rx#=0
objects[obj].ry#=0
objects[obj].rz#=0
objects[obj].colr#=random(1,255)
objects[obj].colg#=random(1,255)
objects[obj].colb#=random(1,255)
objects[obj].cola#=255
objects[obj].transformrx#=0
objects[obj].transformry#=0
objects[obj].transformrz#=0
updatevariables()
inc maxobjects
inc currentobject
endfunction
function create_wireframe()
swap()
white=MakeColor(100,100,100)
for wx=1 to 100 step 2
DrawLine((wx),0,(wx),100,white,white)
DrawLine(0,(wx),100,(wx), white, white)
next
render()
wireframeon=GetImage(0,0,100,100)
swap()
ClearScreen()
white=MakeColor(100,100,100)
DrawBox(0,0,100,100,white,white,white,white,1)
render()
wireframeoff=GetImage(0,0,100,100)
endfunction
function createworld(sizex#, sizey#)
Create3DPhysicsWorld()
SetSkyBoxSunColor(255,0,0)
// SetSkyBoxHorizonColor(0,0,200)
SetSkyBoxSkyColor(0,100,200)
SetSkyBoxHorizonSize(10,1)
SetSkyBoxSunSize(5,10)
SetSkyBoxSunVisible(1)
skyboxonoff=0
SetSkyBoxVisible(skyboxonoff)
plane=CreateObjectplane(sizex#,sizey#)
SetObjectImage(plane,wireframeoff,0)
// SetObjectImage(plane,create_wireframe(),0)
//SKY BOX development - in progress
/* planetop=CreateObjectPlane(sizex#,sizey#)
SetObjectImage(planetop,loadimage("\media\skyboxes\desert_top.png"),0)
planeleft=CreateObjectPlane(sizex#,sizey#)
SetObjectImage(planeleft,loadimage("\media\skyboxes\desert_left.png"),0)
planeright=CreateObjectPlane(sizex#,sizey#)
SetObjectImage(planeright,loadimage("\media\skyboxes\desert_right.png"),0)
planefront=CreateObjectPlane(sizex#,sizey#)
SetObjectImage(planefront,loadimage("\media\skyboxes\desert_front.png"),0)
planeback=CreateObjectPlane(sizex#,sizey#)
SetObjectImage(planeback,loadimage("\media\skyboxes\desert_back.png"),0)
*/
endfunction
function setup3dfield(mode as integer)
select mode
case 1: // Perspective
// Transform Values
x#=0
y#=0
z#=0
// Perspective Values
//Camera Positioning Values
cx#=0
cy#=worldsizey#/8
cz#=-worldsizey# / 2
//Camera Rotation Values
crx#=0
cry#=0
crz#=0
cstep#=1
// Camera Rotations
rx#=90
ry#=0
rz#=90
updatevariables()
endcase
case 2: // Perspective Update old varibales
// Transform Values
x#=oldx#
y#=oldy#
z#=oldz#
// Perspective Values
//Camera Positioning Values
cx#=oldcx#
cy#=oldcy#
cz#=oldcz#
//Camera Rotation Values
crx#=oldcrx#
cry#=oldcry#
crz#=oldcrz#
cstep#=1
// Camera Rotations
rx#=oldrx#
ry#=oldry#
rz#=oldrz#
endcase
case 3: // Top down
// Transform Values
x#=0
y#=0
z#=0
// Perspective Values
//Camera Positioning Values
cx#=0
cy#=worldsizey#-200
cz#=0
//Camera Rotation Values
crx#=90
cry#=0
crz#=0
cstep#=1
// Camera Rotations
rx#=90
ry#=0
rz#=0
endcase
endselect
perspective=mode
endfunction
function updatevariables()
oldx#=x#
oldy#=y#
oldz#=z#
oldcx#=cx#
oldcy#=cy#
oldcz#=cz#
oldcrx#=crx#
oldcry#=cry#
oldcrz#=crz#
oldrx#=rx#
oldry#=ry#
oldrz#=rz#
endfunction
Add more in a few week
Enjoy for the time being