[DBP]
Since in upgrade 5.7 the commands for object screen x, object screen y, and object in screen, don't seem to work as they should.
Instead, they tell you the object is on the screen when it's actually behind the camera.
I've finally came up with a function that will tell you if a certain object is behind the camera.
FUNCTION IfInScreen(object)
onscreen=1 `OBJECT IS CONSIDERED TO BE ON SCREEN
position object 90,camera position x(),camera position Y(),camera position z()
set object to camera orientation 90:move object 90,dist_obj(90,object)
distcam#=dist_cam(object)
distobj#=dist_obj(90,object)
if distcam#<distobj#
onscreen=0 `OBJECT IS BEHIND THE CAMERA
endif
ENDFUNCTION onscreen
function dist_obj(o,o2)
ox#=object position x(o2)
oz#=object position z(o2)
oy#=object position y(o2)
dx#=object position x(o)-ox#
dz#=object position z(o)-oz#
dy#=object position y(o)-oy#
dist#=sqrt((dx#*dx#)+(dz#*dz#)+(dy#*dy#))
endfunction dist#
function dist_cam(o)
ox#=camera position x()
oz#=camera position z()
oy#=camera position y()
dx#=object position x(o)-ox#
dz#=object position z(o)-oz#
dy#=object position y(o)-oy#
dist#=sqrt((dx#*dx#)+(dz#*dz#)+(dy#*dy#))
endfunction dist#
The function will return a value of 1 if the object is infront of the camera, and a value of zero if the object is behind the camera.
The function also uses a dummy object, the default object number of the dummt object is 90, but feel free to change it to whatever value you want.
There are two extra functions for distances, that are used in my function, so here they are if anyone's not familiar with them.
EDIT:
here's an example code.
sync on
sync rate 30
make object cube 1,50 `MAKE CUBE OBJECT
position object 1,100,0,0
position camera 0,0,0:point camera 100,0,0
make object cube 90,0.01:hide object 90 `MAKE DUMMY OBJECT
do
if leftkey()=1 then turn camera left 4
if rightkey()=1 then turn camera right 4
onscreen=IfInScreen(1)
if onscreen=1 then text 10,100,"object is infront of the camera"
if onscreen=0 then text 10,100,"object is behind of the camera"
sync
loop
FUNCTION IfInScreen(object)
onscreen=1 `OBJECT IS CONSIDERED TO BE ON SCREEN
position object 90,camera position x(),camera position Y(),camera position z()
set object to camera orientation 90:move object 90,dist_obj(90,object)
distcam#=dist_cam(object)
distobj#=dist_obj(90,object)
if distcam#<distobj#
onscreen=0 `OBJECT IS BEHIND THE CAMERA
endif
ENDFUNCTION onscreen
function dist_obj(o,o2)
ox#=object position x(o2)
oz#=object position z(o2)
oy#=object position y(o2)
dx#=object position x(o)-ox#
dz#=object position z(o)-oz#
dy#=object position y(o)-oy#
dist#=sqrt((dx#*dx#)+(dz#*dz#)+(dy#*dy#))
endfunction dist#
function dist_cam(o)
ox#=camera position x()
oz#=camera position z()
oy#=camera position y()
dx#=object position x(o)-ox#
dz#=object position z(o)-oz#
dy#=object position y(o)-oy#
dist#=sqrt((dx#*dx#)+(dz#*dz#)+(dy#*dy#))
endfunction dist#