0
을 사용하여 평면에서 점을 선택하는 방법을 사용하여 3 차원 평면을 얻었습니다. 이제 레이 캐스팅 방법을 사용하여 그리드에서 점을 선택하는 방법을 설명합니다. 마우스 좌표와 관련하여 사각형에 점을 어떻게 얻을 수 있습니까? 도움이 될 것입니다.저는 XY32와 Z가있는 사각형 그리드를 그리기 위해 Opentk를 사용하여 마우스
// Replaces gluPerspective. Sets the frustum to perspective mode.
// fovY - Field of vision in degrees in the y direction
// aspect - Aspect ratio of the viewport
// zNear - The near clipping distance
// zFar - The far clipping distance
void perspectiveGL(double fovY, double aspect, double zNear, double zFar)
{
const double pi = 3.1415926535897932384626433832795;
double fW, fH;
fH = System.Math.Tan((fovY/2)/180 * pi) * zNear;
fH = System.Math.Tan(fovY/360 * pi) * zNear;
fW = fH * aspect;
GL.Frustum(-fW, fW, -fH, fH, zNear, zFar);
}
이것은
private void m_OpenTKGLControl_DrawingArea_Paint(object sender, PaintEventArgs e)
{
if (!loaded) // Play nice
return;
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit);
GL.LoadIdentity();
GL.Translate(0, 0, -zoom);
GL.Translate(tx, ty, 0);
GL.Rotate(rotx, 1, 0, 0);
GL.Rotate(roty, 0, 1, 0);
//if (m_pointT_current_cursor.X < 100)
{
GL.PushMatrix(); //set where to start the current object transformations
GL.Color3(1.0, 1.0, 0);
GL.Begin(BeginMode.Lines);
GL.Vertex3(0.0, 0.0, 0.0);
GL.Vertex3(0.0, 0.0, 10.0);//x axis
GL.End();
GL.PopMatrix();
}
double grid_width = 10.0;
// Draw a white grid "floor" for the tetrahedron to sit on.
GL.Color3(Color.FromArgb(68, 68, 68));
GL.Begin(BeginMode.Lines);
for (double i = -grid_width/2.0; i <= grid_width/2.0; i += 1.0)
{
if (i != 0.0)
{
GL.Vertex3(i, 0.0, grid_width/2.0); GL.Vertex3(i, 0.0, -grid_width/2.0);
GL.Vertex3(grid_width/2.0, 0.0, i); GL.Vertex3(-grid_width/2.0, 0.0, i);
}
}
GL.End();
GL.Color3(1.0, 0, 0);
GL.Begin(BeginMode.Lines);
GL.Vertex3(-grid_width/2.0, 0, 0); GL.Vertex3(grid_width/2.0, 0, 0);//x axis
GL.End();
GL.Color3(0, 1.0, 0);
GL.Begin(BeginMode.Lines);
GL.Vertex3(0, -grid_width/2.0, 0); GL.Vertex3(0, grid_width/2.0, 0);//y axis
GL.End();
GL.Color3(0, 0, 1.0);
GL.Begin(BeginMode.Lines);
GL.Vertex3(0, 0, -grid_width/2.0); GL.Vertex3(0, 0, grid_width/2.0);//z axis
GL.End();
GL.Begin(BeginMode.Points); // Draw The Cube Using quads
for (int i = 0; i < m_list_point_cloud.Count(); i++)
{
GL.Color3(Color.FromArgb(m_list_point_cloud[i].RED, m_list_point_cloud[i].GREEN, m_list_point_cloud[i].BLUE)); // Color
GL.Vertex3(m_list_point_cloud[i].X, m_list_point_cloud[i].Y, m_list_point_cloud[i].Z);
GL.PointSize(1);
}
GL.End(); // End Drawing The Point cloud
GL.Flush();
m_OpenTKGLControl_DrawingArea.SwapBuffers();
}
마지막이 부하의 함수 인 glcontrol의 페인트 기능입니다 :
private void SetupViewport()
{
int w = m_OpenTKGLControl_DrawingArea.Width;
int h = m_OpenTKGLControl_DrawingArea.Height;
// prevent divide by 0 error when minimised
if (w == 0)
h = 1;
GL.Viewport(0, 0, w, h);
GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
perspectiveGL(45, (double)w/h, 0.1, 10000);
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadIdentity();
}
이것은 관점의 기능입니다 : 다음과 같이
뷰포트입니다 glcontrol 용
private void m_OpenTKGLControl_DrawingArea_Load(object sender, EventArgs e)
{
loaded = true;
GL.CullFace(CullFaceMode.Back);
GL.ClearColor(Color.FromArgb(57, 57, 57));
GL.ClearDepth(1.0); // Enables Clearing Of The Depth Buffer
GL.DepthFunc(DepthFunction.Lequal); // The Type Of Depth Test To Do
GL.Enable(EnableCap.DepthTest); // Enables Depth Testing
GL.Enable(EnableCap.Multisample);
GL.ShadeModel(ShadingModel.Smooth); // Enables Smooth Color Shading
GL.Hint(HintTarget.PerspectiveCorrectionHint, // Really Nice Perspective Calculations
HintMode.Nicest);
SetupViewport();
}