Opengl 2dline man的源代码 [英] Opengl source code for 2dline man

查看:129
本文介绍了Opengl 2dline man的源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以获得2Dline男人的opengl源代码

到[删除] @ gmail.com



我是什么尝试过:



i已在网站openglprojects试过

但是我没有得到代码

can i please get opengl source code for 2Dline man
to [DELETED]@gmail.com

What I have tried:

i have tried in website openglprojects
but am not getting the code

推荐答案

如果它是开源的,那么是的,你可以。如果不是,只是使用开源代码作为其中的一部分,那将取决于发布开源部分的许可证。



要么方式,它不是我们的,我们不能把它给你,因为我们没有它。尝试作者 - 他们将获得代码。



和BTW:永远不要在任何论坛发布您的电子邮件地址,除非您真的喜欢垃圾邮件!如果有人回复你,你会收到一封电子邮件通知你。
If it's open source, so yes, you can. If it isn't and just uses open source code as a part of it, then that will depend on the licence under which the open source sections are released.

Either way, it's not ours, and we can't give it to you as we don't have it. Try the authors - they will have the code.

And BTW: Never post your email address in any forum, unless you really like spam! If anyone replies to you, you will receive an email to let you know.


#include

#include

#define BASE_HEIGHT 4.0 / 2

#define BASE_RADIUS 1.0 / 2

#define HEAD_HEIGHT 1.25 / 2

#define HEAD_RADIUS 0.75 / 2

#define NECK_HEIGHT 0.5 / 2

#define EYE_LEVEL 0.75 / 2

#define NOSE_LENGTH 0.5 / 2

#define LOWER_ARM_HEIGHT 2.0 / 2

#define LOWER_ARM_WIDTH 0.5 / 2

#define UPPER_ARM_HEIGHT 1.25 / 2

#define UPPER_ARM_WIDTH 0.5 / 2

#define ARM_TRANSLATION 0.22 / 2

#define alpha 0.0

#define pi 3.14159265

静态GLfloat theta [] = {0.0,0.0, 0.0,0.0,0.0,0.0,0.0};

静态GLint轴= 0;

GLUquadricObj * p;

GLfloat x = 0.0;

GLfloat y = 0.0;

GLfloat xpos = 0.0;

GLfloat ypos = 0.0;

GLfloat zpos = 0.0;

GLfloat ambient [3];

GLfloat diffu se [3];

GLfloat specular [3];

GLfloat shiness [] = {50.0f};

float width = 500;

浮动高度= 500;

void base(void);

void head(void);

void neck(void);

void upper_rarm(void);

void upper_larm(void);

void lower_rarm(void);

void lower_larm(void);

void init(void);

void display(void);

void reshape( int width,int height);

void keyboard(unsigned char,int,int);

void processSpecialKeys(int,int,int);

void jump(void);

void lsphere(void);

void init1(void);



void base(void){

double angle,angleInc;

int i;

angle = pi / 180;

angleInc = angle;

glPushMatrix();



ambient [0] = 1.0;环境[1] = 0.0; ambient [2] = 0.0;

diffuse [0] = 1.0; diffuse [1] = 0.0; diffuse [2] = 0.0;

specular [0] = 0.7; specular [1] = 0.6; specular [2] = 0.5;



glMaterialfv(GL_FRONT,GL_AMBIENT,ambient);

glMaterialfv(GL_FRONT,GL_DIFFUSE,diffuse);

glMaterialfv(GL_FRONT,GL_SPECULAR,高光);

glMaterialfv(GL_FRONT,GL_SHININESS,shiness);



glRotatef (-90.0,1.0,0.0,0.0);

gluQuadricDrawStyle(p,GLU_FILL);

gluCylinder(p,BASE_RADIUS,BASE_RADIUS,BASE_HEIGHT,20,20); < br $> b $ b

glPopMatrix();



glPushMatrix();



gluQuadricDrawStyle(p,GLU_FILL);

glTranslatef(0.0,BASE_HEIGHT,0.0);

glRotatef(-90.0,1.0,0.0,0.0);

gluDisk(p,0.0,BASE_RADIUS,20,20);

glTranslatef(0.0,0.0,-BASE_HEIGHT);

gluDisk(p, 0.0,BASE_RADIUS,20,20);

glPopMatrix();

}





void neck(void){

glPushMatrix();



ambient [0] = 1.0;环境[1] = 1.0; ambient [2] = 0.0;

diffuse [0] = 1.0; diffuse [1] = 1.0; diffuse [2] = 0.0;

specular [0] = 0.7; specular [1] = 0.6; specular [2] = 0.5;



glMaterialfv(GL_FRONT,GL_AMBIENT,ambient);

glMaterialfv(GL_FRONT,GL_DIFFUSE,diffuse);

glMaterialfv(GL_FRONT,GL_SPECULAR,高光);

glMaterialfv(GL_FRONT,GL_SHININESS,shiness);



glTranslatef (0.0,BASE_HEIGHT,0.0);

glRotatef(-90.0,1.0,0.0,0.0);

gluQuadricDrawStyle(p,GLU_FILL);

gluCylinder(p,HEAD_RADIUS / 2,HEAD_RADIUS / 2,HEAD_HEIGHT,8,6);

glPopMatrix();

}



