Week04
第四週一開始一樣先到 http://www.cmlab.csie.ntu.edu.tw/~jsyeh/3dcg10/ 網站
下載windows、data、glut32.dll
解壓縮,然後全部拉進windows資料夾裡
接下來點開transformations程式
試試看 glRotatef(角度,x,y,z);
複習上次上課所說的

#include <GL/glut.h>
void display()
{
glPushMatrix(); -->保護程式碼
glTranslatef(0.2,0.2,0);
glSolidTeapot(0.3);
glPopMatrix(); -->還原
glutSwapBuffers();
}
int main( int argc , char ** argv )
{
glutInit( &argc , argv );
glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow( "first window" );
glutDisplayFunc( display );
glutMainLoop( );
}
複習上次上課所說的

#include <GL/glut.h>
void display()
{
glPushMatrix(); -->保護程式碼
glTranslatef(0.2,0.2,0);
glSolidTeapot(0.3);
glPopMatrix(); -->還原
glutSwapBuffers();
}
int main( int argc , char ** argv )
{
glutInit( &argc , argv );
glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow( "first window" );
glutDisplayFunc( display );
glutMainLoop( );
}
開始交滑鼠移動
茶壺會跟著滑鼠移動耶!!
程式碼:
#include <GL/glut.h>
float x=0,y=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef( (x-150)/150.0,-(y-150)/150.0,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void motion(int nowx, int nowy)
{
x=nowx;y=nowy;
display();
}
int main( int argc , char ** argv )
{
glutInit( &argc , argv );
glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow( "week04" );
glutDisplayFunc( display );
glutMotionFunc(motion);
glutMainLoop( );
}
茶壺會跟著滑鼠移動耶!!
程式碼:
#include <GL/glut.h>
float x=0,y=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef( (x-150)/150.0,-(y-150)/150.0,0);
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void motion(int nowx, int nowy)
{
x=nowx;y=nowy;
display();
}
int main( int argc , char ** argv )
{
glutInit( &argc , argv );
glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow( "week04" );
glutDisplayFunc( display );
glutMotionFunc(motion);
glutMainLoop( );
}
--------------------------------------------------------------------------------------------------------------------------
接下來教旋轉
X軸旋轉
程式碼:
#include <GL/glut.h>
float x=0,y=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(x,0,1,0);///X軸旋轉
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void motion(int nowx, int nowy)
{
x=nowx;y=nowy;
display();
}
int main( int argc , char ** argv )
{
glutInit( &argc , argv );
glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow( "week04" );
glutDisplayFunc( display );
glutMotionFunc(motion);
glutMainLoop( );
}
Y軸旋轉
程式碼:
#include <GL/glut.h>
float x=0,y=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(y,1,0,0);///Y軸旋轉
glutSolidTeapot(0.3);
glPopMatrix();
glutSwapBuffers();
}
void motion(int nowx, int nowy)
{
x=nowx;y=nowy;
display();
}
int main( int argc , char ** argv )
{
glutInit( &argc , argv );
glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
glutCreateWindow( "week04" );
glutDisplayFunc( display );
glutMotionFunc(motion);
glutMainLoop( );
}





沒有留言:
張貼留言