2013年5月21日 星期二

513 的14


#include <GL/glut.h>
float rot = 0;
void box()
{
glColor3f(1,0,0);//紅色
glBegin(GL_POLYGON);//多邊型
glVertex3f(-0.3,-0.1,0);//四個頂點
glVertex3f( 0.3,-0.1,0);
glVertex3f( 0.3, 0.1,0);
glVertex3f(-0.3, 0.1,0);
glEnd();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

glPushMatrix();
glColor3f(1,1,1);
glutSolidTeapot(0.3);//茶壺提上來,放背景 
//glTranslatef(0.4,0.15,0);
glRotatef(rot,0,0,1);//第一步,旋轉,只影響下面化的東西
glTranslatef(0.3,0.1,0);//第二步,把物體移動,上面那行旋轉,會轉我們 
box();//劃出一個長條,在前面定義 

glPopMatrix();
glutSwapBuffers();
}
void keyboard(unsigned char key,int x,int y)
{
if (key=='a')rot++;
else if (key=='A')rot--;
glutPostRedisplay();
}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("a");

glutDisplayFunc(display);
glutKeyboardFunc(keyboard);

glutMainLoop();
return 0;
}



#include <GL/glut.h>
float rot = 0;
void box()
{
glColor3f(1,0,0);//紅色
glBegin(GL_POLYGON);//多邊型
glVertex3f(-0.3,-0.1,0);//四個頂點
glVertex3f( 0.3,-0.1,0);
glVertex3f( 0.3, 0.1,0);
glVertex3f(-0.3, 0.1,0);
glEnd();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

glPushMatrix();
glColor3f(1,1,1);
glutSolidTeapot(0.3);//茶壺提上來,放背景
//glTranslatef(0.4,0.15,0);
glTranslatef(0.45,0.15,0);//第三步,把物體移動到特定位子

glRotatef(rot,0,0,1);//第一步,旋轉,只影響下面化的東西
glTranslatef(0.3,0.1,0);//第二步,把物體移動,上面那行旋轉,會轉我們
box();//劃出一個長條,在前面定義

glPopMatrix();
glutSwapBuffers();
}
void keyboard(unsigned char key,int x,int y)
{
if (key=='a')rot++;
else if (key=='A')rot--;
glutPostRedisplay();
}
int main()
{
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("a");

glutDisplayFunc(display);
glutKeyboardFunc(keyboard);

glutMainLoop();
return 0;
}

--------------------------------------------------------

glPushMatrix();

glTranslatef( 0.1,  0.8, 0);//第三步
glRotatef(-50, 0,0,1);//第一步
glTranslatef( 0.6, 0, 0);//第二步
drawWeapon();

glPopMatrix();


Homework 5: 試著做出 2D 鋼鐵人





我做了一隻很可愛的海綿寶寶,我讓她的"右手"
和"領帶"會轉動!!超級可愛




沒有留言:

張貼留言