void head(void){

glPushMatrix();



ambient [0] = 1.0;环境[1] = 0.0; ambient [2] = 1.0;

diffuse [0] = 1.0; diffuse [1] = 0.0; diffuse [2] = 1.0;

specular [0] = 0.7; specular [1] = 0.6; specular [2] = 0.5;



glMaterialfv(GL_FRONT,GL_AMBIENT,ambient);

glMaterialfv(GL_FRONT,GL_DIFFUSE,diffuse);

glMaterialfv(GL_FRONT,GL_SPECULAR,高光);

glMaterialfv(GL_FRONT,GL_SHININESS,shiness);



glRotatef (-90.0,1.0,0.0,0.0);

gluQuadricDrawStyle(p,GLU_FILL);

gluCylinder(p,HEAD_RADIUS,HEAD_RADIUS,HEAD_HEIGHT,20,20); < br $> b $ b

glPushMatrix();



gluDisk(p,0.0,HEAD_RADIUS,20,20);

glTranslatef(0.0,0.0,HEAD_HEIGHT);

gluDisk(p,0.0,HEAD_RADIUS,20,20);

glPopMatrix();



glPushMatrix();

glTranslatef(0.25,-HEAD_RADIUS + 0.12,EYE_LEVEL);



ambient [0] = 1.0;环境[1] = 1.0; ambient [2] = 1.0;

diffuse [0] = 1.0; diffuse [1] = 1.0; diffuse [2] = 1.0;

specular [0] = 0.5; specular [1] = 0.5; specular [2] = 0.5;



glMaterialfv(GL_FRONT,GL_AMBIENT,ambient);

glMaterialfv(GL_FRONT,GL_DIFFUSE,diffuse);

glMaterialfv(GL_FRONT,GL_SPECULAR,高光);

glMaterialfv(GL_FRONT,GL_SHININESS,shiness);



gluQuadricDrawStyle (p,GLU_FILL);

gluSphere(p,0.125,6,6);

glPopMatrix();



glPushMatrix();

glTranslatef(-0.25,-HEAD_RADIUS + 0.12,EYE_LEVEL);

ambient [0] = 1.0;环境[1] = 1.0; ambient [2] = 1.0;

diffuse [0] = 1.0; diffuse [1] = 1.0; diffuse [2] = 1.0;

specular [0] = 0.5; specular [1] = 0.5; specular [2] = 0.5;



glMaterialfv(GL_FRONT,GL_AMBIENT,ambient);

glMaterialfv(GL_FRONT,GL_DIFFUSE,diffuse);

glMaterialfv(GL_FRONT,GL_SPECULAR,高光);

glMaterialfv(GL_FRONT,GL_SHININESS,shiness);





gluQuadricDrawStyle(p,GLU_FILL);

gluSphere(p,0.125,6,6);

glPopMatrix();



glPushMatrix();

ambient [0] = 1.0;环境[1] = 0.5; ambient [2] = 0.0;

diffuse [0] = 1.0; diffuse [1] = 0.5; diffuse [2] = 0.0;

specular [0] = 0.5; specular [1] = 0.5; specular [2] = 0.5;



glMaterialfv(GL_FRONT,GL_AMBIENT,ambient);

glMaterialfv(GL_FRONT,GL_DIFFUSE,diffuse);

glMaterialfv(GL_FRONT,GL_SPECULAR,高光);

glMaterialfv(GL_FRONT,GL_SHININESS,shiness);

glTranslatef(0.0,-HEAD_RADIUS,NOSE_LENGTH) ;

glRotatef(90.0,1.0,0.0,0.0);

gluQuadricDrawStyle(p,GLU_FILL);

gluCylinder(p,0.125,0) ,NOSE_LENGTH,8,6);

glPopMatrix();



glPopMatrix();

} < br $>


void lower_rarm(无效){

glPushMatrix();



环境[0] = 0.0;环境[1] = 1.0; ambient [2] = 0.0;

diffuse [0] = 0.0; diffuse [1] = 1.0; diffuse [2] = 0.0;

specular [0] = 0.7; specular [1] = 0.6; specular [2] = 0.5;



glMaterialfv(GL_FRONT,GL_AMBIENT,ambient);

glMaterialfv(GL_FRONT,GL_DIFFUSE,diffuse);

glMaterialfv(GL_FRONT,GL_SPECULAR,高光);

glMaterialfv(GL_FRONT,GL_SHININESS,shiness);



glTranslatef (0.0,0.5 * LOWER_ARM_HEIGHT,ARM_TRANSLATION);

glScalef(LOWER_ARM_WIDTH,LOWER_ARM_HEIGHT,LOWER_ARM_WIDTH);

glutSolidCube(1.0);

glPopMatrix( );

}



