图形学卡通人物绘制以及交互操作

先来个要求吧:

 根据OpenGL提供的直线,多边形绘制算法(橡皮筋效果),实现基于鼠标交互的卡通人物设计与绘制。使用颜色填充与反走样技术对卡通人物外貌以及衣着进行绘制。实现对卡通人物轮廓的交互控制,点击鼠标左键可以对人物五官位置进行拖拽移动调整。按“↑”按键能够实现卡通人物绕坐标原点(或指定点)进行旋转。

附加要求:选中其中的一个多边形区域,点击鼠标右键,弹出一个菜单,可以对该区域进行不同颜色的选择。可以设计发型、衣服的模版,当作文件进行存储,可以在窗口最右边设计一个模板库,显示保存的发型与衣服,拖拽到卡通人物上可以为卡通人物进行发型或者衣服的替换。


以下是代码:


#include "stdafx.h"
#include <windows.h>
#include <GL/glu.h>
#include <GL/gl.h>
#include <GL/glut.h>
#include <GL/glaux.h>
#include <math.h> 
#include <stdio.h>

#pragma comment(lib,"glaux.lib")

#define Glass	1
#define Stone	2
#define Eye     3
#define Eye1    4
#define Nose    5
#define Cap     6
#define Crown   7
#define Clothes 8
#define Superman 9
#define PI 3.1416
#define MAX_CHAR 128  

static int EYE_COLOR=0;
static int EYE1_COLOR=0;
static int NOSE_COLOR=0;
static int CROWN_COLOR=6;
static int SUPERMAN_COLOR=3;


GLuint texture[4];
GLuint base;

BOOL GLASS_STATE;
BOOL STONE_STATE;
BOOL EYE_STATE;
BOOL EYE1_STATE;
BOOL NOSE_STATE;
BOOL CAP_STATE;
BOOL CROWN_STATE;
BOOL CLOTHES_STATE;
BOOL SUPERMAN_STATE;


GLuint GlassCor[2] = {0,0};
GLuint StoneCor[2] = {20,10};
GLuint EyeCor[2] = {-12,60};
GLuint EyeCor1[2] = {12,60};
GLuint NoseCor[2]={0,60};
GLuint CapCor[2]={0,85};
GLuint CrownCor[2]={0+118,9+70};
GLuint ClothesCor[2]={0+110,0-50};
GLuint SupermanCor[2]={0,0};

int Wide = 0;
int High = 0;

const int N=40;  
float xx[50],yy[50]={0}; 

int select_part=0;

static GLfloat theta =0; 

static GLfloat colors[8][3] = {   
    { 0.0, 0.0, 0.0 }, { 1.0, 0.0, 0.0 },  { 0.0, 1.0, 0.0 }, {0.5,0.5,0.75 },   
	{ 0.0, 1.0, 1.0 }, { 1.0, 0.0, 1.0 }, { 1.0, 1.0, 0.0 }, { 1.0, 1.0, 1.0 }};  

void paintViewportA();
void drawString(const char* str);  
void selectFont(int size, int charset, const char* face);

