Last active
June 13, 2022 00:43
-
-
Save danielbierwirth/e2ade76be3a571c9f1fd to your computer and use it in GitHub Desktop.
OpenTK pick matrix calculation. Transforms viewmatrix according to pick location and picking region. Modified matrix can be used for object pick determination.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// OpenTK/OpenGl pick matrix calculation. Takes pick location,pick region to | |
// modify the current viewport matrix. | |
/// </summary> | |
/// <param name="x">The x pick location.</param> | |
/// <param name="y">The y pick location.</param> | |
/// <param name="deltax">The pick region x bounds.</param> | |
/// <param name="deltay">The pick region y bounds.</param> | |
/// <param name="viewport">The viewport matrix.</param> | |
public void PickMatrix(double x, double y, double deltax, double deltay, int[] viewport) | |
{ | |
if (deltax <= 0 || deltay <= 0) { | |
return; | |
} | |
// Translate and scale the picked region to cover the | |
// canvas | |
GL.Translate((viewport[2] - 2 * (x - viewport[0])) / deltax, | |
(viewport[3] - 2 * (y - viewport[1])) / deltay, 0); | |
GL.Scale(viewport[2] / deltax, viewport[3] / deltay, 1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment