Public Group

# light position

This topic is 2842 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hello.
I wish place a light always at 45°(for example , but the angle can change ) at left of the camera and at 1/2 of the camera dinstance .
The light must follow the camera if i move it.
How i can calculate frame for frame the light position?
I must use dot product?
thanks.

##### Share on other sites
It sounds like you just need a (local) transform for the light, and to concatenate that transform with the camera object's transform each update (which will keep the light in the same configuration with respect to the camera as the camera moves).

I might be misunderstanding the question though.

##### Share on other sites

It sounds like you just need a (local) transform for the light, and to concatenate that transform with the camera object's transform each update (which will keep the light in the same configuration with respect to the camera as the camera moves).

I might be misunderstanding the question though.

thanks , you have understand.
My problem is that i wish find the position of light(at 45 degree...) in an hlsl shader.
In the shader i have the position of the camera, and i wish find the position of the light .

I try this :
 float angle = radians(45.0); float x = CameraModelPosition.x * cos(angle) - CameraModelPosition.y * sin(angle); float y = CameraModelPosition.x * sin(angle) + CameraModelPosition.y * cos(angle); float3 Light0ModelDirection = float3(x, y, CameraModelPosition.z); 

but don't work.

##### Share on other sites

but don't work.

Yeah, I wouldn't expect that to work; it looks like you're just rotating the camera position by 45 degrees, which won't keep the light position constant with respect to the camera as the camera moves.

I think concatenating the transforms is what you're looking for. I can't give you the HLSL-specific details off the top of my head, but it should reduce to either a matrix multiplication or two, or some simple vector math. (Maybe someone else will be able to provide an HLSL example.)

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 11
• ### Forum Statistics

• Total Topics
634090
• Total Posts
3015434
×