今天內容: 旋轉rotate 示範glRotatef / 滑鼠motion v.s. 移動旋轉 / 自動產生Code法
/1/ 先下載解壓縮[data][win32] glut32.dll
在桌面創一個windows的資料夾,把解壓縮後的data、win32、glut32.dill放進去
開啟 Transformation.exe
嘗試glRotatef (x,y,z角度)
/2/打開 codeblocks 並新增一個project
打出程式碼:
#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( );
}
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( );
}
跑程式就會出現可以用滑鼠移動的茶壺
更改程式就會變成可以旋轉的茶壺了
程式碼:(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( );
}
沒有留言:
張貼留言