根据OpenGL提供的直线,多边形绘制算法(橡皮筋效果),实现基于鼠标交互的卡通人物设计与绘制。使用颜色填充与反走样技术对卡通人物外貌以及衣着进行绘制。实现对卡通人物轮廓的交互控制,点击鼠标左键可以对人物五官位置进行拖拽移动调整。按“↑”按键能够实现卡通人物绕坐标原点(或指定点)进行旋转。
附加要求:选中其中的一个多边形区域,点击鼠标右键,弹出一个菜单,可以对该区域进行不同颜色的选择。可以设计发型、衣服的模版,当作文件进行存储,可以在窗口最右边设计一个模板库,显示保存的发型与衣服,拖拽到卡通人物上可以为卡通人物进行发型或者衣服的替换。

#include<iostream>
#include <windows.h>
#include <GL/glu.h>
#include <GL/gl.h>
#include <GL/glut.h>
#include <math.h>
#include <stdio.h>
using namespace std;#define MAX_CHAR    128int window_width = 600;
int window_height = 400;#define LEFT_EYE    1
#define RIGHT_EYE   2
#define LEFT_ARM    3
#define RIGHT_ARM   4
#define JU_PAI      5
#define MOUTH       6
#define HAIR        7
#define TIE         8#define BUFSIZE     512GLuint selectBuf[BUFSIZE];const double PI = 3.1415926;static GLenum mode = GL_RENDER;//判断被选中的是哪个物体
BOOL leftEye_Selected;
BOOL rightEye_selected;
BOOL leftArm_Selected;
BOOL rightArm_Selected;
BOOL juPai_Selected;
BOOL mouth_Selected;
BOOL hair_Selected;
BOOL tie_Selected;/*
drawJuPai(100, 50);
drawMoxigan(220, 150);
glLoadName(RIGHT_ARM);
drawRightArm(-100, 0);glLoadName(LEFT_ARM);
drawLeftArm(-100, 0);glLoadName(MOUTH);
drawMouth(-100,60);
//画眼睛
glLoadName(LEFT_EYE);
drawLeftEye(-65,50);glLoadName(RIGHT_EYE);
drawRightEye(-135,50);
*/
//物体初始坐标
GLuint leftEye[2] = { -65, 50 };
GLuint rightEye[2] = { -135, 50 };
GLuint leftArm[2] = { -50, 0 };
GLuint rightArm[2] = { -150, 0 };
GLuint juPai[2] = { 100, 50 };
GLuint mouth[2] = { -100, 60 };
GLuint hair[2] = { 220, 150 };
GLuint tie[2] = {100,150};int body[2] = { -100, 50 };
static int theta = 0;//获取被选中改变颜色的物体
int selectedToChangeColor = -1;
//颜色数组
double lefteye_color[3] = { 1., 1., 1. };
double righteye_color[3] = { 1., 1., 1. };
double leftarm_color[3] = { 1., 1., 1. };
double rightarm_color[3] = { 1., 1., 1. };
double mouth_color[3] = { 1, 0.8, 0 };
double jupai_color[3] = { 1., 1., 1. };
double tie_color[3] = { 1.0, 0.5, 0 };
double hair_color[3] = { 0.8, 0.2, 0.8 };//菜单颜色
double black[3] = { 0., 0., 0. };
double pink[3] = { 0.95, 0.62, 0.76 };
double yellowishbrown[3] = { 1, 0.8, 0 };
double oranger[3] = { 1.0, 0.5, 0 };
double brown[3] = {0.5,0.25,0.};
double purple[3] = { 0.8, 0.2, 0.8 };
double white[3] = { 1.0, 1.0, 1.0 };GLfloat fAspect;void drawString(const char* str) {static int isFirstCall = 1;static GLuint lists;if (isFirstCall) { // 如果是第一次调用,执行初始化// 为每一个ASCII字符产生一个显示列表isFirstCall = 0;// 申请MAX_CHAR个连续的显示列表编号lists = glGenLists(MAX_CHAR);// 把每个字符的绘制命令都装到对应的显示列表中wglUseFontBitmaps(wglGetCurrentDC(), 0, MAX_CHAR, lists);}// 调用每个字符对应的显示列表,绘制每个字符for (; *str != '\0'; ++str)glCallList(lists + *str);
}
//画圆(tianchong)
void drawCircle(int N, double radius, int angleStart = 0, int angleEnd = 360, double x = 0,double y=0,double s1=1.,double s2=1.){glBegin(GL_POLYGON);double start = (double)angleStart / 360.0*N;double end = (double)angleEnd / 360 * N;for (int i = start; i <end+1; i++){glVertex3f(x+s1*cos(i * 2 * PI / N)*radius,y+ s2*sin(i * 2 * PI / N) *radius, 0.5);}glEnd();
}
//画圆(不填充)
void drawCircle2(int N, double radius, int angleStart = 0, int angleEnd = 360, int x = 0, int y = 0, double s1 = 1., double s2 = 1.){glLineWidth(0.6);glBegin(GL_LINE_STRIP);double start = (double)angleStart / 360.0*N;double end = (double)angleEnd / 360 * N;for (int i = start; i <end+1; i++){glVertex3f(x+s1*cos(i * 2 * PI / N)*radius,y + s2*sin(i * 2 * PI / N) *radius, 0.5);}glEnd();
}//画左眼
void drawLeftEye(int x,int y){glLoadIdentity();glTranslatef(body[0], body[1], 0);glRotatef(theta, 0, 0, 1);glTranslatef(-body[0], -body[1], 0);//睫毛glColor3f(0.0f, 0.0f, 0.0f);glBegin(GL_LINES);glVertex3f(x+0,y+10,0.5);glVertex3f(x+0, y+15, 0.5);glVertex3f(x+5,y + 5*sqrt(3), 0.5);glVertex3f(x+10, y+13, 0.5);glVertex3f(x-5, y+5 * sqrt(3), 0.5);glVertex3f(x-10,y+13, 0.5);glEnd();//眼线drawCircle2(100, 10,0,360,x,y);//眼珠drawCircle(20, 2,0,360,x,y);//眼白glColor3f(lefteye_color[0], lefteye_color[1], lefteye_color[2]);drawCircle(20, 10,0, 360, x, y);
}
//画右眼
void drawRightEye(int x,int y){glLoadIdentity();glTranslatef(body[0], body[1], 0);glRotatef(theta, 0, 0, 1);glTranslatef(-body[0], -body[1], 0);glColor3f(0.0f, 0.0f, 0.0f);//睫毛glColor3f(0.0f, 0.0f, 0.0f);glBegin(GL_LINES);glVertex3f(x+0,y+ 10, 0.5);glVertex3f(x+0, y+15, 0.5);glVertex3f(x+5,y+ 5 * sqrt(3), 0.5);glVertex3f(x+10, y+13, 0.5);glVertex3f(x-5, y+5 * sqrt(3), 0.5);glVertex3f(x-10, y+13, 0.5);glEnd();//画眼线drawCircle2(100,10,0,360,x,y);//眼珠drawCircle(20, 2, 0, 360, x, y);//眼白glColor3f(righteye_color[0], righteye_color[1], righteye_color[2]);//glTranslatef(-40,50, 0);drawCircle(20, 10, 0, 360, x, y);}
//画嘴巴
void drawMouth(int x,int y){glLoadIdentity();glTranslatef(body[0], body[1], 0);glRotatef(theta, 0, 0, 1);glTranslatef(-body[0], -body[1], 0);//描边glColor3f(0,0,0);//下嘴唇//glTranslatef(x,y,0);drawCircle2(50, 40, 235, 305,x, y);//上色glColor3f(mouth_color[0], mouth_color[1], mouth_color[2]);drawCircle(50, 40, 235, 305,x,y);//上嘴唇//glTranslatef(0,-61,0);glColor3f(0, 0, 0);drawCircle2(50,40,55,125,x,y-61);//上色glColor3f(mouth_color[0], mouth_color[1], mouth_color[2]);drawCircle(50, 40, 55, 125,x,y-61);glColor3f(0, 0, 0);//glTranslatef(0, 30, 0);glBegin(GL_LINES);glVertex3f(x-25,y-31,0.5);glVertex3f(x+25, y-31, 0.5);glEnd();}
//画脑袋和身体
void drawHeadandBody(int x,int y){glLoadIdentity();glTranslatef(body[0], body[1], 0);glRotatef(theta, 0, 0, 1);glTranslatef(-body[0], -body[1], 0);////描边glColor3f(0,0,0);drawCircle2(50,60,0,180,x,y);glBegin(GL_LINE_STRIP);glVertex3f(x+60, y, 0.5f);glVertex3f(x+65, y-150, 0.5f);glVertex3f(x-65, y-150, 0.5f);glVertex3f(x-60, y, 0.5f);glEnd();glColor3f(1.0f, 1.0f, 1.0f);//画脑袋drawCircle(50,60,0,360,x,y);//画身体glBegin(GL_POLYGON);glVertex3f(x+60,y,0.5f);glVertex3f(x-60, y, 0.5f);glVertex3f(x-65,y-150, 0.5f);glVertex3f(x+65, y-150, 0.5f);glEnd();
}
void drawLeftArm(int x,int y){glLoadIdentity();glTranslatef(body[0], body[1], 0);glRotatef(theta, 0, 0, 1);glTranslatef(-body[0],-body[1],0);glTranslatef(x,y,0);glRotatef(30, 0, 0, 1);glTranslatef(-x,-y,0);glColor3f(1,1,1);drawCircle(50,50,180,360,x,y,0.25);glColor3f(0, 0, 0);drawCircle2(50, 50, 180, 360,x,y,0.23);drawCircle2(50, 50, 180, 360, x, y, 0.24);drawCircle2(50, 50, 180, 360, x, y, 0.25);drawCircle2(50, 50, 180, 360, x, y, 0.26);}
void drawRightArm(int x, int y){glLoadIdentity();glTranslatef(body[0], body[1], 0);glRotatef(theta, 0, 0, 1);glTranslatef(-body[0], -body[1], 0);glTranslatef(x, y, 0);glRotatef(-30, 0, 0, 1);glTranslatef(-x, -y, 0);glColor3f(1, 1, 1);drawCircle(50, 50, 180, 360, x, y, 0.25);glColor3f(0, 0, 0);drawCircle2(50, 50, 180, 360, x, y, 0.23);drawCircle2(50, 50, 180, 360, x, y, 0.24);drawCircle2(50, 50, 180, 360, x, y, 0.25);drawCircle2(50, 50, 180, 360, x, y, 0.26);}
void drawTie(int x,int y){glLoadIdentity();glTranslatef(x, y, 0);glRotatef(theta, 0, 0, 1);glTranslatef(-x, -y, 0);glTranslatef(x,y,0);glColor3f(tie_color[0],tie_color[1],tie_color[2]);glBegin(GL_POLYGON);glVertex3f(-9, 2, 0.5);glVertex3f(-9, -2, 0.5);glVertex3f(9, -2, 0.5);glVertex3f(9, 2, 0.5);glEnd();glColor3f(0, 0, 0);drawCircle2(20, 10);glColor3f(1, 0.8, 0);drawCircle(20, 10);glTranslatef(0,5,0);glColor3f(tie_color[0], tie_color[1], tie_color[2]);glBegin(GL_POLYGON);glVertex3f(-60,0,0.5);glVertex3f(-60,-10, 0.5);glVertex3f(60, -10, 0.5);glVertex3f(60, 0, 0.5);glEnd();}
void drawJuPai(int x,int y){glLoadIdentity();glTranslatef(x, y, 0);glRotatef(theta, 0, 0, 1);glTranslatef(-x, -y, 0);glTranslatef(x, y, 0);glColor3f(0, 0, 0);//描边(牌子glBegin(GL_LINE_STRIP);glVertex3f(-30, 20, 0.5);glVertex3f(-30, -20, 0.5);glVertex3f(30, -20, 0.5);glVertex3f(30, 20, 0.5);glEnd();glBegin(GL_LINE_STRIP);glVertex3f(-5, -20, 0.5);glVertex3f(-5, -50, 0.5);glVertex3f(5, -50, 0.5);glVertex3f(5, -20, 0.5);glEnd();//牌子glColor3f(jupai_color[0], jupai_color[1], jupai_color[2]);glBegin(GL_POLYGON);glVertex3f(-30, 20, 0.5);glVertex3f(-30, -20, 0.5);glVertex3f(30, -20, 0.5);glVertex3f(30, 20, 0.5);glEnd();glBegin(GL_POLYGON);glVertex3f(-5, -20, 0.5);glVertex3f(-5, -50, 0.5);glVertex3f(5, -50, 0.5);glVertex3f(5, -20, 0.5);glEnd();//手glTranslatef(-40,-70,0);glRotatef(120, 0, 0, 1);glScalef(0.25, 1, 1);glColor3f(1, 1, 1);drawCircle(100, 50, 180, 360);glColor3f(0, 0, 0);drawCircle2(100, 50, 180, 360);}void drawMoxigan(int x,int y){glLoadIdentity();glTranslatef(x, y, 0);glRotatef(theta, 0, 0, 1);glTranslatef(-x, -y, 0);glTranslatef(x,y,0);glRotatef(-50, 0, 0, 1);glColor3f(hair_color[0],hair_color[1],hair_color[2]);drawCircle(50,50,0,90);glTranslatef(50, 0, 0);glRotatef(30, 0, 0, 1);glTranslatef(-50, 0, 0);drawCircle(50, 50, 0, 90);glTranslatef(50, 0, 0);glRotatef(30,0,0,1);glTranslatef(-50,0,0);drawCircle(50, 50, 0, 90);
}void drawClothes(int x,int y){}
void myDisplay()
{/**************伊丽莎白de衣服(开始)**********************/if (mode==GL_SELECT)glPushName(TIE);drawTie(tie[0], tie[1]);if (mode == GL_SELECT)glPushName(JU_PAI);drawJuPai(juPai[0],juPai[1]);if (mode == GL_SELECT)glPushName(HAIR);drawMoxigan(hair[0], hair[1]);/**************伊丽莎白de衣服(结束)**********************//**************伊丽莎白(开始)**********************/glColor3f(1.0f, 1.0f, 1.0f);if (mode == GL_SELECT)glPushName(RIGHT_ARM);drawRightArm(rightArm[0], rightArm[1]);if (mode == GL_SELECT)glPushName(LEFT_ARM);drawLeftArm(leftArm[0], leftArm[1]);if (mode == GL_SELECT)glPushName(MOUTH);drawMouth(mouth[0],mouth[1]);//画眼睛if (mode == GL_SELECT)glPushName(LEFT_EYE);drawLeftEye(leftEye[0],leftEye[1]);if (mode == GL_SELECT)glPushName(RIGHT_EYE);drawRightEye(rightEye[0],rightEye[1]);//华脑袋和身体if (mode == GL_SELECT)glPushName(-1);drawHeadandBody(body[0],body[1]);/**************伊丽莎白(结束)**********************/glPopMatrix();}void testDisplay(){glColor3f(1.0, 0.0, 0.0);if (mode == GL_SELECT)glLoadName(100);glPushMatrix();glBegin(GL_QUADS);glVertex3f(-0.1, 0, 0);glVertex3f(0.1, 0, 0);glVertex3f(0.1, 0.1, 0);glVertex3f(-0.1, 0.1, 0);glEnd();glPopMatrix();/*glColor3f(0.0, 0.0, 1.0);if (mode == GL_SELECT)glLoadName(101);glPushMatrix();glBegin(GL_QUADS);glVertex3f(-0.3, -0.1, 0);glVertex3f(-0.2, -0.1, 0);glVertex3f(-0.2, -0.2, 0);glVertex3f(-0.3, -0.2, 0);glEnd();glPopMatrix();*//*glColor3f(0.0, 0.0, 1.0);if (mode == GL_SELECT)glLoadName(102);glPushMatrix();glBegin(GL_QUADS);glVertex3f(-0.1, -0.1, 0);glVertex3f(0.1, -0.1, 0);glVertex3f(0.1, -0.2, 0);glVertex3f(-0.1, -0.2, 0);glEnd();glPopMatrix();*///glColor3f(1.0f, 1.0f, 0.0f);//if (mode == GL_SELECT)//glLoadName(102);//glPushMatrix();drawCircle(10,0.05,0,360,0.5,0.5);///*//glBegin(GL_POLYGON);//for (int i = 0; i <21; i++){//  glVertex3f(0.5 + cos(i * 2 * PI / 20)*0.05, 0.5 + sin(i * 2 * PI / 20) *0.05, 0);//}//glEnd();*///glBegin(GL_POLYGON);//glVertex3f(-0.3, -0.1, 0);//glVertex3f(-0.2, -0.1, 0);//glVertex3f(-0.2, -0.2, 0);//glVertex3f(-0.3, -0.2, 0);//glEnd();//glPopMatrix();//glutSwapBuffers();
}void judegSectedObject(int x,int y){glClear(GL_COLOR_BUFFER_BIT);GLint hits, viewport[4];glGetIntegerv(GL_VIEWPORT, viewport); //获得viewport  glSelectBuffer(BUFSIZE, selectBuf);   //指定将“图元列表”(点击记录)返回到selectBuf数组中mode = GL_SELECT;glRenderMode(mode);   //进入选择模式glInitNames();glMatrixMode(GL_PROJECTION);//进入投影阶段准备拾取glPushMatrix();//保存原来的投影矩阵glLoadIdentity();gluPickMatrix(x, viewport[3]-y,1,1,viewport);glOrtho(-300, 300, -200, 200, -10, 10);glMatrixMode(GL_MODELVIEW);glLoadIdentity(); myDisplay();//testDisplay();glMatrixMode(GL_PROJECTION);glPopMatrix();  // 返回正常的投影变换  mode = GL_RENDER;hits = glRenderMode(mode);cout << hits;if (hits > 0){GLuint name, *ptr;ptr = selectBuf;int selected_num = 0;for (int i = 0; i < hits; i++){name = *ptr;ptr += 3;ptr += name - 1;cout << i << ":" << *ptr << endl;BOOL timeToBreak = false;if (selected_num == 0){switch (*ptr){case LEFT_EYE:cout << "left eye" << endl;leftEye_Selected = true;selectedToChangeColor = LEFT_EYE;selected_num++;break;case RIGHT_EYE:rightEye_selected = true;selectedToChangeColor = RIGHT_EYE;selected_num++;cout << "right eye" << selected_num << endl;break;case TIE:cout << "tie" << endl;tie_Selected = true;selectedToChangeColor = TIE;selected_num++;break;case JU_PAI:cout << "jupai" << endl;juPai_Selected = true;selectedToChangeColor = JU_PAI;selected_num++;break;case HAIR:cout << "hair" << endl;hair_Selected = true;selectedToChangeColor = HAIR;selected_num++;break;case LEFT_ARM:cout << "left arm" << endl;leftArm_Selected = true;selected_num++;break;case RIGHT_ARM:cout << "right arm" << endl;rightArm_Selected = true;selected_num++;break;case MOUTH:cout << "mouth" << endl;mouth_Selected = true;selectedToChangeColor = MOUTH;selected_num++;break;default:timeToBreak = false;break;}}}}glMatrixMode(GL_MODELVIEW);}
void mouseClick(int btn, int state, int x, int y){if (btn == GLUT_LEFT_BUTTON&&state == GLUT_DOWN){std::cout << "鼠标落下:" << x << "," << y << std::endl;judegSectedObject(x, y);}if (btn == GLUT_LEFT_BUTTON&&state == GLUT_UP){std::cout << "鼠标抬起:" << x << "," << y << std::endl;leftEye_Selected = false;rightEye_selected = false;leftArm_Selected = false;rightArm_Selected = false;juPai_Selected = false;mouth_Selected = false;hair_Selected = false;tie_Selected = false;}
}void init(){glEnable(GL_POINT_SMOOTH);glEnable(GL_LINE_SMOOTH);glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); // Make round points, not square points  glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);  // Antialias the lines  glEnable(GL_BLEND);glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);leftEye_Selected = false;rightEye_selected = false;leftArm_Selected = false;rightArm_Selected = false;juPai_Selected = false;mouth_Selected = false;hair_Selected = false;tie_Selected = false;glEnable(GL_DEPTH_TEST);glClearColor(0.5, 0.5, 0.5, 1);glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}void display(){glMatrixMode(GL_PROJECTION);glPushMatrix();glLoadIdentity();glOrtho(-300, 300, -200, 200, -10, 10);glMatrixMode(GL_MODELVIEW);//glLoadIdentity();myDisplay();glutSwapBuffers();
}
void upToRotate(int key,int x,int y){if (key == GLUT_KEY_UP){theta += 10;glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);display();}if (key == GLUT_KEY_DOWN){theta -= 10;glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);display();}}
void mouseDrag(int x, int y){std::cout << "鼠标拖动:" << x << "," << y << std::endl;if (leftEye_Selected){leftEye[0] = x - window_width / 2;leftEye[1] = window_height / 2 - y;}if (rightEye_selected){rightEye[0] = x - window_width / 2;rightEye[1] = window_height / 2 - y;}if (leftArm_Selected){leftArm[0] = x - window_width / 2;leftArm[1] = window_height / 2 - y;}if (rightArm_Selected){rightArm[0] = x - window_width / 2;rightArm[1] = window_height / 2 - y;}if (juPai_Selected){juPai[0] = x - window_width / 2;juPai[1] = window_height / 2 - y;}if (mouth_Selected){mouth[0] = x - window_width / 2;mouth[1] = window_height / 2 - y + 25;}if (hair_Selected){hair[0] = x - window_width / 2;hair[1] = window_height / 2 - y;}if (tie_Selected){tie[0] = x - window_width / 2;tie[1] = window_height/ 2 - y;}glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT);display();/*glutPostRedisplay();*/
}
void menu(int index){double color[3] = { 0., 0., 0. };/*double yellowishbrown[3] = { 1, 0.8, 0 };double oranger[3] = { 1.0, 0.5, 0 };double brown[3] = { 0.5, 0.25, 0. };double purple[3] = { 0.8, 0.2, 0.8 };double white[3] = { 1.0, 1.0, 1.0 };*/switch (index){case 0:color[0] = black[0];color[1] = black[1];color[2] = black[2];break;case 1:color[0] = pink[0];color[1] = pink[1];color[2] = pink[2];break;case 2:color[0] = yellowishbrown[0];color[1] = yellowishbrown[1];color[2] = yellowishbrown[2];break;case 3:color[0] = oranger[0];color[1] = oranger[1];color[2] = oranger[2];break;case 4:color[0] = brown[0];color[1] = brown[1];color[2] = brown[2];break;case 5:color[0] = purple[0];color[1] = purple[1];color[2] = purple[2];break;case 6:color[0] = white[0];color[1] = white[1];color[2] = white[2];break;default:break;}switch (selectedToChangeColor){case LEFT_EYE:cout << "zuoyan yanse " << index << endl;lefteye_color[0] = color[0];lefteye_color[1] = color[1];lefteye_color[2] = color[2];break;case RIGHT_EYE:cout << "youyan yanse " << index << endl;righteye_color[0] = color[0];righteye_color[1] = color[1];righteye_color[2] = color[2];break;case LEFT_ARM:leftarm_color[0] = color[0];leftarm_color[1] = color[1];leftarm_color[2] = color[2];break;case RIGHT_ARM:rightarm_color[0] = color[0];rightarm_color[1] = color[1];rightarm_color[2] = color[2];break;case MOUTH:mouth_color[0] = color[0];mouth_color[1] = color[1];mouth_color[2] = color[2];break;case JU_PAI:jupai_color[0] = color[0];jupai_color[1] = color[1];jupai_color[2] = color[2];break;case HAIR:hair_color[0] = color[0];hair_color[1] = color[1];hair_color[2] = color[2];break;case TIE:tie_color[0] = color[0];tie_color[1] = color[1];tie_color[2] = color[2];break;default:break;}glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);display();
}void ChangeSize(int w, int h)
{window_width = w;window_height = h;if (h == 0) h = 1;glViewport(0, 0, w, h);fAspect = (GLfloat)w / (GLfloat)h;glMatrixMode(GL_PROJECTION);glLoadIdentity();if (w <= h){glOrtho(-300, 300, -200 * fAspect, 200 * fAspect, -10, 10);}else{glOrtho(-300 * fAspect, 300 * fAspect, -200, 200, -10, 10);}glMatrixMode(GL_MODELVIEW);glLoadIdentity();}
int main(int argc, char* argv[]){glutInit(&argc, argv);glutInitDisplayMode(GLUT_DOUBLE| GLUT_RGB | GLUT_DEPTH);glutInitWindowSize(window_width,window_height);glutCreateWindow("伊丽莎白");init();glutReshapeFunc(ChangeSize);glutDisplayFunc(display);glutMouseFunc(mouseClick);glutMotionFunc(mouseDrag);glutSpecialFunc(upToRotate);glutCreateMenu(menu);glutAddMenuEntry("黑色", 0);glutAddMenuEntry("粉色", 1);glutAddMenuEntry("土黄色", 2);glutAddMenuEntry("橙色",3);glutAddMenuEntry("棕色", 4);glutAddMenuEntry("紫色", 5);glutAddMenuEntry("白色", 6);glutAttachMenu(GLUT_RIGHT_BUTTON);glutMainLoop();return 0;
}

