2023年3月23日 星期四

LAD Week06_階層的轉動

 week06-1_TRT_Robot2_teapot

使用上週程式碼做更改
#include <GL/glut.h>
float angle = 0;
void myCube()
{
glPushMatrix();
glScaled(0.5,0.2,0.2);
glutSolidCube(1);
glPopMatrix();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1,1,1);
glutSolidCube(1);
glPushMatrix();
glTranslatef(0.5,0.5,0);
glRotatef(angle,0.5,0.2,1);
glTranslatef(0.25,0,0);
glColor3f(0,1,0);
myCube();
glPopMatrix();
glPushMatrix();
glTranslatef(-0.5,0.5,0);
glRotatef(angle,0.5,0.2,1);
glTranslatef(0.25,0,0);
glColor3f(0,1,0);
myCube();
glPopMatrix();
glutSwapBuffers();
angle++;
}
int main(int argc, char* argv[] )
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("week05");
glutDisplayFunc(display);
glutIdleFunc(display);
glutMainLoop();
}


圖片更改成茶壺,使其把手掛置選轉軸中心,茶壺把手固定做旋轉
掛在新的位置上

week06-2_robot3_hierarchy

先畫出一個小方塊

加上TRT後再畫出其他小方塊

完成手臂

week06-3_TRT_robot4_arm_hand_left

加入左手手臂,將右手的x軸加上負號即可

week06-4_TRT_robot5_mouse_motion_angle

將angle錢加上負號,旋轉時方可己較自然,再增加滑鼠的函式,使其angle等於x的座標,在註解掉,則可使用滑鼠操控可使用滑鼠操控

練習期中考

https://jsyeh.org/gl/opengl_10_func.html
1.  glPushMatrix(); //備份矩陣 (得到10分)
2.    glTranslatef(x,y,z); //平移 (得到10分)
3.    glRotatef(angle,x,y,z); //旋轉旋轉 (得到10分)
4.    glScalef(x,y,z); //縮放 (得到10分)
5.    glBegin(GL_POLYGON); //開始畫 (得到10分)
6.       glColor3f(r,g,b);//色彩     (得到10分)
7.       glTexCoord2f(tx,ty);//貼圖座標 (得到10分)
8.       glNormal3f(nx,ny,nz);//打光的法向量 (得到10分)
9.       glVertex2f(x,y);//頂點 (得到10分)
10.   glEnd(); //結束畫
11. glPopMatrix(); //還原矩陣 (得到10分)

mouse motion控制

可準確控制角度

沒有留言:

張貼留言