2022年5月17日 星期二

OuO圖學筆記Week13

step1-1 做一個長方形

#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 TRT");
    glutDisplayFunc(display);
    glutMainLoop();
}



step1-2 做一個手臂

#include <GL/glut.h>
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(x, y, z);///3手臂位置
        ///glRotatef( angle, 0, 0, 1);///2旋轉,對z軸
        ///glTranslatef(x2, y2, z2);///1旋轉軸中心
        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 TRT");

    glutDisplayFunc(display);

    glutMainLoop();
}



step
#include <GL/glut.h>
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(x, y, z);///3手臂位置
        ///glRotatef( angle, 0, 0, 1);///2旋轉,對z軸
        glTranslatef(-0.3, -0.4, 0);///1旋轉軸中心
        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 TRT");

    glutDisplayFunc(display);

    glutMainLoop();
}

step
#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();
        ///glTranslatef(x, y, z);///3手臂位置
        glRotatef( angle, 0, 0, 1);///2旋轉,對z軸
        glTranslatef(-0.3, -0.4, 0);///1旋轉軸中心
        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 TRT");

    glutDisplayFunc(display);

    glutMainLoop();
}


step
#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();
        glTranslatef(0.3, 0.4, 0);///3把手臂位置掛回去
        glRotatef( angle, 0, 0, 1);///2旋轉,對z軸
        glTranslatef(-0.3, -0.4, 0);///1旋轉軸中心
        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 TRT");

    glutDisplayFunc(display);

    glutMainLoop();
}


step 滑鼠可以旋轉手臂
#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);
    oldX = x;
    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);///3把手臂位置掛回去
        glRotatef( angle, 0, 0, 1);///2旋轉,對z軸
        glTranslatef(-0.3, -0.4, 0);///1旋轉軸中心
        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 TRT");

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

    glutMainLoop();
}


///Week13 rect TRT
#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);
    oldX = x;
    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);///3把手臂位置掛回去
        glRotatef( angle, 0, 0, 1);///2旋轉,對z軸
        glTranslatef(-0.3, -0.4, 0);///1旋轉軸中心
        glColor3f(1,0,0);///紅色
        glRectf(0.3, 0.5, 0.7, 0.3);///上手臂

        glPushMatrix();
            ///glTranslatef(x, y, z);
            ///glRotatef( angle, 0, 0, 1);
            ///glTranslatef(x2, y2, z2);
            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 TRT");

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

    glutMainLoop();
}


///Week13 rect TRT
#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);
    oldX = x;
    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);///3把手臂位置掛回去
        //glRotatef( angle, 0, 0, 1);///2旋轉,對z軸
        glTranslatef(-0.3, -0.4, 0);///1旋轉軸中心
        glColor3f(1,0,0);///紅色
        glRectf(0.3, 0.5, 0.7, 0.3);///上手臂

        glPushMatrix();
            ///glTranslatef(x, y, z);///3把手臂位置掛回去
            glRotatef( angle, 0, 0, 1);///2旋轉,對z軸
            glTranslatef(-0.7, -0.4, 0);///1手肘旋轉軸中心
            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 TRT");

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

    glutMainLoop();
}


把Rotate註解用掉

///Week13 rect TRT  複製手臂(鏡射)
#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);
    oldX = x;
    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);///3把手臂位置掛回去
        glRotatef( angle, 0, 0, 1);///2旋轉,對z軸
        glTranslatef(-0.3, -0.4, 0);///1旋轉軸中心
        glColor3f(1,0,0);///紅色
        glRectf(0.3, 0.5, 0.7, 0.3);///右上手臂

        glPushMatrix();
            glTranslatef(0.7, 0.4, 0);///3把手臂位置掛回去
            glRotatef( angle, 0, 0, 1);///2旋轉,對z軸
            glTranslatef(-0.7, -0.4, 0);///1手肘旋轉軸中心
            glColor3f(0,1,0);///綠色
            glRectf(0.7, 0.5, 1.0, 0.3);///右下手肘
        glPopMatrix();
    glPopMatrix();


    glPushMatrix();///左半邊
        glTranslatef(-0.3, 0.4, 0);///3把手臂位置掛回去
        glRotatef( angle, 0, 0, 1);///2旋轉,對z軸
        glTranslatef(0.3, -0.4, 0);///1旋轉軸中心
        glColor3f(1,0,0);///紅色
        glRectf(-0.3, 0.5, -0.7, 0.3);///左上手臂

        glPushMatrix();
            glTranslatef(-0.7, 0.4, 0);///3把手臂位置掛回去
            glRotatef( angle, 0, 0, 1);///2旋轉,對z軸
            glTranslatef(0.7, -0.4, 0);///1手肘旋轉軸中心
            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 TRT");

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

    glutMainLoop();
}


沒有留言:

張貼留言

VERY BEAUTIFUL, VERY POWERFUL

一.     一樣先安裝且設定好freeglut,OpecCV, 開啟CodeBlocks建立新專案 week11_gundam,                 把 MyGundam.zip下載解壓縮後的data資料夾放到freeglut/bin裡面 把week09_openc...