一:方塊TRT運用
1-1.
#include <GL/glut.h>
void display()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glRectf(0.5, 0.5, -0.5, -0.5);///畫四方形
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH );
glutInitWindowSize(600, 600);
glutCreateWindow("week13_rect_TRT");
glutDisplayFunc(display);
glutMainLoop();
}
void display()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glRectf(0.5, 0.5, -0.5, -0.5);///畫四方形
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH );
glutInitWindowSize(600, 600);
glutCreateWindow("week13_rect_TRT");
glutDisplayFunc(display);
glutMainLoop();
}
1-2.
#include <GL/glut.h>
void display()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glColor3f(1, 1, 1);
glRectf(0.5, 0.5, -0.5, -0.5);///畫四方形
glPushMatrix();
//glTranslatef();
//glRotatef();
//glTranslatef();
glColor3f(1, 0, 0);
glRectf(0.5, 0.5, 1.0, 0.7);///畫四方形
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH );
//glutInitWindowSize(600, 600);
glutCreateWindow("week13_rect_TRT");
glutDisplayFunc(display);
glutMainLoop();
}
1-3:
#include <GL/glut.h>
float angle=45;
void display()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glColor3f(1, 1, 1);
glRectf(0.5, 0.5, -0.5, -0.5);///畫四方形
glPushMatrix();
//glTranslatef();
glRotatef(angle, 0, 0, 1);///R
glTranslatef(-0.5, -0.4, 0);///T2
glColor3f(1, 0, 0);
glRectf(0.5, 0.5, 1.0, 0.3);///畫四方形
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH );
//glutInitWindowSize(600, 600);
glutCreateWindow("week13_rect_TRT");
glutDisplayFunc(display);
glutMainLoop();
1-4:
#include <GL/glut.h>
float angle=45, oldX=0;
void mouse(int button, int state, int x, int y){
oldX=x;
}
void motion(int x, int y){
angle+=(x-oldX);
oldX=x;
glutPostRedisplay();
}
void display()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glColor3f(1, 1, 1);
glRectf(0.5, 0.5, -0.5, -0.5);///畫四方形
glPushMatrix();
glTranslatef(0.5, 0.5, 0.5);///T1
glRotatef(angle, 0, 0, 1);///R
glTranslatef(-0.5, -0.4, 0);///T2
glColor3f(1, 0, 0);
glRectf(0.5, 0.5, 1.0, 0.3);///畫四方形
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH );
//glutInitWindowSize(600, 600);
glutCreateWindow("week13_rect_TRT");
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutDisplayFunc(display);
glutMainLoop();
}
二:
2-1:
#include <GL/glut.h>
float angle=45, oldX=0;
void mouse(int button, int state, int x, int y){
oldX=x;
}
void motion(int x, int y){
angle+=(x-oldX);
oldX=x;
glutPostRedisplay();
}
void display()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glColor3f(1, 1, 1);
glRectf(0.3, 0.5, -0.3, -0.2);///身體瘦身(對比1)
glPushMatrix();
glTranslatef(0.3, 0.5, 0.5);
glRotatef(angle, 0, 0, 1);///旋轉
glTranslatef(-0.5, -0.4, 0);///旋轉中心放正中心
glColor3f(1, 0, 0);
glRectf(0.5, 0.5, 1.0, 0.3);///上手臂
glPushMatrix();
///把下手肘掛在關節上
///旋轉
///把下手肘的旋轉中心放正中心
glColor3f(0, 1, 0);
glRectf(0.8, 0.5, 1.1, 0.3);///下手肘
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH );
//glutInitWindowSize(600, 600);
glutCreateWindow("week13_rect_TRT");
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutDisplayFunc(display);
glutMainLoop();
}
#include <GL/glut.h>
float angle=45, oldX=0;
void mouse(int button, int state, int x, int y){
oldX=x;
}
void motion(int x, int y){
angle+=(x-oldX);
oldX=x;
glutPostRedisplay();
}
void display()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glColor3f(1, 1, 1);
glRectf(0.3, 0.5, -0.3, -0.2);///身體瘦身(對比1)
glPushMatrix();
glTranslatef(0.3, 0.5, 0);
///glRotatef(angle, 0, 0, 1);///旋轉
glTranslatef(-0.3, -0.4, 0);///旋轉中心放正中心
glColor3f(1, 0, 0);
glRectf(0.3, 0.5, 0.8, 0.3);///上手臂
glPushMatrix();
glTranslatef(0.8, 0.4, 0);///把下手肘掛在關節上
glRotatef(angle, 0, 0, 1);///旋轉
glTranslatef(-0.8, -0.4, 0);///把下手肘的旋轉中心放正中心
glColor3f(0, 1, 0);
glRectf(0.8, 0.5, 1.1, 0.3);///下手肘
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH );
//glutInitWindowSize(600, 600);
glutCreateWindow("week13_rect_TRT");
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutDisplayFunc(display);
glutMainLoop();
}
#include <GL/glut.h>
float angle=45, oldX=0;
void mouse(int button, int state, int x, int y){
oldX=x;
}
void motion(int x, int y){
angle+=(x-oldX);
oldX=x;
glutPostRedisplay();
}
void display()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glColor3f(1, 1, 1);
glRectf(0.3, 0.5, -0.3, -0.2);///身體瘦身(對比1)
glPushMatrix();///右半邊
glTranslatef(0.3, 0.5, 0);
glRotatef(angle, 0, 0, 1);///旋轉
glTranslatef(-0.3, -0.4, 0);///旋轉中心放正中心
glColor3f(1, 0, 0);
glRectf(0.3, 0.5, 0.8, 0.3);///右上手臂
glPushMatrix();
glTranslatef(0.8, 0.4, 0);///把下手肘掛在關節上
glRotatef(angle, 0, 0, 1);///旋轉
glTranslatef(-0.8, -0.4, 0);///把下手肘的旋轉中心放正中心
glColor3f(0, 1, 0);
glRectf(0.8, 0.5, 1.1, 0.3);///右下手肘
glPopMatrix();
glPopMatrix();
glPushMatrix();///左半邊
glTranslatef(-0.3, 0.5, 0);
glRotatef(angle, 0, 0, 1);///旋轉
glTranslatef(+0.3, -0.4, 0);///旋轉中心放正中心
glColor3f(1, 0, 0);
glRectf(-0.3, 0.5, -0.8, 0.3);///左上手臂
glPushMatrix();
glTranslatef(-0.8, 0.4, 0);///把下手肘掛在關節上
glRotatef(angle, 0, 0, 1);///旋轉
glTranslatef(+0.8, -0.4, 0);///把下手肘的旋轉中心放正中心
glColor3f(0, 1, 0);
glRectf(-0.8, 0.5, -1.1, 0.3);///左下手肘
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH );
//glutInitWindowSize(600, 600);
glutCreateWindow("week13_rect_TRT");
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutDisplayFunc(display);
glutMainLoop();
}
3-1:
#include <GL/glut.h>
float angle[20], oldX=0;
int angleID=0;///0:第0個關節, 1:第1個關節...
void keyboard(unsigned char key, int x, int y){///鍵盤數字鍵決定旋轉部位
if(key=='0') angleID=0;///預設0
if(key=='1') angleID=1;
if(key=='2') angleID=2;
if(key=='3') angleID=3;
}
void mouse(int button, int state, int x, int y){
oldX=x;
}
void motion(int x, int y){
angle[angleID]+=(x-oldX);
oldX=x;
glutPostRedisplay();///重畫畫面
}
void display()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glColor3f(1, 1, 1);
glRectf(0.3, 0.5, -0.3, -0.2);///身體瘦身(對比1)
glPushMatrix();///右半邊
glTranslatef(0.3, 0.5, 0);
glRotatef(angle[0], 0, 0, 1);///旋轉
glTranslatef(-0.3, -0.4, 0);///旋轉中心放正中心
glColor3f(1, 0, 0);
glRectf(0.3, 0.5, 0.8, 0.3);///右上手臂
glPushMatrix();
glTranslatef(0.8, 0.4, 0);///把下手肘掛在關節上
glRotatef(angle[1], 0, 0, 1);///旋轉
glTranslatef(-0.8, -0.4, 0);///把下手肘的旋轉中心放正中心
glColor3f(0, 1, 0);
glRectf(0.8, 0.5, 1.1, 0.3);///右下手肘
glPopMatrix();
glPopMatrix();
glPushMatrix();///左半邊
glTranslatef(-0.3, 0.5, 0);
glRotatef(angle[2], 0, 0, 1);///旋轉
glTranslatef(+0.3, -0.4, 0);///旋轉中心放正中心
glColor3f(1, 0, 0);
glRectf(-0.3, 0.5, -0.8, 0.3);///左上手臂
glPushMatrix();
glTranslatef(-0.8, 0.4, 0);///把下手肘掛在關節上
glRotatef(angle[3], 0, 0, 1);///旋轉
glTranslatef(+0.8, -0.4, 0);///把下手肘的旋轉中心放正中心
glColor3f(0, 1, 0);
glRectf(-0.8, 0.5, -1.1, 0.3);///左下手肘
glPopMatrix();
glPopMatrix();
glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH );
//glutInitWindowSize(600, 600);
glutCreateWindow("week13_rect_TRT");
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutDisplayFunc(display);
glutMainLoop();
}
















沒有留言:
張貼留言