LOOP中的C#openGL绘制(for,while语句) [英] C# openGL draw within a LOOP (for, while statement)

查看:127
本文介绍了LOOP中的C#openGL绘制(for,while语句)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,程序员!

我有一个问题!

我已经设法画一条线了.这是代码:

Hello programmers!

I have a question!

I''ve already managed to draw a line. Here is the code:

Gl.glBegin(Gl.GL_LINES);
Gl.glVertex3f(100.0f, 100.0f, 0.0f); // origin of the line
Gl.glVertex3f(200.0f, 140.0f, 5.0f); // ending point of the line
Gl.glEnd();


所以我的问题是,我该如何在循环中绘制一条线或一条火车(称为你想要的")!因此,每次循环时,我都会更改值,最后,它将得出一个奇怪的图或....它只是,我无法设法使用循环绘制!

救命!

[edit]
好吧,我从走"走了,将高斯克鲁格坐标存储在txt文件中.读取txt文件后,我将这些坐标存储在二维数组中.


So my question is, how can i managed to draw a line or a terain (called what u want) within a loop! So i would change the values every time the loop goes around and at the end it would come up with a weird drawing or...whatever. Its just, i cant manage to draw using a loop!

Help!

[edit]
Well i got gauss krueger coordinates stored in a txt file, from a "walk" i made. After reading the txt file i store these coordinates in a two dimensional array.

Example:
coordinate[0,0] = x
coordinate[0,1] = y
coordinate[0,2] = z

// And then
coordinate[1,0] = x
coordinate[1,1] = y
coordinate[1,2] = z


...等等!

因此,我现在想将其的每个点"放入Gl.glVertex3f(float x, float y, float z)

我使用Gl.glBegin(Gl.GL_LINE_STRIP)

在将所有这些循环完成后,应该出现一条与所有这些点和线相连的火车.

我希望我能提供更多的信息!谢谢你的感谢!

[/edit]


...and so on!

So i want now to place every single ''dot'' of this into Gl.glVertex3f(float x, float y, float z)

I use Gl.glBegin(Gl.GL_LINE_STRIP)

And after all this done in a loop, a terain connected with all these dots and lines should show up.

I hope i''ve give more information then before! Thnx for replying!

[/edit]

推荐答案

确定,因此您需要列出要迭代并在其中绘制线的点列表,例如:
OK, so you have a list of points which you need to iterate and draw lines between, something like:
Gl.glBegin(Gl.GL_LINES);
for (int i = 0; i < coordinate.size; i +=2)
{
    Gl.glVertex3f(coordinate[i][0], coordinate[i][1], coordinate[i][2]); // origin of the line
    Gl.glVertex3f(coordinate[i+1][0], coordinate[i+1][1], coordinate[i+1][2]); // ending point of the line
}
Gl.glEnd();


它基本上在每对顶点之间画一条线.如果一个顶点的终点与下一个顶点的起点相同,则将循环的增量值更改为1而不是2.


Which basically draws a line between each pair of vertices. If the ending point of one vertex is the same as the beginning of the next, then change the increment value of the loop to 1 rather than 2.


这篇关于LOOP中的C#openGL绘制(for,while语句)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