Here is a potential one of the other classics i aim to do in one of the months of 2019
// Project: Poweer Drift Revisited
// Created: 2018-12-25
// show all errors
SetErrorMode(2)
#constant screenwidth=1024
#constant screenheight=768
#constant fullscreen=0
#constant screenrate=0
// set window properties
SetWindowTitle( "PowerDrift" )
SetWindowSize( screenwidth, screenheight, fullscreen )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( screenwidth, screenheight ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( screenrate, 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
global map$ as string[71]
// OBJ types
type _3DVector
x#
y#
z#
color
endtype
type _UVVector
U#
V#
endtype
type _FaceVector
vindex
tindex
nindex
endtype
type _modelinfo
name$ as string
vertices as _3DVector[]
normals as _3DVector[]
Textures as _UVVector[]
Faces as _FaceVector
endtype
global objects as _modelinfo[]
// Mesh memblock types
Type Vertex
x as float
y as float
z as float
nx as float
ny as float
nz as float
u as float
v as float
color as integer
endtype
Type Triangle
v1 as integer
v2 as integer
v3 as integer
endtype
Type Mesh
VertexList as Vertex[]
TriangleList as Triangle[]
endtype
global MeshID as Mesh
// Start game loop
createmap()
SetSkyBoxVisible(1)
SetSkyBoxSkyColor(0,200,200)
SetSkyBoxHorizonColor(0,0,70)
plane = CreateObjectPlane(10000,10000)
SetObjectRotation(plane,90,0,0)
SetObjectPosition(plane,500,-20,500)
SetObjectColor(plane,0,255,0,255)
//Interpret whats in the map
// 0 = empty world
// 1 = starting grid
// 2 = dirt track - flat surface like a thin box
// 3 = off road track - height level+0 perhaps like a wooden look and feel cylinder
// 4 = off road track - height level+1 perhaps like a wooden look and feel cylinder
// 5 = off road track - height level+2 perhaps like a wooden look and feel cylinder
// 6 = off road track - height level+3 perhaps like a wooden look and feel cylinder
// 7 = off road track - height level+4 perhaps like a wooden look and feel cylinder
// 8 = checkpoint - overhead banner
// 9 = barrier - side road barrer and collisioner
// A = light curve left
// B = light curve right
// C = sharpe curve left
// D = sharp curve right
// E =
trackpivot = CreateObjectSphere(.1,.1,.1)
tracksize=50
trackrotation=0
peices as integer[3000]
peice=0
for a=0 to map$.length
for b=1 to len(map$[a])
if (mid(map$[a],b,1))="B"
trackrotation=45
peices[peice] = CreateObjectCapsule(tracksize/3,tracksize,tracksize)
SetObjectColor(peices[peice],255,0,0,255)
SetObjectPosition(peices[peice],a*tracksize,4,b*tracksize)
SetObjectRotation(peices[peice],90,trackrotation,0)
endif
if (mid(map$[a],b,1))="C"
trackrotation=-45
peices[peice] = CreateObjectCapsule(tracksize/3,tracksize,tracksize)
SetObjectColor(peices[peice],255,0,0,255)
SetObjectPosition(peices[peice],a*tracksize,4,b*tracksize)
SetObjectRotation(peices[peice],90,trackrotation,0)
endif
if (mid(map$[a],b,1))="D"
trackrotation=90
peices[peice] = CreateObjectCapsule(tracksize/3,tracksize,tracksize)
SetObjectColor(peices[peice],255,250,0,255)
SetObjectPosition(peices[peice],a*tracksize,4,b*tracksize)
SetObjectRotation(peices[peice],90,trackrotation,0)
endif
if (mid(map$[a],b,1))="E"
trackrotation=-45
peices[peice] = CreateObjectCapsule(tracksize/3,tracksize,tracksize)
SetObjectColor(peices[peice],255,250,0,255)
SetObjectPosition(peices[peice],a*tracksize,4,b*tracksize)
SetObjectRotation(peices[peice],90,trackrotation,0)
endif
if (mid(map$[a],b,1))="F"
trackrotation=45
peices[peice] = CreateObjectCapsule(tracksize/3,tracksize,tracksize)
SetObjectColor(peices[peice],255,250,0,255)
SetObjectPosition(peices[peice],a*tracksize,4,b*tracksize)
SetObjectRotation(peices[peice],90,trackrotation,0)
endif
if (mid(map$[a],b,1))="1" // startin grid
peices[peice]=CreateObjectBox(tracksize,1,tracksize)
SetObjectColor(peices[peice],255,255,255,255)
//SetObjectRotation(peices[peice],0,trackrotation,0)
SetObjectPosition(peices[peice],a*tracksize,0,b*tracksize)
FixObjectToObject(peices[peice],trackpivot)
inc peice
endif
if (mid(map$[a],b,1))="2" // dirt track
peices[peice] = CreateObjectBox(tracksize,1,tracksize)
SetObjectColor(peices[peice],162,72,72,255)
SetObjectPosition(peices[peice],a*tracksize,0,b*tracksize)
FixObjectToObject(peices[peice],trackpivot)
inc peice
endif
// lets do the height cylinders
if (mid(map$[a],b,1))="q"
peices[peice] = CreateObjectCylinder(tracksize,tracksize,tracksize)
SetObjectColor(peices[peice],255,255,0,255)
SetObjectRotation(peices[peice],0,90,90)
SetObjectPosition(peices[peice],a*tracksize,-.5,b*tracksize)
FixObjectToObject(peices[peice],trackpivot)
inc peice
endif
if (mid(map$[a],b,1))="w"
peices[peice] = CreateObjectCylinder(tracksize,tracksize,tracksize)
SetObjectColor(peices[peice],255,255,0,255)
SetObjectRotation(peices[peice],0,90,90)
SetObjectPosition(peices[peice],a*tracksize,3,b*tracksize)
FixObjectToObject(peices[peice],trackpivot)
inc peice
endif
if (mid(map$[a],b,1))="e"
peices[peice] = CreateObjectCylinder(tracksize,tracksize,tracksize)
SetObjectColor(peices[peice],255,255,0,255)
SetObjectRotation(peices[peice],0,90,90)
SetObjectPosition(peices[peice],a*tracksize,6,b*tracksize)
FixObjectToObject(peices[peice],trackpivot)
inc peice
endif
if (mid(map$[a],b,1))="r"
peices[peice] = CreateObjectCylinder(tracksize,tracksize,tracksize)
SetObjectColor(peices[peice],255,255,0,255)
SetObjectRotation(peices[peice],0,90,90)
SetObjectPosition(peices[peice],a*tracksize,9,b*tracksize)
FixObjectToObject(peices[peice],trackpivot)
inc peice
endif
if (mid(map$[a],b,1))="t"
peices[peice] = CreateObjectCylinder(tracksize,tracksize,tracksize)
SetObjectColor(peices[peice],255,255,0,255)
SetObjectRotation(peices[peice],0,90,90)
SetObjectPosition(peices[peice],a*tracksize,12,b*tracksize)
FixObjectToObject(peices[peice],trackpivot)
inc peice
endif
if (mid(map$[a],b,1))="y"
peices[peice] = CreateObjectCylinder(tracksize,tracksize,tracksize)
SetObjectColor(peices[peice],255,255,0,255)
SetObjectRotation(peices[peice],0,90,90)
SetObjectPosition(peices[peice],a*tracksize,15,b*tracksize)
FixObjectToObject(peices[peice],trackpivot)
inc peice
endif
if (mid(map$[a],b,1))="u"
peices[peice] = CreateObjectCylinder(tracksize,tracksize,tracksize)
SetObjectColor(peices[peice],255,255,0,255)
SetObjectRotation(peices[peice],0,90,90)
SetObjectPosition(peices[peice],a*tracksize,18,b*tracksize)
FixObjectToObject(peices[peice],trackpivot)
inc peice
endif
if (mid(map$[a],b,1))="i"
peices[peice] = CreateObjectCylinder(tracksize,tracksize,tracksize)
SetObjectColor(peices[peice],255,255,0,255)
SetObjectRotation(peices[peice],0,90,90)
SetObjectPosition(peices[peice],a*tracksize,21,b*tracksize)
FixObjectToObject(peices[peice],trackpivot)
inc peice
endif
if (mid(map$[a],b,1))="o"
peices[peice] = CreateObjectCylinder(tracksize,tracksize,tracksize)
SetObjectColor(peices[peice],255,255,0,255)
SetObjectRotation(peices[peice],0,90,90)
SetObjectPosition(peices[peice],a*tracksize,24,b*tracksize)
FixObjectToObject(peices[peice],trackpivot)
inc peice
endif
if (mid(map$[a],b,1))="p"
peices[peice] = CreateObjectCylinder(tracksize,tracksize,tracksize)
SetObjectColor(peices[peice],255,255,0,255)
SetObjectRotation(peices[peice],0,90,90)
SetObjectPosition(peices[peice],a*tracksize,27,b*tracksize)
FixObjectToObject(peices[peice],trackpivot)
inc peice
endif
if (mid(map$[a],b,1))="9" // barrier
trackrotation=0
peices[peice] = CreateObjectCapsule(tracksize/3,tracksize,tracksize)
SetObjectColor(peices[peice],255,0,250,255)
SetObjectPosition(peices[peice],a*tracksize,4,b*tracksize)
SetObjectRotation(peices[peice],90,trackrotation,0)
// FixObjectToObject(peices[peice],trackpivot)
inc peice
endif
next
next
//AGM_SaveObject(obj,1,"Multiple", "raw:c:\data\","multiple.obj","multiple.mtl", "checkers.png",0)
camerax#=0
cameray#=500
cameraz#=-1000
SetCameraRange(1,.01,10000)
do
// RotateObjectLocalY(trackpivot,.05)
if GetRawKeyState(38) then inc cameraz#,4
if GetRawKeyState(40) then dec cameraz#,4
if GetRawKeyState(37) then inc camerax#,4
if GetRawKeyState(39) then dec camerax#,4
if GetRawKeyState(87) then inc cameray#,4
if GetRawKeyState(83) then dec cameray#,4
SetCameraPosition(1,camerax#,cameray#,cameraz#)
PRINT(GetRawLastKey())
//Print("Saved - look in the area where you saved them")
print(ScreenFPS())
Sync()
loop
Function AddVertex(m ref as Mesh, x as float, y as float, z as float, nx as float, ny as float, nz as float, u as float, v as float, color as integer)
vert as vertex
vert.x = x
vert.y = y
vert.z = z
vert.nx = nx
vert.ny = ny
vert.nz = nz
vert.u = u
vert.v = v
vert.color = color
m.VertexList.Insert(vert)
endfunction
Function AGM_SaveObject(objid, meshindex, group$, folder$, filename$, material$, texture$, debug)
if texture$<>"" then SetObjectImage(objID,LoadImage(folder$+texture$),0)
memblock=CreateMemblockFromObjectMesh(objID,meshindex)
VC = GetMemblockInt(memblock,0)
IC = GetMemblockInt(memblock,4)
Attributes = GetMemblockInt(memblock,8)
counter = GetMemblockInt(memblock,12)
DataOffset = GetMemblockInt(memblock,16)
IndexOffset = GetMemblockInt(memblock,20)
PositionData = GetMemblockInt(memblock,24)
PositionName$ = GetMemblockString(memblock,28,8)
NormalData = GetMemblockInt(memblock,40)
NormalName$ = GetMemblockString(memblock,44,8)
CData = GetMemblockInt(memblock,52)
CName$ = GetMemblockString(memblock,56,8)
ColorData = GetMemblockInt(memblock,60)
ColorName$ = GetMemblockString(memblock,64,8)
if ColorName$=""
colorData=0
ColorName$="No color Data"
endif
if debug=1
repeat
print("Object " + group$)
print("Vertex Count - " + str(vc))
print("Index Count - " + str(IC))
print("Atribute Count - " + str(Attributes))
print("Data Counter - " + str(counter))
print("Data Offset - " + str(DataOffset))
print("Index Offset - " + str(IndexOffset))
print("Position Data - " + str(PositionData))
print("Position String " + positionName$)
print("Normal Data - " + str(NormalData))
print("Normal String " + NormalName$)
print("UV Data - " + str(CData))
print("UV String " + CName$)
print("Color Data - " + str(ColorData))
print("Color String " + ColorName$)
print("Press Space to continue")
print(VC)
print(IC)
print(IC/3)
print(IC/4)
sync()
until GetRawKeyPressed(32)
endif
fw = OpenToWrite(folder$+filename$)
WriteLine(fw,"#AGM Object - " + folder$ + filename$)
WriteLine(fw,"#Exported with AppGameKit")
WriteLine(fw,"")
WriteLine(fw,"mtllib " + material$)
WriteLine(fw,"")
WriteLine(fw,"g " + group$)
WriteLine(fw,"#Vertices")
for v=0 to vc * counter-1 step counter
WriteLine(fw,"v " + str(GetMemblockFloat(memblock,dataoffset+v)) + " " + str(GetMemblockFloat(memblock,dataoffset+v+4)) + " " + str(GetMemblockFloat(memblock,dataoffset+v+8))) // Vertex X,Y,Z
next
WriteLine(fw,"")
WriteLine(fw,"")
WriteLine(fw,"#Normals")
for v=0 to vc * counter-1 step counter
WriteLine(fw,"vn " + str(GetMemblockFloat(memblock,dataoffset+v+12)) + " " + str(GetMemblockFloat(memblock,dataoffset+v+16)) + " " + str(GetMemblockFloat(memblock,dataoffset+v+20))) // Normal x,y,z
next
WriteLine(fw,"")
WriteLine(fw,"")
WriteLine(fw,"#Textures UV's")
for v=0 to vc * counter-1 step counter
WriteLine(fw,"vt " + str(GetMemblockFloat(memblock,dataoffset+v+24)) + " " + str(GetMemblockFloat(memblock,dataoffset+v+28)))
next
WriteLine(fw,"")
WriteLine(fw,"")
WriteLine(fw,"#Faces")
WriteLine(fw,"usemtl Material")
if IC<>0 // Index Couner > 0 so this model as index data at the end to work out the order of faces
for i=0 to (IC / 3)-1
index1=GetMemblockByte(memblock,(indexoffset+(i*12)))+1
index2=GetMemblockByte(memblock,(indexoffset+(i*12)+4))+1
index3=GetMemblockByte(memblock,(indexoffset+(i*12)+8))+1
// WriteLine(fw,"f " + str(index1) + "/0/0 " + str(index2) + "/0/0 " + str(index3) + "/0/0")
WriteLine(fw,"f " + str(index1) + "/" + str(facecount+1) + "/" + str(facecount+1) +" " + str(index2) + "/" + str(facecount) + "/" + str(facecount) + " " + str(index3) + "/" + str(facecount+2) +"/" + str(facecount+2))
next
else
for facecount=1 to vc-2 step 3// VC Vertex Count and no Index count - so the Vertices are straight as is.
WriteLine(fw,"f " + str(facecount) + "/"+str(facecount)+"/" + str(facecount) + " " + str(facecount+1) + "/"+str(facecount+1)+"/" + str(facecount+1)+ " " + str(facecount+2) + "/"+str(facecount+2)+"/" + str(facecount+2))
next
endif
CloseFile(fw)
// write the MTL file
fw = OpenToWrite(folder$ + material$)
WriteLine(fw,"#AGM Material - " + material$)
WriteLine(fw,"#Exported with AppGameKit")
WriteLine(fw,"")
red#=GetObjectColorRed(objid)
green#=GetObjectColorGreen(objid)
blue#=GetObjectColorBlue(objid)
WriteLine(fw,"newmtl Material")
WriteLine(fw,"Kd " + str(red#/255.0) + " " + str(green#/255.0) + " " + str(blue#/255.0))
if texture$<>""
writeLine(fw,"map_Kd "+texture$)
endif
CloseFile(fw)
// sync()
// sleep(1000)
// DeleteObject(objID)
DeleteMemblock(memblock)
endfunction
Function CreateObjectFromMeshWithColor(m ref as mesh)
VertexCount = m.VertexList.Length + 1
IndexCount = (m.TriangleList.Length + 1) * 2
IndexOffset = 72 + VertexCount*36
memblock = CreateMemblock(IndexOffset+IndexCount*4)
SetMemblockInt(memblock,0,VertexCount)
SetMemblockInt(memblock,4,IndexCount)
SetMemblockInt(Memblock,8,4)
SetMemblockInt(memblock,12,36) // no color - 36 if color
SetmemblockInt(memblock,16,72)
SetMemblockInt(memblock,20,IndexOffset)
SetMemblockInt(memblock,24,0x0c000300)
SetMemblockString(Memblock,28,"position")
SetMemblockInt(memblock,40,0x08000300)
SetMemblockString(memblock,44,"normal")
SetMemblockInt(memblock,52,0x04000200)
SetMemblockString(memblock,56,"uv")
SetMemblockInt(memblock,60,0x08010401) // maybe one day or year in 2019 lol
SetMemblockString(memblock,64,"color") // maybe one day or year in 2019 lol
for i = 0 to m.VertexList.Length
SetMemblockFloat(memblock,72+i*36,m.VertexList[i].x)
SetMemblockFloat(memblock,76+i*36,m.VertexList[i].y)
SetMemblockFloat(memblock,80+i*36,m.VertexList[i].z)
SetMemblockFloat(memblock,84+i*36,m.VertexList[i].nx)
SetMemblockFloat(memblock,88+i*36,m.VertexList[i].ny)
SetMemblockFloat(memblock,92+i*36,m.VertexList[i].nz)
SetMemblockFloat(memblock,96+i*36,m.VertexList[i].u)
SetMemblockFloat(memblock,100+i*36,m.VertexList[i].v)
SetMemblockInt(memblock,104+i*36,m.VertexList[i].color) //maybe one day or year in 2019 lol
next
for i = 0 to m.TriangleList.Length
SetMemblockInt(memblock,IndexOffset+i*12,m.TriangleList[i].v1)
SetMemblockInt(memblock,IndexOffset+i*12+4,m.TriangleList[i].v2)
SetMemblockInt(memblock,IndexOffset+i*12+8,m.TriangleList[i].v3)
next
id = CreateObjectFromMeshMemblock(memblock)
// DeleteMemblock(memblock)
endfunction id
Function CreateObjectFromMeshWithUVTexturing(m ref as mesh, texture)
DeleteMemblock(memblock)
VertexCount = m.VertexList.Length + 1
IndexCount = (m.TriangleList.Length + 1) * 2
IndexOffset = 60 + VertexCount*36
memblock = CreateMemblock(IndexOffset+IndexCount*4)
SetMemblockInt(memblock,0,VertexCount)
SetMemblockInt(memblock,4,IndexCount)
SetMemblockInt(Memblock,8,3)
SetMemblockInt(memblock,12,32) // no color - 36 if color
SetmemblockInt(memblock,16,60)
SetMemblockInt(memblock,20,IndexOffset)
SetMemblockInt(memblock,24,0x0c000300)
SetMemblockString(Memblock,28,"position")
SetMemblockInt(memblock,40,0x08000300)
SetMemblockString(memblock,44,"normal")
SetMemblockInt(memblock,52,0x04000200)
SetMemblockString(memblock,56,"uv")
for i = 0 to m.VertexList.Length
SetMemblockFloat(memblock,60+i*32,m.VertexList[i].x)
SetMemblockFloat(memblock,64+i*32,m.VertexList[i].y)
SetMemblockFloat(memblock,68+i*32,m.VertexList[i].z)
SetMemblockFloat(memblock,72+i*32,m.VertexList[i].nx)
SetMemblockFloat(memblock,76+i*32,m.VertexList[i].ny)
SetMemblockFloat(memblock,80+i*32,m.VertexList[i].nz)
SetMemblockFloat(memblock,84+i*32,m.VertexList[i].u)
SetMemblockFloat(memblock,88+i*32,m.VertexList[i].v)
next
DeleteObject(id)
id = CreateObjectFromMeshMemblock(memblock)
SetObjectImage(id,texture,0)
meshmemory = memblock
endfunction id
function AGM_loadobject(file$)
model as _modelinfo
verts as _3DVector
texts as _UVVector
fr = OpenToRead(file$)
groupnumber=0
model.name$=line$
objects.insert(model)
while not FileEOF(fr)
// currentcolor=MakeColor(255,255,255)
line$=ReadLine(fr)
if (mid(line$,1,6)="mtllib")
// load in a material file
mat$ = mid(line$,8,len(line$))
endif
if (mid(line$,1,2)="g " )
// found a group so next find the vertices/normals/textures for this group
endif
if (mid(line$,1,2)="v ")
line$=mid(line$,3,len(line$))
verts.x# = ValFloat(GetStringToken(line$," ",1))
verts.y# = ValFloat(GetStringToken(line$," ",2))
verts.z# = ValFloat(GetStringToken(line$," ",3))
objects[groupnumber].vertices.insert(verts)
endif
if (mid(line$,1,3)="vn ")
line$=mid(line$,4,len(line$))
verts.x# = ValFloat(GetStringToken(line$," ",1))
verts.y# = ValFloat(GetStringToken(line$," ",2))
verts.z# = ValFloat(GetStringToken(line$," ",3))
// normalise the normals
nnx#=verts.x#
nny#=verts.y#
nnz#=verts.z# * -1
length# = sqrt((nnx# * nnx#) + (nny# * nny#) + (nnz# * nnz#))
if length#>31
length#=1/length#
else
nny#=1
length#=1
endif
nx# = nnx# * length#
ny# = nny# * length#
nz# = nnz# * length#
verts.x# = nx#
verts.y# = ny#
verts.z# = nz#
objects[groupnumber].normals.insert(verts)
endif
if (mid(line$,1,3)="vt ")
line$=mid(line$,4,len(line$))
texts.U# = ValFloat(GetStringToken(line$," ",1))
texts.V# = ValFloat(GetStringToken(line$," ",2))
objects[groupnumber].Textures.insert(texts)
endif
if (mid(line$,1,7)="usemtl ")
line$=mid(line$,7,len(line$))
// read the material file to find the corresponding line in the MTL file
matf = OpenToRead(mat$)
found=0
while not FileEOF(matf) or found<>1
// KA - Ambient
// KD - Diffuse
// KS - Specular
matline$=ReadLine(matf)
if matline$ = "newmtl"+line$
repeat
matline$=ReadLine(matf)
if mid(matline$,1,2)="Kd"
matline$=mid(matline$,3,len(matline$))
red# = ValFloat(GetStringToken(matline$," ",1)) * 255.0
green# = ValFloat(GetStringToken(matline$," ",2)) * 255.0
blue# = ValFloat(GetStringToken(matline$," ",3)) * 255.0
currentcolor=MakeColor(red#,green#,blue#)
endif
if mid(matline$,1,7)="map_Kd "
matline$=mid(matline$,8,len(matline$)-1)
matline$=ReplaceString(matline$,"/","\",1)
matline$="\media\" + matline$
map_kd_image = LoadImage(mid(matline$,1,len(matline$)-1))
// map_kd_image=0
currentcolor=MakeColor(255,255,255)
endif
if mid(matline$,1,7)="map_Ka "
matline$=mid(matline$,8,len(matline$)-1)
matline$=ReplaceString(matline$,"/","\",1)
matline$="\media\" + matline$
map_ka_image = LoadImage(mid(matline$,1,len(matline$)-1))
// map_kd_image=0
endif
if mid(matline$,1,7)="map_Ks "
matline$=mid(matline$,8,len(matline$)-1)
matline$=ReplaceString(matline$,"/","\",1)
matline$="\media\" + matline$
map_ks_image = LoadImage(mid(matline$,1,len(matline$)-1))
endif
until matline$=""
found=1
endif
endwhile
CloseFile(matf)
endif
// load the faces data normally straight after the usemtl
if (mid(line$,1,2)="f ")
line$=mid(line$,3,len(line$))
if GetStringToken(line$," ",4)<>""
// this is a polygon structure
polys_vert as integer[4]
polys_text as integer[4]
polys_normals as integer[4]
for c=1 to 4
vertice$=GetStringToken(line$," ",c)
polys_vert[c] = val(GetStringToken(vertice$,"/",1))-1
polys_text[c] = val(GetStringToken(vertice$,"/",2))-1
polys_normals[c] = val(GetStringToken(vertice$,"/",3))-1
next
if normindex<0
normindex=textindex
AddVertex(MeshID, objects[groupnumber].vertices[vertindex].x#,objects[groupnumber].vertices[vertindex].y#,objects[groupnumber].vertices[vertindex].z#, objects[0].normals[normindex].x#, objects[0].normals[normindex].y#, objects[0].normals[normindex].z#, objects[groupnumber].Textures[textindex].U#, objects[groupnumber].Textures[textindex].V#, currentcolor)
else
AddVertex(MeshID, objects[0].vertices[polys_vert[1]].x#,objects[0].vertices[polys_vert[1]].y#,objects[0].vertices[polys_vert[1]].z#, objects[0].normals[polys_normals[1]].x#, objects[0].normals[polys_normals[1]].y#, objects[0].normals[polys_normals[1]].z#, objects[groupnumber].Textures[polys_text[1]].U#, objects[groupnumber].Textures[polys_text[1]].V#, currentcolor)
AddVertex(MeshID, objects[0].vertices[polys_vert[3]].x#,objects[0].vertices[polys_vert[3]].y#,objects[0].vertices[polys_vert[3]].z#, objects[0].normals[polys_normals[3]].x#, objects[0].normals[polys_normals[3]].y#, objects[0].normals[polys_normals[3]].z#, objects[groupnumber].Textures[polys_text[3]].U#, objects[groupnumber].Textures[polys_text[3]].V#, currentcolor)
AddVertex(MeshID, objects[0].vertices[polys_vert[2]].x#,objects[0].vertices[polys_vert[2]].y#,objects[0].vertices[polys_vert[2]].z#, objects[0].normals[polys_normals[2]].x#, objects[0].normals[polys_normals[2]].y#, objects[0].normals[polys_normals[2]].z#, objects[groupnumber].Textures[polys_text[2]].U#, objects[groupnumber].Textures[polys_text[2]].V#, currentcolor)
AddVertex(MeshID, objects[0].vertices[polys_vert[3]].x#,objects[0].vertices[polys_vert[3]].y#,objects[0].vertices[polys_vert[3]].z#, objects[0].normals[polys_normals[3]].x#, objects[0].normals[polys_normals[3]].y#, objects[0].normals[polys_normals[3]].z#, objects[groupnumber].Textures[polys_text[3]].U#, objects[groupnumber].Textures[polys_text[3]].V#, currentcolor)
AddVertex(MeshID, objects[0].vertices[polys_vert[1]].x#,objects[0].vertices[polys_vert[1]].y#,objects[0].vertices[polys_vert[1]].z#, objects[0].normals[polys_normals[1]].x#, objects[0].normals[polys_normals[1]].y#, objects[0].normals[polys_normals[1]].z#, objects[groupnumber].Textures[polys_text[1]].U#, objects[groupnumber].Textures[polys_text[1]].V#, currentcolor)
AddVertex(MeshID, objects[0].vertices[polys_vert[4]].x#,objects[0].vertices[polys_vert[4]].y#,objects[0].vertices[polys_vert[4]].z#, objects[0].normals[polys_normals[4]].x#, objects[0].normals[polys_normals[4]].y#, objects[0].normals[polys_normals[4]].z#, objects[groupnumber].Textures[polys_text[4]].U#, objects[groupnumber].Textures[polys_text[4]].V#, currentcolor)
//AddVertex(MeshID, objects[0].vertices[vertindex].x#,objects[0].vertices[vertindex].y#,objects[0].vertices[vertindex].z#, objects[0].normals[normindex].x#, objects[0].normals[normindex].y#, objects[0].normals[normindex].z#, objects[groupnumber].Textures[textindex].U#, objects[groupnumber].Textures[textindex].V#, currentcolor)
endif
else
// triangle structure
for c=1 to 3
vertice$=GetStringToken(line$," ",c)
vertindex = val(GetStringToken(vertice$,"/",1))-1
textindex = val(GetStringToken(vertice$,"/",2))-1
normindex = val(GetStringToken(vertice$,"/",3))-1
if normindex<0
normindex=textindex
AddVertex(MeshID, objects[groupnumber].vertices[vertindex].x#,objects[groupnumber].vertices[vertindex].y#,objects[groupnumber].vertices[vertindex].z#, objects[0].normals[normindex].x#, objects[0].normals[normindex].y#, objects[0].normals[normindex].z#, objects[groupnumber].Textures[textindex].U#, objects[groupnumber].Textures[textindex].V#, currentcolor)
else
AddVertex(MeshID, objects[0].vertices[vertindex].x#,objects[0].vertices[vertindex].y#,objects[0].vertices[vertindex].z#, objects[0].normals[normindex].x#, objects[0].normals[normindex].y#, objects[0].normals[normindex].z#, objects[groupnumber].Textures[textindex].U#, objects[groupnumber].Textures[textindex].V#, currentcolor)
endif
next
endif
endif
endwhile
obj = CreateObjectFromMeshWithUVTexturingandColor(meshid,map_kd_image,map_ka_image,map_ks_image)
SetObjectColor(obj,255,255,255,255)
//setObjectColorEmissive(obj,100,100,100)
meshid.VertexList.length=-1
meshid.TriangleList.length=-1
CloseFile(fr)
endfunction obj
Function CreateObjectFromMeshWithUVTexturingandColor(m ref as mesh, diffuse,ambient,specular)
DeleteMemblock(memblock)
VertexCount = m.VertexList.Length + 1
IndexCount = (m.TriangleList.Length + 1) * 2
IndexOffset = 72 + VertexCount*36
memblock = CreateMemblock(IndexOffset+IndexCount*4)
SetMemblockInt(memblock,0,VertexCount)
SetMemblockInt(memblock,4,IndexCount)
SetMemblockInt(Memblock,8,4)
SetMemblockInt(memblock,12,36) // no color - 36 if color
SetmemblockInt(memblock,16,72)
SetMemblockInt(memblock,20,IndexOffset)
SetMemblockInt(memblock,24,0x0c000300)
SetMemblockString(Memblock,28,"position")
SetMemblockInt(memblock,40,0x08000300)
SetMemblockString(memblock,44,"normal")
SetMemblockInt(memblock,52,0x04000200)
SetMemblockString(memblock,56,"uv")
SetMemblockInt(memblock,60,0x08010401) // maybe one day or year in 2019 lol
SetMemblockString(memblock,64,"color") // maybe one day or year in 2019 lol
for i = 0 to m.VertexList.Length
SetMemblockFloat(memblock,72+i*36,m.VertexList[i].x)
SetMemblockFloat(memblock,76+i*36,m.VertexList[i].y)
SetMemblockFloat(memblock,80+i*36,m.VertexList[i].z)
SetMemblockFloat(memblock,84+i*36,m.VertexList[i].nx)
SetMemblockFloat(memblock,88+i*36,m.VertexList[i].ny)
SetMemblockFloat(memblock,92+i*36,m.VertexList[i].nz)
SetMemblockFloat(memblock,96+i*36,m.VertexList[i].u)
SetMemblockFloat(memblock,100+i*36,m.VertexList[i].v)
SetMemblockInt(memblock,104+i*36,m.VertexList[i].color) //maybe one day or year in 2019 lol
next
DeleteObject(id)
id = CreateObjectFromMeshMemblock(memblock)
// diffuse
SetObjectImage(id,diffuse,0)
// normal / ambient
// SetObjectImage(id,ambient,1)
// specular
// SetObjectImage(id,specular,2)
// if mode=1 // creates the world or it creates for other small things - like explosion blocks
// we need to keep the world chunk in memory so we can keep updating the vertices
meshmemory = memblock
// endif
// DeleteMemblock(memblock)
endfunction id
function createmap()
// 0 = empty world
// 1 = starting grid
// 2 = dirt track - flat surface like a thin box
// 3 = off road track - height level+0 perhaps like a wooden look and feel cylinder
// 4 = off road track - height level+1 perhaps like a wooden look and feel cylinder
// 5 = off road track - height level+2 perhaps like a wooden look and feel cylinder
// 6 = off road track - height level+3 perhaps like a wooden look and feel cylinder
// 7 = off road track - height level+4 perhaps like a wooden look and feel cylinder
// 8 = checkpoint - overhead banner
// 9 = barrier - side road barrer and collisioner
// A = light curve left
// B = light curve right
// C = sharpe curve left
// D = sharp curve right
// E =
map$[0] ="0000999999999999999999999999999999000000009999999999999999999999999999990000"
map$[1] ="000C22222222122222222222222222222222222222222222222222222222222222222222B000"
map$[2] ="00C2222222221222222222222222222222222222222222222222222222222222222222222B00"
map$[3] ="00D2222222221222222222222222222222222222222222222222222222222222222222222D00"
map$[4] ="00D2222999999999999999999999999999999999999999999999999999999999999992222D00"
map$[5] ="00D222D00000000000000000000000000000000000000000000000000000000000000D222D00"
map$[6] ="00DqqqD00000000000000000000000000D999999999D0000000000000000000000000DqqqD00"
map$[7] ="00DwwwD0000000000000000000000000Dwww0000wwwwD000000000000000000000000DwwwD00"
map$[8] ="00DeeeD000000000000000000000000DeeeD0000DeeeD000000000000000000000000DeeeD00"
map$[9] ="00DrrrD000000000000000000000000DrrrD0000DrrrD000000000000000000000000DrrrD00"
map$[10] ="00DtttD000000000000000000000000DtttD0000DtttD000000000000000000000000DtttD00"
map$[11] ="00DyyyD000000000000000000000000DyyyD0000DyyyD000000000000000000000000DyyyD00"
map$[12] ="00DuuuD000000000000000000000000DuuuD0000DuuuD000000000000000000000000DuuuD00"
map$[13] ="00DiiiD000000000000000000000000DiiiD0000DiiiD000000000000000000000000DiiiD00"
map$[14] ="00DoooD000000000000000000000000DoooD0000DoooD000000000000000000000000DoooD00"
map$[15] ="00DpppD000000000000000000000000DpppD0000DpppD000000000000000000000000DpppD00"
map$[16] ="00DpppD000000000000000000000000DpppD0000DpppD000000000000000000000000DpppD00"
map$[17] ="00DpppD000000000000000000000000DpppD0000DpppD000000000000000000000000DpppD00"
map$[18] ="00DpppD000000000000000000000000DpppD0000DpppD000000000000000000000000DpppD00"
map$[19] ="00DpppD000000000000000000000000DpppD0000DpppD000000000000000000000000DpppD00"
map$[20] ="00DoooD000000000000000000000000DoooD0000DoooD000000000000000000000000DoooD00"
map$[21] ="00DiiiD000000000000000000000000DiiiD0000DiiiD000000000000000000000000DiiiD00"
map$[22] ="00DuuuD000000000000000000000000DuuuD0000DuuuD000000000000000000000000DuuuD00"
map$[23] ="00DyyyD000000000000000000000000DyyyD0000DyyyD000000000000000000000000DyyyD00"
map$[24] ="00DtttD000000000000000000000000DtttD0000DtttD000000000000000000000000DtttD00"
map$[25] ="00DrrrD000000000000000000000000DrrrD0000DrrrD000000000000000000000000DrrrD00"
map$[26] ="00DeeeD000000000000000000000000DeeeD0000DeeeD000000000000000000000000DeeeD00"
map$[27] ="00DwwwD000000000000000000000000DwwwD0000DwwwD000000000000000000000000DwwwD00"
map$[28] ="00DqqqD000000000000000000000000DqqqD0000DqqqD000000000000000000000000DqqqD00"
map$[29] ="00D222D000000000000000000000000D222D0000D222D000000000000000000000000D222D00"
map$[30] ="00D222D000000000000000000000000D222D0000D222D000000000000000000000000D222D00"
map$[31] ="00D22229999999999999999999999992222D0000D22229999999999999999999999992222D00"
map$[32] ="00D22222222222222222222222222222222D0000000022222222222222222222222222222D00"
map$[33] ="00F22222222222222222222222222222222E0000000222222222222222222222222222222E00"
map$[34] ="000F222222222222222222222222222222E0000000222222222222222222222222222222E000"
map$[35] ="0000999999999999999999999999992222E0000000222D999999999999999999999999990000"
map$[36] ="0000999999999999999999999999992222E0000000222D999999999999999999999999990000"
map$[37] ="000C222222221222222222222222222222B0000000022222221222222222222222222222B000"
map$[38] ="00C22222222212222222222222222222222B0000000022222212222222222222222222222B00"
map$[39] ="00D22222222212222222222222222222222D0000000002222212222222222222222222222D00"
map$[40] ="00D2222999999999999999999999990000000000000009999999999999999999999992222D00"
map$[41] ="00D222D000000000000000000000000D222222222222D000000000000000000000000D222D00"
map$[42] ="00DqqqD000000000000000000000000D222222222222D000000000000000000000000DqqqD00"
map$[43] ="00DwwwD000000000000000000000000D222222222222D000000000000000000000000DwwwD00"
map$[44] ="00DeeeD000000000000000000000000DeeeD0000DeeeD000000000000000000000000DeeeD00"
map$[45] ="00DrrrD000000000000000000000000DrrrD0000DrrrD000000000000000000000000DrrrD00"
map$[46] ="00DtttD000000000000000000000000DtttD0000DtttD000000000000000000000000DtttD00"
map$[47] ="00DyyyD000000000000000000000000DyyyD0000DyyyD000000000000000000000000DyyyD00"
map$[48] ="00DuuuD000000000000000000000000DuuuD0000DuuuD000000000000000000000000DuuuD00"
map$[49] ="00DiiiD000000000000000000000000DiiiD0000DiiiD000000000000000000000000DiiiD00"
map$[50] ="00DoooD000000000000000000000000DoooD0000DoooD000000000000000000000000DoooD00"
map$[51] ="00DpppD000000000000000000000000DpppD0000DpppD000000000000000000000000DpppD00"
map$[52] ="00DpppD000000000000000000000000DpppD0000DpppD000000000000000000000000DpppD00"
map$[53] ="00DpppD000000000000000000000000DpppD0000DpppD000000000000000000000000DpppD00"
map$[54] ="00DpppD000000000000000000000000DpppD0000DpppD000000000000000000000000DpppD00"
map$[55] ="00DpppD000000000000000000000000DpppD0000DpppD000000000000000000000000DpppD00"
map$[56] ="00DoooD000000000000000000000000DoooD0000DoooD000000000000000000000000DoooD00"
map$[57] ="00DiiiD000000000000000000000000DiiiD0000DiiiD000000000000000000000000DiiiD00"
map$[58] ="00DuuuD000000000000000000000000DuuuD0000DuuuD000000000000000000000000DuuuD00"
map$[59] ="00DyyyD000000000000000000000000DyyyD0000DyyyD000000000000000000000000DyyyD00"
map$[60] ="00DtttD000000000000000000000000DtttD0000DtttD000000000000000000000000DtttD00"
map$[61] ="00DrrrD000000000000000000000000DrrrD0000DrrrD000000000000000000000000DrrrD00"
map$[62] ="00DeeeD000000000000000000000000DeeeD0000DeeeD000000000000000000000000DeeeD00"
map$[63] ="00DwwwD000000000000000000000000DwwwD0000DwwwD000000000000000000000000DwwwD00"
map$[64] ="00DqqqD000000000000000000000000DqqqD0000DqqqD000000000000000000000000DqqqD00"
map$[65] ="00D222D000000000000000000000000D222D0000D222D000000000000000000000000D222D00"
map$[66] ="00D222D000000000000000000000000D222D0000D222D000000000000000000000000D222D00"
map$[67] ="00D22229999999999999999999999992222D0000D22229999999999999999999999992222D00"
map$[68] ="00D22222222222222222222222222222222D0000D22222222222222222222222222222222D00"
map$[69] ="00F22222222222222222222222222222222E0000F22222222222222222222222222222222E00"
map$[70] ="000F222222222222222222222222222222E000000F222222222222222222222222222222E000"
map$[71] ="0000999999999999999999999999999999000000009999999999999999999999999999990000"
endfunction
I will aim to build of those objects into one mesh when im ready to continue this.
One game at a time though, but the principle is there to make such an app.
Can move around with the cursors and W and D