void lower_larm(void){

glPushMatrix();



ambient [0] = 0.0;环境[1] = 1.0; ambient [2] = 0.0;

diffuse [0] = 0.0; diffuse [1] = 1.0; diffuse [2] = 0.0;

specular [0] = 0.7; specular [1] = 0.6; specular [2] = 0.5;



glMaterialfv(GL_FRONT,GL_AMBIENT,ambient);

glMaterialfv(GL_FRONT,GL_DIFFUSE,diffuse);

glMaterialfv(GL_FRONT,GL_SPECULAR,高光);

glMaterialfv(GL_FRONT,GL_SHININESS,shiness);



glTranslatef (0.0,0.5 * LOWER_ARM_HEIGHT,-ARM_TRANSLATION);

glScalef(LOWER_ARM_WIDTH,LOWER_ARM_HEIGHT,LOWER_ARM_WIDTH);

glutSolidCube(1.0);

glPopMatrix ();

}



void upper_rarm(无效){

glPushMatrix();



ambient [0] = 0.0;环境[1] = 0.0; ambient [2] = 1.0;

diffuse [0] = 0.0; diffuse [1] = 0.0; diffuse [2] = 1.0;

specular [0] = 0.7; specular [1] = 0.6; specular [2] = 0.5;



glMaterialfv(GL_FRONT,GL_AMBIENT,ambient);

glMaterialfv(GL_FRONT,GL_DIFFUSE,diffuse);

glMaterialfv(GL_FRONT,GL_SPECULAR,高光);

glMaterialfv(GL_FRONT,GL_SHININESS,shiness);



glTranslatef (0.0,0.5 * UPPER_ARM_HEIGHT,ARM_TRANSLATION);

glScalef(UPPER_ARM_WIDTH,UPPER_ARM_HEIGHT,UPPER_ARM_WIDTH);

glutSolidCube(1.0);

glPopMatrix( );

}



void upper_larm(无效){

glPushMatrix();



ambient [0] = 0.0;环境[1] = 0.0; ambient [2] = 1.0;

diffuse [0] = 0.0; diffuse [1] = 0.0; diffuse [2] = 1.0;

specular [0] = 0.7; specular [1] = 0.6; specular [2] = 0.5;



glMaterialfv(GL_FRONT,GL_AMBIENT,ambient);

glMaterialfv(GL_FRONT,GL_DIFFUSE,diffuse);

glMaterialfv(GL_FRONT,GL_SPECULAR,高光);

glMaterialfv(GL_FRONT,GL_SHININESS,shiness);



glTranslatef (0.0,0.5 * UPPER_ARM_HEIGHT,-ARM_TRANSLATION);

glScalef(UPPER_ARM_WIDTH,UPPER_ARM_HEIGHT,UPPER_ARM_WIDTH);

glutSolidCube(1.0);

glPopMatrix ();

}





void init1(void){

GLfloat mat_specular [] = {1.0,1.0,1.0,1.0};

GLfloat mat_shininess [] = {50.0};

GLfloat light_position [] = {1.0,1.0, 1.0,1.0};

GLfloat white_light [] = {0.3,0.3,0.3,1.0};

GLfloat lmodel_ambient [] = {1.0,1.0,0.0,1.0} ;

glClearColor(0.0,0.0,0.0,0.0);

glShadeModel(GL_SMOOTH);

glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);

glMaterialfv(GL_FRONT,GL_S HININESS,mat_shininess);

glLightfv(GL_LIGHT0,GL_POSITION,light_position);

glLightfv(GL_LIGHT0,GL_DIFFUSE,white_light);

glLightfv(GL_LIGHT0 ,GL_SPECULAR,white_light);

glLightModelfv(GL_LIGHT_MODEL_AMBIENT,lmodel_ambient);



glEnable(GL_LIGHTING);

glEnable(GL_LIGHT0);

glEnable(GL_DEPTH_TEST);

}



void lsphere(void){

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glutSolidSphere(1.0,20,16);

glFlush();

}



