directional light position

Software: Away3D 4.x

mole, Newbie
Posted: 17 October 2013 10:44 AM   Total Posts: 29

I would like to “attach” a directional light to a camera. I would like the light to be paralell with the camera view angle.
I thought it would be possible to do this this way:

dLight.x=cameraPos.x;
dLight.y=cameraPos.y;
dLight.z=cameraPos.z;
dLight.lookAt(cameraTarget);

This doesn’t seem to work at all. Is this the correct way? Or how would I tackle this problem?

   

Avatar
GoroMatsumoto, Sr. Member
Posted: 17 October 2013 11:50 AM   Total Posts: 166   [ # 1 ]
dLight.direction camera.forwardVector

How about this?
I have not tested this.

About DirectionalLight, read “Let there be light” part in follow article.
http://away3d.com/tutorials/Introduction_to_Materials

   

Avatar
Fabrice Closier, Administrator
Posted: 17 October 2013 01:51 PM   Total Posts: 1265   [ # 2 ]

this is correct.

   

mole, Newbie
Posted: 17 October 2013 02:33 PM   Total Posts: 29   [ # 3 ]

doesn’t seem to work for me. The light is static, even though I update it’s posistion & direction

   

Avatar
GoroMatsumoto, Sr. Member
Posted: 17 October 2013 05:52 PM   Total Posts: 166   [ # 4 ]

@Fabirice
Thank you.

@mole

This type of light does not have a concept of location, only direction. As such, the constructor or the direction property is used to define the angle the light is emminating from. The light from a DirectionalLights has a constant intensity, meaning that it makes no difference how far an object is away from the light source, it will be illuminated in the same way.

You don’t need set the position of dLight.
Just update it’s direction property.

scene.addChild(camera); 

If you can’t get correct result, try this code too.

Good luck.

   

mole, Newbie
Posted: 18 October 2013 02:38 PM   Total Posts: 29   [ # 5 ]

Still, it doesn’t work for me. If I set the direction manually, I can make the light direction change. If I use the camera forward vector… the light always comes from above. Very strange…

   

mole, Newbie
Posted: 18 October 2013 02:58 PM   Total Posts: 29   [ # 6 ]

I think I fixed it. The reason was I set it’s direction before it was added to the scene. I then add it to the scene, but any update after that didn’t work.
If I start updating the direction after it’s been added, it seems to work as expected.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X