如何在opengl中绘制y轴或x轴上的圆柱体
How to draw cylinder in y or x axis in opengl
我只想在opengl中画一个圆柱体。我找到了很多样本,但它们都在z轴上画圆柱体。我想让它们在x或y轴上。我怎么能这么做呢?下面的代码是在z方向绘制圆柱体的代码,我不想让它
GLUquadricObj *quadratic;
quadratic = gluNewQuadric();
gluCylinder(quadratic,0.1f,0.1f,3.0f,32,32);
你可以使用glRotate(angle, x, y, z)
来旋转你的坐标系:
GLUquadricObj *quadratic;
quadratic = gluNewQuadric();
glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
gluCylinder(quadratic,0.1f,0.1f,3.0f,32,32);
http://www.opengl.org/sdk/docs/man/xhtml/glRotate.xml 每次渲染时使用glPushMatrix
glRotatef
绘制圆柱体,并使用glPopMatrix
完成绘图。
交货。: glRotatef(yRotationAngle, 0.0f, 1.0f, 0.0f); // Rotate your object around the y axis on yRotationAngle radians
交货。: OnRender()
函数示例
void OnRender() {
glClearColor(1.0f, 0.0f, 0.0f, 1.0f); // Clear the background
glClear(GL_COLOR_BUFFER_BIT); //Clear the colour buffer
glLoadIdentity(); // Load the Identity Matrix to reset our drawing locations
glRotatef(yRotationAngle, 0.0f, 1.0f, 0.0f); // Rotate our object around the y axis on yRotationAngle radians
// here *render* your cylinder (create and delete it in the other place. Not while rendering)
gluCylinder(quadratic,0.1f,0.1f,3.0f,32,32);
glFlush(); // Flush the OpenGL buffers to the window
}
相关文章:
- 检查输入是否不是整数或数字
- 是否可以初始化不可复制类型的成员变量(或基类)
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 何时在引用或唯一指针上使用移动语义
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 如何在Qt窗口小部件中使用QStringView(或QStringRef)
- 使用一个考虑到std::map中键值的滚动或换行的键
- 如何加载(或映射)文件部分的最大大小,但适合在Windows上的RAM
- Arduino:for/while/if在void setup()或void loop()之前?——错误:之前需要不合格
- 用MacOS Mojave编译C++:致命错误:mpi.h:没有这样的文件或目录
- C / C++ 移位/偏移/向左或向右移动位图?
- 如何修复函数样式强制转换或类型构造的预期"("?
- Xaudio2在更改缓冲区或循环时弹出声音
- 有效地使用std::unordered_map来插入或增加键的值
- 指针或结构的矢量
- 我可以信任表示整数的浮点或双精度来保持精度吗
- 绕Y轴旋转二维正方形,并使用DirectX或openGL以透视投影方式显示
- 如何在opengl中绘制y轴或x轴上的圆柱体
- 使用sfml或openGL激活四轴缓冲立体声
- 当选择最左侧或最右侧的元素作为枢轴时,快速排序显然采用 O(n^2)