本文整理汇总了C#中OpenGL.UnProject方法的典型用法代码示例。如果您正苦于以下问题:C# OpenGL.UnProject方法的具体用法?C# OpenGL.UnProject怎么用?C# OpenGL.UnProject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenGL
的用法示例。
在下文中一共展示了OpenGL.UnProject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseData
/// <summary>
/// This takes the feedback data and turns it into triangles.
/// </summary>
/// <param name="gl"></param>
/// <param name="values">The number of triangles.</param>
protected override void ParseData(OpenGL gl, int values)
{
int count = values;
// Create the triangle.
triangle = new Polygon();
triangle.Name = "Triangulated Polygon";
// For every value in the buffer...
while (count != 0)
{
// Get the token.
float token = feedbackBuffer[values - count];
// Decrement count (move to the next token).
count--;
// Check the type of the token.
switch ((int)token)
{
case (int)OpenGL.GL_PASS_THROUGH_TOKEN:
count--;
break;
case (int)OpenGL.GL_POINT_TOKEN:
// We use only polygons, skip this single vertex (11 floats).
count -= 11;
break;
case (int)OpenGL.GL_LINE_TOKEN:
// We use only polygons, skip this vertex pair (22 floats).
count -= 22;
break;
case (int)OpenGL.GL_LINE_RESET_TOKEN:
// We use only polygons, skip this vertex pair (22 floats).
count -= 22;
break;
case (int)OpenGL.GL_POLYGON_TOKEN:
// Get the number of vertices.
int vertexCount = (int)feedbackBuffer[values - count--];
// Create an array of vertices.
Vertex[] vertices = new Vertex[vertexCount];
// Parse them.
for (int i = 0; i < vertexCount; i++)
{
vertices[i] = new Vertex();
double x = (double)feedbackBuffer[values - count--];
double y = (double)feedbackBuffer[values - count--];
double z = (double)feedbackBuffer[values - count--];
double[] coords = gl.UnProject(x, y, z);
vertices[i].X = (float)coords[0];
vertices[i].Y = (float)coords[1];
vertices[i].Z = (float)coords[2];
// Ignore the four r,g,b,a values and four material coords.
count -= 8;
}
// Add a new face to the current polygon.
triangle.AddFaceFromVertexData(vertices);
break;
}
}
// Triangulate it.
triangle.Triangulate();
}
示例2: PointToVertexOnPlane
/// <summary>
/// This is a utility function that will turn a click
/// on the control to a point on a specified plane.
/// </summary>
/// <param name="gl">OpenGL.</param>
/// <param name="plane">The plane to project onto.</param>
/// <param name="x">The X part of the point.</param>
/// <param name="y">The Y part of the point.</param>
/// <returns>A three-tuple representing the point on the floor.</returns>
protected Vertex PointToVertexOnPlane(OpenGL gl, Plane plane, int x, int y)
{
// The first thing we do is turn the click into a vector that
// is from the camera to the cursor.
double[] point1 = gl.UnProject((double)x, (double)y, 0);
double[] point2 = gl.UnProject((double)x, (double)y, 1);
double[] direction = {point2[0] - point1[0],
point2[1] - point1[1],
point2[2] - point1[2]};
// Now we find out the position when the line intersects the
// ground level.
if(direction[1] == 0)
return null;
double dist = 0;
switch(plane)
{
case Plane.xy:
dist = -1.0 * point1[2] / direction[2];
break;
case Plane.xz:
dist = -1.0 * point1[1] / direction[1];
break;
case Plane.yz:
dist = -1.0 * point1[0] / direction[0];
break;
}
double px = point1[0] + dist*direction[0];
double py = point1[1] + dist*direction[1];
double pz = point1[2] + dist*direction[2];
return new Vertex((float)px, (float)py, (float)pz);
}