Week05
(1)
1-1. 在 https://jsyeh.org/3dcg10,下載data , win32
1-2. 解壓縮,把data放到windows裡
1-3.開Transformation.exe
1-4.下方區域按右鍵,點S(上下兩行程式交換)
(2)
2-1. File-New-Project , 開GLUT
2-2. 設定freeglut
2-3. 程式碼全刪
2-4. 茶壺 按一個鍵可以定位
#include <GL/glut.h>
#include <stdio.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glColor3f(1,1,0);
glutSolidTeapot(0.3);
glutSwapBuffers();
}
void keyboard (unsigned char key, int x ,int y)
{
printf("你按下了 %C 在 %d %d 座標\n",key,x,y);
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("Week05 keyboard");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
}
2-5.做成可隨著滑鼠移動(接續上面)
藍->
橘->
綠->
紫#include <GL/glut.h>
#include <stdio.h>
float x=150,y=150,z=0,scale=1.0 ;
int oldX=0,oldY=0;
void display()
{
glClearColor(0.5,0.5,0.5,1); ///R,G,B,A 其中A半透明功能,目前沒開
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef((x-150)/150.0,-(y-150)/150.0,z);
glScalef(scale,scale,scale);
glColor3f(1,1,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void keyboard (unsigned char key, int mousex ,int mousey)
{
}
void mouse(int button,int state,int mousex,int mousey)
{
oldX=mousex; oldY=mousey;
}
void motion(int mousex,int mousey)
{
if(mousex=oldX>0) scale*=1.01;
if(mousex=oldX>0) scale*=0.99;
/// x+=(mousex-oldX); y+=(mousey-oldY);
oldX=mousex; oldY=mousey;
display();
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("Week05 keyboard");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
沒有留言:
張貼留言