starlord
Jr. Member   Posts: 63
|
 |
«
on:
2003-06-21 11:09:41 » |
|
how can i convert my window position(mouse pos from mouse event) to my "world" position.
i googled an example using gluUnProject but it doesn't return "good" values.
so what i need is to convert my current mouse pos to scene pos so i can cast a ray to pick object under my mouse.
any pointer's to tutorial or example code would be helpfull.
|
|
|
|
|
Orangy Tang
JGO Kernel      Posts: 2960 Medals: 37
Monkey for a head
|
 |
«
Reply #1 on:
2003-06-21 11:15:41 » |
|
Saying it doesn't return good values doesn't help much - wrong values how? You should be able to project two points and create a ray from them.
Otherwise, try using gluProject as a debugging aid to see what values you should be providing to gluUnProject..
|
|
|
|
starlord
Jr. Member   Posts: 63
|
 |
«
Reply #2 on:
2003-06-21 11:28:58 » |
|
doesn't return "good" value mean's that it alway's return's
x:0.0 y:0.0 z:0.0
sorry for not mention it.
|
|
|
|
|
Games published by our own members! Go get 'em!
|
|
Orangy Tang
JGO Kernel      Posts: 2960 Medals: 37
Monkey for a head
|
 |
«
Reply #3 on:
2003-06-21 12:15:00 » |
|
That sounds mighty odd - are you sure your matricies are setup correctly? And that you're retreiving your values correctly? Hows about posting the code? My telepathy isn't working today 
|
|
|
|
starlord
Jr. Member   Posts: 63
|
 |
«
Reply #4 on:
2003-06-21 13:33:28 » |
|
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| float camx = posV.x; float camy = posV.y; float camz = posV.z; int viewport[] = new int[4]; double modelMatrix[] = new double[16]; double projMatrix[]=new double[16]; double rRay[]=new double[3]; gl.glGetIntegerv(GL.GL_VIEWPORT, viewport); gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, modelMatrix); gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, projMatrix); glu.gluUnProject( x, y, 1.0, modelMatrix, projMatrix, viewport, rRay, rRay, rRay); |
|
|
|
|
|
abies
Sr. Member   Posts: 456
|
 |
«
Reply #5 on:
2003-06-21 14:12:36 » |
|
One thing which is wrong for sure is triple rRay at the end. You should pass 3 single-element arrays instead of passing single 3-element array three times.
|
Artur Biesiadowski
|
|
|
Orangy Tang
JGO Kernel      Posts: 2960 Medals: 37
Monkey for a head
|
 |
«
Reply #6 on:
2003-06-21 14:38:23 » |
|
Aye, try changing it to this: 1 2 3 4 5 6 7 8 9 10
| glu.gluUnProject( x, y, 1.0, modelMatrix, projMatrix, viewport, rRay, rRay+4, rRay+8); |
The z value is going to be app dependant, but you can typically chose two arbitrary values such as 1 and 10 and use the two points to construct your ray. Edit: Oops, Jogl code, not lwjgl  So you'll need to make fresh arrays for the extras, not use a pointer offset.
|
|
|
|
starlord
Jr. Member   Posts: 63
|
 |
«
Reply #7 on:
2003-06-22 00:22:15 » |
|
so the last line becomes: 1 2 3 4 5 6 7 8 9 10
| glu.gluUnProject( x, y, 1.0, modelMatrix, projMatrix, viewport, rRay_x, rRay_y, rRay_z); |
right? with rRay_x,y,z being array of size 3. why's that? i'm used to have command like this(c): 1 2
| gluUnProject ((GLfloat)x,(GLfloat)y, 1.0, modelMatrix, projMatrix, viewport, &rRay[0], rRay[1], &rRay[2]); |
so this is becose of pointers? anything else in jogl has this kind of tricks?
|
|
|
|
|
starlord
Jr. Member   Posts: 63
|
 |
«
Reply #8 on:
2003-06-22 00:46:40 » |
|
but it still return's values 0.0,0.0,0.0 and gluUnProject return's GL_FALSE so that's the reason for returning zero's. but why it can't project?
i'm calling this method every time mouse has been clicked on canvas
|
|
|
|
|
starlord
Jr. Member   Posts: 63
|
 |
«
Reply #9 on:
2003-06-22 00:57:37 » |
|
and when i check error's with glError after gluUnProject it give's invalid operation.
and when i put DebugGL to canvas it complain's about every gl.glEnd(); and when i remove them it work's but when i click on canvas so that it call's to method that contains gluUnproject it give's me out of memory exception.
this is bit odd why it give's error from glEnd()?
|
|
|
|
|
Games published by our own members! Go get 'em!
|
|
starlord
Jr. Member   Posts: 63
|
 |
«
Reply #10 on:
2003-06-22 01:21:39 » |
|
now i know the problem,it isn't gluUnProject that is failing, it's glGetDoublev and glGetIntegerv. those return's full of zero's array for GL.GL_MODELVIEW_MATRIX,GL.GL_PROJECTION_MATRIX and GL.GL_VIEWPORT. now i need to know why those fail's and how to fix this. 
|
|
|
|
|
cfmdobbie
JGO Wizard     Posts: 1257
Who, me?
|
 |
«
Reply #11 on:
2003-06-22 02:51:49 » |
|
Post your code for them then 
|
Hellomynameis Charlie Dobbie.
|
|
|
starlord
Jr. Member   Posts: 63
|
 |
«
Reply #12 on:
2003-06-22 04:17:12 » |
|
some init stuff 1 2 3
| double model_view[] = new double[16];; double projection[] = new double[16]; int viewport[] = new int[4]; |
and the code to get the values 1 2 3 4 5 6 7 8
| gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, model_view); int glError = gl.glGetError(); gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, projection); glError = gl.glGetError(); gl.glGetIntegerv(GL.GL_VIEWPORT, viewport); glError = gl.glGetError(); |
|
|
|
|
|
Orangy Tang
JGO Kernel      Posts: 2960 Medals: 37
Monkey for a head
|
 |
«
Reply #13 on:
2003-06-22 05:00:28 » |
|
i'm calling this method every time mouse has been clicked on canvas
I tried the glGet calls exactly as you had them written, and they worked fine - then I noticed you said this. Odds are you're calling glGet from a different thread that the GL context is currently active in. There is a way to change this (i noticed it in the Animator source) but you'll probably have nasty race conditions if you start tinkering with that. My advice would be to set a flag to indicate that your GL thread should project the point, and possibly do the work there, then you avoid most of these issues.
|
|
|
|
starlord
Jr. Member   Posts: 63
|
 |
«
Reply #14 on:
2003-06-22 05:46:48 » |
|
thanks,that was the problem.
|
|
|
|
|
|