Solved

Calculating window and mouse position (OpenGL)

Posted on 2004-04-04
5
2,671 Views
Last Modified: 2013-12-26
Aright, here's a good one, and I'll probably have to do ray casting (help), but I'm looking for something easier.

Here's the setup: I have a window (QUAD object) inside an OpenGL window. When I rotate the Window about the y-axis, I remap the mouse so that it projects down to the window, no matter which angle it is at (or am I making things to difficult?)  
0
Comment
Question by:rossryan
5 Comments
 
LVL 2

Expert Comment

by:Jas001
ID: 10781121
Ok, I hope I understand you...
You're designing some sort of window system and the windows have some kind of animation or movement when they gain focus right? Like laying down to facing the camera?  

Why does the mouse have to be in the window?  Is there something in there they need to click on?  Can you clarify what you're trying to do?
0
 

Author Comment

by:rossryan
ID: 10865843
Hmm. They do not lay face down. Take a look at Project Looking Glass. It's something comparable to that. They may be at an angle, and I think I need the normal to convert back to the angled windows real coordinates.
0
 
LVL 2

Accepted Solution

by:
enkimute earned 500 total points
ID: 10947782
Thats not so difficult.

Lets define some stuff :

Mw = Model View matrix used to transform your 'quad' from object space to world space. (you can get this from gl with glGetFloatfv)
P    = Projection matrix in your openGL setup. (same stuff .. glGetFloatfv)
Mpw = Mw * P = Modelview projection matrix, or the matrix you have to multiply the object space quad with to end up in screenspace. ( a simple matrix multiply )

IMpw = (Mpw)^ -1 = The inverse of the modelview projection matrix. If the original matrix is orthonormal, you can use a cheap matrix invert .. (thats true most of the time).

So multiplying a vertex with IMpw will transform it from screen space back to the object space of your original quad. So if you multiply the position of the mouse cursor
with the IMPw, you get a resulting position that you can correctly compare with the vertex positions of your 'quad'

Hope that clears it up for you !
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Edureka is one of the fastest growing and most effective online learning sites.  We are here to help you succeed.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now