我可以获取示例opengl代码以使用动画不断减小球体的大小 [英] Can I get example opengl code to continously decrease the size of a sphere using animation
本文介绍了我可以获取示例opengl代码以使用动画不断减小球体的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用循环不断减小球体半径,但它似乎不起作用。增加球体大小的动画工作正常。
无法理解为什么不渲染渐变半径。
我请求任何人共享任何可以帮助平滑地设置动画的示例代码同样。
谢谢。
我尝试了什么: < br $> b $ b
I tried to continously decrease the sphere radius using a loop, but it does not seem to work.The animation for increasing sphere size is working fine.
Not able to understand why decreasing radius is not rendered.
I request anyone to share any sample code that can help to smoothly animate the same.
Thank You.
What I have tried:
#include<windows.h>
#include<GL/glut.h>
int r=1,flag=0;
void drawSphere(int r1)
{
glutSolidSphere(r1,30,30);
glFlush();
}
void displaySolid()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3d(1,0,0);
drawSphere(100);
glFlush();
}
void animate(int btn,int state,int x,int y)
{
if(btn==GLUT_LEFT_BUTTON && state==GLUT_DOWN)
{
for(r=200;r<400;r+=3)
{
drawSphere(r);
//glutPostRedisplay();
Sleep(100);
flag=1;
}
r=100;
}
if(btn==GLUT_RIGHT_BUTTON && state==GLUT_DOWN)
{
for(r=60;r>=30;r--)
{
drawSphere(r);
Sleep(100);
}
}
}
int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(700,700);
glutInitWindowPosition(0,0);
glutCreateWindow("sphere test");
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-500,500,-500,500,-500,500);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glutDisplayFunc(displaySolid);
glutMouseFunc(animate);
glEnable(GL_DEPTH_TEST);
glutMainLoop();
return 0;
}
推荐答案
您正在为<分配double
值code> int 变量r
(显然忽略编译器警告......)。
You are assigningdouble
values to theint
variabler
(and apparently ignoring compiler warnings...).
这篇关于我可以获取示例opengl代码以使用动画不断减小球体的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文