Sign in to follow this  
Shai

n00bish question regarding mouse cursor

Recommended Posts

Shai    540
Basically I just want a quad constantly following the cursor. Normally I'd just use gluUnproject to get the world coords and get it over with. However some parts of the screen are empty and some have stuff in them. Now when I use gluUnproject and move from a part with stuff in it to an empty part, I end up with world coords turning into screen coords - which is obviously a problem. The easy way out would be to just draw a huge quad *way* in the background, but I feel like that's cheating. anyone got any suggestions?

Share this post


Link to post
Share on other sites
mikeman    2942
The problem is that in gluUnProject you must supply the (winx,winy,winz) coordinates, but the mouse only gives you (winx,winy),so you can't "cheat" here, you must find a way to supply a certain winz value.

How will you do that, it depends on what you want to do. You can either use a fixed z value between[0,1], so that the quad remains "locked" in a certain depth or draw a plane for instance in the screen and make the quad move along that plane. As I said, it all depends on how you want your program to do this thing, sit down, think about it, and implement it. One idea is to read the zbuffer as you do now, but every time save the zvalue to a variable.If there is "stuff" the screen(z<1) , use the value to gluUnproject, if the pixel is "invalid"(z=1), use the last valid z-value, until you hit a "valid" pixel again.

Share this post


Link to post
Share on other sites
zedzeek    529
perhaps use glOrtho(..) and draw the object like so, or use unproject prehaps use the near clip plane Zvalue (ie not the value u pass for gluPerspective(.,.,near,) for z

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