1-1.
https://jsyeh.org/3dcg10/windows.zip、data.zip(解壓縮)
把data拉到windows資料夾中(右上角換模式 下方可以 drag glRotatef-x y z)
1-2.*week05_rotate new-project-glut-week05_rotate(倒茶壺)
#include <GL/glut.h>
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(180,0,0,1);
glColor3f(1,1,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
int main( int argc, char**argv )
{
glutInit( &argc, argv);
glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow("week05 Rotate");
glutDisplayFunc(display);
glutMainLoop();
}
1-3.*week05_rotate new-project-glut-week05_rotate(正茶壺)
#include <GL/glut.h>
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(angle,0,0,1);
glColor3f(1,1,0);
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("week05 Rotate");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
1-4.*week05__rotate new-project-glut-week05_rotate(正茶壺)
#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);
glColor3f(1,1,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void mouse(int button,int state,int x,int y)
{
oldX=x;
}
void motion(int x,int y)
{
angle+=(x-oldX);
oldX=x;
display();
}
int main( int argc, char**argv )
{
glutInit( &argc, argv);
glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow("week05 Rotate");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
1-5.*week05__mouse new-project-glut-week05_mouse(鼠標按一下新增座標圖形)
#include <stdio.h>
#include <GL/glut.h>
int N=0;
int x[1000],y[1000];
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_LINE_LOOP);
for(int i=0;i<N;i++){
glVertex2f((x[i]-150)/150.0,-(y[i]-150)/150.0);
}
glEnd();
glutSwapBuffers();
}
void mouse(int button,int state,int mouseX,int mouseY)
{
if(state==GLUT_DOWN){
N++;
x[N-1]=mouseX;
y[N-1]=mouseY;
printf("現在按下滑鼠,得到新座標 %d %d\n",x[N-1],y[N-1]);
}
display();
}
int main( int argc, char**argv )
{
glutInit( &argc, argv);
glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow("week05 複習 mouse");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
}
1-6.*week05__mouse new-project-glut-week05_mouse(鼠標拖曳新增座標圖形)
#include <stdio.h>
#include <GL/glut.h>
int N=0;
int x[1000],y[1000];
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_LINE_LOOP);
for(int i=0;i<N;i++){
glVertex2f((x[i]-150)/150.0,-(y[i]-150)/150.0);
}
glEnd();
glutSwapBuffers();
}
void motion(int mouseX,int mouseY)
{
N++;
x[N-1]=mouseX;
y[N-1]=mouseY;
printf("現在按下滑鼠,得到新座標 %d %d\n",x[N-1],y[N-1]);
display();
}
int main( int argc, char**argv )
{
glutInit( &argc, argv);
glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow("week05 複習 mouse");
glutDisplayFunc(display);
glutMotionFunc(motion);
glutMainLoop();
}
沒有留言:
張貼留言