运行效果:

计算机图形学——二维卡通人物交互设计相关推荐

  1. OpenGL初探:二维卡通人物交互设计

    使用OpenGL实现基于鼠标交互的卡通人物和其它环境物体的设计与绘制.使用颜色填充与反走样技术对卡通人物外貌以及衣着进行绘制.实现对卡通人物或物体轮廓的交互控制,点击鼠标左键可以对人物或者物体进行拖拽 ...

  2. 计算机图形学实验——二维卡通人物交互

    计算机图形学实验1.2卡通人物交互 OpenGL卡通人物交互 基础"图元"绘制 OpenGL拾取物体 反走样 略提反走样问题 OpenGL实现二维反走样 放缩.旋转和拖动 小结 O ...

  3. 计算机图形学二维变换知识点,计算机图形学 二维变换及二维.ppt

    计算机图形学 二维变换及二维 第三章 二维变换及二维观察 本章主要内容 3.1二维图形的基本变换 3.2窗口视图变换 3.3复合变换 3.4二维图形裁剪 3.5本章小结 3.1 二维图形的基本变换 3 ...

  4. 计算机图形学二维图形基本变换实验原理,计算机图形学实验:二维图形变换.docx...

    计算机图形学实验:二维图形变换.docx (9页) 本资源提供全文预览,点击全文预览即可全文预览,如果喜欢文档就下载吧,查找使用更方便哦! 19.90 积分 实验三 二维图形变换一.实验任务1. 通 ...

  5. 计算机图形学二维图形基本变换实验原理,江苏大学-计算机图形学第三次实验报告-二维图形变换...

    <江苏大学-计算机图形学第三次实验报告-二维图形变换>由会员分享,可在线阅读,更多相关<江苏大学-计算机图形学第三次实验报告-二维图形变换(13页珍藏版)>请在人人文库网上搜索 ...

  6. 计算机图形学-二维图形变换 笔记总结与代码实战

    文章目录 1.向量基础知识 2.图形坐标系 3.二维图形变换原理 4.二维图形几何变换 5.窗口视区变换 基本二维几何变换代码 二维复合变换实战-五星红旗绘制 1.向量基础知识 为什么向量如此重要:在 ...

  7. 计算机图形学——二维图形几何转换

    文章目录 一.实验目的 二.实验要求 三.实验步骤 1.打开直线扫面转换MFC项目工程,及其中的直线类CLine. 2.二维点类CP2添加齐次坐标 3.设计实现二维图像几何变换类 1.新建二维图形几何 ...

  8. 计算机图形学二维图形基本变换实验原理,【实验课件】二维及三维图形基本变换的实现...

    实验二 二维及三维图形基本变换的实现 一.实验学时 4学时 二.实验类型 设计型实验 三.实验目的和要求 1. 掌握二维图形变换的原理,对一条直线实现二维基本变换(平移.错切.比例.旋转). 2. 掌 ...

  9. 计算机图形学--二维图形变换

    目录 概述 平移 对称 旋转 错切 缩放 概述 对于二维图形来讲,所有基本变换均可以通过确定图形的点的平移.对称.旋转.错切以及缩放几种变换组合得到,而在上述几种变换中,除对称变换外,其余变换均可通过 ...

