好作品上傳




Test Transformation

實作
Mouse進階
C
#include<GL/glut.h>
void display()
{
glClearColor(1,1,0,0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1,0,0);
glTranslatef(0,0.1,0);
glutSolidTeapot(0.3);
glutSwapBuffers();
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DEPTH);
glutCreateWindow("hello3D");
glutDisplayFunc(display);
glutMainLoop();
}
每點撃一次滑鼠移動茶壺
#include<GL/glut.h>
float nowX=0, nowY=0;
void mouse(int button,int state,int x,int y)
{
nowX=(x-150)/150.0;nowY=-(y-150)/150.0;
}
void display()
{
glClearColor(1,1,0,0);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glTranslatef(nowX,nowY,0);
glColor3f(1,0,0);
glTranslatef(0,0.1,0);
glutSolidTeapot(0.3);
glutSwapBuffers();
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DEPTH);
glutCreateWindow("hello3D");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
}
點撃滑鼠自由驅動茶壺上下方位

#include<GL/glut.h>
#include<stdio.h>
#include<math.h>
float nowX=0, 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()
{
glClearColor(1,1,0,1);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glTranslatef(nowX,nowY,0);
glColor3f(1,0,0);
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();
glutSwapBuffers();
}
int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DEPTH);
glutCreateWindow("hello3D");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop();
}
圓for(迴圈)、配上cos() sin()


沒有留言:
張貼留言