@Link102
Hello,
In regards to your original intention, you can do a bit of a trick by having the camera follow the mouse movement. Instead of the regular cursor, create an object that is a certain distance in front of the camera. This will act as your cursor. As you move the camera around and your "cursor", you get the 3d coordinates from the cursor. This will be the world coordinates relative to your matrix. A little math based on the size of the grid squares will allow you to drop the ball at the nearest square.
Now in regards to your posted code, if you are going to move the object relative to the camera angle, you have to treat the object the same way you'd treat a character in a game that you wanted to strafe left and right. The forward backward movement is easy, that's directly coorilated to the camera angle, but left and right will be offset by 90 degrees. Here's your code with a couple of adjustments based on what I'm talking about:
set display mode 1280,1024,32
sync on:sync rate 30
hide mouse
gosub setup_matrix
make object sphere 1,5
X#=500
Z#=500
camX#=400
camY#=50
camZ#=500
zoom=100
do
set cursor 0,0:print zoom
position object 1,X#,Y#,Z#
if mouseclick()=2
cam_Y#=cam_Y#+wrapvalue(MousemoveX()/10)
zoom=zoom+mousemoveY()/2
if zoom<10 then zoom=10
endif
if mouseclick()=1
rem - this is your original code
rem this only covers one case so I commented it out - latch
`X#=newZvalue(X#,camera angle Y(),mousemoveX())
`Z#=newZvalue(Z#,camera angle Y()-180,mousemoveY())
rem treat the object movement like strafing
rem to move it left and right, it's always 90 degrees
rem offset from the angle something is facing - in this case
rem the camera
distx=abs(mousemovex())
if mousemovex() >= 0
x#=newxvalue(x#,camera angle y()+90,distx)
z#=newzvalue(z#,camera angle y()+90,distx)
endif
if mousemovex() < 0
x#=newxvalue(x#,camera angle y()-90,distx)
z#=newzvalue(z#,camera angle y()-90,distx)
endif
rem forward and backward don't need the 90 degree offset
rem but the directions are opposite
disty=mousemovey()*-1
if mousemovey() <>0
x#=newxvalue(x#,camera angle y(),disty)
z#=newzvalue(z#,camera angle y(),disty)
endif
endif
gosub camera
sync
loop
setup_matrix:
ink rgb(150,150,150),0:box 0,0,40,40
ink rgb(255,255,255),0:line 0,0,40,0:line 0,0,0,40:line 40,40,40,0:line 40,40,0,40
get image 1,0,0,41,41
make matrix 1,1000,1000,50,50
prepare matrix texture 1,1,1,1
return
camera:
ocamX#=newXvalue(X#,cam_Y#,zoom)
ocamZ#=newzvalue(Z#,cam_Y#,zoom)
ocamY#=Y#+zoom/2
camX#=camX#+(ocamX#-camX#)/10
camZ#=camZ#+(ocamZ#-camZ#)/10
camY#=camY#+(ocamY#-camY#)/10
campX#=X#-campX#/10
campZ#=Z#-campZ#/10
campY#=Y#-campY#/10
point camera X#,Y#,Z#
position camera camX#,camY#,camZ#
return
Enjoy your day.