List of usage examples for com.badlogic.gdx.graphics.g3d ModelInstance getNode
public Node getNode(final String id)
From source file:com.bladecoder.engine.model.Sprite3DRenderer.java
License:Apache License
private PerspectiveCamera getCamera(ModelInstance modelInstance) { PerspectiveCamera camera3d = new PerspectiveCamera(cameraFOV, width, height); if (cameraPos == null) { Node n = null;/*from w w w. j a va 2s .c om*/ // SET CAMERA POS FROM MODEL IF EXISTS n = modelInstance.getNode(cameraName); if (n != null) { cameraPos = n.translation; } else { cameraPos = new Vector3(0, 0, 5); } } if (cameraRot == null) { Node n = null; // SET CAMERA POS FROM MODEL IF EXISTS n = modelInstance.getNode(cameraName); if (n != null) { float rx = (float) (MathUtils.radiansToDegrees * Math.asin(2 * n.rotation.x * n.rotation.y + 2 * n.rotation.z * n.rotation.w)); float ry = (float) (MathUtils.radiansToDegrees * Math.atan2(2 * n.rotation.x * n.rotation.w - 2 * n.rotation.y * n.rotation.z, 1 - 2 * n.rotation.x * n.rotation.x - 2 * n.rotation.z * n.rotation.z)); float rz = (float) (Math.atan2(2 * n.rotation.y * n.rotation.w - 2 * n.rotation.x * n.rotation.z, 1 - 2 * n.rotation.y * n.rotation.y - 2 * n.rotation.z * n.rotation.z)); setCameraRot(rx, ry, rz); } else { cameraRot = new Vector3(); } } camera3d.position.set(cameraPos); camera3d.rotate(cameraRot.x, 1, 0, 0); camera3d.rotate(cameraRot.y, 0, 1, 0); camera3d.rotate(cameraRot.z, 0, 0, 1); camera3d.near = 0.1f; camera3d.far = 30; camera3d.update(); return camera3d; }