All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.dsl.functions.extra.RotationFunctions.kt Maven / Gradle / Ivy

package org.openrndr.orsl.shadergenerator.phrases.dsl.functions.extra

import org.openrndr.orsl.shadergenerator.dsl.ShaderBuilder
import org.openrndr.orsl.shadergenerator.dsl.Symbol
import org.openrndr.orsl.shadergenerator.dsl.functions.function
import org.openrndr.orsl.shadergenerator.dsl.functions.symbol
import org.openrndr.math.Matrix33
import org.openrndr.math.Vector3

fun ShaderBuilder.normalRotate(point: Symbol, direction: Symbol): Symbol {
    val clipRotate by function { point, direction ->
        val dOx by abs(direction.dot(Vector3.UNIT_X.symbol)) lt 0.99
        val up by if_(dOx) { direction.cross(Vector3.UNIT_X.symbol).normalized } else_ {
            direction.cross(Vector3.UNIT_Y.symbol).normalized
        }
        val right by up.cross(direction)
        val r by Matrix33.fromColumnVectors(right, up, direction) * point
        r
    }
    return clipRotate(point, direction)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy