顯示具有 09163626_劉宥駒 標籤的文章。 顯示所有文章
顯示具有 09163626_劉宥駒 標籤的文章。 顯示所有文章

2023年6月1日 星期四

劉 電腦圖學

 Week 16 總複習

下載Git bash



開啟新專案 week16_all



老師範例==> https://github.com/jsyeh/2023graphicsb/tree/main/week16_all

1.2.3.點線面顏色、移動/旋轉/縮放放與




4.5.6.
階層性關節轉動(T-R-T)



7.
做出機器人


8.
機器人上色


9.


10.




11.12.


13.14.15



16.17.18










19.

https://github.com/jsyeh/2023graphicsb/blob/main/week16_all/step19.cpp 


20.

https://github.com/jsyeh/2023graphicsb/blob/main/week16_all/step20.cpp


21.

https://github.com/jsyeh/2023graphicsb/blob/main/week16_all/step21.cpp


22.

https://github.com/jsyeh/2023graphicsb/blob/main/week16_all/step22.cpp

2023年5月25日 星期四

劉 電腦圖學

 Week 15 Camera 攝影機、投影、運鏡

  

第一堂課

下載windows.zip  data.zip 並解壓縮



開啟檔案





gluLookAt 的九個參數可以調

安裝Git 

下載程式倉庫


開啟新的GLUT 專案 Week15-1_gluLookAt

.



新增程式碼




glutMotionFunc(motion);





float eyeX = 0, eyeY = 0;
void motion(int x, int y)
{
    eyeX = 3*(x-320)/320.0;
    eyeY = 3*(240-y)/240.0;
    glLoadIdentity();
    gluLookAt(eyeX, eyeY, 3, 0, 0, -6, 0, 1, 0);
    glutPostRedisplay();
}



第二堂課




gluPerspective(fovy, aspect, zNear, zFar)

fov:視野張開的角度

aspect:長寬比



開啟新GLUT專案 week15-2_gluPerspective



新增程式碼glOrtho(-ar*3, ar*3, -1.0*3, 1.0*3, 2.0, 100.0);



第三堂課

開啟新專案week15-3_gluPerspective_gluLookAt

#include <GL/glut.h>
void display(){
     glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

     glutSolidTeapot( 0.3 );
     glutSwapBuffers();
}
void motion(int x, int y){
     glLoadIdentity();
     float eyeX = (x-150)/150.0,  eyeY = (150-y)/150.0;
     gluLookAt(eyeX,eyeY,1, 0, 0, 0,  0, 1,0);
     glutPostRedisplay();
}
int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week15");

    glutMotionFunc(motion);
    glutDisplayFunc(display);

    glutMainLoop();
}




新增程式碼
#include <GL/glut.h>
void display(){
     glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

     glutSolidTeapot( 0.3 );
     glutSwapBuffers();
}
void motion(int x, int y){
     glLoadIdentity();
     float eyeX = (x-150)/150.0,  eyeY = (150-y)/150.0;
     gluLookAt(eyeX,eyeY,1, 0, 0, 0,  0, 1,0);
     glutPostRedisplay();
}
void reshape(int w,int h){
    float ar = w / (float) h;
    glViewport(0, 0, w, h);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(60, ar,0.01,1000);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(0,0,1,  0,0,0,  0,1,0);
}
int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week15");

    glutReshapeFunc(reshape);
    glutMotionFunc(motion);
    glutDisplayFunc(display);

    glutMainLoop();
}






2023年5月18日 星期四

劉 電腦圖學

 week 14

主題 切換關節

第一堂課

下載 github



開新的GLUT專案week14-timer

將之前的10行程式碼複製貼上
並新增程式碼

#include <GL/glut.h>
float angle= 0;
void timer(int t)
{
    glutTimerFunc(500, timer, t+1);
    angle += 90;
    glutPostRedisplay();
}
void display()
{
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    glPushMatrix();
     glRotatef(angle, 0, 0, 1);
     glutSolidTeapot( 0.3 );
   glPopMatrix();
   glutSwapBuffers();
}
   int main(int argc, char**argv)
{

  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
  glutCreateWindow("week14");

  glutTimerFunc(3000, timer, 0);
  glutDisplayFunc(display);

  glutMainLoop();

}



開新專案week14-2_timer_play
將14-1貼上

#include <GL/glut.h>
float angle= 0;
void timer(int t)
{
    glutTimerFunc(500, timer, t+1);
    angle += 90;
    glutPostRedisplay();
}
void keyboard(unsigned char key, int x, int y)
{
    glutTimerFunc(0, timer, 0);
}


void display()
{
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    glPushMatrix();
     glRotatef(angle, 0, 0, 1);
     glutSolidTeapot( 0.3 );
   glPopMatrix();
   glutSwapBuffers();
}
   int main(int argc, char**argv)
{

  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
  glutCreateWindow("week14");

  glutKeyboardFunc(keyboard);
  glutDisplayFunc(display);

  glutMainLoop();

}



                                                  會旋轉


第二堂課

開啟Excel
week14-3 使用Excel



將week14-1,week14-2 備份到github



開新的GLUT專案week14-3_timer_alpha_interpolation
將14-2貼上


#include <GL/glut.h>
float angle= 0, newAngle = 0, oldAngle = 0;
float oldx = 0;
void timer(int t)
{
    if(t<100) glutTimerFunc(33, timer, t+1);
    float alpha = t/100.0;
    angle = alpha*newAngle + (1-alpha)*oldAngle;
    glutPostRedisplay();
}
void keyboard(unsigned char key, int x, int y)
{
    glutTimerFunc(0, timer, 0);
}
void mouse(int button, int state, int x, int y){
     if(state==GLUT_DOWN) oldAngle = angle;
     if(state==GLUT_UP) newAngle = angle;
     oldx = x;
     glutPostRedisplay();
}
void motion(int x, int y){
     angle += x-oldx;
     oldx = x;
     glutPostRedisplay();
}

void display()
{
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    glPushMatrix();
     glRotatef(angle, 0, 0, 1);
     glutSolidTeapot( 0.3 );
   glPopMatrix();
   glutSwapBuffers();
}
   int main(int argc, char**argv)
{

  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
  glutCreateWindow("week14");

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

  glutMainLoop();

}




可以用滑鼠來旋轉






第三堂課
開啟Final_project


進行修改