Week03 1-1進到https://jsyeh.org/3dcg10,下載data、win32
再將windows.zip、data.zip解壓縮 1-2將data放到windows裡面,執行Transformation.exe,試試看換模型及調整下方
上週程式新增
void display()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glPushMatrix(); 備份矩陣 移動會累積,因為會修改矩陣
glTranslated(0.5,0.5,0); 右上角
glColor3f(1,1,0);
glutSolidTeapot(0.3);
glPopMatrix();還原矩陣(舊的位置)
glutSwapBuffers();
}
進階:
#include <GL/glut.h>
void myteapot(float x, float y)
{
glPushMatrix();
glTranslatef(x, y,0);
glColor3f(1,1,0);
glutSolidTeapot(0.3);
glPopMatrix();
}
void display()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
myteapot(0.5,0.5);
myteapot(0.5,-0.5);
myteapot(-0.5,0.5);
myteapot(-0.5,-0.5);
glutSwapBuffers();
}
int main(int argc, char** argv)
{
glutInit( &argc, argv);
glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow("week03 移動");
glutDisplayFunc(display);
glutMainLoop() ;
}
用滑鼠寫程式:
#include<GL/glut.h>
#include<stdio.h>
float mouseX=0, mouseY=0;
void myteapot(float x, float y)
{
glPushMatrix();
glTranslatef(x, y, 0);
glColor3f(1,1,0);
glutSolidTeapot(0.1);
glPopMatrix();
}
void display()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
myteapot( (mouseX-150)/150.0,-(mouseY-150)/150.0); 座標換算
glutSwapBuffers();
}
void mouse(int button, int state, int x, int y)
{
printf("%d %d %d %d\n", button ,state,x,y);
mouseX=x; mouseY=y;
}
int main(int argc, char** argv)
{
glutInit( &argc, argv);
glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow("week03 ²¾°Ê");
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutMainLoop() ;
}
沒有留言:
張貼留言