Sign in to follow this  

Clicking on 3d object - positon of click

This topic is 2662 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

Hi, I am trying to make 3d strategy game. I am using mouse to click on gameboard, but problem is that i cant determine where I am clicking on board, all I can get is possition of cursor on screen. I guess theres some equation, but cant find it or make it out.
Any help is appreciated.

Share this post


Link to post
Share on other sites
You can also calculate it yourself.
Get the distance between the screen plane and the camera.
That will be the z component of your ray.
then the x and the y coordinates of your mouse will be the x and y of the ray.
Then you multiply the ray by the camera matrix and you should have a ray that can be used to check mouse object intersections.

Share this post


Link to post
Share on other sites
Quote:
Original post by Hedanito
Then you multiply the ray by the camera matrix and you should have a ray that can be used to check mouse object intersections.
Can you clarify what you mean by 'camera matrix'?

Share this post


Link to post
Share on other sites
Quote:
Original post by jyk
Quote:
Original post by Hedanito
Then you multiply the ray by the camera matrix and you should have a ray that can be used to check mouse object intersections.
Can you clarify what you mean by 'camera matrix'?


The orientation matrix of the camera.
If it's 3x3 matrix, don't forget to add the translation(position of the camera).

Share this post


Link to post
Share on other sites
Quote:
Original post by Hedanito
The orientation matrix of the camera.
If it's 3x3 matrix, don't forget to add the translation(position of the camera).
I believe your solution is incorrect. Have you actually tried the method you describe? Did it work correctly? (If the answer is yes, then I'm guessing that you haven't accurately described whatever method you're using.)

Share this post


Link to post
Share on other sites
Quote:
Original post by jyk
Quote:
Original post by Hedanito
The orientation matrix of the camera.
If it's 3x3 matrix, don't forget to add the translation(position of the camera).
I believe your solution is incorrect. Have you actually tried the method you describe? Did it work correctly? (If the answer is yes, then I'm guessing that you haven't accurately described whatever method you're using.)


Yes I have tried it out. I actually used it in a ray tracer once, which basically send a ray for every pixel. So instead of sending it for every pixel you send it for the pixel that the mouse is on. It's really straightforward. The harder part is the collision with whatever object you want it to hit. Though since he is talking about a gameboard, a simple line plane collision would suffice.

I did notice I forgot one thing. You have to substract half the screen width from the x position and half the screen height from the y position.

It would also be nice if you state why you think it's wrong, then I can go either like "no way!" or "aaah silly of me".

Share this post


Link to post
Share on other sites
Quote:
It would also be nice if you state why you think it's wrong, then I can go either like "no way!" or "aaah silly of me".
Ok:
Quote:
I did notice I forgot one thing. You have to substract half the screen width from the x position and half the screen height from the y position.
:)

In short, there was nothing in your description to account for any sort of viewport transform, without which you're unlikely to get the correct results. (You can account for the viewport in a more or less ad hoc fashion as you described, or use an additional 'viewport' transform along with the model, view, and projection transforms.)

Share this post


Link to post
Share on other sites

This topic is 2662 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