Quote: "there is an age-old bug in DarkBASIC's OBJECT SCREEN X and OBJECT SCREEN Y commands, where an object's position will be indicated 180 degrees from where it actually is"
Since when? I don't recall such a bug.
Quote: "So, moving an object 1 unit from the camera probably won't work"
Yes it will, the distance is irrelevant. Whether you look at a point 1 unit in front of the camera or 1000, the resulting directional vector is the same.
Technically this should position a cube in front of the camera, but I can't figure out why it's not working properly. The Y-coordinate seems way off. If I can figure out why its not right, then you'll be able to get a point in front of the camera for the rest of your calculations.
Rem Project: Dark Basic Pro Project
Rem Created: Saturday, December 01, 2012
Rem ***** Main Source File *****
make matrix 1, 1000, 1000, 20, 20
position camera 0, 50, 0
point camera 100, 0, 100
make object cube 1, 30 : color object 1, rgb(255,0,0)
dist# = 100
sync on
sync rate 60
do
gosub PLAYER_CONTROLS
gosub CAMERA_STATUS
if spacekey() and flag=0
flag = 1
position object 1, rnd(1000), 15, rnd(1000)
endif
if spacekey()=0 then flag=0
if mouseclick() = 1 then inc dist#
if mouseclick() = 2 then dec dist#
xAngle# = camera angle x()
yAngle# = camera angle y()
zAngle# = camera angle z()
cx#=(Cos(ZAngle#)*Sin(YAngle#)*Sin(XAngle#)-Sin(ZAngle#)*Cos(XAngle#))*Dist#
cy#=(Cos(ZAngle#)*Cos(XAngle#)+Sin(ZAngle#)*Sin(YAngle#)*Sin(XAngle#))*Dist#
cz#=(Cos(YAngle#)*Sin(XAngle#))*Dist#
position object 1, camera position x()+cx#*dist#, camera position y()+cy#*dist#, camera position z()+cz#*dist#
set cursor 0,0
print dist#
print cx#
print cz#
print cz#
print
print camera angle x()
print camera angle y()
print camera angle z()
print
print camera position x()
print camera position y()
print camera position z()
print
print object position x(1)
print object position y(1)
print object position z(1)
sync
loop
REM control player's movement
PLAYER_CONTROLS:
runspeed#=0
if shiftkey()=1 then runspeed#=-5.5
if upkey()=1
x#=newxvalue(x#,a#,6+runspeed#)
z#=newzvalue(z#,a#,6+runspeed#)
endif
if downkey()=1
x#=newxvalue(x#,a#,-6-runspeed#)
z#=newzvalue(z#,a#,-6-runspeed#)
endif
if leftkey()=1
x#=newxvalue(x#,wrapvalue(a#-90.0),6.0+runspeed#)
z#=newzvalue(z#,wrapvalue(a#-90.0),6.0+runspeed#)
endif
if rightkey()=1
x#=newxvalue(x#,wrapvalue(a#+90.0),6.0+runspeed#)
z#=newzvalue(z#,wrapvalue(a#+90.0),6.0+runspeed#)
endif
RETURN
REM control player's angle of site/rotation and position
CAMERA_STATUS:
y# = 50
rem rotate camera according to mouse
a#=wrapvalue(a#+(mousemovex()/3.0))
rem position and rotate camera
cxa#=cxa#+(mousemovey()/3.0)
if cxa#<-90.0 then cxa#=-90.0
if cxa#>90.0 then cxa#=90.0
position camera x#,y#,z#
rotate camera wrapvalue(cxa#),a#,0
RETURN
"You're not going crazy. You're going sane in a crazy world!" ~Tick