✌階層轉動
✨打開上週程式
_________________________________________________________________________✨新增選轉
#include <GL/glut.h>
#include <stdio.h>
float vx[2000],vy[2000];
int N=0;
float angle=0;///宣告角度
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(angle,0,0,1);///選轉
glScalef(0.5,0.1,0.1);///變形
glColor3f(0.3,0.3,1.0);///顏色
glutSolidCube(1);///方形
glPopMatrix();
glutSwapBuffers();
}
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("mouse week05");
glutDisplayFunc(display);
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);///轉動角度
glutSolidCube(1);
glPopMatrix();
glutSwapBuffers();
}
int main(int argc,char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("mouse week06");
glutIdleFunc(display);///idle很閒時 一直跑display
glutDisplayFunc(display);
glutMainLoop();
}
___________________________________________________________________________
✨改變方塊旋轉中心
🧷程式
🧷程式
#include <GL/glut.h>
float angle=0;
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
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("mouse week06");
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();
glPopMatrix();
hand();
glutSwapBuffers();
}
int main(int argc,char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("mouse week06");
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();
glutSwapBuffers();
angle++;///移動
}
int main(int argc,char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("mouse week06");
glutIdleFunc(display);
glutDisplayFunc(display);
glutMainLoop();
}
🧷程式
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++;
}







沒有留言:
張貼留言