I've had a mess around and thus far managed to get it working.
I don't think you needed to put
Position Camera xpos,CamHeight,zpos after every Keystate command, i moved it inside the do / Loop part so it constantly updates. Also, and this is just a guess on my part...
where you have declared
xpos = camera position x(0)
zpos = camera position z(0)
Position Camera 0,1024,CamHeight,1024
it seems to think that xpos and zpos are defaulted to 0 and becuase you haven't used the xpos and zpos in the position camera following that, as soon as you move it positions the camera to the default xpos and zpos, so i have changed it to this (like i said thats just a guess but what i did to the code seems to work)
xpos = camera position x(0): xpos = 1024
zpos = camera position z(0) : zpos = 1024
here is the full code for your consideration:-
Rem Created: Tuesday, August 03, 2010
Rem ***** Main Source File *****
Global CamHeight As Float `make global incase i need to call it in a function later
Global CamSpeed As Float `make global incase i need to call it in a function later
Global xpos As Float `make global incase i need to call it in a function later
Global zpos As Float `make global incase i need to call it in a function later
Sync On
Sync Rate 60
set display mode 1024,768,32
Backdrop On
Autocam Off
Randomize Timer()
Set Camera Range 1,10000
`set up the camera
camspeed = 4
camheight = 100
xpos = camera position x(0): xpos = 1024
zpos = camera position z(0) : zpos = 1024
`Point Camera 0,0,0
RemStart
fog on
fog distance 1000
fog color rgb(32,32,128)
set point light 0,0,0,500
position light 0,0,100,0
color light 0,255,255,255
set light range 0,1000
RemEnd
` set the directory to media
set dir "media"
` load base and detail texture
load image "texture.bmp", 1
load image "detail.tga", 2
make object terrain 1 ` create the terrain object
set terrain heightmap 1, "map.bmp" ` set the heightmap
set terrain scale 1, 4, 0.4, 4 ` set the scale
set terrain split 1, 16 ` split value by 16 * 16
set terrain tiling 1, 4 ` detail map tiling
set terrain light 1, 1, -0.25, 0, 1, 1, 0.78, 0.5 ` light - xdir, ydir, zdir, red, green, blue, intensity
set terrain texture 1, 1, 2 ` base and detail texture
build terrain 1 ` finally build the terrain
` load our skybox
load object "skybox2.x", 200
set object light 200, 0
set object texture 200, 3, 1
`position object 200, 1000, 2000, 4000
`scale object 200, 30000, 30000, 30000
position object 200, 1024, 150, 1024
scale object 200, 3500, 1000, 3500
` reset the directory
set dir ".."
Do
GoSub Camera_Control
Gosub information
Position Camera 0,xpos,CamHeight,zpos
update terrain
Sync
Loop
end
```````````Subroutines```````````````
Camera_Control:
` get the height of the terrain at the current camera position
a# = get terrain ground height( 1, camera position x( ), camera position z( ) )
camRotY = wrapvalue(camera angle y(0)+ mousemovex()*0.2)
camRotX = wrapvalue(camera angle x(0)+ mousemovey()*0.2)
if Keystate(17)=1
inc xpos, sin(camRotY)*camspeed
inc zpos, cos(camRotY)*camspeed
endif
if Keystate(31)=1
dec xpos, sin(camRotY)*camspeed
dec zpos, cos(camRotY)*camspeed
endif
if Keystate(30)=1
dec xpos, sin(camRotY+90)*camspeed
dec zpos, cos(camRotY+90)*camspeed
endif
if Keystate(32)=1
dec xpos, sin(camRotY-90)*camspeed
dec zpos, cos(camRotY-90)*camspeed
endif
If Keystate (16)=1
Inc CamHeight
EndIf
If KeyState (18)=1
Dec CamHeight
EndIf
If CamHeight =< a#+15
CamHeight = a#+15
EndIf
rotate camera camRotX,camRotY,0
Return
information:
` start printing at top of screen
set cursor 10, 10
` show frame rate
print "fps = " + str$ ( screen fps ( ) )
` current camera position
print "x = " + str$ ( camera position x ( ) )
print "y = " + str$ ( camera position y ( ) )
print "z = " + str$ ( camera position z ( ) )
print "polygon count = " + str$ ( statistic ( 1 ) )
print ""
return
I can see from your smile, you're not here for the sunset
Windows 7 64 bit, AMD Phenom II x4 Black edition, 4 GB Ram, Radeon HD 4650, 540 GB HDD