我正在使用OpenGL 3制作一部小型动画电影,并在2015年的视觉工作室社区中实现它。我试图制作一个恐龙的动画,至少在第一次向右移动,但我无法使它以某种方式动画。
这是我的主要:
#include "glut.h"
#include "globaldeclare.h"
#include "dino.h"
#include "scene1.h"
#include "scene1_animation.h"
#include <math.h>
void init(void)
{
glClearColor(0.0, 204.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, 500, 0, 500);
glMatrixMode(GL_MODELVIEW);
}
void myIdle() {
frame++;
scene1_dino_idle();
glutPostRedisplay();
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
//Animation happens here
if (scene_counter == 1) {
scene1();
scene1_animation();
}
glutSwapBuffers();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(1300, 800);
glutInitWindowPosition(100, 100);
glutCreateWindow("Walking with dinosaur");
glutDisplayFunc(display);
glutIdleFunc(myIdle);
init();
glutMainLoop();
return 0;
}这是scene1动画发生的地方(但没有发生) :)
void scene1_dino_idle() {
//idle
if (dino_slidey > 0 && dino_count == 1) dino_movey = 1;
if (dino_movey == 1 && dino_count == 1) dino_slidey -= 2;//1
if (dino_slidey < -30 && dino_count == 1) dino_movey = 0;
if (dino_movey == 0 && dino_count == 1) dino_slidey += 2;//1
if (dino_slidex > 1000 && dino_count == 1) { dino_movex = 1; dino_count = 2; dinoleg_count = 2; }
if (dino_movex == 1 && dino_count == 1) dino_slidex -= 6;//4
if (dino_slidex < -1600 && dino_count == 1) dino_movex = 0;
if (dino_movex == 0 && dino_count == 1) dino_slidex += 6;//4
}
void scene1_dino_animation() {
//moving to the right
glPushMatrix();
if (dino_count == 1) {
glTranslatef(dino_slidex, dino_slidey, 0);
glTranslatef(0, 100, 0);
glScalef(0.6, 0.6, 1);
}
glScalef(dinoR_lost, dinoR_lost, 0);
dino();
glPopMatrix();
}
void scene1_animation() {
scene1_dino_animation();
}我的全局变量//帧计数器int帧,scene_counter = 1;
//dino animation
float dino_movex, dino_movey, dino_count, dino_slidex, dino_slidey, dinoR_lost, dinoL_lost;
//dino leg
float dinoleg_angle = 0, dinoleg_move_x, dinoleg_move_y, dinoleg_count = 0;我已经画好了这个场景,但我不能把它动画化。在我看来,我在动画中做得很好,也许在我空闲的功能中的某个地方不允许我让它工作。我什么都试过了,但我不能让它起作用,我也不知道问题出在哪里。请告诉我什么是主要问题。提前谢谢。
发布于 2016-01-01 04:29:18
我设法让它运转起来。在我画的一些场景中,只有一个dino,但是它没有移动,所以我从scene1.h的scene1()中删除了这个scene1()。从那以后,它不见了,但我注意到一些点在移动(我不知道它是从哪里来的)。现在,我通过在glutPostRedisplay()函数中添加scene1_dino_idle()来修正它。然后,我删除这段代码glScalef(dinoR_lost, dinoR_lost, 0);,这样dino就会出现。谢谢大家的帮助。新年快乐。
发布于 2016-01-01 04:06:24
我假设大多数命名的变量都是全局的。由于您没有向我们显示初始值,我将假设它们都为零(除了scene_counter和dino_count;如果其中任何一个为零,什么都不会发生),然后进行几次迭代。(请原谅这条痕迹的拥挤布局。)以下是每次调用scene1_dino_idle()的入口处的值
scene_counter dino_movey dino_slidey dinoleg_count
frame | dino_count | dino_movex | dino_slidex |
| | | | | | | |
1 1* 1* 0 0 0 0 0
2 1 1 0 0 2 6 0
3 1 1 1 0 0 12 0
4 1 1 1 0 -2 18 0
5 1 1 1 0 -4 24 0
. . .
f 1 1 1 0 (f-3)*-2 (f-1)*6 0
. . .
18 1 1 1 0 -30 102 0
19 1 1 0 0 -30 108 0
20 1 1 0 0 -28 114 0
. . .从这个小小的跟踪来看,如果您有问题,似乎是因为scene_counter或dino_count (或两者都是)为零。另一种可能是,您的全局变量存在范围问题;如果声明中有错误,C可能会将其中一个或多个变量视为局部变量。(在C的某些版本中,没有显式声明的变量将默认为int。)
没有你的头像,我们就看不出出了什么问题。
由于一些调试器与图形代码的关系很差,您可能会考虑添加调试代码,以便将变量跟踪到文件中,就像我上面手动做的那样。
最好不用自己编译它,也不用猜测您遗漏了什么,OpenGL代码就可以了。
https://stackoverflow.com/questions/34552945
复制相似问题