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.

Newcomers DBPro Corner / 2D Mouse Coordinates to 3D

Author
Message
CuCuMBeR
21
Years of Service
User Offline
Joined: 11th Jan 2003
Location: Turkey
Posted: 12th Dec 2003 18:21
how to equal the 2d mouse coordinates to 3d coordinates?

to make a selection box for a strategy game like in age of empires
please someone explain with a piece of code.
thank you
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 12th Dec 2003 18:48
look in the help for the command PICK OBJECT
I don't think you can translate 2d-xy coords to 3d-xyz coords

-RUST-

VB.NET makes me all goose-pimply!
David T
Retired Moderator
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 12th Dec 2003 19:10
Quote: "remstart
SIMPLE 3DMOUSE DEMO - DAVID89
remend

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

rem Setup camera + mouse
position camera 0,30,-30
pitch camera down 30
position mouse 400,400

sync on

rem Main loop
do

rem Here we position the mouse object at the cursor's position (code by WhizzRich)
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 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
if object screen y(1) > mousey()+3
move object 1,3
endif
until object screen x(1) =< mousex()+7 and object screen x(1) => mousex()-7 and object screen y(1) =< mousey()+7 and object screen y(1) => mousey()-7
rem -----------------------------------------------------------------------------------

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

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

rem Returns distance between o and o2
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#"


oops forgot to put it in a code tag. never mind

"Help! My keyboard is stuckkkkkkkkkkkkkkkkkkkkkkkkkkkkk"

Mercenaries in Space demo @ http://www.davidtattersall.me.uk
spooky
22
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 12th Dec 2003 19:22
Look at my two snippets here: http://www.thegamecreators.com/?m=forum_view&t=15701&b=7

They show use of PICK OBJECT & PICK SCREEN

@CattleRustler - PICK SCREEN does 2d to 3d conversion given a distance from camera.

Boo!
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 12th Dec 2003 21:42
On this thread, I listed 3 different methods that I've found. I didn't write any of them myself, but gave credit to the known authors.

http://www.dannywartnaby.co.uk/rgt/index.php?board=18;action=display;threadid=1360
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 13th Dec 2003 08:28
cool. i should actually start doing something meaningful in dbp - I have been putting off any game devel until pacth 6.

-RUST-

VB.NET makes me all goose-pimply!
Jaze
21
Years of Service
User Offline
Joined: 20th Nov 2003
Location: Connecticut, USA
Posted: 16th Dec 2003 03:46
@Cattle Rustler - You ever see the demo I made (Attempt at some physics - timer based gfx - gluing it all together) Look at my profile - there's a link or two there


-=/Jaze/=-

Login to post a reply

Server time is: 2024-11-25 20:54:31
Your offset time is: 2024-11-25 20:54:31