本文介绍了如何用OpenGl绘制移动函数图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用OpenGl来为看起来像这样的图形设置动画效果:
以下是我到目前为止的代码:
void GLWidget :: paintGL()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0,1,0); //绿色
//频率线
glLineWidth(3.0);
glBegin(GL_LINE_STRIP);
glVertex2f(-1,0);
glVertex2f(x1,y1);
glEnd();
y1 = randVarGen();
x1 = randVarGen();
,并且我有一个计时器可以每隔50毫秒重新绘制图形。我想从一条直线开始,根据音频文件中的变量(我现在使用的是随机变量),图形应该上下有点像音乐可视化器。
在glBegin(GL_LINE_STRIP);
glVertex2f(0f,0f);
for(float x = 1f; x glVertex2f(x,randVarGen());
glVertex2f(100f,0f);
glEnd();
I'm using OpenGl to animate a graph that looks something like this:
Here's the code I've got so far:
void GLWidget::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0,1,0); //Green
// Frequency Line
glLineWidth(3.0);
glBegin(GL_LINE_STRIP);
glVertex2f(-1,0);
glVertex2f(x1,y1);
glEnd();
y1 = randVarGen();
x1 = randVarGen();
and I have a timer to redraw the graph every 50 ms. I want to start with a straight line and based on variables from an audio file(I'm using random variables for now), the graph should go up and down sort of like a music visualizer.
解决方案
You need to sample the function you want to plot.
glBegin(GL_LINE_STRIP);
glVertex2f(0f, 0f);
for (float x = 1f; x < 100f; x += 1f)
glVertex2f(x, randVarGen());
glVertex2f(100f, 0f);
glEnd();
这篇关于如何用OpenGl绘制移动函数图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!