2014-03-28 6 views
3

어쨌든 (x 텍스트 상자에서) x, y (y 텍스트 상자에서), z (z 텍스트 상자에서)를 vb 형식으로 플롯 할 수 있습니까? Windows 응용 프로그램입니다. x, y, z 좌표를 나타내는 세 개의 텍스트 상자가 있습니다. 나는이 점을 사용자에게 보여줄 수있는 도구 나 방법이 있는지 궁금합니다. enter image description here플롯 (x, y, z)

+0

내가 방금 점 이상을 보여주고 싶은 가정합니다. 좌표 축에는 레이블, 점에 채워진 원 및 점 옆에 레이블이 표시되어야 할 수 있습니다. 또한 좌표 값이 표시 될 수 있습니다. 결과가 무엇인지 구체적으로 기재하십시오. "요점을 표시하는"_how_에는 명확한 설명이 필요합니다. – ja72

답변

1

두 가지 주요 방법이 있습니다. 1) (x, y, z) 좌표를 평면 프로젝트 (x, y)로 변환하고 을 사용하여 화면에 그리거나, 을 사용하여 GLControl에 직접 점을 그 으십시오. 뷰포트 및 투영 먼저

매우 귀엽지는 않지만 여기에 을 사용하는 개념 증명이 OpenTK입니다.

Form

public partial class Form1 : Form 
{ 
    bool loaded=false; 

    public Form1() 
    { 
     InitializeComponent(); 
    } 

    public Vector3 PointCoordinates 
    { 
     get 
     { 
      float x=0, y=0, z=0; 
      float.TryParse(xTextBox.Text, out x); 
      float.TryParse(yTextBox.Text, out y); 
      float.TryParse(zTextBox.Text, out z); 

      return new Vector3(x, y, z); 
     } 
     set 
     { 
      xTextBox.Text=value.X.ToString(); 
      yTextBox.Text=value.Y.ToString(); 
      zTextBox.Text=value.Z.ToString(); 
     } 
    } 
    protected override void OnLoad(EventArgs e) 
    { 
     base.OnLoad(e); 

     PointCoordinates=new Vector3(0, 0, 0); 
     loaded=true; 
     SetupViewPort(); 
    } 

    private void glControl1_Resize(object sender, EventArgs e) 
    { 
     if(!loaded) return; 
     SetupViewPort(); 
    } 

    private void glControl1_Paint(object sender, PaintEventArgs e) 
    { 
     glControl1.MakeCurrent(); 
     GL.ClearColor(glControl1.BackColor); 
     GL.Clear(ClearBufferMask.ColorBufferBit|ClearBufferMask.DepthBufferBit); 

     GL.MatrixMode(MatrixMode.Modelview); 
     GL.LoadIdentity(); 

     SetupCamera(); 

     // Draw Coordinate System 
     GL.LineWidth(1.5f); 
     GL.Begin(PrimitiveType.Lines); 
     GL.Color3(Color.Red); 
     GL.Vertex3(0, 0, 0); 
     GL.Vertex3(1, 0, 0); 
     GL.Vertex3(0.85, 0.05, -0.05); 
     GL.Vertex3(1, 0, 0); 
     GL.Vertex3(0.85, -0.05, 0.05); 
     GL.Vertex3(1, 0, 0); 
     GL.Color3(Color.Green); 
     GL.Vertex3(0, 0, 0); 
     GL.Vertex3(0, 1, 0); 
     GL.Vertex3(-0.05, 0.85, 0.05); 
     GL.Vertex3(0, 1, 0); 
     GL.Vertex3(0.05, 0.85, -0.05); 
     GL.Vertex3(0, 1, 0); 
     GL.Color3(Color.Blue); 
     GL.Vertex3(0, 0, 0); 
     GL.Vertex3(0, 0, 1); 
     GL.Vertex3(-0.05, 0.05, 0.85); 
     GL.Vertex3(0, 0, 1); 
     GL.Vertex3(0.05, -0.05, 0.85); 
     GL.Vertex3(0, 0, 1); 
     GL.End(); 

     // Draw a single point 
     var vector=PointCoordinates; 
     GL.PointSize(5f); 
     GL.Begin(PrimitiveType.Points); 
     GL.Color3(Color.Black); 
     GL.Vertex3(vector); 
     GL.End(); 
     GL.PointSize(3f); 
     GL.Begin(PrimitiveType.Points); 
     GL.Color3(Color.Yellow); 
     GL.Vertex3(vector); 
     GL.End(); 

     glControl1.SwapBuffers(); 
    } 

    void SetupViewPort() 
    { 
     float wt=Math.Max(1, glControl1.Width); 
     float ht=Math.Max(1, glControl1.Height); 
     float sz=(float)Math.Sqrt(ht*wt); 
     GL.Viewport((int)(wt-sz)/2, (int)(ht-sz)/2, (int)sz, (int)sz); 
     var ortho=Matrix4.CreateOrthographic(
      10f, 10f, 1f, 200f); 
     GL.MatrixMode(MatrixMode.Projection); 
     GL.LoadMatrix(ref ortho); 
    } 

    void SetupCamera() 
    { 
     Matrix4 lookAt=Matrix4.LookAt(
         10f, 5f, 15f, 
         0f, 0f, 0f, 
         0f, 1f, 0f); 
     GL.MatrixMode(MatrixMode.Modelview); 
     GL.LoadMatrix(ref lookAt); 
    } 

    private void button1_Click(object sender, EventArgs e) 
    { 
     glControl1.Refresh(); 
    } 

} 
+0

점을 조금 부드럽게하려면'GL.Hint (HintTarget.PointSmoothHint, HintMode.Nicest);도 해보고 싶을 수도 있습니다. – ja72

+0

내 출력물은 위에 게시 한 그림과 유사하지만 말했듯이, 나는 여러 점을 가지고있을 것입니다. 양식이 이미 있는데 양식의 측면에이 기능을 추가하고 싶습니다. 이 코드를 코드에 어떻게 추가해야합니까? 나는 opentk을 설치했다. 코드를 사용하려면이 폴더를 특정 위치에 두어야합니까? – user3396709

+0

프로젝트에서'OpenTK'를 참조 했습니까? 'OpenTK.GLControl'에 대한 참조를 추가하고 기존 양식에'GLControl'을 추가해야합니다. opentk로 문서를 읽고 질문에 [SO]를 게시하십시오. – ja72