Java Code Examples for com.jme3.math.FastMath#RAD_TO_DEG

The following examples show how to use com.jme3.math.FastMath#RAD_TO_DEG . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SceneLoader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void parseCamera(Attributes attribs) throws SAXException {
    camera = new Camera(DEFAULT_CAM_WIDTH, DEFAULT_CAM_HEIGHT);
    if (SAXUtil.parseString(attribs.getValue("projectionType"), "perspective").equals("parallel")){
        camera.setParallelProjection(true);
    }
    float fov = SAXUtil.parseFloat(attribs.getValue("fov"), 45f);
    if (fov < FastMath.PI) { 
        // XXX: Most likely, it is in radians..
        fov = fov * FastMath.RAD_TO_DEG;
    }
    camera.setFrustumPerspective(fov, (float)DEFAULT_CAM_WIDTH / DEFAULT_CAM_HEIGHT, 1, 1000);
    
    cameraNode = new CameraNode(attribs.getValue("name"), camera);
    cameraNode.setControlDir(ControlDirection.SpatialToCamera);
    
    node.attachChild(cameraNode);
    node = null;
}
 
Example 2
Source File: SceneLoader.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void parseCamera(Attributes attribs) throws SAXException {
    camera = new Camera(DEFAULT_CAM_WIDTH, DEFAULT_CAM_HEIGHT);
    if (SAXUtil.parseString(attribs.getValue("projectionType"), "perspective").equals("parallel")){
        camera.setParallelProjection(true);
    }
    float fov = SAXUtil.parseFloat(attribs.getValue("fov"), 45f);
    if (fov < FastMath.PI) { 
        // XXX: Most likely, it is in radians..
        fov = fov * FastMath.RAD_TO_DEG;
    }
    camera.setFrustumPerspective(fov, (float)DEFAULT_CAM_WIDTH / DEFAULT_CAM_HEIGHT, 1, 1000);
    
    cameraNode = new CameraNode(attribs.getValue("name"), camera);
    cameraNode.setControlDir(ControlDirection.SpatialToCamera);
    
    node.attachChild(cameraNode);
    node = null;
}
 
Example 3
Source File: TestAndroidSensors.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private float toDegrees(float rad) {
    return rad * FastMath.RAD_TO_DEG;
}
 
Example 4
Source File: CameraHelper.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * This method converts the given structure to jme camera. Should be used form blender 2.5+.
 * 
 * @param structure
 *            camera structure
 * @param sceneStructure
 *            scene structure
 * @return jme camera object
 * @throws BlenderFileException
 *             an exception is thrown when there are problems with the
 *             blender file
 */
private CameraNode toCamera250(Structure structure, Structure sceneStructure) throws BlenderFileException {
    int width = DEFAULT_CAM_WIDTH;
    int height = DEFAULT_CAM_HEIGHT;
    if (sceneStructure != null) {
        Structure renderData = (Structure) sceneStructure.getFieldValue("r");
        width = ((Number) renderData.getFieldValue("xsch")).shortValue();
        height = ((Number) renderData.getFieldValue("ysch")).shortValue();
    }
    Camera camera = new Camera(width, height);
    int type = ((Number) structure.getFieldValue("type")).intValue();
    if (type != 0 && type != 1) {
        LOGGER.log(Level.WARNING, "Unknown camera type: {0}. Perspective camera is being used!", type);
        type = 0;
    }
    // type==0 - perspective; type==1 - orthographic; perspective is used as default
    camera.setParallelProjection(type == 1);
    float aspect = width / (float) height;
    float fovY; // Vertical field of view in degrees
    float clipsta = ((Number) structure.getFieldValue("clipsta")).floatValue();
    float clipend = ((Number) structure.getFieldValue("clipend")).floatValue();
    if (type == 0) {
        // Convert lens MM to vertical degrees in fovY, see Blender rna_Camera_angle_get()
        // Default sensor size prior to 2.60 was 32.
        float sensor = 32.0f;
        boolean sensorVertical = false;
        Number sensorFit = (Number) structure.getFieldValue("sensor_fit");
        if (sensorFit != null) {
            // If sensor_fit is vert (2), then sensor_y is used
            sensorVertical = sensorFit.byteValue() == 2;
            String sensorName = "sensor_x";
            if (sensorVertical) {
                sensorName = "sensor_y";
            }
            sensor = ((Number) structure.getFieldValue(sensorName)).floatValue();
        }
        float focalLength = ((Number) structure.getFieldValue("lens")).floatValue();
        float fov = 2.0f * FastMath.atan((sensor / 2.0f) / focalLength);
        if (sensorVertical) {
            fovY = fov * FastMath.RAD_TO_DEG;
        } else {
            // Convert fov from horizontal to vertical
            fovY = 2.0f * FastMath.atan(FastMath.tan(fov / 2.0f) / aspect) * FastMath.RAD_TO_DEG;
        }
    } else {
        // This probably is not correct.
        fovY = ((Number) structure.getFieldValue("ortho_scale")).floatValue();
    }
    camera.setFrustumPerspective(fovY, aspect, clipsta, clipend);
    return new CameraNode(null, camera);
}