Registered Member
|
Looking for a better way to do this. I want to unproject a vector, but using a Perspective3d transformation rather than Matrix4d. That way I avoid the division at the end. The matrices are passed into the Arcball class from OpenGL. The code works fine as it is, but I always strive to be a perfectionist! Also, is there an easy way to output a Vector3d object from a Vector4d object?
EDIT: I meant Projective3d, not Perspective3d. Sorry. Thanks in advance.
Last edited by Waxwing on Mon Aug 01, 2011 8:52 am, edited 1 time in total.
|
Registered Member
|
Fantastic, I've found the solution. Just needed to map Affine3d and Projective3d convenience types of Transform to the underlying matrix type of Matrix4d. When I multiply the in vector by mvp the projective division is carried out automatically.
All I need now is a way to output it as a Vector3d object without having to construct it from the individual components. Is there a way?
|
Registered Member
|
Well. I have the same problem as you.
I would like to multiply a Projective3d with a Vector3d but I need everytime to first create a temporary Vector4d. I think this should be made similar as the Affine3d does, where posmultiplication with a vector is allowed. Just for curiosity, in OpenGL how do you pick up the current projection matrix? Do you use
? |
Registered Member
|
We hold the projection matrix in a fixed-size array.
We then pass it to our tracking method as a pointer to a double.
|
Registered Member
|
Ok many thanks.
|
Moderator
|
Such a product with automatic type promotion and perspective division is not available to avoid some possible confusion with point versus vector and the like. But you can still do:
Vector3f a, b; Projective3f P; a = (P * b.homogeneous()).eval().hnormalized(); hnormalized means homogeneous normalization. |
Registered Member
|
Thanks for the advice. hnormalized() did the trick.
What I would ideally like to be able to do is an implicit cast from a Vector4d to a Vector3d similar to what you can do in Nvidia's Cg or OpenGL's GLSL shader languages. In this example I need to convert a Vector3d to and from homogeneous space. There is no projection involved this time.
|
Moderator
|
hm.. with an Affine3d you can directly use vector3 objects:
Vector3d a, b; Affine3d A; a = A.inverse() * b; This is because the last row is assumed to be 0 0 0 1. It essentially behave like a 3x4 matrix. No homogeneous normalization is required. |
Registered Member
|
Thanks. Obvious now.
It was the fact that I was multiplying by the inverse of a matrix which threw me. |
Registered Member
|
Just for information.
The gluProject behaviour can then be simulated in the following way:
Then round the value of pProjected to integer. This is completely equivalent to
|
Registered Member
|
Thanks. I've modified the original code to use a structure.
This is a version written using our VecMath library which is very similar to GLSL. I prefer using friend functions (non-member methods) for operations such as dot product, normalize, inverse, etc. The Eigen library was very useful for prototyping, but we needed something more tailored to OpenGL.
|
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]