Unprojection of points / Homogenous clip coords make me perplex

Started by
1 comment, last by Frederick 13 years ago
Hi,

i have been spending a lot of time to track a bug in my projection pipeline. I am implementing ray picking for my diploma thesis - actually just a UI thing
I did not plan to waste so much time on it.

I used two different methods to unproject:
1) Place an imageplane in front of the camera and shoot a ray
2) Invert the projection matrix multiply and homogenize

In both cases i observed that the generated rays were a little of and missed the scene parts they were suppossed to hit slightly. Just because I ran out of ideas
I translated the ray origin to (0,0, -1) and suddenly it worked perfectly.

I could ignore that little glitch, but it leaves me with a bad feeling as I do not understand what happens behind the curtains. The ray origin should be (0,0,0) - right ?

As I ran into the problem twice, I suppose I did fail to understand all aspects of homogenous clip coordinates. I will post my projection matrices and maybe you guys could
give me some advice what I am doing wrong - This is really starting to frustrate me.


My viewport to NDC matrix (row vectors):

x: (1.0f / (width / 2.0f)), 0, 0 ,0)
y: (0, (1.0f / (height / 2.0f)), 0 ,0)
z: (0, 0, 1 ,0)
w:(-1.0f 1.0f 0 ,1)

My projection matrix: (symmetric frustum)

x: (near / right, 0 0 0)
y: (0 near/top 0 0)
z:(0, 0 (far + near)) / (far - near) 1) //Camera is looking in positive z, opposed to vanilla OpenGL
w(0, 0 -(2 * far * near) / (far - near) 1)


The inverse projection matrix (after Mouse Ray Picking Explained):

x: (right / near, 0 0 0)
y: (0 top / near 0 0)
z: (0 0 0 (far - near) / (-(2*far*near))
w:(0 0 1 (far + near) / ( 2*far*near))

I am not sure the matrices will help, but maybe you got an idea what i might have forgot ?

The actual method (java) looks like this:

/*
* Returns a ray in eye space
*/
public Ray raycast(Point2 position) {
//Viewport to NDC
Point3 pickPoint = paintingSurface.normalise(new Point3(position, 0));

//NDC to eye coordinates
Point3 reprojectedPoint = inverseProjection.multiply(pickPoint);
reprojectedPoint.homogenousDivide();

Vector3 rayDir = reprojectedPoint.subtract(Point3.ZERO);
rayDir.normalize();

return new Ray(new Point3(0,0,-1), rayDir); /// :-(((((( Why???
}


I would be glad if anybody could point out my error.

Thanks a lot,
Frederick
Advertisement

My projection matrix: (symmetric frustum)

x: (near / right, 0 0 0)
y: (0 near/top 0 0)
z:(0, 0 (far + near)) / (far - near) 1) //Camera is looking in positive z, opposed to vanilla OpenGL
w(0, 0 -(2 * far * near) / (far - near) 1)
I'm definitely not sure about this projection matrix. I'm pretty sure it wouldn't come from any perspective or orthographic projection. If you actually do mean for that, what sort of projection are you intending?

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

Hi Geometrian,

thank you so much for pointing that out. Of course it was meant as a projection matrix - and it did the visual - kind of.

I took the matrix from here
But I didn´t notice that the w coordinate of the translational part of this matrix is set to zero. I thought that w of the translational part must always be one. The w value
introduced the weird translation I had to fight with. :angry:

Maybe I have to rethink my whole approach concerning matrices. I learned from David Eberlys fine "Geometric Tools" that it is a good idea to distinct point and vectors.
And I distinct them per type. So I have a point and a vector class. Points w is always 1, Vector w is always 0. At least I thought so.
I had to relax this lately because the homogenous approach to perspective division demands w values different from zero or one.

My whole approach to matrices is somewhat broken now. Maybe I will rewrite them. My current approach looks like this:

public class Matrix3 {

private Vector3 x, y, z;
private Point3 w;

[...]
}[/quote]

Up to now I liked it and thought it was elegant, but there are cases like projection when w actually is not a point.

Now i do something like:

matrix3.w().setW(0.0f) [/quote] which contradicts the statement that w is of type point3.

Maybe I have to abandon this approach. I also have never seen anybody do it like this - there might be a reason.... :unsure:

Thank you so much and extra pair of eyes can really do wonders sometimes - I was so stuck in my approach - I would have never noticed that glitch.

Frederick

This topic is closed to new replies.

Advertisement