2022年3月15日 星期二

古利夏醫生的艾爾迪亞日記week04



安培右手定則

右手握住螺線管,四根手指朝著電流方向指去,然後將大拇指沿著螺線管的中心軸伸直,則磁場的方向即為大拇指所指的方向。 右手定則也可以用來辨明一條電線四周磁場的方向。 對於這用法,右手定則稱為「安培右手定則」,或「安培定則」。
2.茶壺轉動程式碼:#include <GL/glut.h>static void display(void){    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);    glPushMatrix();    glRotatef(90,0,0,1);    glutSolidTeapot(0.3);    glPopMatrix();    glutSwapBuffers();}int main(int argc,char**argv){    glutInit( &argc,argv);    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);    glutCreateWindow("week04_Rotate");    glutDisplayFunc(display);    glutMainLoop();}


茶壺可以用滑鼠轉動(motion)
程式碼:#include <GL/glut.h>float angle=0;void display(){    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);    glPushMatrix();    glRotatef(angle,0,0,1);    glutSolidTeapot(0.3);    glPopMatrix();    glutSwapBuffers();}void motion(int x,int y){    angle = x;    display();}int main(int argc,char**argv){    glutInit( &argc,argv);    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);    glutCreateWindow("week04_Rotate");    glutDisplayFunc(display);    glutMotionFunc(motion);    glutMainLoop();}
week04-3 
程式碼:#include <GL/glut.h>float angle=0,oldX=0;void display(){    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);    glPushMatrix();    glRotatef(angle,0,0,1);    glutSolidTeapot(0.3);    glPopMatrix();    glutSwapBuffers();}void motion(int x,int y){    angle += (x-oldX);    oldX = x;    display();}void mouse(int button,int state,int x,int y){    oldX = x;}int main(int argc,char**argv){    glutInit( &argc,argv);    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);    glutCreateWindow("week04_Rotate");    glutDisplayFunc(display);    glutMotionFunc(motion);    glutMouseFunc(mouse);    glutMainLoop();}











沒有留言:

張貼留言

VERY BEAUTIFUL, VERY POWERFUL

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