最新文章

  1. cacti监控服务器的数据迁移
  2. 【2019暑假刷题笔记-树的遍历】总结
  3. 【网络协议】TCP中的四大定时器
  4. 【转】ABP源码分析二:ABP中配置的注册和初始化
  5. Linux Shell脚本专栏_批量主机远程执行命令脚本_08
  6. Angular 2 之七 依赖注入
  7. 【LeetCode】49. Group Anagrams
  8. leap通过掌心或手指的某一关节做一条射线
  9. cad安装日志文件发生错误_Cad2012安装总是到60%左右失败,现贴出安装出错的安装日志文件,望大神帮忙解决下...
  10. 三菱plc恒压供水程序+威纶触摸屏程序本成已用于实际项目中
  11. 许可证加密的WMV文件破解
  12. CSS 边框 border属性
  13. dfuse 和 EOS Studio 携手让开发者工具更上一层楼
  14. mac文件反选_【PS反选键是什么?】Photoshop该如何进行反向选择?
  15. 一、计算机基础: 特点、数制、编码、组成
  16. kali下载软件时出现“部分索引文件下载失败,如果忽略他们,那将转而使用旧的索引文件”
  17. oracle11g导入或导出dump文件
  18. InputStreamReader、BufferedReader输出内容的区别
  19. Python与Ansys apdl有限元系列二:矩阵位移法计算桁架结构
  20. 让我思潮翻滚的IBM面试内容

热门文章

  1. 工笔佛像怎么看和基本线条怎么画
  2. 艺赛旗RPA--经验分享:Python 中的“特殊”函数
  3. 数据链路层 (一)------ 计算机网络(三)
  4. 模板语言(VTL):入门
  5. android设置EditText为不可编辑状态
  6. ASP.NET Ajax调用WCF服务示例dudu
  7. Python 提取图片中的GPS信息
  8. 基于QT实现的图元拖曳、定点滚轮旋转和缩放
  9. php文件域的作用,在word中何为域
  10. 51单片机small compact large区别