Jump to content
  • Advertisement
Sign in to follow this  
renegat

problem with projecting monitor coordinates to scene coordinates

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

I'm trying to create selection area in my game (to select players). After left mouse button I'm capturing mouse position (x,y coordinates - monitor). Problem is that I don't know how to project this coordinates on the scene. The selection would be on the xy plane (of scene, horizontal plane), at 0 value of z axis. The selection should exacly match the mouse positions (both when mousedown and mouseup). The problem is with projection matrix. The view has 45 degree of fov view parameter, also the camera is rotated with some variable angle. With this projection matrix elements which are far away are smaller, and those which are close are bigger. That's the reason why I can't project monitor coordinates to the scene coordinates. I would solve this if I would be using orthographic matrix projection (which I don't want to use). Now if I'm clicking in the bottom of a screen the selection has proper width, coordinates, while on the top of screen selection is much shorter. If anyone understands my problem, or want to help me don't hesitate to write a reply :)

Share this post


Link to post
Share on other sites
Advertisement
This is a quick run-down of using the selection buffer in OpenGL(If that's what you're using). It also gives a few snippets of code dealing with generating a pick ray based on the projection matrix. The code is also probably opengl specific, but the general method would probably still apply.

I suppose that, instead of moving the mouse cursor around the screen, you could have the picking shoot only out of the center, much like a gun in an fps. Then the pick ray would be really easy to calculate. But that wouldn't feel good if you're trying to select units in an rts, I suppose. Depends on your needs...

Does this help any?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!