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

commonMain.ru.casperix.math.Transform.kt Maven / Gradle / Ivy

There is a newer version: 1.1.1
Show newest version
package ru.casperix.math

import ru.casperix.math.geometry.fDEGREE_TO_RADIAN
import ru.casperix.math.quad_matrix.float32.Matrix3f
import kotlin.math.cos
import kotlin.math.sin

data class Transform(
    val x: Float = 0f,
    val y: Float = 0f,
    val rotation: Float = 0f,
    val scaleX: Float = 0f,
    val scaleY: Float = 0f,
    val shearX: Float = 0f,
    val shearY: Float = 0f,
) {
    fun toLHSMatrix():Matrix3f {
        return toABCD().toMatrix()
    }

    private fun toABCD(): TransformABCD {
        val radian = rotation * fDEGREE_TO_RADIAN
        val cos = cos(radian)
        val sin = sin(radian)
        return TransformABCD(
            x, -y,
            cos * scaleX,
            -sin* scaleY,
            sin * scaleX,
            cos* scaleY,
        )
//        val rx: Float = (rotation + shearX) * fDEGREE_TO_RADIAN
//        val ry: Float = (rotation + 90 + shearY) * fDEGREE_TO_RADIAN
//        return TransformABCD(
//            x, y,
//            cos(rx) * scaleX,
//            cos(ry) * scaleY,
//            sin(rx) * scaleX,
//            sin(ry) * scaleY,
//        )
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy