If cube-mapped skies are subject to rotation, it would be nice if rotation affected them
the same way it affects other geometries. In the case of rotation around the Y-axis,
the effect appears to be backward.
In the following test code, I apply the same rotation to the floor and the sky
(by pressing the “T” or “Y” key) and see them turn in opposite directions.
Why is the sky rotating the wrong way?
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import com.jme3.system.JmeVersion;
import com.jme3.util.SkyFactory;
public class Main extends SimpleApplication implements ActionListener {
Spatial floor, sky;
float angle;
public static void main(String[] arguments) {
Main application = new Main();
application.start();
}
@Override
public void simpleInitApp() {
System.out.printf("jME3-core version is %s%n", JmeVersion.FULL_NAME);
cam.setLocation(new Vector3f(-7f, 4f, 8f));
cam.setRotation(new Quaternion(0.0036812495f, 0.944684f, -0.010609083f, 0.3277894f));
sky = SkyFactory.createSky(assetManager,
"Scenes/Beach/FullskiesSunset0068.dds",
SkyFactory.EnvMapType.CubeMap);
rootNode.attachChild(sky);
Box b = new Box(10f, 0.1f, 10f);
floor = new Geometry("floor", b);
Material mat = new Material(assetManager,
"Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.White);
mat.setTexture("ColorMap",
assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
floor.setMaterial(mat);
rootNode.attachChild(floor);
angle = 0f;
inputManager.addMapping("left", new KeyTrigger(KeyInput.KEY_T));
inputManager.addMapping("right", new KeyTrigger(KeyInput.KEY_Y));
inputManager.addListener(this, "left");
inputManager.addListener(this, "right");
}
@Override
public void onAction(String name, boolean ongoing, float ignored) {
if (!ongoing) {
return;
}
if (name.equals("left")) {
angle += 0.1f;
System.out.print("rotate both spatials left");
} else if (name.equals("right")) {
angle -= 0.1f;
System.out.printf("rotate both spatials right");
} else {
return;
}
System.out.printf(" to %f radians from start%n", angle);
Quaternion rotation = new Quaternion();
rotation.fromAngleNormalAxis(angle, Vector3f.UNIT_Y);
floor.setLocalRotation(rotation);
sky.setLocalRotation(rotation);
}
}