libgdx / box2dlights

Fork of box2dlights by Kalle Hamalainen
Apache License 2.0
256 stars 81 forks source link

Attached coneLight angle offset #47

Closed hard2bit closed 9 years ago

hard2bit commented 9 years ago

Hello there,

Currently if you create a ConeLight you can set its world position, cone aperture and direction, and that is just fine. However, if you attach the light to a physical body, there doesn't seem to be a way of setting a rotation offset between the light and the body - the light always points to where the body points its 0 angle (If you rotate the body, the light becomes rotated but there doesn't seem to be a way of giving an initial offset to this angle); i.e. the angle initially set is just ignored. So I have a car with front and back lights (2D car seen from the top), and I can't find a way of pointing one light to the front and the other one to the back, having both lights attached to the car body. In addition, in newer versions of the Box2DLights library I had to change the Light.attachToBody(body, x, y) method to Light.attachToBody(body), with no information about the change (haven't found any, I mean) and it would be great if the Box2D debugger could show the lights origin because it's a little troublesome.

So, is this rotation offset achievable without having to manually update a detached light's position and rotation?

rinold commented 9 years ago

In addition, in newer versions of the Box2DLights library I had to change the Light.attachToBody(body, x, y) method to Light.attachToBody(body), with no information about the change (haven't found any, I mean)

You should use the actual type of light instead of it's abstract base:

ConeLight frontLight = <your light constructor here>;
// Then you can attach it with offset
frontLight.attach(body, x, y);
// Or you can attach it with offset and fixed angle - this is what you want as I understand:
frontLight.attach(body, x, y, degrees);

it would be great if the Box2D debugger could show the lights origin because it's a little troublesome.

Box2d engine is not aware about what lights are, however you can submit a separate enhancement request to provide some box2dlights debugging rendering mechanism.

hard2bit commented 9 years ago

That was it. Thank you very much, I saw the constructor inside the PositionalLight source, but I initially thought the problem was related to being a different verison of the library.

Cheers!