#include <windows.h> // Standard Header For Most Programs
#include <gl/glut.h> // The GL Utility Toolkit (Glut) Header
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "tgaload.h"
#pragma comment( lib, "opengl32.lib" ) // Search For OpenGL32.lib While Linking
#pragma comment( lib, "glu32.lib" )
#define ColoredVertex(c, v) { glColor3fv(c); glVertex3fv(v); }
#define M_PI 3.14159265358979323846
static float c=M_PI/180.0f;
static int du=90,oldmy=-1,oldmx=-1;
static float r=1.5f,h=0.0f;
GLint texList[1];
GLuint texture_id[2];
GLUquadricObj *sphere;
GLUquadricObj *cylinder;
void Mouse(int button, int state, int x, int y)
{
if(state==GLUT_DOWN)
oldmx=x,oldmy=y;
}
void onMouseMove(int x,int y)
{
du+=x-oldmx;
h+=0.03f*(y-oldmy);
if(h>1.0f) h=1.0f;
else if(h<-1.0f) h=-1.0f;
oldmx=x,oldmy=y;
}
void drawLeftWings()
{
static int list=0;
//top wing
GLfloat PointA[] = { 0.0, 0.02, 0.0};
GLfloat PointB[] = { -0.1, 0.9, -0.32};
GLfloat PointC[] = { -0.1, 0.35, -0.36};
GLfloat PointD[] = { 0.0, 0.0, 0.0};
//middle wing
GLfloat PointA2[] = { 0.0, 0.02, 0.0};
GLfloat PointB2[] = { -0.1, 0.26, -0.37};
GLfloat PointC2[] = { -0.1, -0.2, -0.36};
GLfloat PointD2[] = { 0.0, 0.0, 0.0};
//bottom wing
GLfloat PointA1[] = { 0.0, 0.02, 0.0};
GLfloat PointB1[] = { -0.1, -0.25, -0.3};
GLfloat PointC1[] = { -0.1, -0.85, -0.3};
GLfloat PointD1[] = { 0.0, 0.0, 0.0};
GLfloat ColorR[] = {1, 0, 0};
GLfloat ColorG[] = {0, 1, 0};
GLfloat ColorB[] = {0, 0, 1};
GLfloat ColorY[] = {1, 1, 0};
list = glGenLists(1);
glNewList(list, GL_COMPILE);
glBegin(GL_TRIANGLES);
// ABC
ColoredVertex(ColorR, PointA);
ColoredVertex(ColorG, PointB);
ColoredVertex(ColorB, PointC);
// ACD
ColoredVertex(ColorR, PointA);
ColoredVertex(ColorB, PointC);
ColoredVertex(ColorY, PointD);
// CBD
ColoredVertex(ColorB, PointC);
ColoredVertex(ColorG, PointB);
ColoredVertex(ColorY, PointD);
// BAD
ColoredVertex(ColorG, PointB);
ColoredVertex(ColorR, PointA);
ColoredVertex(ColorY, PointD);
// ABC1
ColoredVertex(ColorR, PointA1);
ColoredVertex(ColorG, PointB1);
ColoredVertex(ColorB, PointC1);
// ACD1
ColoredVertex(ColorR, PointA1);
ColoredVertex(ColorB, PointC1);
ColoredVertex(ColorY, PointD1);
// CBD1
ColoredVertex(ColorB, PointC1);
ColoredVertex(ColorG, PointB1);
ColoredVertex(ColorY, PointD1);
// BAD1
ColoredVertex(ColorG, PointB1);
ColoredVertex(ColorR, PointA1);
ColoredVertex(ColorY, PointD1);
// ABC2
ColoredVertex(ColorR, PointA2);
ColoredVertex(ColorG, PointB2);
ColoredVertex(ColorB, PointC2);
// ACD2
ColoredVertex(ColorR, PointA2);
ColoredVertex(ColorB, PointC2);
ColoredVertex(ColorY, PointD2);
// CBD2
ColoredVertex(ColorB, PointC2);
ColoredVertex(ColorG, PointB2);
ColoredVertex(ColorY, PointD2);
// BAD2
ColoredVertex(ColorG, PointB2);
ColoredVertex(ColorR, PointA2);
ColoredVertex(ColorY, PointD2);
glEnd();
glEndList();
glCallList(list);
}
void drawRightWings()
{
static int list=0;
//top wing
GLfloat PointA[] = { 0.0, 0.02, 0.0};
GLfloat PointB[] = { 0.1, 0.9, -0.32};
GLfloat PointC[] = { 0.1, 0.35, -0.36};
GLfloat PointD[] = { 0.0, 0.0, 0.0};
//middle wing
GLfloat PointA2[] = { 0.0, 0.02, 0.0};
GLfloat PointB2[] = { 0.1, 0.26, -0.37};
GLfloat PointC2[] = { 0.1, -0.2, -0.36};
GLfloat PointD2[] = { 0.0, 0.0, 0.0};
//bottom wing
GLfloat PointA1[] = { 0.0, 0.02, 0.0};
GLfloat PointB1[] = { 0.1, -0.25, -0.3};
GLfloat PointC1[] = { 0.1, -0.85, -0.3};
GLfloat PointD1[] = { 0.0, 0.0, 0.0};
GLfloat ColorR[] = {1, 0, 0};
GLfloat ColorG[] = {0, 1, 0};
GLfloat ColorB[] = {0, 0, 1};
GLfloat ColorY[] = {1, 1, 0};
list = glGenLists(1);
glNewList(list, GL_COMPILE);
glBegin(GL_TRIANGLES);
// ABC
ColoredVertex(ColorR, PointA);
ColoredVertex(ColorG, PointB);
ColoredVertex(ColorB, PointC);
// ACD
ColoredVertex(ColorR, PointA);
ColoredVertex(ColorB, PointC);
ColoredVertex(ColorY, PointD);
// CBD
ColoredVertex(ColorB, PointC);
ColoredVertex(ColorG, PointB);
ColoredVertex(ColorY, PointD);
// BAD
ColoredVertex(ColorG, PointB);
ColoredVertex(ColorR, PointA);
ColoredVertex(ColorY, PointD);
// ABC1
ColoredVertex(ColorR, PointA1);
ColoredVertex(ColorG, PointB1);
ColoredVertex(ColorB, PointC1);
// ACD1
ColoredVertex(ColorR, PointA1);
ColoredVertex(ColorB, PointC1);
ColoredVertex(ColorY, PointD1);
// CBD1
ColoredVertex(ColorB, PointC1);
ColoredVertex(ColorG, PointB1);
ColoredVertex(ColorY, PointD1);
// BAD1
ColoredVertex(ColorG, PointB1);
ColoredVertex(ColorR, PointA1);
ColoredVertex(ColorY, PointD1);
// ABC2
ColoredVertex(ColorR, PointA2);
ColoredVertex(ColorG, PointB2);
ColoredVertex(ColorB, PointC2);
// ACD2
ColoredVertex(ColorR, PointA2);
ColoredVertex(ColorB, PointC2);
ColoredVertex(ColorY, PointD2);
// CBD2
ColoredVertex(ColorB, PointC2);
ColoredVertex(ColorG, PointB2);
ColoredVertex(ColorY, PointD2);
// BAD2
ColoredVertex(ColorG, PointB2);
ColoredVertex(ColorR, PointA2);
ColoredVertex(ColorY, PointD2);
glEnd();
glEndList();
glCallList(list);
}
void drawTail(GLUquadric* gluQ, GLfloat tailAng2)
{
glPushMatrix();
glRotatef(180.0, 0.0, 1.0, 0.0);
gluSphere(gluQ, 0.32, 30, 25);
glTranslatef(0.0, 0.0, 0.2);
glRotatef(tailAng2, 1.0, 0.0, 0.0);
gluCylinder(gluQ, 0.15, 0.13, 0.36, 30, 25);
glTranslatef(0.0, 0.0, 0.4);
gluSphere(gluQ, 0.28, 30, 25);
glTranslatef(0.0, 0.0, 0.15);
glRotatef(-30.0, 1.0, 0.0, 0.0);
gluCylinder(gluQ, 0.14, 0.12, 0.3, 30, 25);
glTranslatef(0.0, 0.0, 0.3);
gluSphere(gluQ, 0.17, 30, 25);
glTranslatef(0.0, 0.0, 0.07);
glRotatef(-30.0, 1.0, 0.0, 0.0);
gluCylinder(gluQ, 0.11, 0.09, 0.2, 30, 25);
glTranslatef(0.0, 0.0, 0.19);
gluSphere(gluQ, 0.11, 30, 25);
glTranslatef(0.0, 0.0, 0.11);
glutSolidTorus(0.03, 0.05, 20, 15);
glTranslatef(0.0, 0.0, 0.03);
glutSolidTorus(0.025, 0.045, 20, 15);
glTranslatef(0.0, 0.0, 0.025);
glutSolidTorus(0.02, 0.04, 20, 15);
glTranslatef(0.0, 0.0, 0.015);
glutSolidCone(0.045, 0.1, 30, 25);
glPopMatrix();
}
void drawSnowman(GLUquadric* gluQ, GLfloat wingAng, GLfloat tailAng1, GLfloat tailAng2)
{
/*glColorMaterial(GL_FRONT, GL_AMBIENT);
glColor3f(0.75, 0.75, 0.75);
glColorMaterial(GL_FRONT, GL_EMISSION);
glColor3f(0.0, 0.2, 0.0);
glColorMaterial(GL_FRONT, GL_SPECULAR);
glColor3f(0.75, 0.75, 0.75);
glColorMaterial(GL_FRONT, GL_DIFFUSE);
glColor3f(0.75, 0.75, 0.75);*/
glPushMatrix();
//body
glColor3f(1.0, 1.0, 1.0);
gluSphere(gluQ, 0.4, 26, 13);//bottom
glPushMatrix();
glRotatef(tailAng1, 0.0, 1.0, 0.0);
glTranslatef(0.0, 0.0, -0.45);
drawTail(gluQ, tailAng2);
glPopMatrix();
glTranslatef(0.0, 0.55, 0.0);
计算机图形学大作业
3星 · 超过75%的资源 需积分: 49 116 浏览量
2015-06-01
19:09:48
上传
评论 30
收藏 11.14MB ZIP 举报
普通网友
- 粉丝: 3
- 资源: 4
最新资源
- 数据源-数据可视化(七):Pandas香港酒店数据高级分析,涉及相关系数,协方差,数据离散化,透视表等精美可视化展示
- linux常用命令大全.doc
- 格拉斯哥大学空缺职位申请详细介绍Applicant Guide.pdf
- mmexport1702953347189.mp4
- 2023NOC软件创意编程初中组C++决赛
- 2023NOC软件创意编程赛项真题-python初中决赛
- 2023NOC软件创意编程赛项真题-python小高决赛
- WA4320H-FIT-集客AP220G-FULL编程器固件
- 2023NOC软件创意编程赛项真题图形化小学高年级-决赛
- 2023NOC软件创意编程赛项真题图形化小学低年级-决赛
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