无效显示(无效){



glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glLoadIdentity();

gluLookAt(0.3,5.3,12.0,0.0,1.25,0.0,0.0,1.0,0.0);



glPushMatrix();

ambient [0] = 1.0;环境[1] = 0.3;环境[2] = 0.3;

diffuse [0] = 1.0; diffuse [1] = 1.0; diffuse [2] = 1.0;

specular [0] = 0.7; specular [1] = 0.6; specular [2] = 0.5;



glMaterialfv(GL_FRONT,GL_AMBIENT,ambient);

glMaterialfv(GL_FRONT,GL_DIFFUSE,diffuse);

glMaterialfv(GL_FRONT,GL_SPECULAR,高光);

glMaterialfv(GL_FRONT,GL_SHININESS,shiness);





glTranslatef(0.0,5.0,0.0);

lsphere();

glPopMatrix();



glPushMatrix();

ambient [0] = 0.3;环境[1] = 0.3;环境[2] = 0.3;

diffuse [0] = 0.0; diffuse [1] = 0.0; diffuse [2] = 1.0;

specular [0] = 0.7; specular [1] = 0.6; specular [2] = 0.5;



glMaterialfv(GL_FRONT,GL_AMBIENT,ambient);

glMaterialfv(GL_FRONT,GL_DIFFUSE,diffuse);

glMaterialfv(GL_FRONT,GL_SPECULAR,高光);

glMaterialfv(GL_FRONT,GL_SHININESS,shiness);



glTranslatef (3.0,0.5,1.0);

glutSolidCube(1.0);

glPopMatrix();



glPushMatrix ();

ambient [0] = 0.3;环境[1] = 0.3;环境[2] = 0.3;

diffuse [0] = 1.0; diffuse [1] = 0.0; diffuse [2] = 1.0;

specular [0] = 0.7; specular [1] = 0.6; specular [2] = 0.5;



glMaterialfv(GL_FRONT,GL_AMBIENT,ambient);

glMaterialfv(GL_FRONT,GL_DIFFUSE,diffuse);

glMaterialfv(GL_FRONT,GL_SPECULAR,高光);

glMaterialfv(GL_FRONT,GL_SHININESS,shiness);



glTranslatef (-4.0,0.5,3.0);

glutSolidCone(0.5,1.5,20,15);

glPopMatrix();



glPushMatrix();

ambient [0] = 0.3;环境[1] = 0.3;环境[2] = 0.3;

diffuse [0] = 1.0; diffuse [1] = 0.0; diffuse [2] = 0.0;

specular [0] = 0.7; specular [1] = 0.6; specular [2] = 0.5;



glMaterialfv(GL_FRONT,GL_AMBIENT,ambient);

glMaterialfv(GL_FRONT,GL_DIFFUSE,diffuse);

glMaterialfv(GL_FRONT,GL_SPECULAR,高光);

glMaterialfv(GL_FRONT,GL_SHININESS,shiness);



glTranslatef (-3.0,0.5,-3.0);

glutSolidTeapot(1.0);

glPopMatrix();



glPushMatrix();

ambient [0] = 0.5;环境[1] = 0.5;环境[2] = 0.5;

diffuse [0] = 1.0; diffuse [1] = 1.0; diffuse [2] = 1.0;

specular [0] = 0.7; specular [1] = 0.6; specular [2] = 0.5;



glMaterialfv(GL_FRONT,GL_AMBIENT,ambient);

glMaterialfv(GL_FRONT,GL_DIFFUSE,diffuse);

glMaterialfv(GL_FRONT,GL_SPECULAR,高光);

glMaterialfv(GL_FRONT,GL_SHININESS,shiness);



glBegin (GL_POLYGON);

glVertex3f(5.0,0.0,5.0);

glVertex3f(5.0,0.0,-5.0);

glVertex3f( - 5.0,0.0,-5.0);

glVertex3f(-5.0,0.0,5.0);

glVertex3f(5.0,0.0,5.0);

glEnd();



glPopMatrix();



glTranslatef(xpos,ypos,zpos);

glRotatef(theta [0],0.0,1.0,0.0);

base();

neck();



glPushMatrix();

glTranslatef(0.0,BASE_HEIGHT + HEAD_HEIGHT / 2,0.0);

glRotatef(theta [2 ],1.0,0.0,0.0);

glRotatef(theta [1],0.0,1.0,0.0);

head();

glPopMatrix();





glPushMatrix();

glTranslatef(BASE_RADIUS,BASE_HEIGHT - BASE_RADIUS / 2,0.0);

glRotatef(180.0,0.0,0.0,1.0);

glRotatef(270.0,0.0,1.0,0.0) ;

glRotatef(theta [4],0.0,0.0,1.0);

lower_rarm();

glTranslatef(0.0,LOWER_ARM_HEIGHT,0.0 );

glRotatef(0.0,0.0,0.0,180.0);

glRotatef(theta [6],0.0,0.0,1.0);

upper_rarm();

glPopMatrix();



glPushMatrix();

glTranslatef(-BASE_RADIUS, BASE_HEIGHT - BASE_RADIUS / 2,0.0);

glRotatef(180.0,0.0,0.0,1.0);

glRotatef(270.0,0.0,1.0,0.0);

glRotatef(theta [3],0.0,0.0,1.0);

lower_larm();

glTranslatef(0.0,LOWER_ARM_HEIGHT,0.0);

glRotatef(0.0,0.0,0.0,180.0);

glRotatef(theta [5],0.0,0.0,1.0);

upper_larm() ;

glPopMatrix();





glFlush();

glutSwapBuffers ();

}



