Matrix4f tmp = new Matrix4f(rot);
tmp.invert();
transform.mul(tmp);
DirectionalLight light = scene.getLights()[lightRotationMode];
Vector3f direction = new Vector3f();
light.getDirection(direction);
transform.transform(direction);
light.setDirection(direction);
// this calls detach/attach => more flicker
//scene.showLightVector(direction.x,direction.y,direction.z);
// update pos, don't move view
pos2DX = newX;
pos2DY = newY;
peerWindow.repaint();
return;
}
// rotate all lights together with view
if (scene!=null) {
float dx=(float)(newX-pos2DX)/wsize;
float dy=(float)(newY-pos2DY)/wsize;
if (inverse) {
dx = -dx;
dy = -dy;
}
drotX.rotX(dy * 2 * (float)Math.PI);
drotY.rotY(dx * 2 * (float)Math.PI);
Matrix4f transform = new Matrix4f(rot);
transform.mul(drotX);
transform.mul(drotY);
Matrix4f tmp = new Matrix4f(rot);
tmp.invert();
transform.mul(tmp);
DirectionalLight[] lights = scene.getLights();
Vector3f direction = new Vector3f();
for (int i=0; i<lights.length; ++i) {
lights[i].getDirection(direction);
transform.transform(direction);
lights[i].setDirection(direction);
}