OpenGL:绘制2个圆柱体
OpenGL: draw 2 cylinder
我试图绘制两个圆柱体,都填充了相同的纹理,但我已经设法只绘制了第一个,这是我的绘制函数:
void display(void)
{
// Projection plane
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//a->draw(mouseY);
//draw first cylinder WORKING
glPushMatrix();
glRotatef(mouseY, 0, 0, 1);
quadratic = gluNewQuadric();
gluQuadricNormals(quadratic, GLU_SMOOTH);
gluQuadricTexture(quadratic, GL_TRUE);
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glRotatef(90,0,0,1);
glTranslatef(0,-1.0,0);
glMatrixMode(GL_PROJECTION);
gluCylinder(quadratic,fh_cyl,fh_cyl,fw_cyl,50,1000);
if(!exec) //used only one time to get a visible cylinder
{
glTranslatef(fX_cylpos,fY_cylpos,0);
glRotatef(90, 0.0, 1, 0.0); //rotate object 90° on Y axis
glRotatef(fangle_cyl, 1.0, 0.0, 0.0); //0° = vertical / 90° = horizontal
exec=true;
}
glPopMatrix();
glPushMatrix();
//draw second cylinder NOT WORKING
glRotatef(mouseY, 0, 0, 1);
quadratic2 = gluNewQuadric();
gluQuadricNormals(quadratic2, GLU_SMOOTH);
gluQuadricTexture(quadratic2, GL_TRUE);
gluCylinder(quadratic2,fh_cyl,fh_cyl,fw_cyl,50,1000);
if(!exec2)
{
glTranslatef(fX_cylpos+200,fY_cylpos,0);
glRotatef(90, 0.0, 1, 0.0); //rotate object 90° on Y axis
glRotatef(fangle_cyl, 1.0, 0.0, 0.0); //0° = vertical / 90° = horizontal
exec2=true;
}
glPopMatrix();
//b->draw(mouseY);
glutSwapBuffers();
}
这是重塑函数:
void reshape(int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
//glOrtho(-1000.0, 1000.0*(screen_h/screen_w), -1000.0, 1000.0*(screen_h/screen_w), 1000.0, -110.0);
glOrtho(fOrtoXinit, fOrtoXend, fOrtoYinit, fOrtoYend , 1000, -1000.0);
glMatrixMode(GL_MODELVIEW);
}
if
语句中的代码用于垂直绘制圆柱体,如下图所示,然后用鼠标沿x轴旋转圆柱体以滚动数字:预览
感谢Reto Koradi的回复,我已经设法画了2个圆柱体,同时我仍然有两个问题:1. 我不知道我需要改变什么才能把一个圆柱放在另一个圆柱旁边;2. 我认为我的解决方案,画一个垂直的圆柱体使用if
语句不是一个好方法…
编辑后的代码:
if(!exec) //basically IF is not used anymore
{
glTranslatef(fX_cylpos,fY_cylpos,0);
glRotatef(90, 0.0, 1, 0.0); //rotate object 90° on Y axis
glRotatef(fangle_cyl, 1.0, 0.0, 0.0); //0° = vertical / 90° = horizontal
//exec=true;
}
gluCylinder(quadratic,fh_cyl,fh_cyl,fw_cyl,50,1000);
glPopMatrix();
glPushMatrix();
//draw second cylinder NOT WORKING
glRotatef(mouseY, 0, 0, 1);
quadratic2 = gluNewQuadric();
gluQuadricNormals(quadratic2, GLU_SMOOTH);
gluQuadricTexture(quadratic2, GL_TRUE);
if(!exec2)
{
glTranslatef(fX_cylpos+200,fY_cylpos,20);
glRotatef(90, 0.0, 1, 0.0); //rotate object 90° on Y axis
glRotatef(fangle_cyl, 1.0, 0.0, 0.0); //0° = vertical / 90° = horizontal
exec2=true;
}
gluCylinder(quadratic2,fh_cyl,fh_cyl,fw_cyl,50,1000);
glPopMatrix();
这是用鼠标移动圆柱一点后的结果预览
是这个打字错误吗?
gluQuadricTexture(quadratic2, GL_TRUE);
gluCylinder(quadratic,fh_cyl,fh_cyl,fw_cyl,50,1000);
->
gluQuadricTexture(quadratic2, GL_TRUE);
gluCylinder(quadratic2,fh_cyl,fh_cyl,fw_cyl,50,1000);
相关文章:
- 比较并显示使用最小值(a,b)和最大值(a、b)升序排列的4个数字
- 删除一个线程上有数百万个字符串的大型哈希映射会影响另一个线程的性能
- 如何在C++中从两个单独的for循环中添加两个数组
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 模板-模板参数推导:三个不同的编译器三种不同的行为
- 处理多个异常集合的C++方法
- 什么时候在C++中返回常量引用是个好主意
- 给定n个元素的m个集合.在C++中找到出现在最大集合数中的元素
- 当在同一名称空间中有两个具有相同签名的函数时,会发生什么
- 尝试通过多个向量访问变量时,向量下标超出范围
- Ardunio UNO解决了多个重叠的定时器循环
- 如何返回一个类的两个对象相加的结果
- 如何使用OpenCV将RBG图像转换为HSV,并将H、S和V值保存为C++中的3个独立图像
- 是否可以通过C++扩展强制多个python进程共享同一内存
- 数到第n个楼梯的路(顺序无关紧要)
- 基于多个条件处理地图中的所有元素
- 为多个会话保留XPtr
- 如何在C++中初始化嵌套类中的2个memeber
- 运算符C++ "delete []"仅删除 2 个前值
- OpenGL:绘制2个圆柱体