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
Solved

Calculating window and mouse position (OpenGL)

Posted on 2004-04-04
5
2,675 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

765 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