Search in sources :

Example 1 with LightState

use of com.ardor3d.renderer.state.LightState 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;
}
Also used : LightState(com.ardor3d.renderer.state.LightState) ColladaImporter(com.ardor3d.extension.model.collada.jdom.ColladaImporter) Node(com.ardor3d.scenegraph.Node) CameraNode(com.ardor3d.scenegraph.extension.CameraNode) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) Matrix3(com.ardor3d.math.Matrix3) ResourceSource(com.ardor3d.util.resource.ResourceSource) Spatial(com.ardor3d.scenegraph.Spatial) DirectionalLight(com.ardor3d.light.DirectionalLight) ColladaStorage(com.ardor3d.extension.model.collada.jdom.data.ColladaStorage) BMText(com.ardor3d.ui.text.BMText)

Example 2 with LightState

use of com.ardor3d.renderer.state.LightState 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;
}
Also used : LightState(com.ardor3d.renderer.state.LightState) ResourceSource(com.ardor3d.util.resource.ResourceSource) Spatial(com.ardor3d.scenegraph.Spatial) ColladaImporter(com.ardor3d.extension.model.collada.jdom.ColladaImporter) Node(com.ardor3d.scenegraph.Node) CameraNode(com.ardor3d.scenegraph.extension.CameraNode) DirectionalLight(com.ardor3d.light.DirectionalLight) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) ColladaStorage(com.ardor3d.extension.model.collada.jdom.data.ColladaStorage) Matrix3(com.ardor3d.math.Matrix3)

Aggregations

ColladaImporter (com.ardor3d.extension.model.collada.jdom.ColladaImporter)2 ColladaStorage (com.ardor3d.extension.model.collada.jdom.data.ColladaStorage)2 DirectionalLight (com.ardor3d.light.DirectionalLight)2 Matrix3 (com.ardor3d.math.Matrix3)2 Vector3 (com.ardor3d.math.Vector3)2 ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)2 LightState (com.ardor3d.renderer.state.LightState)2 Node (com.ardor3d.scenegraph.Node)2 Spatial (com.ardor3d.scenegraph.Spatial)2 CameraNode (com.ardor3d.scenegraph.extension.CameraNode)2 ResourceSource (com.ardor3d.util.resource.ResourceSource)2 BMText (com.ardor3d.ui.text.BMText)1