Search in sources :

Example 1 with Shape3D

use of javafx.scene.shape.Shape3D in project FXyzLib by Birdasaur.

the class BillboardBehavior method updateMatrix.

/**
     * Updates the transformation matrix.
     * can change the Translate for fixed distance  
     */
default default void updateMatrix() {
    Transform cam = getOther().getLocalToSceneTransform(), self = getBillboardNode().getLocalToSceneTransform();
    Bounds b;
    double cX, cY, cZ;
    if (!(getBillboardNode() instanceof Shape3D)) {
        b = getBillboardNode().getBoundsInLocal();
        cX = b.getWidth() / 2;
        cY = b.getHeight() / 2;
        cZ = b.getDepth() / 2;
    } else {
        cX = self.getTx();
        cY = self.getTy();
        cZ = self.getTz();
    }
    Point3D camPos = new Point3D(cam.getTx(), cam.getTy(), cam.getTz());
    Point3D selfPos = new Point3D(cX, cY, cZ);
    Vector3D up = Vector3D.UP, forward = new Vector3D((selfPos.getX()) - camPos.getX(), (selfPos.getY()) - camPos.getY(), (selfPos.getZ()) - camPos.getZ()).toNormal(), right = up.crossProduct(forward).toNormal();
    up = forward.crossProduct(right).toNormal();
    switch(getBillboardMode()) {
        case SPHERICAL:
            affine.setMxx(right.x);
            affine.setMxy(up.x);
            affine.setMzx(forward.x);
            affine.setMyx(right.y);
            affine.setMyy(up.y);
            affine.setMzy(forward.y);
            affine.setMzx(right.z);
            affine.setMzy(up.z);
            affine.setMzz(forward.z);
            affine.setTx(cX * (1 - affine.getMxx()) - cY * affine.getMxy() - cZ * affine.getMxz());
            affine.setTy(cY * (1 - affine.getMyy()) - cX * affine.getMyx() - cZ * affine.getMyz());
            affine.setTz(cZ * (1 - affine.getMzz()) - cX * affine.getMzx() - cY * affine.getMzy());
            break;
        case CYLINDRICAL:
            affine.setMxx(right.x);
            affine.setMxy(0);
            affine.setMzx(forward.x);
            affine.setMyx(0);
            affine.setMyy(1);
            affine.setMzy(0);
            affine.setMzx(right.z);
            affine.setMzy(0);
            affine.setMzz(forward.z);
            affine.setTx(cX * (1 - affine.getMxx()) - cY * affine.getMxy() - cZ * affine.getMxz());
            affine.setTy(cY * (1 - affine.getMyy()) - cX * affine.getMyx() - cZ * affine.getMyz());
            affine.setTz(cZ * (1 - affine.getMzz()) - cX * affine.getMzx() - cY * affine.getMzy());
            break;
    }
}
Also used : Vector3D(org.fxyz.geometry.Vector3D) Point3D(javafx.geometry.Point3D) Bounds(javafx.geometry.Bounds) Shape3D(javafx.scene.shape.Shape3D) Transform(javafx.scene.transform.Transform)

Example 2 with Shape3D

use of javafx.scene.shape.Shape3D in project FXyzLib by Birdasaur.

the class ScatterPlot method setXYZData.

public void setXYZData(List<Double> xData, List<Double> yData, List<Double> zData, List<Color> colors) {
    xAxisData = xData;
    yAxisData = yData;
    zAxisData = zData;
    scatterDataGroup.getChildren().clear();
    //uses 0's for the other axes that are larger.
    for (int i = 0; i < xAxisData.size(); i++) {
        final Shape3D dataSphere = createDefaultNode(nodeRadius);
        double translateY = 0.0;
        double translateZ = 0.0;
        if (!yAxisData.isEmpty() && yAxisData.size() > i)
            translateY = yAxisData.get(i);
        if (!zAxisData.isEmpty() && zAxisData.size() > i)
            translateZ = zAxisData.get(i);
        dataSphere.setTranslateX(xAxisData.get(i));
        dataSphere.setTranslateY(translateY);
        dataSphere.setTranslateZ(translateZ);
        dataSphere.setMaterial(new PhongMaterial(colors.get(i)));
        scatterDataGroup.getChildren().add(dataSphere);
    }
}
Also used : Shape3D(javafx.scene.shape.Shape3D) PhongMaterial(javafx.scene.paint.PhongMaterial)

Aggregations

Shape3D (javafx.scene.shape.Shape3D)2 Bounds (javafx.geometry.Bounds)1 Point3D (javafx.geometry.Point3D)1 PhongMaterial (javafx.scene.paint.PhongMaterial)1 Transform (javafx.scene.transform.Transform)1 Vector3D (org.fxyz.geometry.Vector3D)1