I am working on a function that will point the camera to a position so that when pointing to a position the camera can go up side down which the built in command can not do. So far I have the following code but I can't get it to work correctly any suggestions?
set display mode 1024, 768, 32
sync on
sync rate 30
autocam off
global angX#
global angY#
make object cube 1, 50
do
text 0, 0, str$(ay#)
//ay# = ay# + .1
//xp# = sin(ay#) * 200
//yp# = cos(ay#) * 200
//position camera xp#, 0, yp#
//pointCamera(0, 0, 0)
controlCamera(500)
sync
loop
function pointCamera(toX#, toY#, toZ#)
camPosX# = camera position x()
camPosY# = camera position y()
camPosZ# = camera position z()
cameraAngleX# = angle2DPoint(camPosZ#, camPosY#, toZ#, toY#)
cameraAngleY# = angle2DPoint(camPosX#, camPosZ#, toX#, toZ#)
text 0, 40, "Cam pos x:" + str$(camPosX#)
text 0, 60, "Cam pos y:" + str$(camPosY#)
text 0, 80, "Cam pos z:" + str$(camPosZ#)
text 0, 120, "Cam ang x:" + str$(camera angle x())
text 0, 140, "Cam ang y:" + str$(camera angle y())
text 0, 160, "Cam ang z:" + str$(camera angle z())
xrotate camera cameraAngleX#
yrotate camera cameraAngleY#
endfunction
function angle2DPoint(x1#, y1#, x2#, y2#)
angle# = AtanFull1(x1#, y1#, x2#, y2#)
endfunction angle#
function AtanFull1(x1#, y1#, x2#, y2#)
distX# = dif(x1#, x2#)
distY# = dif(y1#, y2#)
angle# = AtanFull(distX#, distY#)
text 500, 100, "x1 :" + str$(x1#)
text 500, 120, "y1 :" + str$(y1#)
text 500, 140, "x2 :" + str$(x2#)
text 500, 160, "y2 :" + str$(y2#)
if x1# < x2# and y1# < y2#
angle# = (90 - angle#) * -1
endif
if x1# <= x2# and y1# >= y2#
angle# = 90 - angle#
endif
if x1# > x2# and y1# > y2#
angle# = 90 + angle#
endif
if x1# >= x2# and y1# <= y2#
angle# = 180 + (90 - angle#)
endif
endfunction angle#
function dif(n1#, n2#)
ret# = n2#
if n2# > n1#
ret# = n2# - n1#
else
ret# = n1# - n2#
endif
endfunction ret#
function controlCamera(dis#)
position camera 0, 0, 0
point camera 0, 0, 0
mx = mousemovex();
my = mousemovey();
angX# = angX# + mx
angY# = angY# + my
cx# = (sin(angX#) * cos(angY#)) * (dis# / 2)
cy# = sin(angY#) * (dis# / 2)
cz# = (cos(angX#) * cos(angY#)) * (dis# / 2)
position camera cx#, cy#, cz#
pointCamera(0, 0, 0)
endfunction