Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / I'm first! RTS mouse snippet.

Author
Message
David T
Retired Moderator
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
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)
David T
Retired Moderator
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
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.

indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 27th Aug 2002 13:03
no mate thats a terrrible snippet.


quickly redeem yourself with a working one

David T
Retired Moderator
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
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#
Richard Davey
Retired Moderator
22
Years of Service
User Offline
Joined: 30th Apr 2002
Location: On the Jupiter Probe
Posted: 27th Aug 2002 16:37
Wrap your code with the "code" tag to stop it being munged by the forum.

Cheers,

Rich
David T
Retired Moderator
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
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"

"Yes, Yes, Yes, Yes, Yes, Yes, No."

"Honey! I've completed my tax return!"
David T
Retired Moderator
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 27th Aug 2002 18:20
Hmm - it worked. Must have been a weird anomaly.

"Yes, Yes, Yes, Yes, Yes, Yes, No."

"Honey! I've completed my tax return!"
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
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.

Chroma
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: - Please Select -
Posted: 13th Sep 2002 01: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

Blimey Mate!
Ian T
22
Years of Service
User Offline
Joined: 12th Sep 2002
Location: Around
Posted: 13th Sep 2002 21:29
LOL, DBP isn't THAT simple...

Thanks for the snippit

--Mouse
SamotH
22
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Greece
Posted: 22nd Sep 2002 13:21
I thought DBpro would have it's own 3d mouse commands...

VietStylist
22
Years of Service
User Offline
Joined: 20th Sep 2002
Location: Australia
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

VietStylist
22
Years of Service
User Offline
Joined: 20th Sep 2002
Location: Australia
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

VietStylist
22
Years of Service
User Offline
Joined: 20th Sep 2002
Location: Australia
Posted: 29th Sep 2002 17:29
Don't worry. Already found another full version of it.

Vs

David T
Retired Moderator
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
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



I love Star Trek.
Especially the Episodes with Starships in.
sinny
21
Years of Service
User Offline
Joined: 7th Feb 2003
Location:
Posted: 10th Mar 2003 12:01
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
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

Hamish McHaggis
21
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 10th Mar 2003 17:25
Sinny brought it back from the dead!

Why the hell'd you ask me for crying out loud!?!
malcom2073
21
Years of Service
User Offline
Joined: 12th Mar 2003
Location:
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.

Login to post a reply

Server time is: 2024-11-24 04:46:00
Your offset time is: 2024-11-24 04:46:00