the problem with spaceships is that picking the aspect is important if you want to get accurate bounding boxes. I try to ignore the aspect and just go off the max diagonal size. this only works unless your space ships are long and thin
Give this a bash and see if it is close to what you are after. It is a cut down version of a system I was trying to use a little while back
`set up display
set display mode desktop width(), desktop height(), 32
autocam off
sync on: sync rate 60
`make a random oblong shape to represent our ship in space
x=RND(5)+1
y=RND(5)+1
z=RND(5)+1
make object box 1,x,y,z
`preinitialised camera variables
camerafollow=0
camtargetobj=1
do
`spacekey will enable/disable camera lock on target
if spacekey() and spacelock=0
spacelock=1
camerafollow = abs(camerafollow-1)
ENDIF
if spacekey()=0 then spacelock=0
`go to the camera control subroutine
gosub cameracontrol
`I decided to turn this into a function, to aid in expandability.
`i.e. if you have an array of units you can simply call this function for any or all of them
selbox(1)
text 10,10,"Camera Heading : " + str$(camera angle y(),0)
text 10,20,"Camera Pitch : " + str$(camera angle x(),0)
text 10,30,"Camera Follow on? = " + str$(camerafollow,0)
text 10,50,"use the arrow keys to move the camera left, right, fwd and backward"
text 10,60,"use the mousewheel to scroll the viewport"
text 10,70,"click and drag the middle mouse button to pan the camera view"
text 10,80,"hit spacebar to toggle camera following on the block"
sync
LOOP
function selbox(object)
`this function will draw 4 x 2D lines around whatever object I can
`it uses the range between the object and camera, and the size of the object
`to work out the pixel height.
`I know that a 1 db unit high object at a distance of 1 db unit from the camera
`is approximately equal to the full screen height
`ONLY IF THE DEFAULT FOV IS STILL IN USE
`I leave it to you to work out the FoV change necessary
`(if you need to, it aint that hard)
`the boxscale variable alters how far around the object the box is drawn
boxscale#=0.8
`get the object screen coords
ax= object screen x(object)
ay= object screen y(object)
`instead of working out the aspect, i use the largest diagonal as the object size
sizex# = object size x(object,1)
sizey# = object size y(object,1)
sizez# = object size z(object,1)
size#=sqrt((sizex#*size#)+(sizey#*sizey#)+(sizez#*sizez#))
range#=camrange(object)
pixeloffset = boxscale#*size#*screen height()/range#
top = ay - pixeloffset
bottom = ay + pixeloffset
left = ax - pixeloffset
right = ax + pixeloffset
`box left,top,right,bottom
line left,top,right,top
line right,top,right,bottom
line right,bottom,left,bottom
line left,bottom,left,top
`note that once you have the top, bottom, left and right coords
`you can use them to position sprites, text, hud objects, anything you like
endfunction
function camrange(object)
`simple range function, I am not normally a fan of using sqrt but this is only a demo :P
ax#=object position x(object)
ay#=object position y(object)
az#=object position z(object)
cx#=camera position x()
cy#=camera position y()
cz#=camera position z()
range#=sqrt(((ax#-cx#)*(ax#-cx#)) + ((ay#-cy#)*(ay#-cy#)) + ((az#-cz#)*(az#-cz#)))
ENDFUNCTION range#
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#=0.5 `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#=100 `max and min camera ranges
minrange#=10
`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
remstart
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
remend
`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#=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
hope that is the kind of thing you are after.
p.s. I left a bunch of useless code in there commented out - just ignore it
*edit* just had a thought. Dunno if all of this will work in DBC, I was in DBPro when i did that, but I *think* it is adaptable
This is not the Sig you are looking for....