PDA

View Full Version : سوال: انیمیشن سازی توسط openl



mezood
یک شنبه 23 شهریور 1393, 14:11 عصر
هدف از نوشتن این کد اینه که 1 مثلث حول محور z دوران بکنه ، 1 تابع به اسم display نوشتم و توش مثلث رو مشخص کردم و از دستور glrotatef استفاده کردم تا مثلث به اندازه time درجه دوران بکنه.
برای اینکه انیمیشن ایجاد بشه لازمه که time تغییر بکنه واسه همین تابع idle رو نوشتم تا 0.1 0.1 ب0 time اضافه کنه. حالا مشکل اینجاست که نمی دونم time رو کجا باید تعریف بکنم.

#include<glut.h>

void init()
{
glClearColor(0,0,0,0);
gluOrtho2D(-5,5,-5,5);
}


void display()
{

glClear(GL_COLOR_BUFFER_BIT);//clear the screen


glColor3f(1,0,0);//set color to red


glPushMatrix();//create a new matrix


glRotatef(time,0,0,1);//rotate the triangle on z axis based on how much time has passed


glBegin(GL_TRIANGLES);//start drawing triangles
glVertex2f(3,-4);
glVertex2f(3.5,-3);
glVertex2f(4,-4);
glEnd();//stop drawing triangles


glPopMatrix();//stops current transformations to the matrix
glFlush(); //draw everything to the screen
glutPostRedisplay();//start drawing again
}


void idle()
{

time=time+0.1;//increase the time variable


if(time>360)
time=0;//reset the time variable
}


main(int argc, char**argv)
{
glutInit(&argc,argv);//initialize GLUT
glutInitWindowSize(800,600);//define the window size
glutInitWindowPosition(10,50);//position the window
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);//define the drawing mode
glutCreateWindow("lesson 3");// create our Window
init();//initialize our variables
glutDisplayFunc(display);//tell Glut what our display funcion is
glutIdleFunc(idle);
glutMainLoop();//keep the program running
return 0;
}

ali chegini
دوشنبه 24 شهریور 1393, 16:57 عصر
سلام.
time یک متغیره سراسری که میتونی بعد از هدر فایل تعریفش کنی.
نوعش رو float بزار.

mezood
چهارشنبه 26 شهریور 1393, 13:04 عصر
سلام.
time یک متغیره سراسری که میتونی بعد از هدر فایل تعریفش کنی.
نوعش رو float بزار.
خیلی خیلی ممنون