Java Code Examples for org.joml.Vector3f#y()

The following examples show how to use org.joml.Vector3f#y() . 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: SaveCameraConfiguration.java    From sciview with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void run() {
    try {
        FileWriter fw = new FileWriter(saveFile);
        BufferedWriter bw = new BufferedWriter(fw);

        if( !Files.getFileExtension(saveFile.getAbsolutePath()).equalsIgnoreCase("clj") )
            throw new IOException("File must be Clojure (extension = .clj)");

        Vector3f pos = sciView.getCamera().getPosition();
        Quaternionf rot = sciView.getCamera().getRotation();

        String scriptContents = "; @SciView sciView\n\n";
        scriptContents += "(.setPosition (.getCamera sciView) (cleargl.GLVector. (float-array [" + pos.x() + " " + pos.y() + " " + pos.z() + "])))\n";
        scriptContents += "(.setRotation (.getCamera sciView) (com.jogamp.opengl.math.Quaternion. " + rot.x() + " " + rot.y() + " " + rot.z() + " " + rot.w() + "))\n";

        bw.write(scriptContents);

        bw.close();
        fw.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 2
Source File: SciView.java    From sciview with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Position all lights that were initialized by default around the scene in a circle at Y=0
 */
public void surroundLighting() {
    OrientedBoundingBox bb = getSubgraphBoundingBox(getScene(), notAbstractBranchingFunction);
    OrientedBoundingBox.BoundingSphere boundingSphere = bb.getBoundingSphere();
    // Choose a good y-position, then place lights around the cross-section through this plane
    float y = 0;
    Vector3f c = boundingSphere.getOrigin();
    float r = boundingSphere.getRadius();
    for( int k = 0; k < lights.size(); k++ ) {
        PointLight light = lights.get(k);
        float x = (float) (c.x() + r * Math.cos( k == 0 ? 0 : Math.PI * 2 * ((float)k / (float)lights.size()) ));
        float z = (float) (c.y() + r * Math.sin( k == 0 ? 0 : Math.PI * 2 * ((float)k / (float)lights.size()) ));
        light.setLightRadius( 2 * r );
        light.setPosition( new Vector3f( x, y, z ) );
    }
}
 
Example 3
Source File: NodePropertyTreeCellRenderer.java    From sciview with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Converts a GLVector containing an RGB color to a GLVector containing
 * the color converted to HSL space. The RGB colors are assumed to be within [0, 1],
 * which is scenery's convention. Divide by 255 before otherwise.
 *
 * The conversion algorithm follows https://en.wikipedia.org/wiki/HSL_and_HSV#Conversion_RGB_to_HSL/HSV_used_commonly_in_software_programming
 *
 * @param rgb RGB color, with each channel in [0, 1].
 * @return converted color in HSL space
 */
public static Vector3f convertRGBtoHSL(Vector3f rgb) {
    float max = Math.max(rgb.x(), Math.max(rgb.y(), rgb.z()));
    float min = Math.min(rgb.x(), Math.min(rgb.y(), rgb.z()));
    float h;
    float s;
    float l = (max + min)/2.0f;

    if(max == min) {
        h = 0.0f;
        s = 0.0f;
    } else {
        float diff = max - min;
        if(l > 0.5f) {
            s = diff / (2 - max - min);
        } else {
            s = diff / (max + min);
        }

        if(max == rgb.x()) {
            h = (rgb.y() - rgb.z()) / diff + (rgb.y() < rgb.z() ? 6.0f : 0.0f);
        } else if(max == rgb.y()) {
            h = (rgb.z() - rgb.x()) / diff + 2.0f;
        } else {
            h = (rgb.x() - rgb.y()) / diff + 4.0f;
        }

        h /= 6.0f;
    }

    return new Vector3f(h, s, l);
}
 
Example 4
Source File: ParticleDemo.java    From sciview with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void faceNodeAlongVelocity(Node n, Vector3f vel) {
    n.getMetadata().put("velocity",vel);

    Quaternionf newRot = new Quaternionf();
    Vector3f dir = new Vector3f(vel.x(), vel.y(), vel.z());
    Vector3f up = new Vector3f(0f, 1f, 0f);
    newRot.lookAlong(dir, up);
    n.setRotation(newRot);
}