我在opengl中有一些对象,对象是在x位置查看,我想让它在y位置查看如何制作它? 这是代码
Gl.glBegin(Gl.GL_TRIANGLES);
for (iogl = 0; (iogl <= 360); iogl = (iogl + 3))
{
Gl.glColor3f(1, 0, 0);
Gl.glVertex3f(4 * (float)Math.Sin(Math.PI / 180 * iogl), 4 * (float)Math.Cos(Math.PI / 180 * iogl), 25);
Gl.glVertex3f(4 * (float)Math.Sin(Math.PI / 180 * (iogl + 20)), 4 * (float)Math.Cos(Math.PI / 180 * (iogl + 20)), 25);
Gl.glVertex3f(0, 0, 35);
}
Gl.glEnd();
Gl.glBegin(Gl.GL_QUADS);
for (iogl = 0; (iogl <= 359); iogl++)
{
//Tabung
Gl.glColor3f(1, 1, 1);
Gl.glVertex3f(4 * (float)Math.Sin(Math.PI / 180 * iogl), 4 * (float)Math.Cos(Math.PI / 180 * iogl), 25);
Gl.glVertex3f(4 * (float)Math.Sin(Math.PI / 180 * (iogl + 30)), 4 * (float)Math.Cos(Math.PI / 180 * (iogl + 30)), 25);
Gl.glVertex3f(4 * (float)Math.Sin(Math.PI / 180 * iogl), 4 * (float)Math.Cos(Math.PI / 180 * iogl), 6);
Gl.glVertex3f(4 * (float)Math.Sin(Math.PI / 180 * (iogl + 30)), 4 * (float)Math.Cos(Math.PI / 180 * (iogl + 30)), 6);
}
Gl.glEnd();
Gl.glBegin(Gl.GL_QUADS);
for (iogl = 0; (iogl <= 359); iogl++)
{
//Merah Tengah
Gl.glColor3f(1, 0, 0);
Gl.glVertex3f(4 * (float)Math.Sin(Math.PI / 180 * iogl), 4 * (float)Math.Cos(Math.PI / 180 * iogl), 6);
Gl.glVertex3f(4 * (float)Math.Sin(Math.PI / 180 * (iogl + 30)), 3 * (float)Math.Cos(Math.PI / 180 * (iogl + 30)), 6);
Gl.glVertex3f(3 * (float)Math.Sin(Math.PI / 180 * iogl), (3) * (float)Math.Cos(Math.PI / 180 * iogl), 3);
Gl.glVertex3f(3 * (float)Math.Sin(Math.PI / 180 * (iogl + 20)), (3) * (float)Math.Cos(Math.PI / 180 * (iogl + 20)), 3);
}
Gl.glEnd();
Gl.glBegin(Gl.GL_QUADS);
for (iogl = 0; (iogl <= 359); iogl++)
{
//PUTIH Belakang
Gl.glColor3f(1, 1, 1);
Gl.glVertex3f(3 * (float)Math.Sin(Math.PI / 180 * iogl), 3 * (float)Math.Cos(Math.PI / 180 * iogl), 3);
Gl.glVertex3f(3 * (float)Math.Sin(Math.PI / 180 * (iogl + 20)), 3 * (float)Math.Cos(Math.PI / 180 * (iogl + 20)), 3);
Gl.glVertex3f(3 * (float)Math.Sin(Math.PI / 180 * iogl), 3 * (float)Math.Cos(Math.PI / 180 * iogl), -20);
Gl.glVertex3f(3 * (float)Math.Sin(Math.PI / 180 * (iogl + 20)), 3 * (float)Math.Cos(Math.PI / 180 * (iogl + 20)), -20);
}
Gl.glEnd();
Gl.glBegin(Gl.GL_POLYGON);
for (iogl = 0; (iogl <= 359); iogl++)
{
//putih alas Belakang
Gl.glColor3f(1, 1, 1);
Gl.glVertex3f(3.5f * (float)Math.Sin(Math.PI / 180 * iogl), 3.5f * (float)Math.Cos(Math.PI / 180 * iogl), -20);
Gl.glVertex3f(3.5f * (float)Math.Sin(Math.PI / 180 * (iogl + 20)), 3.5f * (float)Math.Cos(Math.PI / 180 * iogl + 20), -20);
Gl.glVertex3f(3.5f * (float)Math.Sin(Math.PI / 180 * iogl), 3.5f * (float)Math.Cos(Math.PI / 180 * iogl), -25);
Gl.glVertex3f(3.5f * (float)Math.Sin(Math.PI / 180 * (iogl + 20)), 3.5f * (float)Math.Cos(Math.PI / 180 * iogl + 20), -25);
}
Gl.glEnd();
Gl.glBegin(Gl.GL_POLYGON);
for (iogl = 0; (iogl <= 360); iogl = (iogl + 90))
{
Gl.glColor3f(1, 0, 0);
Gl.glVertex3f(0, 0, -25);
Gl.glVertex3f(0, 10 * (float)Math.Sin(Math.PI / 180 * iogl), -17);
Gl.glVertex3f(10 * (float)Math.Cos(Math.PI / 180 * iogl), 0, -25);
Gl.glVertex3f(0, 0, -25);
Gl.glVertex3f(10 * (float)Math.Cos(Math.PI / 180 * iogl), 0, -17);
Gl.glVertex3f(0, 10 * (float)Math.Sin(Math.PI / 180 * iogl), -25);
}
Gl.glEnd();
这里是对象是x位置的截图,我想让它(站立)在y位置我应该添加什么代码
答案 0 :(得分:0)
在开头调用glTranslatef函数。这将使矩阵倍增,您绘制的所有内容都将相对于平移坐标。
答案 1 :(得分:0)
在您的情况下,您需要围绕Z轴将火箭旋转90度,使其在y轴上站立。
如果你把这一行放在你发布的代码的开头,它应该可以工作。
GL.Rotate(90.0f, 0.0f, 0.0f, 1.0f);