Show differencesHistory of post edits
#2caibbor
Posted 11 July 2012 - 11:12 AM
I'm very close, but not quite there yet.
// for use with glVeiwport
const int GL_VP_X = 0;
const int GL_VP_Y = 1;
const int GL_VP_W = 2;
const int GL_VP_H = 3;
Line3f GetPickLine( void ) {
const int* vp = game->renderer.viewport;
// map UI mouse pos to [-1,1]
Vec3f pos( game->input.GetUIMousePos() );
pos.x = 2 * pos.x / vp[GL_VP_W] - 1; // todo * aspectRatio
pos.y = 1 - 2 * pos.y / vp[GL_VP_H]; // invert y axis
// get the inverted modelViewProjection matrix
Mat4f mv( game->renderer.modelMatrix );
Mat4f mvpi = Mat4f( game->renderer.projectionMatrix ) * mv;
mvpi.InvertRotationOrtho();
mvpi.InvertTranspositionOrtho();
// multiply mouse pos and modelViewProjection matrix to get a point on that ray
pos = mvpi * pos;
Vec3f cam( -mv.Column3f(3) ); // camera position is last column of modelView matrix
return Line3f( cam, pos );
}
#1caibbor
Posted 11 July 2012 - 11:11 AM
I'm very close, but not quite there yet.
Line3f GetPickLine( void ) {
const int* vp = game->renderer.viewport;
// map UI mouse pos to [-1,1]
Vec3f pos( game->input.GetUIMousePos() );
pos.x = 2 * pos.x / vp[GL_VP_W] - 1; // todo * aspectRatio
pos.y = 1 - 2 * pos.y / vp[GL_VP_H]; // invert y axis
// get the inverted modelViewProjection matrix
Mat4f mv( game->renderer.modelMatrix );
Mat4f mvpi = Mat4f( game->renderer.projectionMatrix ) * mv;
mvpi.InvertRotationOrtho();
mvpi.InvertTranspositionOrtho();
// multiply mouse pos and modelViewProjection matrix to get a point on that ray
pos = mvpi * pos;
Vec3f cam( -mv.Column3f(3) ); // camera position is last column of modelView matrix
return Line3f( cam, pos );
}