顯示具有 HW10 標籤的文章。 顯示所有文章
顯示具有 HW10 標籤的文章。 顯示所有文章

2014年5月29日 星期四

01163052_高健智, HW10, Week10

#include <Gl/glut.h>
#include <stdio.h>
float teapotX=0,teapotY=0;
float angleX=0,startX=0;
void keyboard(unsigned char key, int x, int y)
{
printf("%c %d %d\n",key, x, y);
if(key=='a' || key=='A') teapotX+=0.1;
if(key=='b' || key=='B') teapotX-=0.1;
if(key=='c' || key=='C') teapotY+=0.1;
if(key=='d' || key=='D') teapotY-=0.1;
glutPostRedisplay();
}
void mouse(int button, int state, int x, int y)
{
printf("%d %d %d %d\n",button ,state ,x ,y);
}

void motion(int x, int y)
{
printf("%d %d\n", x, y);
angleX+=(x-startX);
glutPostRedisplay();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(teapotX, teapotY, 0);
glRotatef(angleX,0,1,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week10");

glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMotionFunc(motion);

glutMainLoop();
}



2014年4月24日 星期四

01160766_吳逸凡, hw10,week10


01160873_林瑋真




第10周

#include <GL/glut.h>
#include <stdio.h>
float teapotX=0,teapotY=0,angleX=0,startX=0,angleY=0,startY=0;
void keyboard(unsigned char key, int x, int y)
{
printf("%c %d %d\n", key, x, y);
if(key=='a' || key=='A') teapotX+=0.1;
if(key=='b' || key=='B') teapotX-=0.1;
if(key=='c' || key=='C') teapotY+=0.1;
if(key=='d' || key=='D') teapotY-=0.1;
glutPostRedisplay();
}
void mouse(int button, int state, int x, int y)
{
printf("%d %d %d %d\n", button, state , x, y);
startX=x;
startY=y;
}
void motion(int x, int y)
{
printf("%d %d\n", x, y);
angleX+= (x-startX); startX = x;
angleY+= (y-startY); startY = y;
glutPostRedisplay();
}
void display()
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(teapotX, teapotY, 0);
glRotatef(angleX, 0, -1, 0);
glRotatef(angleY, -1, 0, 0);
glutSolidTeapot(0.3);
glPopMatrix();
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);
glutMouseFunc(mouse);
glutMotionFunc(motion);
myLight();
glutMainLoop();
}





第十週課堂作業

鍵盤移動茶壺
顯示滑鼠鍵盤的小黑視窗
滑鼠轉動茶壺
做出像maya的轉動(簡單版)




01160670_林浩正, HW10, Week10


week10(2)


01160686_葉梓灝,week10,HW10


第10週作業




week10,01160686_葉梓灝,HW10


第十周課堂作業


鍵盤控制移動



鍵盤控制顯示位置

滑鼠控制移動


滑鼠控制轉動


打光+旋轉







第十週課堂作業




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();
}





01160634_童琬尹, HW10, Week10




02362554 week10


第十周課堂作業


01160235_謝采玲, HW10, Week10

●按'w'、's'、'a'、'd'可以上下左右(下方2photo)

●將滑鼠左鍵的按下、移動、放開的位置輸出(下方photo)

●以x、y軸轉動&打光
●自由旋轉 :3


●打光
void myLight()
{
const GLfloat light_position[]={2.0f, 5.0f, -5.0, 0.0f};
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
}





Week10課堂作業


可上下左右移動的茶壺





可透過滑鼠轉動的茶壺(X軸)

可隨意旋轉的打光茶壺

打光程式碼

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);
}