Sign in to follow this  

Mouse Position Clicking

This topic is 4758 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok Ive yet to start writing any code on my next project, but I have been brain storming, and I've come across a few questions. The first of which I will explain. Practically every MMORPG out right now, you are able to click on the items in the game window, picking them up etc. How does the client tell, that the mouse is over x item in the game. IE, I want to highlight the item the cursor is over, and when the item is clicked, I want to fire an event that Item with serial X was clicked, and process it.

Share this post


Link to post
Share on other sites
Depends how you depict your items. If they're just a 2D overlay, using bitmaps for example, then you just check the screen co-ordinates of the mouse at the time of clicking and check it against what objects are currently visible.

If it's done in 3D (and I guess this holds for things like RTS's as well), then you need to cast a Ray from the viewpoint in the direction of sight, and intersect it against the polygons / bounding volumes of all visible objects. When you get an intersection, you know which object you're over.

Once you've identified an object, you could just have a flag stored at object level, or an activeobject pointer, to let you know if there is an active object. Then you just operate on that object (move, right-click for commands, whatever).

Hope this helps,
Jim.

Share this post


Link to post
Share on other sites
Quote:

im curious as to how you tell if an item is not visible though


Have a look for the following topics; the GameDev articles section is probably your best starting point.

Picking - this is the process of telling what's under the mouse
Frustrum Culling - what's actually visible on the screen
Scene Graph - a way of organising your objects to make these processes as efficient as possible.

All the best,
Jim.

Share this post


Link to post
Share on other sites

This topic is 4758 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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