#include <GL/glut.h>
float angle1=0;
void display()
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glColor3f(0.1,0.1,1);
glutSolidTeapot(0.3);
glPushMatrix();
glTranslatef(0.5, 0.15, 0);
glRotatef(angle1,0,0,1);
glTranslatef(0.3,0,0);
glScalef(1,0.3,0.3);
glColor3f(1,0,0);
glutSolidSphere(0.3,30,30);
glPopMatrix();
glPopMatrix();
glFlush();
}
void motion(int x, int y)
{
angle1=x;
glutPostRedisplay();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutCreateWindow("dfkhiodfklghdfmhkltuighsdrklgyuwjopmhgfhim,");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
#include <GL/glut.h>
float angle=0,oldX=0,oldY=0;
void drawBody(){
glPushMatrix();
glScalef(1, 0.5, 0.5);
glutSolidCube(1);
glPopMatrix();
}
void drawArm(){
glPushMatrix();
glScalef(0.6, 0.3, 0.3);
glutSolidCube(1);
glPopMatrix();
}
void display()
{
{
glColor3ub(100,100,100);
GLfloat pos[]={0,0,-1,0};
glLightfv(GL_LIGHT0, GL_POSITION, pos);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
glPushMatrix();
glTranslatef(0.5, 0, 0);
glRotatef(angle, 0,0,1);
glTranslatef(0.25, 0,0);
drawArm();
glPushMatrix();
glTranslatef(0.25, 0, 0);
glRotatef(angle, 0,0,1);
glTranslatef(0.25, 0,0);
drawArm();
glPopMatrix();
glPopMatrix();
glPushMatrix();
glTranslatef(-0.5, 0, 0);
glRotatef(-angle, 0,0,1);
glTranslatef(-0.25, 0,0);
drawArm();
glPushMatrix();
glTranslatef(-0.25, 0, 0);
glRotatef(-angle, 0,0,1);
glTranslatef(-0.25, 0,0);
drawArm();
glPopMatrix();
glPopMatrix();
drawBody();
glFlush();
}
void motion(int x, int y)
{ angle -= y - oldY;
oldY=y; oldX=x;
}
void mouse(int button, int state, int x, int y){
if(state==GLUT_DOWN) { oldX=x; oldY=y; }
}
void timer(int t)
{
glutTimerFunc(20, timer, t+1);
glutPostRedisplay();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutCreateWindow("dfnhodfnhdfgnkldfmjkghsdmgkladrtbmhiosuisgjfomhfji");
glutDisplayFunc(display);
glutTimerFunc(20, timer, 0);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
#include <stdio.h>
#include <GL/glut.h>
FILE *fout=NULL;
FILE *fin=NULL;
float oldX=0, oldY=0,angle[10]={};
int angleID=1;
void drawBody(){
glPushMatrix();
glScalef(1, 0.5, 0.5);
glutSolidCube(1);
glPopMatrix();
}
void drawArm(){
glPushMatrix();
glScalef(0.6, 0.3, 0.3);
glutSolidCube(1);
glPopMatrix();
}
void display()
{
{
glColor3ub(100,100,100);
GLfloat pos[]={0, 0, -1, 0};
glLightfv(GL_LIGHT0, GL_POSITION, pos);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
glPushMatrix();
glTranslatef(0.5, 0, 0);
glRotatef(angle[1], 0,0,1);
glTranslatef(0.25, 0,0);
drawArm();
glPushMatrix();
glTranslatef(0.25, 0, 0);
glRotatef(angle[2], 0,0,1);
glTranslatef(0.25, 0,0);
drawArm();
glPopMatrix();
glPopMatrix();
glPushMatrix();
glTranslatef(-0.5, 0, 0);
glRotatef(-angle[3], 0,0,1);
glTranslatef(-0.25, 0,0);
drawArm();
glPushMatrix();
glTranslatef(-0.25, 0, 0);
glRotatef(-angle[4], 0,0,1);
glTranslatef(-0.25, 0,0);
drawArm();
glPopMatrix();
glPopMatrix();
drawBody();
glFlush();
}
void motion(int x, int y)
{ angle[angleID]-= y - oldY;
oldY=y; oldX=x;
if(fout==NULL)
fout=fopen("a.txt","w+");
for(int i=0;i<10;i++)
{
printf("%f ",angle[i]);
fprintf(fout,"%f ",angle[i]);
}
printf("\n");
fprintf(fout,"\n");
}
void timerPlay(int t)
{
glutTimerFunc(500,timerPlay,t+1);
if(fin==NULL)
fin=fopen("a.txt","r");
for(int i=0;i<10;i++)
{
fscanf(fin,"%f",&angle[i]);
printf("%f ",angle[i]);
}
glutPostRedisplay();
}
void mouse(int button, int state, int x, int y){
if(state==GLUT_DOWN) { oldX=x; oldY=y; }
}
void timer(int t)
{
glutTimerFunc(20, timer, t+1);
glutPostRedisplay();
}
void keyboard(unsigned char key,int x,int y)
{
if(key=='1')angleID=1;
if(key=='2')angleID=2;
if(key=='3')angleID=3;
if(key=='4')angleID=4;
if(key=='p') glutTimerFunc(10,timerPlay,0);
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutCreateWindow("trhokoprkghopkdfopgkopdfjgjkiopqwejtioj");
glutDisplayFunc(display);
glutTimerFunc(20, timer, 0);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutKeyboardFunc(keyboard);
glutMainLoop();
}
沒有留言:
張貼留言