void DrawSphereTexture(int x,int y)
{	

   glEnable(GL_BLEND);             //启用混合功能,将图形颜色同周围颜色相混合  
   glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);  
   glEnable(GL_POINT_SMOOTH);       //点抗锯齿  
   glEnable(GL_LINE_SMOOTH);        //线抗锯齿  
   glEnable(GL_POLYGON_SMOOTH);     //多边形抗锯齿  
 
   

   glLoadIdentity ();
   glRotatef (-30.0, 0.0, 0.0, 1.0);
   glRotatef(theta, 0.0, 0.0, 1.0);  
   //第三步 画手臂   左
   glColor3f(1.0f,1.0f,1.0f);  
   glBegin(GL_POLYGON);          //用线进行图形连接  
   for(int i=0;i<N;i++)  
   {  
   xx[i]=16*cos(2*i*PI/N)-28;  
   yy[i]=40*sin(2*i*PI/N)-10;  
   glVertex2f(xx[i],yy[i]);  
   }
   glEnd();
   //再描一遍线
   glColor3f(0.0f,0.0f,0.0f);
   glBegin(GL_LINE_LOOP);           
   for(int i=0;i<N;i++)  
   {  
   xx[i]=16*cos(2*i*PI/N)-28;  
   yy[i]=40*sin(2*i*PI/N)-10;  
   glVertex2f(xx[i],yy[i]);  
   }
   glEnd();

   //画手臂  右

   glLoadIdentity ();
   glRotatef(theta, 0.0, 0.0, 1.0);  
   glRotatef (30.0, 0.0, 0.0, 1.0);
   glColor3f(1.0f,1.0f,1.0f);  
   glBegin(GL_POLYGON);          //用线进行图形连接  
   for(int i=0;i<N;i++)  
   {  
   xx[i]=16*cos(2*i*PI/N)+28;  
   yy[i]=40*sin(2*i*PI/N)-10;  
   glVertex2f(xx[i],yy[i]);  
   }
   glEnd();
   //再描一遍线
   glColor3f(0.0f,0.0f,0.0f);
   glBegin(GL_LINE_LOOP);           
   for(int i=0;i<N;i++)  
   {  
   xx[i]=16*cos(2*i*PI/N)+28;  
   yy[i]=40*sin(2*i*PI/N)-10;  
   glVertex2f(xx[i],yy[i]);  
   }
   glEnd();


   //开始画腿************************************************************************
   glLoadIdentity ();
   glRotatef(theta, 0.0, 0.0, 1.0);  
   glRotatef (8.0, 0.0, 0.0, 1.0);
   glColor3f(1.0f,1.0f,1.0f);  
   glBegin(GL_POLYGON);          //用线进行图形连接  
   for(int i=0;i<N;i++)  
   {  
   xx[i]=15*cos(2*i*PI/N)-22;  
   yy[i]=33*sin(2*i*PI/N)-37;  
   glVertex2f(xx[i],yy[i]);  
   }
   glEnd();
   //再描一遍线
   glColor3f(0.0f,0.0f,0.0f);
   glBegin(GL_LINE_LOOP);           
   for(int i=0;i<N;i++)  
   {  
   xx[i]=15*cos(2*i*PI/N)-22;  
   yy[i]=33*sin(2*i*PI/N)-37;  
   glVertex2f(xx[i],yy[i]);  
   }
   glEnd();


   //画右腿
   glLoadIdentity ();
   glRotatef(theta, 0.0, 0.0, 1.0);  
   glRotatef (-8.0, 0.0, 0.0, 1.0);
   glColor3f(1.0f,1.0f,1.0f);  
   glBegin(GL_POLYGON);          //用线进行图形连接  
   for(int i=0;i<N;i++)  
   {  
   xx[i]=15*cos(2*i*PI/N)+22;  
   yy[i]=33*sin(2*i*PI/N)-37;  
   glVertex2f(xx[i],yy[i]);  
   }
   glEnd();
    //再描一遍线
   glColor3f(0.0f,0.0f,0.0f);
   glBegin(GL_LINE_LOOP);           
   for(int i=0;i<N;i++)  
   {  
   xx[i]=15*cos(2*i*PI/N)+22;  
   yy[i]=33*sin(2*i*PI/N)-37;  
   glVertex2f(xx[i],yy[i]);  
   }
   glEnd();



   glLoadIdentity ();
   glRotatef(theta, 0.0, 0.0, 1.0);  
   //再画身体*********************************************************************
   glColor3f(1.0f,1.0f,1.0f);  
   glBegin(GL_POLYGON);          //用线进行图形连接  
   for(int i=0;i<N;i++)  
   {  
   xx[i]=40*cos(2*i*PI/N);  
   yy[i]=45*sin(2*i*PI/N);  
   glVertex2f(xx[i],yy[i]);  
   }
   glEnd();
   //再描一遍线
   glColor3f(0.0f,0.0f,0.0f);
   glBegin(GL_LINE_LOOP);           
   for(int i=0;i<N;i++)  
   {  
   xx[i]=40*cos(2*i*PI/N);  
   yy[i]=45*sin(2*i*PI/N);  
   glVertex2f(xx[i],yy[i]);  
   }
   glEnd();

   //画头部
   glLoadIdentity ();
   g
  • 4
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值