Solved

Calculating window and mouse position (OpenGL)

Posted on 2004-04-04
5
2,676 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ckserve 7 193
Spell-checking 1 101
valarray submatrix representation using gslice 2 133
Any decent scenery blocks for my RTS 6 95
Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

763 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