OpenGL光照模型:
- 全局泛光强度
- 视点位置在景物的位置
- 物体的正面和背面是否分别进行光照计算
全局环境光:
使用参数 : GL_LIGHT_MODLE_AMBIENT
GLfloat globle_ambient[] = { 0.2f, 0.2f, 0.2f, 1.0f }; //全局环境光
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, globle_ambient); //设置
globle_ambient 所用的值为GL_LIGHT_MODEL_AMBIENT的缺省值
这些数值产生小亮的白色环境光
光源位置与衰减:
无穷远光源:定向光源,光到达物体时是平行光 | 距离的变换对光强几乎无影响
近光源:定位光源,光源在场景的位置影响场景的光照效果,尤其影响光到达物体的方向 | 光强有衰减因子
衰减因子:环境光、漫射光、镜面光
使用参数: GL_POSITION
GLfloat light_position[] = { 0.0f, 0.0f, 10.0f, 0.0f };
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
其中:函数glLightfv(x,y,z,w)中x,y,z是光源的方向,w则表示光源的类型(平行光、定位光)
机器人行走动画
参考文章:呀,没有收藏。。。。emmmm
下载连接:openGL+vs2013机器人行走动画
main.h
#include<windows.h>
#include <iostream>
using namespace std;
#include<gl\GL.h>
#include<gl\GLU.h>
#include<gl\glut.h>
GLfloat body_material[] = { 0.0f, 0.5f, 0.5f, 1.0f };
GLfloat body_specular_mat[] = { 0.0f, 1.0f, 1.0f, 1.0f };
GLfloat body_shininess_mat[] = { 100.0f };
GLfloat body_emission_mat[] = { 0.0f, 0.3f, 0.3f, 1.0f };
GLfloat shrandfoot_material[] = { 0.2f, 0.2f, 0.2f, 1.0f };
GLfloat shrandfoot_diffuse_mat[] = { 0.8f, 0.8f, 0.8f, 1.0f };
GLfloat shrandfoot_shininess_mat[] = { 0.1f };
GLfloat head_ambient_mat[] = { 0.6f, 0.6f, 0.0f, 1.0f };
GLfloat head_diffuse_mat[] = { 0.8f, 0.8f, 0.8f, 1.0f };
GLfloat head_specular_mat[] = { 0.3f, 0.3f, 0.3f, 1.0f };
GLfloat head_shininess_mat[] = { 5.0f };
GLfloat head_emission_mat[] = { 0.7f, 0.7f, 0.0f, 1.0f };
GLfloat eye_ambient_mat[] = { 0.2f, 0.2f, 0.2f, 1.0f };
GLfloat eye_diffuse_mat[] = { 0.8f, 0.8f, 0.8f, 1.0f };
GLfloat eye_specular_mat[] = { 0.4f, 0.4f, 0.4f, 1.0f };
GLfloat eye_shininess_mat[] = { 0.1f };
GLfloat eye_emission_mat[] = { 0.0f, 0.0f, 0.0f, 1.0f };
GLfloat mouth_material[] = { 1.0f, 0.0f, 1.0f, 1.0f };
GLfloat mouth_diffuse_mat[] = { 0.0f, 0.5f, 0.5f, 1.0f };
GLfloat mouth_shininess_mat[] = { 100.0f };
static int angle = 0, neck = 0,
lshoulder = -5, rshoulder = 5,
lelbow = -10, relbow = 10,
lhips = 5, rhips = -5,
lfoot = -20, rfoot = 20,
flagneck = 0, flaglshoulder = 0, flagrshoulder = 0,
flaglelbow = 0, flagrelbow = 0,
flaglhips = 0,flagrhips = 0, flaglfoot = 0, flagrfoot = 0;
bool IsStop = false;
void init();
void draw_body();
void draw_shoulder();
void draw_foot();
void draw_head();
void draw_eye();
void draw_mouth();
void move();
void display();
void reshape(int w, int h);
void keyboard(unsigned char key, int x, int y);
void TimerFunction(int value);
void welcome();
main.cpp
#include "main.h"
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RED);
glutInitWindowSize(600, 600);
glutInitWindowPosition(100, 100);
glutCreateWindow("机器人行走动画");
welcome();
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutTimerFunc(33, TimerFunction, 1);
glutMain