Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (108)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  window pos to gl pos  (Read 6746 times)
0 Members and 1 Guest are viewing this topic.
Offline starlord

Junior Member





« Posted 2003-06-21 17: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.
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #1 - Posted 2003-06-21 17: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..

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline starlord

Junior Member





« Reply #2 - Posted 2003-06-21 17: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! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #3 - Posted 2003-06-21 18: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 Wink

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline starlord

Junior Member





« Reply #4 - Posted 2003-06-21 19:33:28 »

Grin

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,            //mouse x
     y,            //mouse y
     1.0,            //z but which is the correct value????
     modelMatrix,
      projMatrix,
      viewport,
      rRay,
      rRay,
      rRay);
Offline abies

Senior Member





« Reply #5 - Posted 2003-06-21 20: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
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #6 - Posted 2003-06-21 20:38:23 »

Aye, try changing it to this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
glu.gluUnProject( 
 x,  //mouse x
y,  //mouse y
1.0,  //z but which is the correct value????
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 Embarrassed So you'll need to make fresh arrays for the extras, not use a pointer offset.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline starlord

Junior Member





« Reply #7 - Posted 2003-06-22 06:22:15 »

so the last line becomes:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
 glu.gluUnProject(
 x,  //mouse x
y,  //mouse y
1.0,  //z but which is the correct value????
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?


Offline starlord

Junior Member





« Reply #8 - Posted 2003-06-22 06: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
Offline starlord

Junior Member





« Reply #9 - Posted 2003-06-22 06: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! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline starlord

Junior Member





« Reply #10 - Posted 2003-06-22 07: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.  Smiley
Offline cfmdobbie

Senior Member


Medals: 1


Who, me?


« Reply #11 - Posted 2003-06-22 08:51:49 »

Post your code for them then Smiley

Hellomynameis Charlie Dobbie.
Offline starlord

Junior Member





« Reply #12 - Posted 2003-06-22 10: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();
//this gives iinvalid operation string when using gluErrorString
gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, projection);
glError = gl.glGetError();
//this gives invalid operation string when using gluErrorString
gl.glGetIntegerv(GL.GL_VIEWPORT, viewport);
glError = gl.glGetError();
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #13 - Posted 2003-06-22 11:00:28 »

Quote

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.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline starlord

Junior Member





« Reply #14 - Posted 2003-06-22 11:46:48 »

thanks,that was the problem.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (16 views)
2014-07-30 21:08:39

Riven (22 views)
2014-07-29 18:09:19

Riven (14 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (32 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (42 views)
2014-07-24 01:59:36

Riven (42 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!