Skip to content

Commit 5a9ba3e

Browse files
committed
fix lights position when setting camera rotation
1 parent a996562 commit 5a9ba3e

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/renderer/webgl/pipelines/LightPipeline.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,18 @@ var LightPipeline = new Class({
197197

198198
var lightName = 'uLights[' + i + '].';
199199

200-
cameraMatrix.transformPoint(light.x, light.y, tempVec2);
201-
202-
this.set2f(lightName + 'position', tempVec2.x - (camera.scrollX * light.scrollFactorX * camera.zoom), height - (tempVec2.y - (camera.scrollY * light.scrollFactorY) * camera.zoom));
200+
if (camera.rotation !== 0)
201+
{
202+
// When camera is rotated, use the camera matrix transformation which handles rotation, scroll, and zoom
203+
cameraMatrix.transformPoint(light.x - (camera.scrollX * light.scrollFactorX), light.y - (camera.scrollY * light.scrollFactorY), tempVec2);
204+
this.set2f(lightName + 'position', tempVec2.x, height - tempVec2.y);
205+
}
206+
else
207+
{
208+
// When camera is not rotated, use the original faster calculation
209+
cameraMatrix.transformPoint(light.x, light.y, tempVec2);
210+
this.set2f(lightName + 'position', tempVec2.x - (camera.scrollX * light.scrollFactorX * camera.zoom), height - (tempVec2.y - (camera.scrollY * light.scrollFactorY) * camera.zoom));
211+
}
203212
this.set3f(lightName + 'color', color.r, color.g, color.b);
204213
this.set1f(lightName + 'intensity', light.intensity);
205214
this.set1f(lightName + 'radius', light.radius);

0 commit comments

Comments
 (0)