Code V1 enjoy..
rem
rem AGK Application
rem made by Alex aka Jack
rem Online Arts 2014
rem movies.online-arts.de
rem
SetVirtualResolution ( 1920, 1080 )
SetDisplayAspect( 16.0 / 16.0 )
rem Init app
SetSyncRate(60,0)
SetClearColor(128,64,0)
setcamerarange(1,15,2000)
setcamerafov(1,90)
rem floorobj=CreateObjectBox( 1000,1, 1000 )
SetClearColor( 200,240,240 )
ClearDepthBuffer()
type terrain_def
one as string
two as string
three as string
endtype
rem get the start time
starttime#=timer()
rem this function creates a terrain
rem 1=8x8, 2=16x16, 3=32x32
rem num,type
create_terrain(1,3)
rem randomize the height
rem randomize_terrain(3,0.05)
heightmap=loadimage("heightmap2.png")
add_heightmap_to_terrain(1,heightmap,0.05)
rem build the map borders
for x=1 to 33
rem set_terrain_height(1,x,1,10.0+random(1,30))
rem set_terrain_height(1,x,33,10.0+random(1,30))
next x
for y=1 to 33
rem set_terrain_height(1,1,y,10.0+random(1,30))
rem set_terrain_height(1,33,y,10.0+random(1,30))
next y
rem save the modifions
save_terrain(1,"final_terrain.obj")
rem get the end time of the measurement
endtime#=timer()-starttime#
rem load the terrain and apply a texture
terrain=loadobject("final_terrain.obj")
terrt=loadimage("texture.jpg")
rem SetObjectImage( floorobj,1,0)
setobjectimage(terrain,terrt,0)
setobjectscale(terrain,200,20,200)
rem create a player object for the camera
playerobj=createobjectsphere(10,5,5)
setobjectposition(playerobj,3,200,3)
rem A Wizard Did It!
setobjectvisible(playerobj,0)
rem A Wizard Did It!
do
print(endtime#)
rem Old position
oldx#=GetObjectX(playerobj)
oldy#=GetObjectY(playerobj)-1.0
oldz#=GetObjectZ(playerobj)
if GetRawKeyState(38)=1 then MoveObjectLocalZ(playerobj,-4.0)
if GetRawKeyState(40)=1 then MoveObjectLocalZ(playerobj,4.0)
if GetRawKeyState(37)=1 then RotateObjectGlobalY(playerobj,-4.0)
if GetRawKeyState(39)=1 then RotateObjectGlobalY(playerobj,4.0)
SetCameraPosition(1,getobjectx(playerobj)+sin(getobjectangley(playerobj))*100,getobjecty(playerobj)+20,getobjectz(playerobj)+cos(getobjectangley(playerobj))*100)
rem SetCameraRotation( 1, getcameraanglex(1), getcameraangley(1), getcameraanglez(1) )
SetCameraLookAt( 1, getobjectx(playerobj), getobjecty(playerobj), getobjectz(playerobj), 0 )
newx#=GetObjectX(playerobj)
newy#=GetObjectY(playerobj)
newz#=GetObjectZ(playerobj)
Sync()
loop
function add_heightmap_to_terrain(ternum,heightmap,hh#)
tertype=terrains[ternum]
if tertype=1
harver=81
endif
if tertype=2
harver=289
endif
if tertype=3
harver=1089
endif
global dim map[sqrt(harver),sqrt(harver)]
global tileCountX as integer
tileCountX=sqrt(harver)
global tileCountY as integer
tileCountY=sqrt(harver)
CreateMemblockFromImage(1,heightmap)
global imgWidth as integer
global imgheight as integer
imgWidth=sqrt(harver)
imgheight=sqrt(harver)
Rem Loop through all vertices in the matrix
for y = 1 to tileCountY
Rem Scale matrix vert to proportionate image pixel
py = (y * imgHeight) / (tileCountY+1)
for x = 1 to tileCountX
Rem Scale matrix vert to proportionate image pixel
px = (x * imgWidth) / (tileCountX+1)
i = (py * imgWidth + px)*4 + 12
c = getmemblockbyte(1, i)
t# = c
rem map[x,y]=t#/1
cn=sqrt(harver)
vertices_map[x+((cn*y)-cn)].two=str((t#/1)*hh#)
rem vertices_map[i].two=str(t#*0.05)
next x
next y
DeleteMemblock( 1 )
x=1
y=1
for i=1 to harver-1
inc x
if x=>31
x=1
rem inc y
endif
next i
endfunction
function create_terrain(ternum,tertype)
global dim terrains[32]
if tertype=1
rem harver= number of verticles in the obj file
harver=81
n$="8x8.obj"
endif
if tertype=2
rem harver= number of verticles in the obj file
harver=289
n$="16x16.obj"
endif
if tertype=3
harver=1089
n$="32x32.obj"
endif
terrains[ternum]=tertype
global verticles_count as integer
global dim terrain_verticles[harver*4] as string
global dim vertices_map[harver*4] as terrain_def
mapfile=OpenToRead(n$)
for i=1 to harver*4
cur_read$=readline(mapfile)
terrain_verticles[i]=cur_read$
if i=<harver
vertices_map[i].one=SplitString(cur_read$, " ", 1)
vertices_map[i].two=SplitString(cur_read$, " ", 2)
vertices_map[i].three=SplitString(cur_read$, " ", 3)
endif
next i
rem if SplitString(cur_read$, " ", 0)="v"
rem inc count3
rem inc verticles_count
rem terrain_verticles[verticles_count]=SplitString(cur_read$, " ", 2)
rem endif
closefile(mapfile)
endfunction
function randomize_terrain(ternum,cadd#)
tertype=terrains[ternum]
if tertype=1
harver=81
endif
if tertype=2
harver=289
endif
if tertype=3
harver=1089
endif
for i=1 to harver
c#=(random(1,100))*cadd#
cs$=str(c#)
vertices_map[i].two=cs$
next i
endfunction
function set_terrain_height(ternum,x,y,height#)
vertices_map[x+((cn*y)-cn)].two=str(height#)
tertype=terrains[ternum]
if tertype=1
harver=81
endif
if tertype=2
harver=289
endif
if tertype=3
harver=1089
endif
cn=sqrt(harver)
vertices_map[x+((cn*y)-cn)].two=str(height#)
endfunction
rem this is the save function of the terrain
function save_terrain(ternum,name$)
tertype=terrains[ternum]
if tertype=1
harver=81
endif
if tertype=2
harver=289
endif
if tertype=3
harver=1089
endif
if getfileexists(name$)=1 then deletefile(name$)
mapfile=opentowrite(name$)
for i=1 to harver*4
rem write the new verticles information
if i=<harver
vec$="v "+vertices_map[i].one+" "+vertices_map[i].two+" "+vertices_map[i].three
writeline(mapfile,vec$)
else
rem write the rest of the file with no modifications
writeline(mapfile,terrain_verticles[i])
endif
next i
closefile(mapfile)
endfunction
rem not my function but really useful
rem this gets the amount of 'segments' that a string can be split into
rem this is based off of 1, not 0. so, if the string and delimiter you pass in
rem returns a counted valueof 3, you can get segments 0-2 from it.
function SplitStringCount(pString as string, pDelimiter as string)
delimitCount as integer
i as integer
rem get length of string
pStringLength as integer
pStringLength = len(pString)
rem parse through the string and count how many delimited chars there are
for i = 0 to pStringLength - 1
if mid(pString, i + 1, 1) = pDelimiter
delimitCount = delimitCount + 1
endif
next i
delimitCount = delimitCount + 1
endfunction delimitCount
rem this splits a string by its delimiter and will return one segment of it.
rem to see how many segments there are, use SplitStringCount.
rem NOTE: SplitString is 0-based, whereas SplitStringCount is 1-based.
rem This is so that SplitStringCount will return a total value of segments (e.g., 3)
rem and to access them in SplitString, you'll use values 0-2.
REM NOTE, if this function 'errors' out - e.g., invalid segment (negative number or too a high a number)
REM this function will return the ENTIRE string back to you.
REM if the function was successful, it will only send back a segment as the return value.
function SplitString(pString as string, pDelimiter as string, pSegment)
delimitCount as integer
myReturn as string
myReturn = ""
charCount as integer
segmentCount as integer
exitSearch as integer
i as integer
rem get the length of the original source string
pStringLength as integer
pStringLength = len(pString)
rem count how many delimiters there are in the string
for i = 0 to pStringLength - 1
if mid(pString, i + 1, 1) = pDelimiter
delimitCount = delimitCount + 1
endif
next i
rem if there are no delimiters found in the original source string
rem or there was an invalid segment number passed in (negative, too high a number)
rem return the original source string
if delimitCount = 0 or pSegment < 0 or pSegment > delimitCount
exitfunction pString
endif
rem this is only applicable to the non-first segment.
rem this finds the first character after a selected delimiter.
rem if we wanted to split up 'foo,bar' and get the second segment, this would return the position of 'b'
rem since the first letter of the first segment starts at 0, we can ignore it
if pSegment > 0
for i = 0 to pStringLength - 1
charCount = charCount + 1
if mid(pString, i + 1, 1) = pDelimiter
segmentCount = segmentCount + 1
if segmentCount = pSegment
exit
endif
endif
next i
endif
rem return an empty string
rem if the last character in the original source string was a delimiter: foo,bar,
if charCount >= pStringLength
myReturn = ""
exitfunction myReturn
endif
rem now we search through and add characters that we need to our return variable.
rem keep adding eltters until we hit a delimiter or the string ends
while exitSearch = 0 and charCount < pStringLength
if mid(pString, charCount + 1, 1) = pDelimiter
exitSearch = 1
else
myReturn = myReturn + mid(pString, charCount + 1, 1)
charCount = charCount + 1
endif
endwhile
rem return value
endfunction myReturn
This project was inspired by this thread:
http://forum.thegamecreators.com/?m=forum_view&t=210562&b=48
Edit: Are there any other workarounds you can image for AppGameKit?
Is there any way to get transparency working on a 3d texture?
Maybe a pixel shader? IDK temporary
[/center]