Sign in to follow this  
ilian

Object Picking problem

Recommended Posts

ilian    138
My goal is to trace a ray from the mosue cursor position into the scren and see what it hits. Due to the API I am using, this is the only information I have: Position of the Camera in world coordinates. Direction/angles the camera is looking. mouse coordinates in screen space. the mouse coordiantes in world coordinates on the near plane of the frustrum. So since I allready have the position, I now just need a direction to draw my line, is it possible to get from only this info? The obvious simple case is that if the mouse is in the exact center of the screen, I can use the cameras direction to pick my object. But what about, when the cursor is not in the exact center? I should be able to use its position in world coordiantes on teh nearplane, and the cameras world posistion/angle to get the proper direction, right? Im just not sure how. Anyone want to help give me a kick start on this?

Share this post


Link to post
Share on other sites
Guimo    463
If you have "the mouse coordiantes in world coordinates on the near plane of the frustrum" and you have the camera position in world coords, then you have a direction vector (Worldmousepos - CameraPosition).

Luck!
Guimo

Share this post


Link to post
Share on other sites
ilian    138
hey! that was quite obvious, wasnt it!

I just couldnt see it for some reason, but It definately makes sense, got it working, thanks a lot for the help.

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