public override ILPoint3Df Screen2World2D(int x, int y) { Vector3 tmp; Glu.UnProject(new Vector3(x, y, 0), m_modelViewMatrix, m_projMatrix, m_viewMatrix, out tmp); return(new ILPoint3Df(tmp.X, tmp.Y, m_clippingView.CenterF.Z)); }
/// <summary> /// transform from screen space into world space using OpenGL /// </summary> /// <param name="x">screen X</param> /// <param name="y">screen Y</param> /// <returns>world coord</returns> public override void Screen2World(int x, int y, out ILPoint3Df nearClip, out ILPoint3Df farClip) { // TODO: check the Z coord values. 0.68 here was result of trial only! Vector3 far, near; Glu.UnProject(new Vector3(x, y, 0.0f), m_modelViewMatrix, m_projMatrix, m_viewMatrix, out near); Glu.UnProject(new Vector3(x, y, 1.0f), m_modelViewMatrix, m_projMatrix, m_viewMatrix, out far); // transform back from unit cube to clipping view farClip = new ILPoint3Df(far.X, far.Y, far.Z); //m_clippingView.Map(far.X, far.Y, far.Z); nearClip = new ILPoint3Df(near.X, near.Y, near.Z); //m_clippingView.Map(near.X, near.Y, near.Z); }
public void GetScreenPoint(int x, int y, Matrix4 model, out Vector3 p1, out Vector3 p2) { LoadTransformation(model); double[] modelMatrix = new double[16]; double[] projmatrix = new double[16]; int[] viewport = new int[4]; GL.GetInteger(GetPName.Viewport, viewport); GL.GetDouble(GetPName.ModelviewMatrix, modelMatrix); GL.GetDouble(GetPName.ProjectionMatrix, projmatrix); y = height - y; // OpenGL renders with (0,0) on bottom, mouse reports with (0,0) on top Glu.UnProject(new Vector3(x, y, 0.1f), modelMatrix, projmatrix, viewport, out p1); Glu.UnProject(new Vector3(x, y, 1.0f), modelMatrix, projmatrix, viewport, out p2); }