功能实现:根据OpenGL提供的直线,多边形绘制算法,实现基于鼠标交互的卡通人物设计与绘制。使用颜色填充与反走样技术对人脸进行绘制。实现对卡通人脸的交互控制,点击鼠标左键可以对人脸进行拖拽移动。按“↑”按键能够实现卡通人脸绕坐标原点进行旋转。
附加要求:选中其中的一个多边形区域,点击鼠标右键,弹出一个菜单,可以对该区域进行不同颜色的选择。
#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>
#include<iostream>
#include<fstream>
#include <iostream>
#include <string>
#include<math.h>
using namespace std;
float xc;//鼠标左键按下时的x坐标
float yc;//鼠标左键按下时的y坐标
float dx;//移动距离
float dy;
float hair[7][2]={
{12,43},{-12,40},{-30,20},{-6,32},{4,25},{15,37},{30,32}};
float leftbrow[4][2]={
{-15,20},{-11,24},{-4,25},{0,22}};
float rightbrow[4][2]={
{7,22},{12,26},{17,27},{22,22}};
float face[5][2]={
{-22,24},{-18,-9},{2,-23},{22,-5},{27,33}};
float eyes[2][2]={
{-6,19},{14,20}};
float nose[3][2]={
{4,19},{-8,-1},{8,-1}};
float mouth[4][2]={
{-14,-7},{17,-4},{10,-11},{-1,-13}};
float box_hair[4]={-30,30,20,43};//包围盒,分别为Xmin,Xmax,Ymin,Ymax
float box_nose[4]={-8,8,-1,19};
float box_mouth[4]={-14,17,-13,-4};
bool moving = false; //是否处于移动人脸的状态
bool change_color=false;
int color[6]={1,2,3,4,5,6};//hair,nose,mouth,face,brow,eye
int in_polygon;
float theta=0;
GLfloat colors[7][3] = { {1.0, 1.0, 1.0 }, { 1.0, 0.0, 0.0 },
{ 0.0, 1.0, 0.0 }, { 0.0, 0.0, 1.0 }, { 0.0, 1.0, 1.0 },
{ 1.0, 0.0, 1.0 }, { 1.0, 1.0, 0.0 } };