Posted: 27th Aug 2002 13:00
Here is a 3D mouse snippet that I've put together from many different sources over the past year-and-a-bit. I find it works best for me.


position camera 200,200,200


rem make mouse
make object cube 1,5
position object 1,0,0,0

rem make other object
make object sphere 2,5
position object 2,0,0,0



position camera 0,30,-30
pitch camera down 30

position mouse 400,400

sync on
do

repeat
if object screen x(1) mousex()+3
position object 1,object position x(1)-1,object position y(1),object position z(1)
endif
if object screen y(1) mousey()+3
move object 1,3
endif
until object screen x(1) = mousex()-7 and object screen y(1) = mousey()-7

position object 1,object position x(1),object position y(1),object position z(1)

set cursor 10,10
print "Distance between objects: ";dist_obj(1,2)

if dist_obj(1,2)
Posted: 27th Aug 2002 13:00
Oh dear - this might not be DBP compatible. Oops.

But the facedemo didn't have it in so it might be needed.
Posted: 27th Aug 2002 13:03
no mate thats a terrrible snippet.


quickly redeem yourself with a working one
Posted: 27th Aug 2002 16:33
Argh! The forums have cut my code short! Here is part 2:

continuing from after [ ]:

[if dist_obj(1,2)] <4 then print "Mouse over!"
if dist_obj(1,2)<4 and mouseclick()=1 then print "Clicked On!"

sync

loop

function dist_obj(o,o2)
ox#=object position x(o2)
oz#=object position z(o2)
oy#=object position y(o2)
dx#=object position x(o)-ox#
dz#=object position z(o)-oz#
dy#=object position y(o)-oy#
dist#=sqrt((dx#*dx#)+(dz#*dz#)+(dy#*dy#))
endfunction dist#
Posted: 27th Aug 2002 16:37
Wrap your code with the "code" tag to stop it being munged by the forum.

Cheers,

Rich
Posted: 27th Aug 2002 18:19
Rich - I did, that is what's so mysterious!



IE gives "Line 39: document.Post.msgBody is null or not an object"
Posted: 27th Aug 2002 18:20
Hmm - it worked. Must have been a weird anomaly.
Posted: 27th Aug 2002 18:33
the arrow tags are not defined as part of the code snippet and since HTML uses them its falgged it and thrown the whole code out.

this is my theory < > are your culprits.
Posted: 13th Sep 2002 1:42
Funny! When I first saw the line of code "rem make other object" I didn't see the "rem" and thought "make other object" was a command. hehehe
Posted: 13th Sep 2002 21:29
LOL, DBP isn't THAT simple...

Thanks for the snippit
Posted: 22nd Sep 2002 13:21
I thought DBpro would have it's own 3d mouse commands...
Posted: 28th Sep 2002 17:42
It does (I think). See those vector commands in the command list. They will allow 100000000% percent accurate detection of objects and even matrices maybe too.

Vs
Posted: 28th Sep 2002 18:09
Err.. The snippet doesn't seem to work. What do you put between:
if object screen x(1)...mousex()
and
if object screen y(1)...mousey()?

Vs
Posted: 29th Sep 2002 17:29
Don't worry. Already found another full version of it.

Vs
Posted: 5th Oct 2002 17:48
Well, something went wrong with the forums (didn't include the code in a code tag) and so it detected the < and > signs and cut them out.

Here is the FULL version. Hopefully

+ Code Snippet
repeat
if object screen x(1) &lt; mousex()-3
position object 1,object position x(1)+1,object position y(1),object position z(1)
endif
if object screen x(1) &gt; mousex()+3
position object 1,object position x(1)-1,object position y(1),object position z(1)
endif
if object screen y(1) &lt; mousey()-3
move object 1,-3
endif
if object screen y(1) &gt; mousey()+3
move object 1,3
endif
until object screen x(1) =&lt; mousex()+7 and object screen x(1) =&gt; mousex()-7 and object screen y(1) =&lt; mousey()+7 and object screen y(1) =&gt; mousey()-7
Posted: 10th Mar 2003 12:01
Posted: 10th Mar 2003 12:22
hehe this is like the first post ever here on this forum area.

lol how long did that take to come full circle
Posted: 10th Mar 2003 17:25
Sinny brought it back from the dead!
Posted: 14th Mar 2003 13:41
The problem with your code david, is that it limits speed. You need to have it move the object the distance between the mouse object on screen and the cursor. That will make it follow the mouse almost exactly, except in super zoomed in views, and super zoomed out views. Anywhere from 200 to 3000 above a matrix should work fine. If DBP worked i'd write up a copy of my old code, I had a very nice working one.