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.

Dark GDK / How to get Mouse coordinate and .. ?

Author
Message
study
15
Years of Service
User Offline
Joined: 12th Dec 2008
Location:
Posted: 15th Dec 2008 18:58
I have some question, ie I want to make a Top-Down shooter game, i want to use mouse as aim, i need to get mouse X and Y coordinate each frame to rotate my character face to my mouse position ( aim ).
how can i get mouse coordinate and save them in a variable and how can i get the current direction of object ?
( I saw dbMouseMoveX() and dbMouseMoveY() but i don't want to turn with them i want to get position of x )
Regards
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 15th Dec 2008 20:52 Edited at: 15th Dec 2008 20:54
You could do the following , you would think there would be an easier way but there doesn't seem to be a command to retrieve mouse co-ordinates.

Declare global variables.


Then in your main loop.



You might want to limit the movement to your screen size.
You can use dbRotateSprite to turn your character.
You may need to use a bit of trigonometry to find the angle for your character to face.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 15th Dec 2008 21:27
You can use the functions dbMouseX() and dbMouseY() to do all that work for you - they return the current screen coordinates of the mouse pointer.

Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 15th Dec 2008 21:45 Edited at: 15th Dec 2008 21:46
Quote: "You can use the functions dbMouseX() and dbMouseY() to do all that work for you - they return the current screen coordinates of the mouse pointer."


Thats a better idea, couldn't find those commands in my documentation.
study
15
Years of Service
User Offline
Joined: 12th Dec 2008
Location:
Posted: 15th Dec 2008 22:26
thanks Matty, thanks IanM
I don't have dbMouseX() and dbMouseY() in my documentation too
are you sure these works? or maybe i need some updates? why there are not in documentation? is some other functions that are not in documentation?
Thanks again
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 15th Dec 2008 23:28
I've just checked my documentation - they're not listed in the contents, but if you select the Input category, they are listed in the main panel.

Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 15th Dec 2008 23:49
So it is, I never look at the main panel, but I will from now on.
Very strange the way a handfull of commands are omitted from the contents.
study
15
Years of Service
User Offline
Joined: 12th Dec 2008
Location:
Posted: 16th Dec 2008 00:07

I saw them in DardSDKInput.h after my last post
study
15
Years of Service
User Offline
Joined: 12th Dec 2008
Location:
Posted: 16th Dec 2008 00:21
Ow one other, I don't need trigonometry calculations too, its same for dbPointObject()
Dark GDK is good for curious Peoples !
study
15
Years of Service
User Offline
Joined: 12th Dec 2008
Location:
Posted: 16th Dec 2008 03:35
New problem.
I think i should do something like matty code.
dbMouseX() and dbMouseY() give me x and y of screen but my 3d object is not relative to screen. I have two way but i don't know wich one is possible and how, do you know?:
1- finding my 3d object x and y in screen to do calculation with mouse x and y.
2- finding my mouse x, y and z in 3d world of my object to calculate 3d
-------
I think the first one is more easier, what do you think? how can i get my object x and y in screen?
or do you have ane better idea for this game? i want to aim with mouse and move with keyboard but its top-down shooter, like GTA2
regards
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 16th Dec 2008 12:53
Have a look at:
dbObjectScreenX()
dbObjectScreenY()
Ive never used them but it sounds like just what your after.
study
15
Years of Service
User Offline
Joined: 12th Dec 2008
Location:
Posted: 17th Dec 2008 05:09
Thanks a lot, it helped me so much, but my object y in screen is different with my mouse y, I think its problem of my object origin right? my object face is his backward in default too.
how can i change my object sides and origin? in my work it's Colonel-X.x ( from 3dobject tutorial )
Thanks again
study
15
Years of Service
User Offline
Joined: 12th Dec 2008
Location:
Posted: 17th Dec 2008 06:40
i got my answer, object origin was correct. i have used dbprint() and my usefull screen was change, when i delete them my screen changed complete and my both mouse and object coordinate is same now.
sorry my english is not good

Login to post a reply

Server time is: 2024-09-30 13:33:36
Your offset time is: 2024-09-30 13:33:36