I want to implement a 3d environment, at first will start with a cube.
And i want to implement a click event for this object, like Click event for a button.
The problem is i don't know how to implement this, or where to start.
Can someone give me some advice and/or references?

Thank you, Chris

Recommended Answers

All 4 Replies

As a starting point, you need to think of your mouse cursor as a "ray" that intersects through your 3D world at an angle that is perpendicular to your current projection.

Then you check which object you hit first with your "mouse ray" and that is the object you have clicked on.

No, sorry, i think i asked wrong, i know how to do that, what i want to know
is how i can add a feature like this:
mnuPaste.Click += new EventHandler(mnuPaste_Click);
the result should be
cube.Click += new EventHandler(cube_Click); for example
But the question is, can it be done in the case the object is not a button, but a object i created

If the object you created doesn't already have that event. Then you need to write you own, which involves the procedure I laid out above.

Yes. You will need to look into event programming though. I suspect you are using a Direct3D environment - if this is the case you may want to set up an on-click event for the 3D area, then inside that event use Ketsuekiame's method of finding which object was clicked on, then fire the on-click event for that object.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.