v oid键盘(unsigned char key,int x,int y){

switch(key){

case'a':theta [1] + = 5.0;

if(theta [1]> 90.0)

theta [1] = 90.0;

休息;



case'z':theta [ 1] - = 5.0;

if(theta [1] 45.0)

theta [2] = 45.0;

break;



case'p':theta [2] - = 5.0;

if(theta [2] 5)

xpos = 5;

if(zpos> 5)

zpos = 5;

if(xpos 5)

xpos = 5;

if(zpos> 5)

zpos = 5;

if(xpos< -5)

xpos = -5;

if(zpos< -5)

zpos = -5;

break ;

case GLUT_KEY_LEFT:theta [0] - = 5.0;休息;

案例GLUT_KEY_RIGHT:theta [0] + = 5.0; break;

case GLUT_KEY_PAGE_UP:ypos + = 1.0;休息;

案例GLUT_KEY_PAGE_DOWN:ypos - = 1.0;休息;

}

glutPostRedisplay();

}



无效重塑(int w,int h){

glViewport(0,0,w,h);

glMatrixMode(GL_PROJECTION);

glLoadIdentity( );

gluPerspective(100.0,(GLfloat)w /(GLfloat)h,0.5,100.0);

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

}



void init(void){

GLfloat lightIntensity [] = {0.7 f,0.7f,0.7f,1.0f};

GLfloat light_position [] = {2.0f,6.0f,3.0f,0.0f};



glEnable(GL_LIGHTING);

glEnable(GL_LIGHT0);

glShadeModel(GL_SMOOTH);

glEnable(GL_DEPTH_TEST);

glEnable(GL_NORMALIZE );



glLightfv(GL_LIGHT0,GL_POSITION,light_position);

glLightfv(GL_LIGHT0,GL_DIFFUSE,lightIntensity);



glClearColor(0.0,0.0,0.0,0.0);

glColor3f(1.0,0.0,0.0);

p = gluNewQuadric() ;

}



int main(int argc,char ** argv){

glutInit(& argc,argv);

glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);

glutInitWindowSize(宽度,高度);

glutCreateWindow(机器人) );

init();

init1();

glutReshapeFunc(重塑);

glutDisplayFunc(显示);

glutKeyboardFunc(键盘);

glutSpecialFunc(processSpecialKeys);

glutMainLoop();

返回0 ;

}
#include
#include
#define BASE_HEIGHT 4.0/2
#define BASE_RADIUS 1.0/2
#define HEAD_HEIGHT 1.25/2
#define HEAD_RADIUS 0.75/2
#define NECK_HEIGHT 0.5/2
#define EYE_LEVEL 0.75/2
#define NOSE_LENGTH 0.5/2
#define LOWER_ARM_HEIGHT 2.0/2
#define LOWER_ARM_WIDTH 0.5/2
#define UPPER_ARM_HEIGHT 1.25/2
#define UPPER_ARM_WIDTH 0.5/2
#define ARM_TRANSLATION 0.22/2
#define alpha 0.0
#define pi 3.14159265
static GLfloat theta[] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
static GLint axis = 0;
GLUquadricObj *p;
GLfloat x = 0.0;
GLfloat y = 0.0;
GLfloat xpos = 0.0;
GLfloat ypos = 0.0;
GLfloat zpos = 0.0;
GLfloat ambient[3];
GLfloat diffuse[3];
GLfloat specular[3];
GLfloat shiness[] = {50.0f};
float width = 500;
float height = 500;
void base(void);
void head(void);
void neck(void);
void upper_rarm(void);
void upper_larm(void);
void lower_rarm(void);
void lower_larm(void);
void init(void);
void display(void);
void reshape (int width, int height);
void keyboard(unsigned char, int, int);
void processSpecialKeys(int, int, int);
void jump (void);
void lsphere (void);
void init1 (void);

