我在使用顶点从文本文件更改我正在调用的多边形的大小时遇到问题。每当我尝试更改文本文件中顶点的坐标并运行程序时,形状保持相同的大小,当我返回文本文件时,所有坐标都已更改回来。如何更改形状大小?
以下是我用于此的代码:
void cal_vertices() {
// open a file for writing pentagon vertices
ofstream outfile("vertices1.txt");
float a = 2 * 3.1415926 / 5.0;
float x1 = 0.0, y1 = 1.0;
outfile << x1 << " " << y1 << endl;;
float x, y;
for (int i = 1; i < 5; i++) {
x = x1 * cos(a * i) - y1 * sin(a * i);
y = y1 * cos(a * i) + x1 * sin(a * i);
outfile << x << " " << y << endl;;
}
outfile.close();
}
void read_vertices() {
//reads verticies from the text file
ifstream infile("vertices1.txt");
for (int i = 0; i < 5; i++){
infile >> vertices[i][0];
infile >> vertices[i][1];
cout << vertices[i][0] << " " << vertices[i][1] << endl;
}
}
void init(){
cal_vertices();
read_vertices();
glNewList(listname, GL_COMPILE);
glColor4f(red, green, blue, 1.0);
glBegin(GL_LINE_LOOP);
for (int i = 0; i < 5; i++){
glVertex3f(vertices[i][0], vertices[i][1], 0.0);
}
glEnd();
glEndList();
答案 0 :(得分:0)
试试这个:
glPushMatrix ();
glScalef (2.0F, 2.0F, 2.0F);
glBegin(GL_LINE_LOOP);
...
glEnd();
glPopMatrix ();
这应该会使每个维度中多边形的大小加倍。