OpenGL 点数组动画
我正在尝试对我创建的随机点进行动画处理,以便它们在屏幕上移动并重新出现,这是我到目前为止所做的,但不起作用。代码不是我所拥有的完整版本,我只发布了内容我认为这个问题就足够了,有人可以帮我动画化这些点吗
void TimerFunc(int value)
{
xpos[0]=xpos[0]+0.25;
glutPostRedisplay();
glutTimerFunc(25, TimerFunc, 1);
}
struct Point
{
float rship;
};
std::vector< Point > points;
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT); /* clear window */
glColor3f(1.0, 1.0, 1.0); /* white drawing objects */
/* define object to be drawn as a square polygon */
//Draw points
glEnableClientState( GL_VERTEX_ARRAY );
glVertexPointer( 2, GL_FLOAT, sizeof(Point), &points[0].x );
glPointSize( 1 ); //1 pixel dot
glDrawArrays( GL_POINTS, 0, points.size() );
glDisableClientState( GL_VERTEX_ARRAY );
//glEnable( GL_POINT_SMOOTH );/*round smooth points*/
glFlush(); /* execute drawing commands in buffer */
}
int main(int argc, char** argv)
for( int i = 0; i <250; ++i )
{
Point pt;
pt.x = -100 + (rand() % 200);
pt.y = -100 + (rand() % 200);
points.push_back(pt);
xpos[i] = pt.x;
ypos[i] = pt.y;
}
I am trying to animate random point that i have created so they move across the screen and re-appear this is what i have done so far but does not work.the code is not the completed version of what i have i have only posted what i thought would be enough for this question could anyone help me animated the points
void TimerFunc(int value)
{
xpos[0]=xpos[0]+0.25;
glutPostRedisplay();
glutTimerFunc(25, TimerFunc, 1);
}
struct Point
{
float rship;
};
std::vector< Point > points;
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT); /* clear window */
glColor3f(1.0, 1.0, 1.0); /* white drawing objects */
/* define object to be drawn as a square polygon */
//Draw points
glEnableClientState( GL_VERTEX_ARRAY );
glVertexPointer( 2, GL_FLOAT, sizeof(Point), &points[0].x );
glPointSize( 1 ); //1 pixel dot
glDrawArrays( GL_POINTS, 0, points.size() );
glDisableClientState( GL_VERTEX_ARRAY );
//glEnable( GL_POINT_SMOOTH );/*round smooth points*/
glFlush(); /* execute drawing commands in buffer */
}
int main(int argc, char** argv)
for( int i = 0; i <250; ++i )
{
Point pt;
pt.x = -100 + (rand() % 200);
pt.y = -100 + (rand() % 200);
points.push_back(pt);
xpos[i] = pt.x;
ypos[i] = pt.y;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
又快又脏:
Quick 'n dirty: