Login  Register

bad use of depths in Picking.java

classic Classic list List threaded Threaded
9 messages Options Options
Embed post
Permalink
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

bad use of depths in Picking.java

gouessej
Administrator
6039 posts
Hi!

Picking.java is a provided example of JOGL 2 here:
http://jogamp.org/jogl-demos/src/demos/misc/Picking.java

The both lines above are wrong:
z1 = (float) buffer.get(offset) / 0x7fffffff; offset++;
z2 = (float) buffer.get(offset) / 0x7fffffff; offset++;

Actually, the select buffer contains 32-bits unsigned integers stored into 32-bits signed integers. Then, the last digit is wrongly used as a sign bit. As Java has no unsigned type, at least 33 bits are required to store these positive values with their sign. Therefore, the long type (64 bits) should be used. The both lines above often work correctly except when the depth values are bigger than 2^31. I assume that they have been copied from an example written in C++. We should rather do this:
z1 = (float) (buffer.get(offset)& 0xffffffffL) / 0x7fffffff; offset++;
z2 = (float) (buffer.get(offset)& 0xffffffffL) / 0x7fffffff; offset++;
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: bad use of depths in Picking.java

gouessej
Administrator
6039 posts
Please find the patch below:
136,137c136,137
<           z1 = (float) buffer.get(offset) / 0x7fffffff; offset++;
<           z2 = (float) buffer.get(offset) / 0x7fffffff; offset++;
---
>           z1 = (float) (buffer.get(offset)& 0xffffffffL) / 0x7fffffff; offset++;
>           z2 = (float) (buffer.get(offset)& 0xffffffffL) / 0x7fffffff; offset++;
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: bad use of depths in Picking.java

Sven Gothel
Administrator
2933 posts
On Friday, September 17, 2010 11:10:18 gouessej [via jogamp] wrote:

>
> Please find the patch below:
> 136,137c136,137
> <           z1 = (float) buffer.get(offset) / 0x7fffffff; offset++;
> <           z2 = (float) buffer.get(offset) / 0x7fffffff; offset++;
> ---
> >           z1 = (float) (buffer.get(offset)& 0xffffffffL) / 0x7fffffff;
> > offset++;
> >           z2 = (float) (buffer.get(offset)& 0xffffffffL) / 0x7fffffff;
> > offset++;
>
>

Thx, fixed with: d1830d4ccd8c2db30896e987638228c45e251564

Pls send me a pull request next time :)

~Sven

Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: bad use of depths in Picking.java

gouessej
Administrator
6039 posts
A pull request? Does it have something to do with GIT? I'm a newbie in GIT... Thanks.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: bad use of depths in Picking.java

gouessej
Administrator
6039 posts
Ok now I know how to perform a pull request. I've made a fork on github.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: bad use of depths in Picking.java

Michael Bien
407 posts
cool ;)

On 09/30/2010 03:14 PM, gouessej [via jogamp] wrote:
Ok now I know how to perform a pull request. I've made a fork on github.


View message @ http://jogamp.762907.n3.nabble.com/bad-use-of-depths-in-Picking-java-tp1446213p1608187.html
To start a new topic under jogamp, email [hidden email]
To unsubscribe from jogamp, click here.


-- 
http://michael-bien.com/
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: bad use of depths in Picking.java

gouessej
Administrator
6039 posts
I cannot use EGit, I get a NullPointerException when committing :(
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: bad use of depths in Picking.java

Demoscene Passivist
Administrator
214 posts
EGit is quite beta. I wouldnt use it if you are not forced to. I recommend using the gitbash/git cmdline interface as long as EGit is that bugged. It's quite easy to use and gives u far more control over things if stg went wrong with ur commit.
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: bad use of depths in Picking.java

gouessej
Administrator
6039 posts
You're right, I will have to use it in command line.
Julien Gouesse | Personal blog | Website