Posted: 3rd Aug 2003 10:36
Someone had asked for this about a week ago, and I don't recall them get a satisfactory response.

If they did, post a link to the response so I can tweak this code; it's still very rough.

. . . As long as you click the middle of the object, you're good to go.

Once it gets closer to the camera, the further edges are not clickable, but probably 50-70% of the middle will be.

Use the arrow keys to move the object.

+ Code Snippet
`(c) 2003 J.C. Crawford
`http://jcprogs.50megs.com
`eighttruths@yahoo.com

` Please note a credit for any use of the code in any program where it has been used.

`Thank you.




sync on

make object sphere 2, 100
position camera 0,100,500
point camera 0,0,0



do


a=mousex()
b=mousey()

osx=object screen x(2)
osy=object screen y(2)

set cursor object screen x(2),object screen y(2)
print object screen x(2)
set cursor object screen x(2),object screen y(2)+15
print object screen y(2)

if downkey()=1 then move object 2, -2
if upkey()=1 then move object 2,2
if rightkey()=1 then turn object right 2,2
if leftkey()=1 then turn object left 2,-2

tag=0


`Calculate the onscreen size, roughly, of the 3D.

r=(object position z(2))

if r>0 
	r=sqrt(r)
	ss=object size(2)+r
	tag=1
endif

if r<0
	r=sqrt(abs(r))
	ss=object size(2)-r
	tag=1
endif

`A check to avoid a div by zero error.
if tag=0 then ss=object size(2)
`Done with that.

`Allows you to still have something click on when the obj becomes
`a dot.
if ss<1 then ss=1

`ZONECLICKED
`Basically, it's screen size - the size of the object,
`With an earlier tweak for distance.

`You will have to adjust this if you get frisky about moving the camera.
if zoneclicked(osx-ss,osy-ss,osx+ss,osy+ss)=1
	ink rgb(255,0,rnd(155)),0
	set cursor 180,180
	print "Clicked the left button!"
endif

print ss
print object position z(2)
print r


sync
loop


function zoneclicked(x1,y1,x2,y2)
	clicked=0
	if mousex()>x1 and mousex()<x2
		if mousey()>y1 and mousey()<y2
			if mouseclick()=1
				clicked=1
			endif
		endif
	endif
endfunction clicked

Posted: 3rd Aug 2003 14:37
theres a command thatwill do that for you in dbpro
Posted: 3rd Aug 2003 20:02
I suspected. Still too sheap to upgrade.
Posted: 4th Aug 2003 0:30
Check out james's 'bullet' style code. It sends a imaginary bullet from the mouse cursuror out into 3d space. Then you can use dbs collision or your own collision code to detect if the bullet hits anythings. Its great because it works for matrixes AND objects.

http://www.darkbasicpro.com/apollo/view.php?t=13689&b=6
Posted: 4th Aug 2003 8:24
i've done something Similar. Also a wand that just is moved in 3D by the mouse works well.
Posted: 11th Aug 2003 1:24
"theres a command thatwill do that for you in dbpro"

What command?
Posted: 11th Aug 2003 1:32
In update 5 there are some new commands. Main one of interest here is:

PICK OBJECT
This command will return the Object Number of the closest object at the specified screen coordinates. The objects that are tested against the 2D
coordinate are only those within the Object Start and Object End range in order to speed up specific tests. If no object exists at the coordinate, a
value of zero is returned. If an object number is returned, additional data will be generated and stored internally. This extra data can be retrieved
using the GET PICK VECTOR and GET PICK DISTANCE commands.

SYNTAX
Return Integer=PICK OBJECT(Screen X, Screen Y, Object Start, Object End)