Sorry for third post, but this is too important for an edit I think.
I made point lights work, and also a 'SET World' command, which checks the ambient light, the red,green and blue colors of it, the colors of the backdrop, whether fog is on, it's range and color.
Code:
REM Project: Map Compiler
REM Created: 07/11/2006 10:10:20
REM
REM ***** Main Source File *****
REM
`setup
sync on : sync rate 60
set display mode 1024,768,32 : hide mouse
autocam off : set camera range 1,0x7fffffff
startUp()
`load a map
name$=loadMap("map1.txt")
`Camera
Dist#=500
AngX#=45
AngY#=45
`Main Loop
Do
`Control
AngX#=wrapvalue(AngX#+mousemovey())
AngY#=wrapvalue(AngY#+mousemovex())
if mouseclick()=1 then dec Dist#,2
if mouseclick()=2 then inc Dist#,2
cx#=sin(AngY#)*cos(angX#)*Dist#
cy#=-sin(AngX#)*Dist#
cz#=cos(AngY#)*cos(angX#)*Dist#
position camera cx#,cy#,cz#
rotate camera 180+AngX#,AngY#,0
Sync
Loop
`Functions
function startUp()
dim objTaken(0) as boolean
dim lgtTaken(0) as boolean
dim entObj(0) as integer
dim entLgt(0) as integer
endfunction
function loadMap(map as string)
local com as string
local brace as string
local objDir as string
local var as string
local done as boolean
local ents as integer
open to read 1,map
repeat
if file end(1)=1
done=1
else
read string 1,com
if left$(com,2)<>"//" or left$(com,1)<>"`" or lower$(left$(com,3))<>"rem"
if lower$(com)="name"
read string 1,brace
read string 1,name$
read string 1,brace
endif
if lower$(com)="set world"
read string 1,brace
read string 1,var : var=removeSpace(var) : amb=val(var)
read string 1,var : var=removeSpace(var) : ar=val(var)
read string 1,var : var=removeSpace(var) : ag=val(var)
read string 1,var : var=removeSpace(var) : ab=val(var)
read string 1,var : var=removeSpace(var) : bckr=val(var)
read string 1,var : var=removeSpace(var) : bckg=val(var)
read string 1,var : var=removeSpace(var) : bckb=val(var)
read string 1,var : var=removeSpace(var) : fog=val(var)
read string 1,var : var=removeSpace(var) : frng=val(var)
read string 1,var : var=removeSpace(var) : fr=val(var)
read string 1,var : var=removeSpace(var) : fg=val(var)
read string 1,var : var=removeSpace(var) : fb=val(var)
read string 1,brace
setWorld(amb,ar,ag,ab,bckr,bckg,bckb,fog,frng,fr,fg,fb)
endif
if lower$(com)="add sphere"
read string 1,brace
read string 1,var : var=removeSpace(var) : posx#=val(var)
read string 1,var : var=removeSpace(var) : posy#=val(var)
read string 1,var : var=removeSpace(var) : posz#=val(var)
read string 1,var : var=removeSpace(var) : angx#=val(var)
read string 1,var : var=removeSpace(var) : angy#=val(var)
read string 1,var : var=removeSpace(var) : angz#=val(var)
read string 1,var : var=removeSpace(var) : sizx#=val(var)
read string 1,var : var=removeSpace(var) : sizy#=val(var)
read string 1,var : var=removeSpace(var) : sizz#=val(var)
read string 1,brace
o=addSphere(posx#,posy#,posz#,angx#,angy#,angz#,sizx#,sizy#,sizz#)
endif
if lower$(com)="add cube"
read string 1,brace
read string 1,var : var=removeSpace(var) : posx#=val(var)
read string 1,var : var=removeSpace(var) : posy#=val(var)
read string 1,var : var=removeSpace(var) : posz#=val(var)
read string 1,var : var=removeSpace(var) : angx#=val(var)
read string 1,var : var=removeSpace(var) : angy#=val(var)
read string 1,var : var=removeSpace(var) : angz#=val(var)
read string 1,var : var=removeSpace(var) : sizx#=val(var)
read string 1,var : var=removeSpace(var) : sizy#=val(var)
read string 1,var : var=removeSpace(var) : sizz#=val(var)
read string 1,brace
addCube(posx#,posy#,posz#,angx#,angy#,angz#,sizx#,sizy#,sizz#)
endif
if lower$(com)="add object"
read string 1,brace
read string 1,objDir : objDir=removeSpace(objDir)
read string 1,var : var=removeSpace(var) : posx#=val(var)
read string 1,var : var=removeSpace(var) : posy#=val(var)
read string 1,var : var=removeSpace(var) : posz#=val(var)
read string 1,var : var=removeSpace(var) : angx#=val(var)
read string 1,var : var=removeSpace(var) : angy#=val(var)
read string 1,var : var=removeSpace(var) : angz#=val(var)
read string 1,var : var=removeSpace(var) : sizx#=val(var)
read string 1,var : var=removeSpace(var) : sizy#=val(var)
read string 1,var : var=removeSpace(var) : sizz#=val(var)
read string 1,brace
addObject(objDir,posx#,posy#,posz#,angx#,angy#,angz#,sizx#,sizy#,sizz#)
endif
if lower$(com)="add pointlight"
read string 1,brace
read string 1,var : var=removeSpace(var) : posx#=val(var)
read string 1,var : var=removeSpace(var) : posy#=val(var)
read string 1,var : var=removeSpace(var) : posz#=val(var)
read string 1,var : var=removeSpace(var) : red=val(var)
read string 1,var : var=removeSpace(var) : green=val(var)
read string 1,var : var=removeSpace(var) : blue=val(var)
read string 1,var : var=removeSpace(var) : range#=val(var)
read string 1,brace
addLight(posx#,posy#,posz#,range#,rgb(red,green,blue))
endif
endif
endif
until done
close file 1
endfunction name$
function deleteMap()
local oents as integer : oents=array count(entObj())
local lents as integer : lents=array count(entLgt())
for e=1 to oents
delete object entobj(e)
next e
for e=1 to lents
delete light entlgt(e)
next e
fog off
set ambient light 50
color ambient light 0
color backdrop 0
endfunction
function setWorld(amb,ar,ag,ab,bckr,bckg,bckb,fog,frng,fr,fg,fb)
set ambient light amb
color ambient light rgb(ar,ag,ab)
backdrop on : color backdrop rgb(bckr,bckg,bckb)
if fog=1
fog on
fog distance frng
fog color rgb(fr,fg,fb)
else
fog off
endif
endfunction
function addSphere(x#,y#,z#,ax#,ay#,az#,sx#,sy#,sz#)
local oNum as integer
oNum=freeObject()
make object sphere oNum,100
scale object oNum,sx#,sy#,sz#
position object oNum,x#,y#,z#
rotate object oNum,ax#,ay#,az#
array insert at bottom entObj() : entCount=array count(entObj()) : entObj(entCount)=oNum
endfunction oNum
function addCube(x#,y#,z#,ax#,ay#,az#,sx#,sy#,sz#)
local oNum as integer
oNum=freeObject()
make object cube oNum,100
scale object oNum,sx#,sy#,sz#
position object oNum,x#,y#,z#
rotate object oNum,ax#,ay#,az#
array insert at bottom entObj() : entCount=array count(entObj()) : entObj(entCount)=oNum
endfunction oNum
function addObject(obj$,x#,y#,z#,ax#,ay#,az#,sx#,sy#,sz#)
local oNum as integer
oNum=freeObject()
load object obj$,oNum
scale object oNum,sx#,sy#,sz#
position object oNum,x#,y#,z#
rotate object oNum,ax#,ay#,az#
array insert at bottom entObj() : entCount=array count(entObj()) : entObj(entCount)=oNum
endfunction oNum
function addLight(x#,y#,z#,r#,col)
local lNum as integer
lNum=freeLight()
make light lNum
set point light lNum,x#,y#,z#
set light range lNum,r#
color light lNum,col
endfunction lNum
function getEntityObject(ent)
local obj as integer
obj=entObj(ent)
endfunction obj
function getEntitylight(ent)
local lgt as integer
lgt=entLgt(ent)
endfunction lgt
function removeSpace(st$)
local length as integer : length=len(st$)
for i=1 to length
let$=mid$(st$,i)
if let$<>" "
new$=new$+let$
endif
next i
endfunction new$
function freeObject()
local Num as integer
array insert at bottom objTaken() : num=array count(objTaken())
if object exist(num)=0 and objTaken(num)=0
objTaken(num)=1 : exitfunction num
endif
endfunction 0
function freeLight()
local Num as integer
array insert at bottom lgtTaken() : num=array count(lgtTaken())
if light exist(num)=0 and lgtTaken(num)=0
lgtTaken(num)=1 : exitfunction num
endif
endfunction 0
And a test map.
// Name Level
NAME
{
~Test Map~
}
// Set World
SET World
{
30
255
0
255
0
0
0
0
0
0
0
0
}
// Add Objects
ADD Sphere
{
-50
0
0
0
0
0
100
100
100
}
ADD Cube
{
50
0
0
0
0
0
100
100
100
}
// Add Lights
ADD PointLight
{
0
100
0
255
0
0
2000
}
ADD PointLight
{
0
-100
0
0
0
255
1500
}
Just save it as a .txt in your project folder. It feels good to have something like that in only 1 line
[edit]
There, now supports all primitives and is ready to use. I might make a map editor. If anyone can think of anything else (that isn't shaders) then tell me.
REM Project: Map Compiler
REM Created: 07/11/2006 10:10:20
REM
REM ***** Main Source File *****
REM
`setup
sync on : sync rate 60
set display mode 1024,768,32 : hide mouse
autocam off : set camera range 1,0x7fffffff
startUp()
`load a map
name$=loadMap("map1.txt")
`Camera
Dist#=500
AngX#=225
AngY#=45
`Main Loop
Do
`Control
AngX#=wrapvalue(AngX#+mousemovey())
AngY#=wrapvalue(AngY#+mousemovex())
if mouseclick()=1 then dec Dist#,2
if mouseclick()=2 then inc Dist#,2
cx#=sin(AngY#)*cos(angX#)*Dist#
cy#=-sin(AngX#)*Dist#
cz#=cos(AngY#)*cos(angX#)*Dist#
position camera cx#,cy#,cz#
rotate camera 180+AngX#,AngY#,0
`User Info
text 10,10,"Map Name: "+name$
text 10,30,"Move the Mouse to Rotate the Camera"
text 10,50,"LMB/RMB Moves the Camera"
Sync
Loop
`Functions
function startUp()
dim objTaken(0) as boolean
dim lgtTaken(0) as boolean
dim entObj(0) as integer
dim entLgt(0) as integer
endfunction
function loadMap(map as string)
local com as string
local brace as string
local objDir as string
local var as string
local done as boolean
local ents as integer
open to read 1,map
repeat
if file end(1)=1
done=1
else
read string 1,com
if left$(com,2)<>"//" or left$(com,1)<>"`" or lower$(left$(com,3))<>"rem"
if lower$(com)="name"
read string 1,brace
read string 1,name$
read string 1,brace
endif
if lower$(com)="set world"
read string 1,brace
read string 1,var : var=removeSpace(var) : amb=val(var)
read string 1,var : var=removeSpace(var) : ar=val(var)
read string 1,var : var=removeSpace(var) : ag=val(var)
read string 1,var : var=removeSpace(var) : ab=val(var)
read string 1,var : var=removeSpace(var) : bckr=val(var)
read string 1,var : var=removeSpace(var) : bckg=val(var)
read string 1,var : var=removeSpace(var) : bckb=val(var)
read string 1,var : var=removeSpace(var) : fog=val(var)
read string 1,var : var=removeSpace(var) : frng=val(var)
read string 1,var : var=removeSpace(var) : fr=val(var)
read string 1,var : var=removeSpace(var) : fg=val(var)
read string 1,var : var=removeSpace(var) : fb=val(var)
read string 1,brace
setWorld(amb,ar,ag,ab,bckr,bckg,bckb,fog,frng,fr,fg,fb)
endif
if lower$(com)="add sphere"
read string 1,brace
read string 1,var : var=removeSpace(var) : posx#=val(var)
read string 1,var : var=removeSpace(var) : posy#=val(var)
read string 1,var : var=removeSpace(var) : posz#=val(var)
read string 1,var : var=removeSpace(var) : angx#=val(var)
read string 1,var : var=removeSpace(var) : angy#=val(var)
read string 1,var : var=removeSpace(var) : angz#=val(var)
read string 1,var : var=removeSpace(var) : sizx#=val(var)
read string 1,var : var=removeSpace(var) : sizy#=val(var)
read string 1,var : var=removeSpace(var) : sizz#=val(var)
read string 1,brace
o=addSphere(posx#,posy#,posz#,angx#,angy#,angz#,sizx#,sizy#,sizz#)
endif
if lower$(com)="add cube"
read string 1,brace
read string 1,var : var=removeSpace(var) : posx#=val(var)
read string 1,var : var=removeSpace(var) : posy#=val(var)
read string 1,var : var=removeSpace(var) : posz#=val(var)
read string 1,var : var=removeSpace(var) : angx#=val(var)
read string 1,var : var=removeSpace(var) : angy#=val(var)
read string 1,var : var=removeSpace(var) : angz#=val(var)
read string 1,var : var=removeSpace(var) : sizx#=val(var)
read string 1,var : var=removeSpace(var) : sizy#=val(var)
read string 1,var : var=removeSpace(var) : sizz#=val(var)
read string 1,brace
addCube(posx#,posy#,posz#,angx#,angy#,angz#,sizx#,sizy#,sizz#)
endif
if lower$(com)="add cone"
read string 1,brace
read string 1,var : var=removeSpace(var) : posx#=val(var)
read string 1,var : var=removeSpace(var) : posy#=val(var)
read string 1,var : var=removeSpace(var) : posz#=val(var)
read string 1,var : var=removeSpace(var) : angx#=val(var)
read string 1,var : var=removeSpace(var) : angy#=val(var)
read string 1,var : var=removeSpace(var) : angz#=val(var)
read string 1,var : var=removeSpace(var) : sizx#=val(var)
read string 1,var : var=removeSpace(var) : sizy#=val(var)
read string 1,var : var=removeSpace(var) : sizz#=val(var)
read string 1,brace
addCone(posx#,posy#,posz#,angx#,angy#,angz#,sizx#,sizy#,sizz#)
endif
if lower$(com)="add cylinder"
read string 1,brace
read string 1,var : var=removeSpace(var) : posx#=val(var)
read string 1,var : var=removeSpace(var) : posy#=val(var)
read string 1,var : var=removeSpace(var) : posz#=val(var)
read string 1,var : var=removeSpace(var) : angx#=val(var)
read string 1,var : var=removeSpace(var) : angy#=val(var)
read string 1,var : var=removeSpace(var) : angz#=val(var)
read string 1,var : var=removeSpace(var) : sizx#=val(var)
read string 1,var : var=removeSpace(var) : sizy#=val(var)
read string 1,var : var=removeSpace(var) : sizz#=val(var)
read string 1,brace
addCylinder(posx#,posy#,posz#,angx#,angy#,angz#,sizx#,sizy#,sizz#)
endif
if lower$(com)="add plain"
read string 1,brace
read string 1,var : var=removeSpace(var) : posx#=val(var)
read string 1,var : var=removeSpace(var) : posy#=val(var)
read string 1,var : var=removeSpace(var) : posz#=val(var)
read string 1,var : var=removeSpace(var) : angx#=val(var)
read string 1,var : var=removeSpace(var) : angy#=val(var)
read string 1,var : var=removeSpace(var) : angz#=val(var)
read string 1,var : var=removeSpace(var) : sizx#=val(var)
read string 1,var : var=removeSpace(var) : sizy#=val(var)
read string 1,brace
addPlain(posx#,posy#,posz#,angx#,angy#,angz#,sizx#,sizy#)
endif
if lower$(com)="add triangle"
read string 1,brace
read string 1,var : var=removeSpace(var) : x1#=val(var)
read string 1,var : var=removeSpace(var) : y1#=val(var)
read string 1,var : var=removeSpace(var) : z1#=val(var)
read string 1,var : var=removeSpace(var) : x2#=val(var)
read string 1,var : var=removeSpace(var) : y2#=val(var)
read string 1,var : var=removeSpace(var) : z2#=val(var)
read string 1,var : var=removeSpace(var) : x3#=val(var)
read string 1,var : var=removeSpace(var) : y3#=val(var)
read string 1,var : var=removeSpace(var) : z3#=val(var)
read string 1,brace
addTriangle(x1#,y1#,z1#,x2#,y2#,z2#,x3#,y3#,z3#)
endif
`cone, cylinder, plain, triangle
if lower$(com)="add object"
read string 1,brace
read string 1,objDir : objDir=removeSpace(objDir)
read string 1,var : var=removeSpace(var) : posx#=val(var)
read string 1,var : var=removeSpace(var) : posy#=val(var)
read string 1,var : var=removeSpace(var) : posz#=val(var)
read string 1,var : var=removeSpace(var) : angx#=val(var)
read string 1,var : var=removeSpace(var) : angy#=val(var)
read string 1,var : var=removeSpace(var) : angz#=val(var)
read string 1,var : var=removeSpace(var) : sizx#=val(var)
read string 1,var : var=removeSpace(var) : sizy#=val(var)
read string 1,var : var=removeSpace(var) : sizz#=val(var)
read string 1,brace
addObject(objDir,posx#,posy#,posz#,angx#,angy#,angz#,sizx#,sizy#,sizz#)
endif
if lower$(com)="add pointlight"
read string 1,brace
read string 1,var : var=removeSpace(var) : posx#=val(var)
read string 1,var : var=removeSpace(var) : posy#=val(var)
read string 1,var : var=removeSpace(var) : posz#=val(var)
read string 1,var : var=removeSpace(var) : red=val(var)
read string 1,var : var=removeSpace(var) : green=val(var)
read string 1,var : var=removeSpace(var) : blue=val(var)
read string 1,var : var=removeSpace(var) : range#=val(var)
read string 1,brace
addLight(posx#,posy#,posz#,range#,rgb(red,green,blue))
endif
endif
endif
until done
close file 1
endfunction name$
function deleteMap()
local oents as integer : oents=array count(entObj())
local lents as integer : lents=array count(entLgt())
for e=1 to oents
delete object entobj(e)
next e
for e=1 to lents
delete light entlgt(e)
next e
fog off
set ambient light 50
color ambient light 0
color backdrop 0
endfunction
function setWorld(amb,ar,ag,ab,bckr,bckg,bckb,fog,frng,fr,fg,fb)
set ambient light amb
color ambient light rgb(ar,ag,ab)
backdrop on : color backdrop rgb(bckr,bckg,bckb)
if fog=1
fog on
fog distance frng
fog color rgb(fr,fg,fb)
else
fog off
endif
endfunction
function addSphere(x#,y#,z#,ax#,ay#,az#,sx#,sy#,sz#)
local oNum as integer
oNum=freeObject()
make object sphere oNum,100
position object oNum,x#,y#,z#
rotate object oNum,ax#,ay#,az# : fix object pivot oNum
scale object oNum,sx#,sy#,sz#
array insert at bottom entObj() : entCount=array count(entObj()) : entObj(entCount)=oNum
endfunction oNum
function addCube(x#,y#,z#,ax#,ay#,az#,sx#,sy#,sz#)
local oNum as integer
oNum=freeObject()
make object cube oNum,100
position object oNum,x#,y#,z#
rotate object oNum,ax#,ay#,az# : fix object pivot oNum
scale object oNum,sx#,sy#,sz#
array insert at bottom entObj() : entCount=array count(entObj()) : entObj(entCount)=oNum
endfunction oNum
function addCone(x#,y#,z#,ax#,ay#,az#,sx#,sy#,sz#)
local oNum as integer
oNum=freeObject()
make object cone oNum,100
position object oNum,x#,y#,z#
rotate object oNum,ax#,ay#,az# : fix object pivot oNum
scale object oNum,sx#,sy#,sz#
array insert at bottom entObj() : entCount=array count(entObj()) : entObj(entCount)=oNum
endfunction oNum
function addCylinder(x#,y#,z#,ax#,ay#,az#,sx#,sy#,sz#)
local oNum as integer
oNum=freeObject()
make object cylinder oNum,100
position object oNum,x#,y#,z#
rotate object oNum,ax#,ay#,az# : fix object pivot oNum
scale object oNum,sx#,sy#,sz#
array insert at bottom entObj() : entCount=array count(entObj()) : entObj(entCount)=oNum
endfunction oNum
function addPlain(x#,y#,z#,ax#,ay#,az#,sx#,sy#)
local oNum as integer
oNum=freeObject()
make object plain oNum,sx#,sy#
position object oNum,x#,y#,z#
rotate object oNum,ax#,ay#,az# : fix object pivot oNum
array insert at bottom entObj() : entCount=array count(entObj()) : entObj(entCount)=oNum
endfunction oNum
function addTriangle(x1#,y1#,z1#,x2#,y2#,z2#,x3#,y3#,z3#)
local oNum as integer
oNum=freeObject()
make object triangle oNum,x1#,y1#,z1#,x2#,y2#,z2#,x3#,y3#,z3#
array insert at bottom entObj() : entCount=array count(entObj()) : entObj(entCount)=oNum
endfunction oNum
function addObject(obj$,x#,y#,z#,ax#,ay#,az#,sx#,sy#,sz#)
local oNum as integer
oNum=freeObject()
load object obj$,oNum
position object oNum,x#,y#,z#
rotate object oNum,ax#,ay#,az# : fix object pivot oNum
scale object oNum,sx#,sy#,sz#
array insert at bottom entObj() : entCount=array count(entObj()) : entObj(entCount)=oNum
endfunction oNum
function addLight(x#,y#,z#,r#,col)
local lNum as integer
lNum=freeLight()
make light lNum
set point light lNum,x#,y#,z#
set light range lNum,r#
color light lNum,col
endfunction lNum
function getEntityObject(ent)
local obj as integer
obj=entObj(ent)
endfunction obj
function getEntityLight(ent)
local lgt as integer
lgt=entLgt(ent)
endfunction lgt
function removeSpace(st$)
local length as integer : length=len(st$)
for i=1 to length
let$=mid$(st$,i)
if let$<>" "
new$=new$+let$
endif
next i
endfunction new$
function freeObject()
local Num as integer
array insert at bottom objTaken() : num=array count(objTaken())
if object exist(num)=0 and objTaken(num)=0
objTaken(num)=1 : exitfunction num
endif
endfunction 0
function freeLight()
local Num as integer
array insert at bottom lgtTaken() : num=array count(lgtTaken())
if light exist(num)=0 and lgtTaken(num)=0
lgtTaken(num)=1 : exitfunction num
endif
endfunction 0
And here's a map to try it with.
// Name Level
NAME
{
~Test Map~
}
// Set World
SET World
{
30
255
0
255
0
0
0
0
0
0
0
0
}
// Add Objects
ADD Sphere
{
-50
0
0
0
0
0
100
100
100
}
ADD Cone
{
-50
62
0
0
0
0
100
100
100
}
ADD Cube
{
50
0
0
0
0
0
100
100
100
}
ADD Cylinder
{
50
0
0
90
0
0
20
300
20
}
ADD Triangle
{
0
50
0
105
85
0
100
50
0
}
//Ground
ADD Plain
{
0
-100
0
90
0
0
500
500
}
// Add Lights
ADD PointLight
{
0
100
0
255
0
0
2000
}
ADD PointLight
{
0
-100
0
0
0
255
1500
}
ADD PointLight
{
0
0
150
255
0
0
1500
}
ADD PointLight
{
0
0
-150
0
255
0
1500
}
//Create markers for lights
ADD Sphere
{
0
100
0
0
0
0
5
5
5
}
ADD Sphere
{
0
-100
0
0
0
0
5
5
5
}
ADD Sphere
{
0
0
150
0
0
0
5
5
5
}
ADD Sphere
{
0
0
-150
0
0
0
5
5
5
}
[edit]
Comments!!