您的位置:首页 > 编程语言 > C#

CSharpGL(21)用鼠标拾取、拖拽VBO图元内的点、线或本身

2016-05-03 19:21 573 查看
[b]CSharpGL(21)用鼠标拾取、拖拽VBO图元内的点、线或本身 [/b]

效果图

以最常见的三角形网格(用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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: