G'day Guys,
Was buggering around with a sort of level editor I am trying to put together, and came up with an odd result.
Basically every time I left click or right click to raise and lower my terrain, the camhead# and campitch# variables get reset to their defaults. All of the other camera variables, (the target positions and camera range) behave as normal
I *think* that it has something to do with the way that the mouse inputs are updated every loop, but I am at a loss to explain why. If anyone has any clues it would be appreciated
At the moment my main loop looks like:
do
gosub cameracontrol
gosub mouseinput
sync
loop
This is the mouseinput code:
mouseinput:
pick screen mousex(),mousey(),1000
nx# = get pick vector x()+camera position x()
ny# = get pick vector y()+camera position y()
nz# = get pick vector z()+camera position z()
pick screen mousex(),mousey(),0.1
ox# = get pick vector x()+camera position x()
oy# = get pick vector y()+camera position y()
oz# = get pick vector z()+camera position z()
hit=SC_raycast(0,ox#,oy#,oz#,nx#,ny#,nz#,0)
hitx#=SC_getstaticcollisionx()
hitz#=SC_getstaticcollisionz()
hitobj = sc_getobjecthit()
cursorx=round(hitx#,1)
cursorz=round(hitz#,1)
position object 3,cursorx,get matrix height(1,cursorx,cursorz),cursorz
if mouseclick()=1 and leftclicktoggle=0
leftclicktoggle=1
raiselevel(cursorx,cursorz)
endif
if mouseclick()=2 and rightclicktoggle=0
rightclicktoggle=1
lowerlevel(cursorx,cursorz)
endif
if mouseclick()=0
leftclicktoggle=0
rightclicktoggle=0
endif
return
and this is my camera control routine:
cameracontrol:
Remstart This subroutine will control the camera as follows:
Middle Button - Activate pan mode, moving the mouse in the x direction will rotate the camera
around the current camera target. Moving the mouse in the y direction will elevate
the camera
Camera Scrolling - with either the boundary zones aroudn the screen or with the arrow keys
Scroll Wheel - zooms in and out between maxrange# and minrange#
remend
campitch#=camera angle x()
camhead#=camera angle y()
boundary=20 `the width in pixels of the camera scrolling zone around the screen
camspeed#=1.0 `how fast the camera can scroll
camrotspd#=0.5 `how fast the camera rotates
maxpitch#=80 `max and min camera pitch angles
minpitch#=10
maxrange#=10 `max and min camera ranges
minrange#=2
`Camera Zoom on scrollwheel
camrange#=camrange#-(mousemovez()/50)
if camrange#<minrange# then camrange#=minrange#
if camrange#>maxrange# then camrange#=maxrange#
`Camera Panning with mouse while middle button is clicked
tempx#=mousemovex()
tempy#=mousemovey()
if mouseclick()=4
camhead#=wrapvalue(camhead#+(tempx#*camrotspd#))
campitch#=wrapvalue(campitch#+(tempy#*camrotspd#/2))
endif
if campitch#>maxpitch# then campitch#=maxpitch#
if campitch#<minpitch# then campitch#=minpitch#
`yrotate camera yang#
rotate camera campitch#, camhead#, 0
`Camera scrolling by boundary zones (note: I DONT want the camera to scroll while I am panning it
if not (mouseclick()=4)
if mousey()<boundary
cameratargetx#=cameratargetx# + (camspeed#*sin(camera angle y()))
cameratargetz#=cameratargetz# + (camspeed#*cos(camera angle y()))
endif
if mousey()>(screen height() - boundary)
cameratargetx#=cameratargetx# + (camspeed#*sin(camera angle y()+180))
cameratargetz#=cameratargetz# + (camspeed#*cos(camera angle y()+180))
endif
if mousex()<boundary
cameratargetx#=cameratargetx# + (camspeed#*sin(camera angle y()-90))
cameratargetz#=cameratargetz# + (camspeed#*cos(camera angle y()-90))
endif
if mousex()>(screen width() - boundary)
cameratargetx#=cameratargetx# + (camspeed#*sin(camera angle y()+90))
cameratargetz#=cameratargetz# + (camspeed#*cos(camera angle y()+90))
endif
endif
`But I DO still want to be able to scroll using the arrowkeys, at the same time as I pan the view (with middle mouse button clicked)
if mousex()>boundary and mousex()<(screen width()-boundary) and mousey()>boundary and mousey()<(screen height()-boundary)
if upkey()
cameratargetx#=cameratargetx# + (camspeed#*sin(camera angle y()))
cameratargetz#=cameratargetz# + (camspeed#*cos(camera angle y()))
endif
if downkey()
cameratargetx#=cameratargetx# + (camspeed#*sin(camera angle y()+180))
cameratargetz#=cameratargetz# + (camspeed#*cos(camera angle y()+180))
endif
if leftkey()
cameratargetx#=cameratargetx# + (camspeed#*sin(camera angle y()-90))
cameratargetz#=cameratargetz# + (camspeed#*cos(camera angle y()-90))
endif
if rightkey()
cameratargetx#=cameratargetx# + (camspeed#*sin(camera angle y()+90))
cameratargetz#=cameratargetz# + (camspeed#*cos(camera angle y()+90))
endif
endif
cameratargety#=0 `get terrain ground height (1,cameratargetx#,cameratargetz#)
`This next bit will override all of the previous stuff, only if the camerafollow mode is set to '1'
`if camerafollow = 1
` cameratargetx# = object position x(camtargetobj)
` cameratargety# = object position y(camtargetobj)
` cameratargetz# = object position z(camtargetobj)
`endif
`determine the new camera position based on the range, heading and pitch to the camera target
camx#=cameratargetx#-(camrange#*sin(camhead#)*cos(campitch#))
camy#=cameratargety#+(camrange#*sin(campitch#))
camz#=cameratargetz#-(camrange#*cos(camhead#)*cos(campitch#))
position camera camx#,camy#,camz#
return
(I have left out the raiselevel and lowerlevel functions for this post, as they dont have any mouse or camera commands in them.)
*edit*
yeah, well, you know how "I have left out the raiselevel and lowerlevel functions for this post, as they dont have any mouse or camera commands in them." ?
Well, they do contain object creation commands, and I cunningly left out the 'autocam off' command at the top, so every time they were called the camera reset itself
A mod can lock or delete this post at will! (hide my noobishness please!)
This is not the Sig you are looking for....