2014年4月24日 星期四

01160306_呂季樺_第十周



#include <GL/glut.h>
float teapotX=0, teapotY=0;
void keyboard(unsigned char key, int x, int y)
{
if(key=='w') teapotY+=0.1;
if(key=='s') teapotY-=0.1;
if(key=='a') teapotX-=0.1;
if(key=='d') teapotX+=0.1;
glutPostRedisplay();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(teapotX, teapotY, 0);//teapotX,teapotY use
//glRotatef(teapotZ, 0);
glutSolidTeapot(0.3);
glPushMatrix();
glutSwapBuffers();
}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week10");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);//new!
glutMainLoop();

}

#include <GL/glut.h>
#include <stdio.h>//讓你printf可以運作 

float teapotX=0, teapotY=0, teapotZ=0;;
void keyboard(unsigned char key, int x, int y)
{//new!!
printf("%c %d %d\n",key ,x, y);//印出是按甚麼鍵
//要小心 要去設定ALT+P 設定Console小黑視窗
//滑鼠在哪邊跟移動有關 
if(key=='w') teapotY+=0.1;
if(key=='s') teapotY-=0.1;
if(key=='a') teapotX-=0.1;
if(key=='d') teapotX+=0.1;
if(key=='r') teapotZ+=5;
glutPostRedisplay();
}
void mouse(int botton, int state, int x, int y)
{//這個mouse函式,只有在按下去/彈起來 (Press/Release)才會被用到(開始/結束) 
printf("%d %d %d %d\n",botton, state, x, y);
}
void motion(int x, int y) 
{//但是中間移動的動作在這把XY座標拿來用 
printf("%d %d\n", x, y);
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(teapotX, teapotY, 0);//teapotX,teapotY use
glRotatef(teapotZ, 1,1,0);
glutSolidTeapot(0.3);
glPushMatrix();
glutSwapBuffers();
}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week10");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);//new! 0~255  ASCII 不含特殊鍵 
glutMouseFunc(mouse);//new!
glutMotionFunc(motion);
//glutPassiveMotionFunc(passivenotion);
glutMainLoop();
}
#include <GL/glut.h>
#include <stdio.h>//讓你printf可以運作 
float teapotX=0, teapotY=0, teapotZ=0;
float angleX=0, startX=0;
float angleY=0, startY=0;
void mouse(int botton, int state, int x, int y)
{//這個mouse函式,只有在按下去/彈起來 (Press/Release)才會被用到(開始/結束) 
printf("%d %d %d %d\n",botton, state, x, y);
startX=x;
startY=y;
}
void motion(int x, int y) 
{//但是中間移動的動作在這把XY座標拿來用 
printf("%d %d\n", x, y);
angleX+= (x-startX); startX=x;
angleY+= (x-startY); startY=y;
glutPostRedisplay();
void display()
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(teapotX, teapotY, 0);//teapotX,teapotY use
glRotatef(angleX, 0,-1,0);
glRotatef(angleY, -1,0,0);
glutSolidTeapot(0.3);
glPushMatrix();
glutSwapBuffers();
}
void myLight()
{
const GLfloat light_position[]={ 2.0f, 5.0f, -5.0f, 0.0f};
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0, GL_POSITION, light_position); 
}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week10");
glutDisplayFunc(display);
//glutKeyboardFunc(keyboard);//new! 0~255  ASCII 不含特殊鍵 
glutMouseFunc(mouse);//new!
glutMotionFunc(motion);
myLight();
//glutPassiveMotionFunc(passivenotion);
glutMainLoop();
}





沒有留言:

張貼留言