CSharpGL(21)用鼠标拾取、拖拽VBO图元内的点、线或本身
2016-05-03 19:21
573 查看
[b]CSharpGL(21)用鼠标拾取、拖拽VBO图元内的点、线或本身 [/b]
在拾取模式为GeometryType.Point时,你可以拾取单个的顶点。
public override PickedGeometry Pick(RenderEventArgs arg, uint stageVertexId, int x, int y)
原CSharpGL的其他功能(3ds解析器、TTF2Bmp、CSSL等),我将逐步加入新CSharpGL。
欢迎对OpenGL有兴趣的同学关注(https://github.com/bitzhuwei/CSharpGL)
效果图
以最常见的三角形网格(用GL_TRIANGLES方式进行渲染)为例。在拾取模式为GeometryType.Point时,你可以拾取单个的顶点。
public override PickedGeometry Pick(RenderEventArgs arg, uint stageVertexId, int x, int y) { uint lastVertexId; if (!this.GetLastVertexIdOfPickedGeometry(stageVertexId, out lastVertexId)) { return null; } GeometryType geometryType = arg.PickingGeometryType; if (geometryType == GeometryType.Point) { DrawMode mode = this.GetIndexBufferPtr().Mode; if (this.OnPrimitiveTest(lastVertexId, mode)) { return PickPoint(stageVertexId, lastVertexId); } else { return null; } } else if (geometryType == GeometryType.Line) { // 找到 lastIndexId RecognizedPrimitiveIndex lastIndexId = this.GetLastIndexIdOfPickedGeometry( arg, lastVertexId, x, y); if (lastIndexId == null) { Debug.WriteLine( "Got lastVertexId[{0}] but no lastIndexId! Params are [{1}] [{2}] [{3}] [{4}]", lastVertexId, arg, stageVertexId, x, y); { return null; } } else { // 获取pickedGeometry DrawMode mode = this.GetIndexBufferPtr().Mode; GeometryType typeOfMode = mode.ToGeometryType(); if (geometryType == typeOfMode) { return PickWhateverItIs(stageVertexId, lastIndexId, typeOfMode); } else { OneIndexLineSearcher searcher = GetLineSearcher(mode); if (searcher != null)// line is from triangle, quad or polygon { return SearchLine(arg, stageVertexId, x, y, lastVertexId, lastIndexId, searcher); } else if (mode == DrawMode.Points)// want a line when rendering GL_POINTS { return null; } else { throw new Exception(string.Format("Lack of searcher for [{0}]", mode)); } } } } else { // 找到 lastIndexId RecognizedPrimitiveIndex lastIndexId = this.GetLastIndexIdOfPickedGeometry( arg, lastVertexId, x, y); if (lastIndexId == null) { Debug.WriteLine( "Got lastVertexId[{0}] but no lastIndexId! Params are [{1}] [{2}] [{3}] [{4}]", lastVertexId, arg, stageVertexId, x, y); { return null; } } else { DrawMode mode = this.GetIndexBufferPtr().Mode; GeometryType typeOfMode = mode.ToGeometryType(); if (typeOfMode == geometryType)// I want what it is { return PickWhateverItIs(stageVertexId, lastIndexId, typeOfMode); } else { return null; } //{ throw new Exception(string.Format("Lack of searcher for [{0}]", mode)); } } } }
public override PickedGeometry Pick(RenderEventArgs arg, uint stageVertexId, int x, int y)
总结
在完成后,我以为彻底解决了拾取问题。等完成本文后,我不再这么想了。还是谦虚点好。原CSharpGL的其他功能(3ds解析器、TTF2Bmp、CSSL等),我将逐步加入新CSharpGL。
欢迎对OpenGL有兴趣的同学关注(https://github.com/bitzhuwei/CSharpGL)
相关文章推荐
- C# WinForm控件美化扩展系列之ListBox
- 【C#设计模式-享元模式】
- C#计算器编程教学课程前言
- C#入门学习
- c#操作XML文件:增,删,改,查(返回DataTable)
- C#匿名方法返回值赋值给变量
- c#之process类相关整理
- c#匿名类型
- Visual studio C#语言输出调试信息到Output窗口方法
- 记《learning hard C#学习笔记》 书中一个错误
- C#通过Thrift连接查询HBase主要方法总结
- C#中Dictionary小记
- 【C#】基础知识—程序调试与异常处理机制
- C# 提示语句总汇
- C#可变变量Params,out,ref
- C#中Collection,List和ArrayList的区别(转)
- C#课后习题---列表框实验
- C#课后习题--单选按钮和复选框实验
- c#大圣之路笔记——c#通过页面把excel中的数据导入到DB中(全部)
- C# Socket连接 无法访问已释放的对象