【OpenGL】光源处理 / 机器人行走动画

本文探讨了OpenGL中的光照模型,包括全局泛光强度、视点位置对光照的影响以及物体正背面的光照计算。同时,讲解了全局环境光的概念,并分析了光源位置与光的衰减对场景光照效果的作用。此外,还提到了机器人行走动画的实现,提供了相关资源链接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考文章:OpenGL特殊光处理

 

OpenGL光照模型:

  1. 全局泛光强度
  2. 视点位置在景物的位置
  3. 物体的正面和背面是否分别进行光照计算

 

全局环境光:

使用参数 : 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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值