加入旋轉 amgle
程式碼:
#include <GL/glut.h>
int N=0, vx[3000], vy[3000];
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); ///清空
glPushMatrix();
glRotatef(angle, 0, 0, 1); ///旋轉, 對z軸轉
glScalef(0.5, 0.1, 0.1); ///調成細長的
glColor3f(0.3,0.3,1.0); ///藍藍的
glutSolidCube(1); ///方塊
glPopMatrix(); ///還原矩陣
glutSwapBuffers(); ///交換兩倍的buffers
}
void motion( int x, int y)
{
angle++;
display(); ///增加後,重畫畫面
}
void keyboard( unsigned char key, int x, int y)
{
}
int main(int argc, char ** argv)
{
glutInit( &argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("08160766我是聰明人");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMotionFunc(motion);
glutMainLoop();
}
程式碼:
#include <GL/glut.h>
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(angle++, 0,0,1);
glColor3f(0.2,0.2,1.0);
glutSolidCube(1);
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char ** argv)
{
glutInit( &argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("08160766我是聰明人");
glutIdleFunc(display);
glutDisplayFunc(display); ///(4)等一下要顯示的函式
glutMainLoop(); ///(5)主要迴圈
}
程式碼:
#include <GL/glut.h>
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
///glRotatef(angle++, 0,0,1);
///glColor3f(0.2,0.2,1.0);
glTranslatef(-0.25,0,0); ///將旋轉中心, 放在正中心
glScalef(0.5,0.1,0.1); ///細細長長的
glutSolidCube(1); ///方塊
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char ** argv)
{
glutInit( &argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH); ///顯示模式
glutCreateWindow("08160766我是聰明人"); ///開窗
glutIdleFunc(display); ///idle很閒的時候, 就重畫面
glutDisplayFunc(display);
glutMainLoop();
}
程式碼:
#include <GL/glut.h>
float angle=0;
void hand()
{
glPushMatrix();
glScalef(0.5,0.1,0.1);
glutSolidCube(1);
glPopMatrix();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(-0.25,0,0); ///把正確轉動的手臂,掛在肩上
glRotatef(angle++, 0,0,1); ///轉動
glTranslatef(-0.25,0,0); ///將旋轉中心,放在正中心
hand();
glPopMatrix();
hand();
glutSwapBuffers();
}
int main(int argc, char ** argv)
{
glutInit( &argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("08160766我是聰明人");
glutIdleFunc(display);
glutDisplayFunc(display);
glutMainLoop();
}
程式碼:
#include <GL/glut.h>
float angle=0;
void hand()
{
glPushMatrix();
glScalef(0.5,0.1,0.1);
glutSolidCube(1);
glPopMatrix();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(-0.25,0,0);
glRotatef(angle, 0,0,1);
///glColor3f(0.2,0.2,1.0);
glTranslatef(-0.25,0,0);
hand();
glPushMatrix();
glTranslatef(-0.25, 0, 0);
glRotatef(angle, 0,0,1);
glTranslatef(-0.25,0,0);
hand();
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
angle++;
}
int main(int argc, char ** argv)
{
glutInit( &argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("08160766我是聰明人");
glutIdleFunc(display);
glutDisplayFunc(display);
glutMainLoop();
}
程式碼:
#include <GL/glut.h>
float angle=0;
void hand()
{
glPushMatrix();
glScalef(0.5,0.1,0.1);
glutSolidCube(1);
glPopMatrix();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix(); ///左手臂
glTranslatef(-0.25,0,0);
glRotatef(angle, 0,0,1);
///glColor3f(0.2,0.2,1.0);
glTranslatef(-0.25,0,0);
hand(); ///上手臂
glPushMatrix();
glTranslatef(-0.25, 0, 0);
glRotatef(angle, 0,0,1);
glTranslatef(-0.25,0,0);
hand(); ///下手肘
glPopMatrix();
glPopMatrix();
glPushMatrix(); ///右手臂
glTranslatef(+0.25,0,0);
glRotatef(-angle, 0,0,1);
///glColor3f(0.2,0.2,1.0);
glTranslatef(+0.25,0,0);
hand(); ///上手臂
glPushMatrix();
glTranslatef(+0.25, 0, 0);
glRotatef(-angle, 0,0,1);
glTranslatef(+0.25,0,0);
hand(); ///下手肘
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
angle++;
}
int main(int argc, char ** argv)
{
glutInit( &argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("08160766我是聰明人");
glutIdleFunc(display);
glutDisplayFunc(display);
glutMainLoop();
}
完整註解的程式碼👇
#include <GL/glut.h>
float angle=0;
void hand()
{
glPushMatrix();
glScalef(0.5,0.1,0.1);
glutSolidCube(1);
glPopMatrix();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix(); ///左半邊
glTranslatef(-0.25,0,0); ///手臂,掛上去肩關節
glRotatef(angle, 0,0,1); ///轉動
glTranslatef(-0.25,0,0); ///將旋轉中心,放在正中心
hand(); ///上手臂
glPushMatrix();
glTranslatef(-0.25, 0, 0); ///把正確轉動的手臂,掛在肘關節
glRotatef(angle, 0,0,1); ///轉動
glTranslatef(-0.25,0,0); ///將旋轉中心,放在正中心
hand(); ///下手肘
glPopMatrix();
glPopMatrix();
glPushMatrix(); ///右半邊
glTranslatef(+0.25,0,0); ///手臂,掛上去肩關節
glRotatef(-angle, 0,0,1); ///轉動
glTranslatef(+0.25,0,0); ///將旋轉中心,放在正中心
hand(); ///上手臂
glPushMatrix();
glTranslatef(+0.25, 0, 0); ///把正確轉動的手臂,掛在肘關節
glRotatef(-angle, 0,0,1); ///轉動
glTranslatef(+0.25,0,0); ///將旋轉中心,放在正中心
hand(); ///下手肘
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
angle++;
}
int main(int argc, char ** argv)
{
glutInit( &argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("08160766我是聰明人");
glutIdleFunc(display);
glutDisplayFunc(display);
glutMainLoop();
}






沒有留言:
張貼留言