openGL光照随相机旋转
openGL lighting rotates with camera
我正试图建立一些简单的大学课程,我刚刚试图点亮它,但灯光似乎与相机旋转,这是完全恼人的…
我已经使用粘贴器将我的代码粘贴到下面(这样它就不会拉伸页面),但这里也有一点解释:
我在Display::Init(使用PoolLight类)中添加了灯光。在Display::Resize中设置摄像头。它被放置在'pool table'的上方(0,0,80),向下看(0,0,-1),X轴向前/向上(1,0,0)。
相机的这个简单的移动和旋转也调整了灯光,但没有调整几何形状(或者它可能调整了几何形状,而不是灯光,我不是很确定)。
我在这里读了一些关于同样问题的其他答案,但我真的不太明白。我希望有人能用更简单的术语给我解释一下,或者指出一些我不小心漏掉的明显的东西。
总之,下面是代码:
主显示类
PoolLight类:
#include "PoolLight.h"
#include "Glut/glut.h"
#include "GL/gl.h"
#include "GL/glu.h"
PoolLight::PoolLight(GLenum lightNumber, GLenum lightType, float red, float green, float blue, bool distant, float posX, float posY, float posZ)
{
this->lightNumber = lightNumber;
this->lightType = lightType;
color[0] = red; color[1] = green; color[2] = blue; color[3] = 1;
position[0] = posX; position[1] = posY; position[2] = posZ; position[3] = (int) (!distant);
glLightfv(lightNumber, lightType, color);
glLightfv(lightNumber, GL_POSITION, position);
enabled(true);
}
PoolLight::~PoolLight(void)
{
}
void PoolLight::setSpotlight(float angle, float attenuation, float dirX, float dirY, float dirZ) {
glLightf(lightNumber, GL_SPOT_EXPONENT, angle);
glLightf(lightNumber, GL_CONSTANT_ATTENUATION, attenuation);
glLightf(lightNumber, GL_LINEAR_ATTENUATION, 0.0f);
glLightf(lightNumber, GL_QUADRATIC_ATTENUATION, 0.0f);
spotDirection[0] = dirX; spotDirection[1] = dirY; spotDirection[2] = dirZ;
glLightfv(lightNumber, GL_SPOT_DIRECTION, spotDirection);
glLightf(lightNumber, GL_SPOT_CUTOFF, 60);
}
void PoolLight::enabled(bool enabled) {
if (enabled) glEnable(lightNumber);
else glDisable(lightNumber);
}
改变摄像机位置后,用光源的世界坐标再次调用glLightfv(lightNumber, GL_POSITION, position)
。然后绘制场景
相关文章:
- 将"Compass"与相机旋转隔离开GL
- 如何围绕对象旋转相机?
- 如何使用gluLookAt围绕OpenGL中的点旋转相机视图
- 如何校准相机焦距,平移和旋转给定四个点
- 从iPhone相机拍摄的视频似乎被OpenCV旋转了90度?我该如何解决这个问题?
- 相机的旋转方向在一段时间后反转
- 将网格与VTK相机对齐(相机的视觉表示,随之移动和旋转的网格)
- 直接相机旋转的错误控制
- 如何使OpenGL相机旋转360度
- C++OpenGl相机旋转使用四元数问题
- 尝试保持光标居中时,相机旋转会受损
- OpenGL第一人称相机旋转和平移
- 在openGL或更具体的LWJGL中,一个人如何相对于相机旋转
- 使用lookAt进行相机旋转
- 变换四元数相机旋转矩阵- OpenCV
- 使用相机旋转使四边形始终显示在相机前面(c++/opengl)
- OpenGL 相机旋转不起作用
- 如何累积相机旋转
- GLM相机X,Y旋转引入Z旋转的问题
- openGL光照随相机旋转