如何解决单击时如何在 OpenGL/OpenTK 中显示三角形的长度?
我有一个关于 OpenGL/OpenTK 的问题。假设我已经在 OpenGL/OpenTK 窗口中绘制并显示了一个简单的三角形(比如说一个等边三角形)。
现在,假设我想通过单击三角形来知道三角形的长度,并在窗口上显示长度值(虽然我可以手动计算它)。有没有办法实现这一目标?不一定是长度,也可以是坐标。
如果您知道如何实现这一点,请告诉我。
** 这是我的代码 *****
我正在创建一个名为 tryOpenTK(在 C# 中)的项目。这是名为 Game2D 的类。
using System;
using OpenTK;
using OpenTK.Graphics.OpenGL;
namespace tryOpenTK
{
public class Game2D
{
GameWindow window;
public Game2D(GameWindow wd)
{
this.window = wd;
start();
}
public void start()
{
window.Load += loaded;
window.Resize += resize;
window.RenderFrame += renderFrame; // place where you draw something
window.Run(1.0 / 60.0); // frame rate - 60 times per second
}
public void loaded(object o,EventArgs e)
{
GL.ClearColor(0.0f,0.0f,0.0f);
}
public void renderFrame(object o,EventArgs e) // to draw something
{
GL.LoadIdentity();
GL.Clear(ClearBufferMask.ColorBufferBit);
GL.Begin(BeginMode.Triangles); // tell openGL to draw some primitive shapes
GL.Color3(1.0,0.0,0.0); // specify the red color for triangle using RGB
GL.Vertex2(1.0,1.0);
GL.Vertex2(49.0,1.0);
GL.Vertex2(25.0,49.0);
GL.End();
window.SwapBuffers();
}
public void resize(object o,EventArgs e)
{
GL.Viewport(0,window.Width,window.Height);
GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
GL.Ortho(-50.0,50.0,-50.0,-1.0,1.0);
GL.MatrixMode(MatrixMode.Modelview);
}
}
}
*** 这是主函数 **
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenTK;
namespace tryOpenTK
{
class Program
{
static void Main(string[] args)
{
var window = new GameWindow(500,500);
var gm = new Game2D(window);
Console.WriteLine();
Console.WriteLine("Press enter to finish...");
Console.ReadLine();
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。