void base (void) {
double angle, angleInc;
int i;
angle = pi / 180;
angleInc = angle;
glPushMatrix();

ambient[0] = 1.0; ambient[1] = 0.0; ambient[2] = 0.0;
diffuse[0] = 1.0; diffuse[1] = 0.0; diffuse[2] = 0.0;
specular[0] = 0.7; specular[1] = 0.6; specular[2] = 0.5;

glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
glMaterialfv(GL_FRONT, GL_SHININESS, shiness);

glRotatef (-90.0, 1.0, 0.0, 0.0);
gluQuadricDrawStyle(p, GLU_FILL);
gluCylinder (p, BASE_RADIUS, BASE_RADIUS, BASE_HEIGHT, 20, 20);

glPopMatrix();

glPushMatrix();

gluQuadricDrawStyle (p, GLU_FILL);
glTranslatef (0.0, BASE_HEIGHT, 0.0);
glRotatef (-90.0, 1.0, 0.0, 0.0);
gluDisk (p, 0.0, BASE_RADIUS, 20, 20);
glTranslatef (0.0, 0.0, -BASE_HEIGHT);
gluDisk (p, 0.0, BASE_RADIUS, 20, 20);
glPopMatrix();
}


void neck (void) {
glPushMatrix();

ambient[0] = 1.0; ambient[1] = 1.0; ambient[2] = 0.0;
diffuse[0] = 1.0; diffuse[1] = 1.0; diffuse[2] = 0.0;
specular[0] = 0.7; specular[1] = 0.6; specular[2] = 0.5;

glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
glMaterialfv(GL_FRONT, GL_SHININESS, shiness);

glTranslatef(0.0, BASE_HEIGHT, 0.0);
glRotatef (-90.0, 1.0, 0.0, 0.0);
gluQuadricDrawStyle(p, GLU_FILL);
gluCylinder (p, HEAD_RADIUS/2, HEAD_RADIUS/2, HEAD_HEIGHT, 8, 6);
glPopMatrix();
}

void head (void) {
glPushMatrix();

ambient[0] = 1.0; ambient[1] = 0.0; ambient[2] = 1.0;
diffuse[0] = 1.0; diffuse[1] = 0.0; diffuse[2] = 1.0;
specular[0] = 0.7; specular[1] = 0.6; specular[2] = 0.5;

glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
glMaterialfv(GL_FRONT, GL_SHININESS, shiness);

glRotatef (-90.0, 1.0, 0.0, 0.0);
gluQuadricDrawStyle(p, GLU_FILL);
gluCylinder (p, HEAD_RADIUS, HEAD_RADIUS, HEAD_HEIGHT, 20, 20);

glPushMatrix();

gluDisk (p, 0.0, HEAD_RADIUS, 20, 20);
glTranslatef (0.0, 0.0, HEAD_HEIGHT);
gluDisk (p, 0.0, HEAD_RADIUS, 20, 20);
glPopMatrix();

glPushMatrix();
glTranslatef (0.25, -HEAD_RADIUS+0.12, EYE_LEVEL);

ambient[0] = 1.0; ambient[1] = 1.0; ambient[2] = 1.0;
diffuse[0] = 1.0; diffuse[1] = 1.0; diffuse[2] = 1.0;
specular[0] = 0.5; specular[1] = 0.5; specular[2] = 0.5;

glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
glMaterialfv(GL_FRONT, GL_SHININESS, shiness);

gluQuadricDrawStyle(p, GLU_FILL);
gluSphere (p, 0.125, 6, 6);
glPopMatrix();

glPushMatrix();
glTranslatef (-0.25, -HEAD_RADIUS+0.12, EYE_LEVEL);
ambient[0] = 1.0; ambient[1] = 1.0; ambient[2] = 1.0;
diffuse[0] = 1.0; diffuse[1] = 1.0; diffuse[2] = 1.0;
specular[0] = 0.5; specular[1] = 0.5; specular[2] = 0.5;

glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
glMaterialfv(GL_FRONT, GL_SHININESS, shiness);


gluQuadricDrawStyle(p, GLU_FILL);
gluSphere (p, 0.125, 6, 6);
glPopMatrix();

glPushMatrix();
ambient[0] = 1.0; ambient[1] = 0.5; ambient[2] = 0.0;
diffuse[0] = 1.0; diffuse[1] = 0.5; diffuse[2] = 0.0;
specular[0] = 0.5; specular[1] = 0.5; specular[2] = 0.5;

glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
glMaterialfv(GL_FRONT, GL_SHININESS, shiness);
glTranslatef(0.0, -HEAD_RADIUS, NOSE_LENGTH);
glRotatef(90.0, 1.0, 0.0, 0.0);
gluQuadricDrawStyle(p, GLU_FILL);
gluCylinder(p, 0.125, 0, NOSE_LENGTH, 8,6);
glPopMatrix();

glPopMatrix();
}

