Posted: 6th May 2003 15:04
I see alot questions, I don't know this has been done already, because I don't need it, but I've been playing around a bit. And I have made a function. It's very simple. It just makes a tiny little sphere that moves from your camera position and then 1000(meter?) away. When it collides the function returns the number it collides to otherwise zero is returned. This is the function with an example program how to use it:
+ Code Snippet
rem Initializing and making a scene
sync on
autocam off
make object cube 1,10
make object cube 2,20
make object cube 3,5
make object cube 4,30
make object cube 5,10
make object cube 6,20
make object cube 7,5
make object cube 8,14
position object 1,0,0,50
position object 2,20,40,10
position object 3,-20,0,20
position object 4,-10,-10,-40
position object 5,-5,-10,10
position object 6,10,20,-10
position object 7,10,-5,20
position object 8,-10,10,10
set global collision on

rem The mainloop the object that will be selected will be coloured red
rem And you will see the object number in the upperleft
do
rem This for-next loop has to go from the first object to the last
rem In this case it's 1 to 4
for a=1 to 8
color object a,rgb(255,255,255)
next a
if obj>0 then color object obj,rgb(255,0,0)
text 0,0,str$(obj)
if mouseclick()=1 then obj=objsel(0)
rotate camera wrapvalue(camera angle x()+mousemovey()),wrapvalue(camera angle y()+mousemovex()),wrapvalue(camera angle z())
position mouse 320,240
sync
loop

rem The function, always call the function with objsel(0)
function objsel(obj)
if object exist(999)=0 then make object sphere 999,0.1
hide object 999
position object 999,camera position x(),camera position y(),camera position z()
rotate object 999,camera angle x(),camera angle y(),camera angle z()
for a=1 to 1000
move object 999,1
if object collision(999,0)>0
obj=object collision(999,0)
exit
endif
next a
endfunction obj
Posted: 6th May 2003 15:14
It's really fast and accurate, it will always select the object when you're mouse is on it, but if you click a tiny milimeter away from the object it doesn't work!
Posted: 6th May 2003 17:30
yes, it work, but what some people want, it is the the mouse select the object, not the center
so you have to do the same, but not rotate the sphere as the camera, but .. I don't know how to explain it in english (I speak french ^^) ..
if you can move the mouse, you cannot use your system, and some people want to be able to move the mouse (for games as Warzone 2100), so you have to find the angle that is between the mouse and the camera, but .. oh, I don't know how to explain it ....
I'm not bad at mathematics, and I find the angles easy to find, but there's something odd.. look at it :

+ Code Snippet
sync on
sync rate 50

make object sphere 1,1

do
fovy# = 38.6598
fovx# = 31
mx# = mousex()
my# = mousey()
angley# = ((mx# - screen width()/2)) / screen width() * fovy# * 2
anglex# = ((my# - screen height()/2)) / screen height() * fovx# * 2
sax# = wrapvalue(camera angle x()+anglex#)
say# = wrapvalue(camera angle y()+angley#)
if mouseclick()=1
   position object 1,camera position x(),camera position y(),camera position z()
   rotate object 1,sax#,say#,0
endif
move object 1,0.5
sync
loop


with it, we should have the good angles, but ... I don't know why, when the mouse is in the corners of the screen, it doesnt work at all, but when it stay near the middle of the height OR (nor and, or ) the middle of the width, it work very well....
I found the fovx# and fovy# by positionning a sphere where I see it in the up-right corner of the screen, so I know which angles are visibles on X and Y
but .. there's another way to do that .. whyn use the mouse and not a sprite that we paste on the true coordinates ? with the mouse we change the angles, we move the object, and when it hit something (maybe a banana ?) or it is very far, we stop it and paste the sprite on its coordinates .. I try to do that now
Posted: 6th May 2003 18:51
here's an other code .. :
+ Code Snippet
rem it work with all resolutions .. Why am I so great ?
set display mode 1024,768,16
sync on
sync rate 50

rem yeah, still thoses numbers :D
fovy# = 38.6598
fovx# = 31


