Search in sources :

Example 1 with PositionableSceneElement

use of org.jwildfire.create.eden.scene.PositionableSceneElement in project JWildfire by thargor6.

the class AddSceneObjectsVisitor method calcTransform.

private Matrix4 calcTransform(PositionableSceneElement pElement) {
    Matrix4 transform = Matrix4.IDENTITY;
    List<Matrix4> transforms = new ArrayList<Matrix4>();
    PositionableSceneElement element = pElement;
    while (element != null) {
        transforms.add(Matrix4.scale(element.getSize().getX(), element.getSize().getY(), element.getSize().getZ()));
        if (MathLib.fabs(element.getOrientation().getAlpha()) > MathLib.EPSILON) {
            transforms.add(Matrix4.rotateX((float) Math.toRadians(element.getOrientation().getAlpha())));
        }
        if (MathLib.fabs(element.getOrientation().getBeta()) > MathLib.EPSILON) {
            transforms.add(Matrix4.rotateY((float) Math.toRadians(element.getOrientation().getBeta())));
        }
        if (MathLib.fabs(element.getOrientation().getGamma()) > MathLib.EPSILON) {
            transforms.add(Matrix4.rotateZ((float) Math.toRadians(element.getOrientation().getGamma())));
        }
        transforms.add(Matrix4.translation(element.getPosition().getX(), element.getPosition().getY(), element.getPosition().getZ()));
        element = element.getParent();
    }
    for (int i = transforms.size() - 1; i >= 0; i--) {
        transform = transform.multiply(transforms.get(i));
    }
    return transform;
}
Also used : PositionableSceneElement(org.jwildfire.create.eden.scene.PositionableSceneElement) ArrayList(java.util.ArrayList) Matrix4(org.sunflow.math.Matrix4)

Aggregations

ArrayList (java.util.ArrayList)1 PositionableSceneElement (org.jwildfire.create.eden.scene.PositionableSceneElement)1 Matrix4 (org.sunflow.math.Matrix4)1