MCPcopy Create free account
hub / github.com/cinder/Cinder / windowToObjectCoord

Function windowToObjectCoord

src/cinder/gl/wrapper.cpp:649–665  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

647}
648
649vec3 windowToObjectCoord( const mat4 &modelMatrix, const ci::vec2 &coordinate, float z )
650{
651 // Build the viewport (x, y, width, height).
652 vec2 offset = gl::getViewport().first;
653 vec2 size = gl::getViewport().second;
654 vec4 viewport = vec4( offset.x, offset.y, size.x, size.y );
655
656 // Calculate the view-projection matrix.
657 mat4 viewProjectionMatrix = gl::getProjectionMatrix() * gl::getViewMatrix();
658
659 // Calculate the intersection of the mouse ray with the near (z=0) and far (z=1) planes.
660 vec3 nearPlane = glm::unProject( vec3( coordinate.x, size.y - coordinate.y, 0 ), modelMatrix, viewProjectionMatrix, viewport );
661 vec3 farPlane = glm::unProject( vec3( coordinate.x, size.y - coordinate.y, 1 ), modelMatrix, viewProjectionMatrix, viewport );
662
663 // Calculate world position.
664 return ci::lerp( nearPlane, farPlane, ( z - nearPlane.z ) / ( farPlane.z - nearPlane.z ) );
665}
666
667vec2 objectToWindowCoord( const mat4 &modelMatrix, const ci::vec3 &coordinate )
668{

Callers 1

updateMethod · 0.50

Calls 4

getViewportFunction · 0.85
getProjectionMatrixFunction · 0.85
getViewMatrixFunction · 0.85
lerpFunction · 0.50

Tested by 1

updateMethod · 0.40