I have encountered a very strange problem when using functions.
I have this main file :
Rem Project: AdvTerrWShdr
Rem Created: Tuesday, March 08, 2011
Rem ***** Main Source File *****
sync on
sync rate 60
autocam off
hide mouse
disable escapekey
//vars
camheight# = 0.0
sensitivity# = 1.0
//make camera for fullscreen render shader
make camera 1
color backdrop 1, rgb(0, 0, 128)
load camera effect "bloom.fx", 1, 0
set camera effect 1, 1, 2
//make fullscreen render plane
make object plain 2, 2, 2, 1
load effect "quad.fx", 2, 0
set object effect 2, 2
texture object 2, 0, 2
load image "TerrainAssets/terr_tex.jpg", 1
load image "TerrainAssets/terr_det.tga", 2
make object terrain 1
set terrain heightmap 1, "TerrainAssets/terr_hgt.jpg"
set terrain scale 1, 1, 0.6, 1
set terrain split 1, 16
set terrain tiling 1, 4
set terrain light 1, 1, -0.25, 0, 1, 1, 0.78, 0.5
set terrain texture 1, 1, 2
build terrain 1
position camera 385,23,100
camheight# = get terrain ground height(1, camera position x(), camera position z())
camheight# = camheight# + 3
position camera 385, camheight#, 100
//position shader camera
position camera 1, camera position x(), camera position y(), camera position z()
position object 2, camera position x(1), camera position y(1), camera position z(1)
do
CameraSystem()
position mouse screen width()/2,screen height()/2
rotate camera 1,wrapvalue(camera angle x(1)+mousemovey()*sensitivity#),wrapvalue(camera angle y(1)+mousemovex()*sensitivity#),0
rotate camera 0,wrapvalue(camera angle x(1)+mousemovey()*sensitivity#),wrapvalue(camera angle y(1)+mousemovex()*sensitivity#),0
update terrain
//render shader camera
show object 1
hide object 2
sync camera 1
show object 2
hide object 1
//render main camera
sync mask %001
sync
//hide fullscreen plane
hide object 2
DiagnosticsHUD()
loop
and a function file:
function CameraSystem()
q# = get terrain ground height(1, camera position x(), camera position z())
if keystate(17) = 1 then move camera 2 //w - move forward
if keystate(31) = 1 then move camera -2 //s - move backward
//strafe
if keystate(30) = 1
turn camera left 1, 90
move camera 1, 1
turn camera right 1, 90
turn camera left 90
move camera 1
turn camera right 90
endif
if keystate(32) = 1
turn camera right 1, 90
move camera 1, 1
turn camera left 1, 90
turn camera right 90
move camera 1
turn camera left 90
endif
// if keystate(30) = 1
// turn camera left 2 //a - turn camera left
// turn camera left 1, 2
// endif
//
// if keystate(32) = 1
// turn camera right 2 //d - turn camera right
// turn camera right 1, 2
// endif
// if keystate(16) = 1 //user presses q - camera floats up
// inc camheight#, 2.0
// position camera camera position x(), camheight#, camera position z()
// endif
// if keystate(18) = 1 //user presses e - camera floats down
// dec camheight#, 2.0
// if camheight# >= q# + 3
// position camera camera position x(), camheight#, camera position z()
// else
// position camera camera position x(), q# + 3, camera position z()
// camheight# = q# + 3
// endif
// endif
// if keystate(19) = 1 //if user presses r - reset to ground level
// camheight# = get terrain ground height(1, camera position x(), camera position z())
// camheight# = camheight# + 3
// position camera camera position x(), camheight#, camera position z()
// endif
if keystate(45) = 1
destroy terrain 1
delete camera 1
end
endif
camheight# = get terrain ground height(1, camera position x(), camera position z())
camheight# = camheight# + 3
position camera camera position x(), camheight#, camera position z()
position camera 1, camera position x(), camera position y(), camera position z()
position object 2, camera position x(1), camera position y(1), camera position z(1)
endfunction
function DiagnosticsHUD()
set cursor 0, 0
print "camera 0 angle x: " + str$(camera angle x())
print "camera 0 angle y: " + str$(camera angle y())
print "camera 0 angle z: " + str$(camera angle z())
print "camera 1 angle x: " + str$(camera angle x(1))
print "camera 1 angle y: " + str$(camera angle y(1))
print "camera 1 angle z: " + str$(camera angle z(1))
endfunction
My main problem is this ...
I have these lines
CameraSystem()
position mouse screen width()/2,screen height()/2
rotate camera 1,wrapvalue(camera angle x(1)+mousemovey()*sensitivity#),wrapvalue(camera angle y(1)+mousemovex()*sensitivity#),0
rotate camera 0,wrapvalue(camera angle x(1)+mousemovey()*sensitivity#),wrapvalue(camera angle y(1)+mousemovex()*sensitivity#),0
Everything works fine.
However, if I stick the last mouse commands in the function itself, the mouse stops moving. Any idea as to why? I find this very strange.