void lower_rarm(void) {
glPushMatrix();

ambient[0] = 0.0; ambient[1] = 1.0; ambient[2] = 0.0;
diffuse[0] = 0.0; diffuse[1] = 1.0; diffuse[2] = 0.0;
specular[0] = 0.7; specular[1] = 0.6; specular[2] = 0.5;

glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
glMaterialfv(GL_FRONT, GL_SHININESS, shiness);

glTranslatef(0.0, 0.5 * LOWER_ARM_HEIGHT, ARM_TRANSLATION);
glScalef(LOWER_ARM_WIDTH, LOWER_ARM_HEIGHT, LOWER_ARM_WIDTH);
glutSolidCube(1.0);
glPopMatrix();
}

void lower_larm(void) {
glPushMatrix();

ambient[0] = 0.0; ambient[1] = 1.0; ambient[2] = 0.0;
diffuse[0] = 0.0; diffuse[1] = 1.0; diffuse[2] = 0.0;
specular[0] = 0.7; specular[1] = 0.6; specular[2] = 0.5;

glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
glMaterialfv(GL_FRONT, GL_SHININESS, shiness);

glTranslatef(0.0, 0.5 * LOWER_ARM_HEIGHT, -ARM_TRANSLATION);
glScalef(LOWER_ARM_WIDTH, LOWER_ARM_HEIGHT, LOWER_ARM_WIDTH);
glutSolidCube(1.0);
glPopMatrix();
}

void upper_rarm(void) {
glPushMatrix();

ambient[0] = 0.0; ambient[1] = 0.0; ambient[2] = 1.0;
diffuse[0] = 0.0; diffuse[1] = 0.0; diffuse[2] = 1.0;
specular[0] = 0.7; specular[1] = 0.6; specular[2] = 0.5;

glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
glMaterialfv(GL_FRONT, GL_SHININESS, shiness);

glTranslatef(0.0, 0.5 * UPPER_ARM_HEIGHT, ARM_TRANSLATION);
glScalef(UPPER_ARM_WIDTH, UPPER_ARM_HEIGHT, UPPER_ARM_WIDTH);
glutSolidCube(1.0);
glPopMatrix();
}

void upper_larm(void) {
glPushMatrix();

ambient[0] = 0.0; ambient[1] = 0.0; ambient[2] = 1.0;
diffuse[0] = 0.0; diffuse[1] = 0.0; diffuse[2] = 1.0;
specular[0] = 0.7; specular[1] = 0.6; specular[2] = 0.5;

glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
glMaterialfv(GL_FRONT, GL_SHININESS, shiness);

glTranslatef(0.0, 0.5 * UPPER_ARM_HEIGHT, -ARM_TRANSLATION);
glScalef(UPPER_ARM_WIDTH, UPPER_ARM_HEIGHT, UPPER_ARM_WIDTH);
glutSolidCube(1.0);
glPopMatrix();
}


void init1(void){
GLfloat mat_specular[] = {1.0, 1.0, 1.0, 1.0};
GLfloat mat_shininess[] = {50.0};
GLfloat light_position[] = {1.0, 1.0, 1.0, 1.0};
GLfloat white_light[] = {0.3, 0.3, 0.3, 1.0};
GLfloat lmodel_ambient[] = {1.0, 1.0, 0.0, 1.0};
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_SMOOTH);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light);
glLightfv(GL_LIGHT0, GL_SPECULAR, white_light);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
}

void lsphere(void){
glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT);
glutSolidSphere(1.0, 20, 16);
glFlush();
}

