Search in sources :

Example 1 with Vector3D

use of org.fxyz.geometry.Vector3D 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 Vector3D

use of org.fxyz.geometry.Vector3D in project FXyzLib by Birdasaur.

the class MathUtils method computeNormal.

public static Vector3D computeNormal(Vector3D v1, Vector3D v2, Vector3D v3) {
    Vector3D a1 = v1.sub(v2);
    Vector3D a2 = v3.sub(v2);
    return a2.crossProduct(a1).toNormal();
}
Also used : Vector3D(org.fxyz.geometry.Vector3D)

Aggregations

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