week13
(1)
1-1.開 CodeBlocks/GLUT/GLUT
1-2.貼十行程式,把茶壺換Rect(); ->方形
#include <GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glRectf(0.3,0.5,-0.3,-0.5);
glutSwapBuffers();
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutInitWindowSize(600,600);
glutCreateWindow("Week13 rect");
glutDisplayFunc(display);
glutMainLoop();
}
1-3.刪註解 -->加顏色跟手臂 ,改軸心 ,加角度,手掛回身體
#include <GL/glut.h>
float angle=45;
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glColor3f(1,1,1);
glRectf(0.3,0.5,-0.3,-0.5);
glPushMatrix();
glColor3f(1,0,0);///紅
glRectf(0.3,0.5,0.7,0.3);
glPopMatrix();
glutSwapBuffers();
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
///glutInitWindowSize(600,600);
glutCreateWindow("Week13 rect");
glutDisplayFunc(display);
glutMainLoop();
}
1-4.按滑鼠可以旋轉手臂
#include <GL/glut.h>
float angle=45,oldX=0;
void mouse(int button,int state,int x,int y){
oldX=x;
}
void motion(int x,int y){
angle +=(x-oldX);
glutPostRedisplay();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glColor3f(1,1,1);
glRectf(0.3,0.5,-0.3,-0.5);
glPushMatrix();
glTranslatef(0.3,0.4,0);
glRotatef(angle,0,0,1);
glTranslatef(-0.3,-0.4,0);
glColor3f(1,0,0);
glRectf(0.3,0.5,0.7,0.3);
glPopMatrix();
glutSwapBuffers();
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
///glutInitWindowSize(600,600);
glutCreateWindow("Week13 rect");
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutDisplayFunc(display);
glutMainLoop();
}
(2)
2-1.
#include <GL/glut.h>
float angle=0,oldX=0;
void mouse(int button,int state,int x,int y){
oldX=x;
}
void motion(int x,int y){
angle +=(x-oldX);
glutPostRedisplay();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glColor3f(1,1,1);
glRectf(0.3,0.5,-0.3,-0.5);
glPushMatrix();
glTranslatef(0.3,0.4,0);
glRotatef(angle,0,0,1);
glTranslatef(-0.3,-0.4,0);
glColor3f(1,0,0);
glRectf(0.3,0.5,0.7,0.3);
glPushMatrix();
///glTranslatef(0.3,0.4,0);
///glRotatef(angle,0,0,1);
///glTranslatef(-0.3,-0.4,0);
glColor3f(0,1,0);
glRectf(0.7,0.5,1.0,0.3);
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
///glutInitWindowSize(600,600);
glutCreateWindow("Week13 rect");
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutDisplayFunc(display);
glutMainLoop();
}
#include <GL/glut.h>
float angle=45,oldX=0;
void mouse(int button,int state,int x,int y){
oldX=x;
}
void motion(int x,int y){
angle +=(x-oldX);
glutPostRedisplay();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glColor3f(1,1,1);
glRectf(0.3,0.5,-0.3,-0.5);
glPushMatrix();
glTranslatef(0.3,0.4,0);
///glRotatef(angle,0,0,1);
glTranslatef(-0.3,-0.4,0);
glColor3f(1,0,0);
glRectf(0.3,0.5,0.7,0.3);
glPushMatrix();
glTranslatef(0.7,0.4,0);
glRotatef(angle,0,0,1);
glTranslatef(-0.7,-0.4,0);
glColor3f(0,1,0);
glRectf(0.7,0.5,1.0,0.3);
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
///glutInitWindowSize(600,600);
glutCreateWindow("Week13 rect");
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutDisplayFunc(display);
glutMainLoop();
}
2-3.
#include <GL/glut.h>
float angle=45,oldX=0;
void mouse(int button,int state,int x,int y){
oldX=x;
}
void motion(int x,int y){
angle +=(x-oldX);
glutPostRedisplay();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glColor3f(1,1,1);
glRectf(0.3,0.5,-0.3,-0.5);
glPushMatrix();
glTranslatef(0.3,0.4,0);
glRotatef(angle,0,0,1);
glTranslatef(-0.3,-0.4,0);
glColor3f(1,0,0);
glRectf(0.3,0.5,0.7,0.3);
glPushMatrix();
glTranslatef(0.7,0.4,0);
glRotatef(angle,0,0,1);
glTranslatef(-0.7,-0.4,0);
glColor3f(0,1,0);
glRectf(0.7,0.5,1.0,0.3);
glPopMatrix();
glPopMatrix();
glPushMatrix();
glTranslatef(-0.3,0.4,0);
glRotatef(angle,0,0,1);
glTranslatef(0.3,-0.4,0);
glColor3f(1,0,0);
glRectf(-0.3 , 0.5 , -0.7 , 0.3);
glPushMatrix();
glTranslatef(-0.7,0.4,0);
glRotatef(angle,0,0,1);
glTranslatef(0.7,-0.4,0);
glColor3f(0,1,0);
glRectf(-0.7 , 0.5 , -1.0 , 0.3);
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
///glutInitWindowSize(600,600);
glutCreateWindow("Week13 rect");
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutDisplayFunc(display);
glutMainLoop();
}





沒有留言:
張貼留言