void display(void) {

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(0.3, 5.3, 12.0, 0.0, 1.25, 0.0, 0.0, 1.0, 0.0);

glPushMatrix();
ambient[0] = 1.0; ambient[1] = 0.3; ambient[2] = 0.3;
diffuse[0] = 1.0; diffuse[1] = 1.0; diffuse[2] = 1.0;
specular[0] = 0.7; specular[1] = 0.6; specular[2] = 0.5;

glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
glMaterialfv(GL_FRONT, GL_SHININESS, shiness);


glTranslatef(0.0, 5.0, 0.0);
lsphere();
glPopMatrix();

glPushMatrix();
ambient[0] = 0.3; ambient[1] = 0.3; ambient[2] = 0.3;
diffuse[0] = 0.0; diffuse[1] = 0.0; diffuse[2] = 1.0;
specular[0] = 0.7; specular[1] = 0.6; specular[2] = 0.5;

glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
glMaterialfv(GL_FRONT, GL_SHININESS, shiness);

glTranslatef(3.0, 0.5, 1.0);
glutSolidCube(1.0);
glPopMatrix();

glPushMatrix();
ambient[0] = 0.3; ambient[1] = 0.3; ambient[2] = 0.3;
diffuse[0] = 1.0; diffuse[1] = 0.0; diffuse[2] = 1.0;
specular[0] = 0.7; specular[1] = 0.6; specular[2] = 0.5;

glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
glMaterialfv(GL_FRONT, GL_SHININESS, shiness);

glTranslatef(-4.0, 0.5, 3.0);
glutSolidCone(0.5, 1.5, 20, 15);
glPopMatrix();

glPushMatrix();
ambient[0] = 0.3; ambient[1] = 0.3; ambient[2] = 0.3;
diffuse[0] = 1.0; diffuse[1] = 0.0; diffuse[2] = 0.0;
specular[0] = 0.7; specular[1] = 0.6; specular[2] = 0.5;

glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
glMaterialfv(GL_FRONT, GL_SHININESS, shiness);

glTranslatef(-3.0, 0.5, -3.0);
glutSolidTeapot(1.0);
glPopMatrix();

glPushMatrix();
ambient[0] = 0.5; ambient[1] = 0.5; ambient[2] = 0.5;
diffuse[0] = 1.0; diffuse[1] = 1.0; diffuse[2] = 1.0;
specular[0] = 0.7; specular[1] = 0.6; specular[2] = 0.5;

glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
glMaterialfv(GL_FRONT, GL_SHININESS, shiness);

glBegin(GL_POLYGON);
glVertex3f(5.0, 0.0, 5.0);
glVertex3f(5.0, 0.0, -5.0);
glVertex3f(-5.0, 0.0, -5.0);
glVertex3f(-5.0, 0.0, 5.0);
glVertex3f(5.0, 0.0, 5.0);
glEnd();

glPopMatrix();

glTranslatef (xpos, ypos, zpos);
glRotatef(theta[0], 0.0, 1.0, 0.0);
base();
neck();

glPushMatrix();
glTranslatef(0.0, BASE_HEIGHT + HEAD_HEIGHT/2, 0.0);
glRotatef(theta[2], 1.0, 0.0, 0.0);
glRotatef(theta[1], 0.0, 1.0, 0.0);
head();
glPopMatrix();


glPushMatrix();
glTranslatef(BASE_RADIUS, BASE_HEIGHT - BASE_RADIUS / 2, 0.0);
glRotatef(180.0, 0.0, 0.0, 1.0);
glRotatef(270.0, 0.0, 1.0, 0.0);
glRotatef(theta[4], 0.0, 0.0, 1.0);
lower_rarm();
glTranslatef(0.0, LOWER_ARM_HEIGHT, 0.0);
glRotatef(0.0, 0.0, 0.0, 180.0);
glRotatef(theta[6], 0.0, 0.0, 1.0);
upper_rarm();
glPopMatrix();

glPushMatrix();
glTranslatef(-BASE_RADIUS, BASE_HEIGHT - BASE_RADIUS / 2, 0.0);
glRotatef(180.0, 0.0, 0.0, 1.0);
glRotatef(270.0, 0.0, 1.0, 0.0);
glRotatef(theta[3], 0.0, 0.0, 1.0);
lower_larm();
glTranslatef(0.0, LOWER_ARM_HEIGHT, 0.0);
glRotatef(0.0, 0.0, 0.0, 180.0);
glRotatef(theta[5], 0.0, 0.0, 1.0);
upper_larm();
glPopMatrix();


glFlush();
glutSwapBuffers();
}

void keyboard (unsigned char key, int x, int y) {
switch (key) {
case 'a': theta[1] += 5.0;
if (theta[1] > 90.0)
theta[1] = 90.0;
break;

case 'z': theta[1] -= 5.0;
if (theta[1] 45.0)
theta[2] = 45.0;
break;

case 'p': theta[2] -= 5.0;
if (theta[2] 5)
xpos = 5;
if (zpos > 5)
zpos = 5;
if (xpos 5)
xpos = 5;
if (zpos > 5)
zpos = 5;
if (xpos < -5)
xpos = -5;
if (zpos < -5)
zpos = -5;
break;
case GLUT_KEY_LEFT: theta[0] -= 5.0; break;
case GLUT_KEY_RIGHT: theta[0] += 5.0; break;
case GLUT_KEY_PAGE_UP: ypos += 1.0; break;
case GLUT_KEY_PAGE_DOWN: ypos -= 1.0; break;
}
glutPostRedisplay();
}

void reshape(int w, int h) {
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(100.0, (GLfloat) w / (GLfloat) h, 0.5, 100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void init (void) {
GLfloat lightIntensity[] = {0.7f, 0.7f, 0.7f, 1.0f};
GLfloat light_position[] = {2.0f, 6.0f, 3.0f, 0.0f};

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glEnable(GL_NORMALIZE);

glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightIntensity);

glClearColor(0.0, 0.0, 0.0, 0.0);
glColor3f(1.0, 0.0, 0.0);
p = gluNewQuadric();
}

int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(width, height);
glutCreateWindow("Robot");
init();
init1();
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutSpecialFunc (processSpecialKeys);
glutMainLoop();
return 0;
}


这篇关于Opengl 2dline man的源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