rem a lovely sphere :D
make object sphere 1,1

do
rem to change or not to change the angles ? that is not the question ^_^
sx# = mousemovex()
sy# = mousemovey()
anglex# = anglex# + (sy#/10)
angley# = angley# + (sx#/10)

rem there's a limitation for the angles
if angley# < -fovy# then angley# = -fovy#
if anglex# < -fovx# then anglex# = -fovx#
if angley# > fovy# then angley# = fovy#
if anglex# > fovx# then anglex# = fovx#

rem position, rotate and move the object
position object 1,camera position x(),camera position y(),camera position z()
xrotate object 1,wrapvalue(camera angle x()+anglex#)
yrotate object 1,wrapvalue(camera angle y()+angley#)
move object 1,100

rem the mouse
position mouse object screen x(1),object screen y(1)

sync
loop


now, we have a code that work better that the last, but the mouse isn't draw very well, it's still a bit behind the true object's position ...
I think that it's a good start, but there are a few things to do :
1. when the mouse is in a corner, there's a small but, because of the limitation of the angle .. it can be repared easily
2. we cannot select an object, but I didn't do this code to select something, but to position an object at the mouse's coordinates ^^
Posted: 6th May 2003 20:32
Bonjour, ça va bien? Je suis holandais. Je ne parle pas Francais bien...

I understand what you said . This is the object selection code with your code included(kind of), thank you very much!!! The only thing that needs fixing is the corner thingie. Maybe you know a solution. But it's much better than first now, merci beaucoup.

+ Code Snippet
rem ---3D camera rotation---
rem RTSpider with great help from Attreid

rem Initializing and making a scene
sync on
autocam off
make object cube 1,10
make object cube 2,20
make object cube 3,5
make object cube 4,30
make object cube 5,10
make object cube 6,20
make object cube 7,5
make object cube 8,14
position object 1,0,0,50
position object 2,20,40,10
position object 3,-20,0,20
position object 4,-10,-10,-40
position object 5,-5,-10,10
position object 6,10,20,-10
position object 7,10,-5,20
position object 8,-10,10,10
set global collision on
fovy# = 38.6598
fovx# = 31
make object sphere 999,0.1
hide object 999
set object rotation zyx 999

rem The mainloop the object that will be selected will be coloured red
rem And you will see the object number in the upperleft
do
rem This for-next loop has to go from the first object to the last
rem In this case it's 1 to 8
for a=1 to 8
color object a,rgb(255,255,255)
next a
if obj>0 then color object obj,rgb(255,0,0)
text 0,0,str$(obj)
if mouseclick()=1 then obj=objsel(0)
if leftkey()=1 then yrotate camera wrapvalue(camera angle y()-1)
if rightkey()=1 then yrotate camera wrapvalue(camera angle y()+1)
if upkey()=1 then xrotate camera wrapvalue(camera angle x()-1)
if downkey()=1 then xrotate camera wrapvalue(camera angle x()+1)
sx# = mousemovex()
sy# = mousemovey()
anglex# = anglex# + (sy#/10)
angley# = angley# + (sx#/10)
if angley# < 0-fovy# then angley# = 0-fovy#
if anglex# < 0-fovx# then anglex# = 0-fovx#
if angley# > fovy# then angley# = fovy#
if anglex# > fovx# then anglex# = fovx#
show object 999
position object 999,camera position x(),camera position y(),camera position z()
xrotate object 999,wrapvalue(camera angle x()+anglex#)
yrotate object 999,wrapvalue(camera angle y()+angley#)
move object 999,10
rotate object 999,camera angle x(),camera angle y(),camera angle z()
move object 999,-10
xrotate object 999,wrapvalue(camera angle x()+anglex#)
yrotate object 999,wrapvalue(camera angle y()+angley#)
sync
loop

rem The function, always call the function with objsel(0)
function objsel(obj)
for a=1 to 1000
move object 999,1
if object collision(999,0)>0
obj=object collision(999,0)
exit
endif
next a
endfunction obj