-
大小: 1.29MB文件类型: .7z金币: 1下载: 0 次发布日期: 2023-09-21
- 语言: C#
- 标签: OpenGL拾取 拾取教程 PickMatrix MSAA
资源简介
用OpenTK做的OpenGL拾取。代码注释中包含了拾取的原理及过程。用的是C#语言。
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using OpenTK.Platform;
using OpenTK.Input;
///更多内容
/// http://download.csdn.net/user/llimite
///关注我吧
namespace Picking
{
class Pick: GameWindow
{
//判断鼠标是否按下
private bool isRButtonDown;
private bool isLButtonDown;
//选择缓存
private int[] selectBuf=new int[1024];
//鼠标位置
private Point mousepos;
//点击的数量,与拾取视口相交的物体的数量
private int intersetion;
//视口
private int[] view=new int[4];
//创建一个800*600的窗口,32位真彩色,8位深度,8位模板缓存,8倍多重采样
//多重采样需要显卡支持
public Pick():base(800600new GraphicsMode(32888)“OpenTK Picking“GameWindowFlags.FixedWindow)
{
//添加两个事件处理
MouseDown += Pick_MouseDown;
MouseUp += Pick_MouseUp;
}
//鼠标按键释放
void Pick_MouseUp(object sender OpenTK.Input.MouseButtonEventArgs e)
{
if (e.Mouse.IsButtonUp(MouseButton.Left))
{
isLButtonDown = false;
}
if (e.Mouse.IsButtonUp(MouseButton.Right))
{
isRButtonDown = false;
}
mousepos = e.Position;
}
//鼠标按键按下
void Pick_MouseDown(object sender OpenTK.Input.MouseButtonEventArgs e)
{
if(e.Mouse.IsButtonDown(MouseButton.Left))
{
isLButtonDown=true;
}
if (e.Mouse.IsButtonDown(MouseButton.Right))
{
isRButtonDown = true;
}
mousepos = e.Position;
}
protected override void onload(EventArgs e)
{
base.onload(e);
GL.ClearColor(0.5f 0.5f 0.5f 1.0f);
}
//改变窗口时,更新视口
protected override void onresize(EventArgs e)
{
base.onresize(e);
GL.Viewport(0 0 Width Height);
GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
}
protected override void OnUpdateframe(frameEventArgs e)
{
base.OnUpdateframe(e);
}
//重写绘图函数
protected override void OnRenderframe(frameEventArgs e)
{
base.OnRenderframe(e);
GL.Clear(ClearBufferMask.ColorBufferBit|ClearBufferMask.DepthBufferBit );
GL.ClearColor(0.5f 0.5f 0.5f 1.0f);
//启用混合
GL.Enable(EnableCap.Blend);
GL.BlendFunc(BlendingFactorSrc.SrcAlpha BlendingFactorDest.OneMinusSrcAlpha);
//启用深度测试
GL.Enable(EnableCap.DepthTest);
GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
//相当于gluPerspective
Matrix4 perspective = Matrix4
- 上一篇:ASP.NET 新闻发布系统
- 下一篇:基于C#的波形显示控件的实现[附完整]
评论
共有 条评论