Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#include <GLUT/glut.h> //for mac
- //buffer : angle_b
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <GL/glut.h>
- #include <time.h>
- FILE *fpr;
- static float g_angle = 0.0f;
- static float sec;
- static float *angle_b;
- static float xtrans=0.0f,ytrans=0.0f;
- static float sscale=1.0f;
- int g_pressed = 0;
- int i=0;
- int flag;
- int*flag_m;
- unsigned int timer;
- float timer1,timer2,timer3;
- int g_prevX = -1;
- float value;
- int num;
- clock_t passage;
- void output_scan(FILE *fp,float *store,int *flag_kana);
- void reshape(int width, int height)
- {
- static GLfloat lightPosition[4] = {0.25f, 1.0f, 0.25f, 0.0f};
- static GLfloat lightDiffuse[3] = {1.0f, 1.0f, 1.0f};
- static GLfloat lightAmbient[3] = {0.25f, 0.25f, 0.25f};
- static GLfloat lightSpecular[3] = {1.0f, 1.0f, 1.0f};
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- glShadeModel(GL_SMOOTH);
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(45.0, (double)width / (double)height, 0.1, 100.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- gluLookAt(0.5, 1.5, 2.5, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
- glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
- glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse);
- glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
- glLightfv(GL_LIGHT0, GL_SPECULAR, lightSpecular);
- }
- void display()
- {
- if(i<num)
- {
- i=i+1;
- }
- else
- {
- i=0;
- }
- static GLfloat vertices [8][3] =
- {
- {-0.5f, -0.5f, 0.5f},
- { 0.5f, -0.5f, 0.5f},
- { 0.5f, 0.5f, 0.5f},
- {-0.5f, 0.5f, 0.5f},
- { 0.5f, -0.5f, -0.5f},
- {-0.5f, -0.5f, -0.5f},
- {-0.5f, 0.5f, -0.5f},
- { 0.5f, 0.5f, -0.5f}
- };
- static GLfloat normals[6][3] =
- {
- { 0.0f, 0.0f, 1.0f},
- { 0.0f, 0.0f, -1.0f},
- { 1.0f, 0.0f, 0.0f},
- {-1.0f, 0.0f, 0.0f},
- { 0.0f, 1.0f, 0.0f},
- { 0.0f, -1.0f, 0.0f}
- };
- static GLfloat diffuse[3] = {1.0f, 0.0f, 0.0f};
- static GLfloat ambient[3] = {0.25f, 0.25f, 0.25f};
- static GLfloat specular[3] = {1.0f, 1.0f, 1.0f};
- static GLfloat shininess[1] = {32.0f};
- glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
- glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
- glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
- glMaterialfv(GL_FRONT, GL_SHININESS, shininess);
- glEnable(GL_DEPTH_TEST);
- glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glPushMatrix();
- glTranslatef(xtrans, ytrans,0. );
- glRotatef(g_angle, 0.0f, 1.0f, 0.0f);
- glScalef(sscale,sscale,sscale);
- //printf("x=%f\n",xtrans);
- //printf("y=%f\n",ytrans);
- //printf("z=%f\n",sscale);
- // 前
- glBegin(GL_POLYGON);
- glNormal3fv(normals[0]);
- glVertex3fv(vertices[0]);
- glVertex3fv(vertices[1]);
- glVertex3fv(vertices[2]);
- glVertex3fv(vertices[3]);
- glEnd();
- // 後
- glBegin(GL_POLYGON);
- glNormal3fv(normals[1]);
- glVertex3fv(vertices[4]);
- glVertex3fv(vertices[5]);
- glVertex3fv(vertices[6]);
- glVertex3fv(vertices[7]);
- glEnd();
- // 右
- glBegin(GL_POLYGON);
- glNormal3fv(normals[2]);
- glVertex3fv(vertices[1]);
- glVertex3fv(vertices[4]);
- glVertex3fv(vertices[7]);
- glVertex3fv(vertices[2]);
- glEnd();
- // 左
- glBegin(GL_POLYGON);
- glNormal3fv(normals[3]);
- glVertex3fv(vertices[5]);
- glVertex3fv(vertices[0]);
- glVertex3fv(vertices[3]);
- glVertex3fv(vertices[6]);
- glEnd();
- // 上
- glBegin(GL_POLYGON);
- glNormal3fv(normals[4]);
- glVertex3fv(vertices[3]);
- glVertex3fv(vertices[2]);
- glVertex3fv(vertices[7]);
- glVertex3fv(vertices[6]);
- glEnd();
- // 下
- glBegin(GL_POLYGON);
- glNormal3fv(normals[5]);
- glVertex3fv(vertices[1]);
- glVertex3fv(vertices[0]);
- glVertex3fv(vertices[5]);
- glVertex3fv(vertices[4]);
- glEnd();
- glPopMatrix();
- glutSwapBuffers();
- }
- void time(int value)
- {
- //printf("y=%f\n",timer);
- //timer1=angle_b[7*i]*CLOCKS_PER_SEC;
- printf("i=%d\n",i);
- //timer1=angle_b[7*i];
- //timer2=angle_b[7*i+1];
- //timer3=angle_b[7*i+2];
- timer1=angle_b[7*i]*CLOCKS_PER_SEC/100;
- timer2=angle_b[7*i+1]*CLOCKS_PER_SEC/100;
- timer3=angle_b[7*i+2]*CLOCKS_PER_SEC/100;
- g_angle=angle_b[7*i+3];
- xtrans=angle_b[7*i+4];
- ytrans=angle_b[7*i+5];
- sscale=angle_b[7*i+6];
- flag=flag_m[i];
- //printf("x=%f\n",timer1);
- //printf("y=%f\n",timer2);
- //printf("z=%f\n",timer3);
- //printf("h=%f\n",g_angle);
- //printf("u=%f\n",xtrans);
- //printf("p=%f\n",ytrans);
- //printf("o=%f\n",sscale);
- //printf("t=%d\n",flag);
- if(flag==1)
- {
- timer=timer1;
- }
- else if(flag==2)
- {
- timer=timer2;
- }
- else if(flag==3)
- {
- timer=timer3;
- }
- else
- {
- timer=0;
- }
- printf("timer=%d\n",timer);
- glutPostRedisplay();
- //glutTimerFunc(timer,time,value);
- glutTimerFunc(timer,time,0);
- }
- int main(int argc, char* argv[])
- {
- float x,y;
- //int num;
- if(argc!=3)
- {
- fprintf(stderr,"Usage: %s (1)txtFile\n",argv[0]);
- return 0;
- }
- //Open VTK file for save
- if((fpr=fopen(argv[1],"r"))==NULL)
- {
- printf("The file can't be opened. The program is exit.\n");
- return 0;
- }
- num=atoi(argv[2]);
- //Load angle buffer
- angle_b=(float *)malloc(7*num*sizeof(float));
- flag_m=(int *)malloc(num*sizeof(int));
- output_scan(fpr,angle_b,flag_m);
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
- glutInitWindowPosition(100, 100);
- glutInitWindowSize(640, 480);
- glutCreateWindow("Mouse Motion Cube");
- glutReshapeFunc(reshape);
- //glutMotionFunc(motion);
- glutDisplayFunc(display);
- //glutTimerFunc(0.1,time, 0);
- glutTimerFunc(timer,time, 0);
- glutMainLoop();
- fclose(fpr);
- }
- void output_scan(FILE *fp,float *store,int *flag_kana)
- {
- float a,b,c,d,e,f,g;
- int h;
- int count=0;
- while(fscanf(fpr,"%f %f %f %f %f %f %f %d",&a,&b,&c,&d,&e,&f,&g,&h)!=EOF)
- {
- store[count*7]=a;
- store[count*7+1]=b;
- store[count*7+2]=c;
- store[count*7+3]=d;
- store[count*7+4]=e;
- store[count*7+5]=f;
- store[count*7+6]=g;
- printf("a=%f\n",a);
- printf("count=%f\n",store[count*7]);
- flag_kana[count]=h;
- count=count+1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement