|
@@ -317,23 +317,28 @@ const Vec3< float > &Kam3D::getWorldPosition() const
|
|
|
|
|
|
const Vec3< float > Kam3D::getWorldPosition( Punkt screen ) const
|
|
|
{
|
|
|
- Vec3< float > point = Vec3< float >( ( screen.x - viewport.x ) / ( 0.5f * viewport.width ) - 1, ( screen.y - viewport.y ) / ( 0.5f * viewport.height ) - 1, 0 );
|
|
|
- Mat4< float > mat = proj * view;
|
|
|
- mat = mat.getInverse();
|
|
|
- point = mat * point;
|
|
|
- return point;
|
|
|
+ Vec3< float > point = Vec3< float >( ( screen.x - viewport.x ) / ( 0.5f * viewport.width ) - 1, ( viewport.height - ( screen.y - viewport.y ) ) / ( 0.5f * viewport.height ) - 1, 0.1f );
|
|
|
+ Mat4< float > mat = getProjectionMatrix();
|
|
|
+ Mat4< float > inv = getViewMatrix().getInverse();
|
|
|
+ point.x = ( point.x * 0.1f ) / mat.elements[ 0 ][ 0 ];
|
|
|
+ point.y = ( point.y * 0.1f ) / mat.elements[ 1 ][ 1 ];
|
|
|
+ return inv * point;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const Vec3< float > Kam3D::getWorldDirection( Punkt screen ) const
|
|
|
{
|
|
|
- Vec3< float > point = Vec3< float >( ( screen.x - viewport.x ) / ( 0.5f * viewport.width ) - 1, ( screen.y - viewport.y ) / ( 0.5f * viewport.height ) - 1, 0 );
|
|
|
+ Vec3< float > point = Vec3< float >( ( screen.x - viewport.x ) / ( 0.5f * viewport.width ) - 1, ( viewport.height - ( screen.y - viewport.y ) ) / ( 0.5f * viewport.height ) - 1, 0.1f );
|
|
|
Vec3< float > pointT = Vec3< float >( point.x, point.y, 1 );
|
|
|
- Mat4< float > mat = proj * view;
|
|
|
- mat = mat.getInverse();
|
|
|
- point = mat * point;
|
|
|
- pointT = mat * pointT;
|
|
|
+ Mat4< float > mat = getProjectionMatrix();
|
|
|
+ Mat4< float > inv = getViewMatrix().getInverse();
|
|
|
+ point.x = ( point.x * 0.1f ) / mat.elements[ 0 ][ 0 ];
|
|
|
+ point.y = ( point.y * 0.1f ) / mat.elements[ 1 ][ 1 ];
|
|
|
+ pointT.x = ( pointT.x ) / mat.elements[ 0 ][ 0 ];
|
|
|
+ pointT.y = ( pointT.y ) / mat.elements[ 1 ][ 1 ];
|
|
|
+ point = inv * point;
|
|
|
+ pointT = inv * pointT;
|
|
|
return pointT - point;
|
|
|
}
|
|
|
|