简体   繁体   English

OpenGL:跟随相机的光源?

[英]OpenGL: Light source that follows the camera?

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.请告诉我真相。

Section 18.050, How can I make my light move or not move and control the light position? 第 18.050 节,如何让我的灯移动或不移动并控制灯的位置? : :

First, you must understand how the light position is transformed by OpenGL.首先,您必须了解 OpenGL 是如何变换光线位置的。

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, ... ) .当您通过调用glLightfv( GL_LIGHTn, GL_POSITION, ... )指定灯光位置时,灯光位置会根据 ModelView 矩阵堆栈当前顶部的内容进行转换。 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.如果您稍后更改 ModelView 矩阵,例如当下一帧的视图发生变化时,灯光位置不会被 ModelView 矩阵的新内容自动重新转换。 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, ... ) .如果你想更新灯光的位置,你必须通过调用glLightfv( GL_LIGHTn, GL_POSITION, ... )再次指定灯光位置。

... ...

  • How can I make my light position stay fixed relative to my eye position?我怎样才能使我的灯光位置相对于我的眼睛位置保持固定? How do I make a headlight?如何制作头灯?

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.为此,请将 ModelView 矩阵设置为恒等式,然后指定您的灯光位置。 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.要制作头灯(看起来位于眼睛或靠近眼睛并沿着视线发光的灯),请将 ModelView 设置为 identity,将灯位置设置在(或靠近)原点,并将方向设置为负 Z 轴。

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.通常,您在程序初始化时指定一次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM