opengl机器人纹理_opengl机器人设计

2020-02-27 其他范文 下载本文

opengl机器人纹理由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“opengl机器人设计”。

opengl 机器人 纹理

#include

#include

#include

#include

#include

static GLfloat xRot = 0.0f;static GLfloat yRot = 0.0f;//是否停止转动

bool IsStop=false;

//光照

使用光源

GLfloat lightPos[] = { 1.0f, 0.0f,-1.0f, 0.0f };GLfloat specular[] = { 1.0f, 1.0f, 1.0f,-1.0f};//反射光 GLfloat specref[] = { 1.0f, 1.0f, 1.0f, 1.0f };//a GLfloat ambientLight[] = { 0.5f, 0.5f, 0.5f, 1.0f};//环绕光 GLfloat spotDir[] = { 0.0f, 0.0f,-1.0f };GLboolean bEdgeFlag = TRUE;

void showText(void);

void resetPerspectiveProjection();

void setOrthographicProjection();

void Something();void renderBitmapString(float x, float y, void *font,char *string);

//设置背景

void SetupRC(void)

{

glEnable(GL_CULL_FACE);glEnable(GL_LIGHTING);glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientLight);glLightfv(GL_LIGHT0,GL_DIFFUSE,ambientLight);glLightfv(GL_LIGHT0,GL_SPECULAR,specular);glLightfv(GL_LIGHT0,GL_POSITION,lightPos);

glLightf(GL_LIGHT0,GL_SPOT_CUTOFF,30.0f);glLightf(GL_LIGHT0,GL_SPOT_EXPONENT,20.0f);glEnable(GL_LIGHT0);glEnable(GL_COLOR_MATERIAL);glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);

glMaterialfv(GL_FRONT, GL_SPECULAR,specref);glMateriali(GL_FRONT, GL_SHININESS,8);glClearColor(0.0f, 0.0f, 0.0f, 1.0f);}

void display(void)

{

glClear(GL_COLOR_BUFFER_BIT);glShadeModel(GL_SMOOTH);if(IsStop==false){ turn =(turn1);

if(shoulder1>=0){elbow=elbow-1.2;}

else{elbow=elbow+1.2;}

}

else

{

shoulder1 =(shoulder11);

shoulder2 =(shoulder2 + 1);

}

else

{

shoulder1 =(shoulder1 + 1);

shoulder2 =(shoulder21);

if(shoulder1>=0){elbow=elbow-1.2;}

else{elbow=elbow+1.2;}

}

else

{

shoulder1 =(shoulder11);

shoulder2 =(shoulder2

+ 1);

}

else {

shoulder1 =(shoulder1 + 1);

shoulder2 =(shoulder25)% 360;

glutPostRedisplay();IsStop=true;break;

case 'a'://左转 turn =(turn + 5)% 360;

glutPostRedisplay();IsStop=true;break;

case 'l':

shoulder1 =(shoulder1 + 2)% 360;

shoulder2 =(shoulder25)% 360;

shoulder2 =(shoulder2 + 10)% 360;

glutPostRedisplay();IsStop=true;break;

case 'P': IsStop=false;break;case 'p': IsStop=false;break;case 27:

exit(0);

break;default:

break;

}

}

//设置视觉角度

void setOrthographicProjection()

{

glMatrixMode(GL_PROJECTION);

glPushMatrix();

glLoadIdentity();

gluOrtho2D(0, w, 0, h);

glScalef(1,-1, 1);

glTranslatef(0,-h, 0);

glMatrixMode(GL_MODELVIEW);

}

void resetPerspectiveProjection()

{

glMatrixMode(GL_PROJECTION);

glPopMatrix();

glMatrixMode(GL_MODELVIEW);

} //光源的坐标变化

void SpecialKeys(int key, int x, int y){ if(key == GLUT_KEY_UP)xRot-= 5.0f;if(key == GLUT_KEY_DOWN)xRot += 5.0f;if(key == GLUT_KEY_LEFT)yRot-= 5.0f;if(key == GLUT_KEY_RIGHT)yRot += 5.0f;if(key > 356.0f)xRot = 0.0f;if(key 356.0f)yRot = 0.0f;if(key

//鼠标事件

void Mouse(int button,int state, int x, int y)

{

if(state == GLUT_DOWN)//鼠标按下 { if(x=0){ //向右旋转 yRot += 5.0f;}else if(y>=0){ //向上旋转 xRot-= 5.0f;}else if(y 356.0f)xRot = 0.0f;if(xRot 356.0f)yRot = 0.0f;if(yRot

void TimerFunction(int value){ display();glutPostRedisplay();glutTimerFunc(33,TimerFunction, 1);} //主函数

int main(int argc, char** argv)

{

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);

glutInitWindowSize(800, 600);

glutInitWindowPosition(100, 100);

glutCreateWindow(“机器人 按W向前走

按s向后走

按a向左转

按d向右转

按p可以自行转动”);SetupRC();

glutDisplayFunc(display);

glutReshapeFunc(resha

pe);

glutKeyboardFunc(keyboard);glutSpecialFunc(SpecialKeys);glutMouseFunc(Mouse);glutTimerFunc(33, TimerFunction, 1);// glutIdleFunc(display);

glutMainLoop();

return 0;

}

《opengl机器人纹理.docx》
将本文的Word文档下载,方便收藏和打印
推荐度:
opengl机器人纹理
点击下载文档
相关专题 opengl机器人设计 纹理 机器人 opengl opengl机器人设计 纹理 机器人 opengl
[其他范文]相关推荐
    [其他范文]热门文章
      下载全文