作業互評上傳





課堂(2)
//translate
//rotate
//右手原理(右手安培定則)
//scale
課堂(3)(4)
glPushMatrix();
glTranslatef(x,y,z);
glPopMatrix();
mouse移動
程式碼:
#include <GL/glut.h>
float nowx=0;float nowy=0;
void mouse(int button, int state, int x, int y)
{
nowx =(x-150)/150.0; nowy =-(y-150)/150.0;
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT); //把屏幕上的颜色清空
glClearColor(1,1,0,0);
glPushMatrix();//備份Matrix
glTranslatef(nowx,nowy,0);
glColor3f(1,0.25,0.2); //改顏色RGBA
glutSolidTeapot(0.3);
glPopMatrix();//還原Matrix
glutSwapBuffers();
}
int main( int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("hello3D");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
}

課堂(5)
程式碼:
#include <GL/glut.h>
#include<stdio.h>
#include<math.h>
float nowx=0;float nowy=0;
void mouse(int button, int state, int x, int y)
{
nowx =(x-150)/150.0; nowy =-(y-150)/150.0;
printf("glTranslatef(%f,%f,0);\n",nowx,nowy);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT); //把屏幕上的颜色清空
glClearColor(1,1,0,0);
glPushMatrix();//備份Matrix
glTranslatef(nowx,nowy,0);
glColor3f(0,0,0); //改顏色RGBA
//glutSolidTeapot(0.3);
glBegin(GL_POLYGON);
for(float angle=0; angle<3.14159265358979*2;angle+=0.1){
glVertex2f(0.2*cos(angle),0.2*sin(angle));
}
glEnd();
glPopMatrix();//還原Matrix
glutSwapBuffers();
}
int main( int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow("hello3D");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
}
沒有留言:
張貼留言