use of com.ardor3d.light.DirectionalLight in project energy3d by concord-consortium.
the class SceneManager method createCompass.
private Node createCompass() throws IOException {
final ResourceSource source = ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_MODEL, "compass.dae");
final ColladaImporter colladaImporter = new ColladaImporter();
// Load the collada scene
Logger.getLogger(ColladaAnimUtils.class.getName()).setLevel(Level.SEVERE);
Logger.getLogger(ColladaMaterialUtils.class.getName()).setLevel(Level.SEVERE);
final ColladaStorage storage = colladaImporter.load(source);
final Node compass = storage.getScene();
BMText txt;
final double Z = 0.1;
txt = new BMText("N", "N", FontManager.getInstance().getAnnotationFont(), Align.South);
txt.setTextColor(ColorRGBA.BLACK);
txt.setAutoRotate(false);
txt.setTranslation(2, 0.0, Z);
txt.setRotation(new Matrix3().fromAngles(0.0, MathUtils.HALF_PI, -MathUtils.HALF_PI));
compass.attachChild(txt);
txt = new BMText("S", "S", FontManager.getInstance().getAnnotationFont(), Align.South);
txt.setTextColor(ColorRGBA.BLACK);
txt.setAutoRotate(false);
txt.setTranslation(-2, -0.0, Z);
txt.setRotation(new Matrix3().fromAngles(0.0, -MathUtils.HALF_PI, MathUtils.HALF_PI));
compass.attachChild(txt);
txt = new BMText("W", "W", FontManager.getInstance().getAnnotationFont(), Align.South);
txt.setAutoRotate(false);
txt.setTranslation(-0.0, 2, Z);
txt.setRotation(new Matrix3().fromAngles(-MathUtils.HALF_PI, 0.0, 0.0));
compass.attachChild(txt);
txt = new BMText("E", "E", FontManager.getInstance().getAnnotationFont(), Align.South);
txt.setAutoRotate(false);
txt.setTranslation(-0.0, -2, Z);
txt.setRotation(new Matrix3().fromAngles(MathUtils.HALF_PI, MathUtils.PI, 0.0));
compass.attachChild(txt);
final DirectionalLight light = new DirectionalLight();
light.setDirection(new Vector3(0, 0, -1));
light.setEnabled(true);
final LightState lightState = new LightState();
lightState.attach(light);
compass.setRenderState(lightState);
compass.getSceneHints().setLightCombineMode(LightCombineMode.Replace);
compass.updateWorldRenderStates(true);
final Node compassNode = new Node();
compassNode.setRotation(new Matrix3().fromAngles(-MathUtils.HALF_PI, 0.0, 0.0));
compassNode.attachChild(compass);
System.out.println("done");
compass.addController(new SpatialController<Spatial>() {
@Override
public void update(final double time, final Spatial caller) {
final Vector3 direction = getCamera().getDirection().normalize(null);
direction.setZ(0);
direction.normalizeLocal();
double angle = -direction.smallestAngleBetween(Vector3.UNIT_Y);
if (direction.dot(Vector3.UNIT_X) > 0) {
angle = -angle;
}
angle -= MathUtils.HALF_PI;
compass.setRotation(new Matrix3().fromAngles(0.0, 0.0, angle - 0.3));
}
});
return compassNode;
}
use of com.ardor3d.light.DirectionalLight in project energy3d by concord-consortium.
the class SceneManager method createEarth.
private Node createEarth() throws IOException {
final ResourceSource source = ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_MODEL, "earth.dae");
final ColladaImporter colladaImporter = new ColladaImporter();
final ColladaStorage storage = colladaImporter.load(source);
final Node earth = storage.getScene();
final DirectionalLight light = new DirectionalLight();
light.setDirection(new Vector3(0, 0, -1));
light.setEnabled(true);
final LightState lightState = new LightState();
lightState.attach(light);
earth.setRenderState(lightState);
earth.getSceneHints().setLightCombineMode(LightCombineMode.Replace);
earth.updateWorldRenderStates(true);
final Node node = new Node();
node.setRotation(new Matrix3().fromAngles(-MathUtils.HALF_PI, 0.0, 0.0));
node.attachChild(earth);
earth.addController(new SpatialController<Spatial>() {
@Override
public void update(final double time, final Spatial caller) {
final Vector3 direction = getCamera().getDirection().normalize(null);
direction.setZ(0);
direction.normalizeLocal();
double angle = -direction.smallestAngleBetween(Vector3.UNIT_Y);
if (direction.dot(Vector3.UNIT_X) > 0) {
angle = -angle;
}
angle -= MathUtils.HALF_PI;
earth.setRotation(new Matrix3().fromAngles(0, 0, angle));
}
});
return node;
}
Aggregations