OpenGL:跟随相机的光源?

OpenGL:跟随相机的光源?

问题描述:

伙计们,这怎么可能.但在我之前的项目中,事实并非如此.我不知道我是如何尝试这种效果的.请说实话.

Guys, how can this be. But in my previous projects, it wasn't. And I don't know how I attempt this effect. Tell me the truth, please.

第 18.050 节,如何让我的灯移动或不移动并控制灯的位置?:

首先,您必须了解光位置由OpenGL.

First, you must understand how the light position is transformed by OpenGL.

灯光位置变换为当前顶部的内容当您使用 ModelView 矩阵堆栈时通过电话指定灯光位置到 glLightfv( GL_LIGHTn, GL_POSITION, ... ).如果您稍后更改 ModelView矩阵,比如当视图改变时对于下一帧,灯光位置不会自动重新转换ModelView 的新内容矩阵.如果你想更新光的位置,你必须再次通过电话指定灯光位置到 glLightfv( GL_LIGHTn, GL_POSITION, ... ).

The light position is transformed by the contents of the current top of the ModelView matrix stack when you specify the light position with a call to glLightfv( GL_LIGHTn, GL_POSITION, ... ). If you later change the ModelView matrix, such as when the view changes for the next frame, the light position isn't automatically retransformed by the new contents of the ModelView matrix. If you want to update the light’s position, you must again specify the light position with a call to glLightfv( GL_LIGHTn, GL_POSITION, ... ).

...

  • 如何让我的灯光位置相对于我的眼睛保持固定位置?如何制作车头灯?

您需要指定眼睛中的光线坐标空间.为此,请设置ModelView 矩阵到身份,然后指定您的灯光位置.做一个头灯(一种看起来像位于或靠近眼睛和沿着视线发光),设置将 ModelView 设置为身份,设置位于(或附近)的灯光位置原点,并将方向设置为负 Z 轴.

You need to specify your light in eye coordinate space. To do so, set the ModelView matrix to the identity, then specify your light position. To make a headlight (a light that appears to be positioned at or near the eye and shining along the line of sight), set the ModelView to the identity, set the light position at (or near) the origin, and set the direction to the negative Z axis.

当灯的位置固定时相对于眼睛,你不需要重新指定每个灯的位置框架.通常,您指定一次当您的程序初始化时.

When a light’s position is fixed relative to the eye, you don't need to respecify the light position for every frame. Typically, you specify it once when your program initializes.