Sign in to follow this  
mdonati

Handling mouse input with Direct3D with C#

Recommended Posts

mdonati    100
Hi, I'm working on a proof of concept for my game and I want to know how to handle mouse input with Direct3D. I draw a lot of figures to the screen and I'd like to know when the mouse is over any of them. I have an approach: gameloop: while(app is running) get mouse's coordinates for each figure if mouse's coordinates are inside the figure's area then do whatever needed to be done render figures That's how I'm thinking of it, but I can see a few disadvantages: 1. I can't handle mouse events within the figure (just like windows form's controls do). So, every figure need to have a public method MouseDown, MouseMove, etc. I think that's not a good design. 2. It will lack of performance when the amount of figures grows up, since a lot of checks will need to be done. I want to know the standard way (if there's one) of handling mouse input to do that. I'm working with c#, framework versión 2.0 and Direct3D libs. Best regards.

Share this post


Link to post
Share on other sites
Washu    7829
Well, Direct3D doesn't DO mouse input. It is strictly a rendering API. Ignoring that little tidbit though...

1. If each figure does something different, then why shouldn't that figure be the one to interpret the mouse action and decide what to do? On the other hand: If they all use the same action, then it is silly to have each one duplicate that functionality. Really this is mainly a design issue and you should weigh the alternatives and use the one that fits your problem best.

2. Use spacial partitioning then, or only test the objects in the current frustum or the objects in the current frustum that are between minZ and maxZ (if you only want a subset of the objects). A sphere frustum test is a very quick way to eliminate objects.

Share this post


Link to post
Share on other sites
mdonati    100
Thanks for your reply.
I'm sorry, I forgot to tell you two important issues: the first one, I'm using DirectInput to read mouse events. The second one, I'm using Direct3D, but my game
will be a 2D game (so, my proof of concept is 2D-based as well).
But, I also think that the concept you mentioned (sphere frustum) can be applied with this scenario (can it?).
Thanks again.

Regards.

Share this post


Link to post
Share on other sites
Tom KQT    1704
Sorry for going a bit off the main topic, but what are your reasons for using DirectInput for mouse?
Even Microsoft suggest using windows messages rather than DI for mouse and keyboard input, it has also been already discussed many times here.

Share this post


Link to post
Share on other sites
mdonati    100
I think that the Poll() method fits better within a gameloop.
This is my first time developing games, I didn't know what microsoft recommends.
Even handling mouse events with messages, the same question arises.

Cheers.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this