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.

DarkBASIC Discussion / 3D mouse click

Author
Message
Furiousuk
21
Years of Service
User Offline
Joined: 10th Jan 2003
Location: United Kingdom
Posted: 24th Jan 2003 20:17
I'm making a 3D RTS game and that uses a fixed camera angle, but moveable camera position with a zoom in/out.

I want the user to be able to 'click' on a unit to select it and then 'click' to move it to another position. I'm using a matrix to hold all of my positions, so the game will play something like 'Civilisation' or 'Master of Magic' but in 3D.

I'm having a lot of trouble realising where the user 'clicked' to select a unit. I can have the mouse cursor in the middle of the screen and work out where the camera is pointing using math but this means moving the camera around freely, and with objects on the screen it slows down too much. So, I decided to fix the camera angle to speed things up but now I'm having difficulty working out a function which returns where the user 'clicks' in 3D world.

Can anybody help me with this?
Hamish McHaggis
21
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 24th Jan 2003 21:25
There are the commands "Object Screen X()" and "Object Screen Y()" and "Object In Screen()". The latter tells you if an object is showing on the screen and the other two return the coordinates of the object's origin. You could combine these commands with some maths working out how much of the screen they should take up by finding their distance from the camera, something like...

if mouseclick()=1
if mousex()>=objectscreenx-objectsize/camtoobjdistance and mousex()<=objectscreenx+objectsize/camtoobjdistance
if mousey()>=ahsg blah blah blah...

you get the idea

Yum! Yum! Yum! Yum!
Furiousuk
21
Years of Service
User Offline
Joined: 10th Jan 2003
Location: United Kingdom
Posted: 24th Jan 2003 23:03
Cheers I was thinking about grabbing objects using those commands, thanks for clarifying how to use them correctly

Do you know how I could 'click' on a matrix point?

I've used trigonometry to work out the matrix point that the camera points to, but i haven't worked out how to translate mousex() and mousey() positions into positions on the matrix (3D world).

Any ideas?
Thanx for you help already.

Login to post a reply

Server time is: 2024-05-05 01:51:02
Your offset time is: 2024-05-05 01:51:02