 ! (c)Joe Groff bsd license
-USING: accessors classes.struct kernel locals math math.functions
-math.matrices.simd math.vectors math.vectors.simd sequences
-sequences.private specialized-arrays typed ;
+USING: accessors classes.struct generalizations kernel locals
+math math.functions math.matrices.simd math.vectors
+math.vectors.simd sequences sequences.private specialized-arrays
+typed ;
 QUALIFIED-WITH: alien.c-types c
 SIMD: c:float
 SPECIALIZED-ARRAY: float-4


    float-4{ 0.0 0.0 0.0 1.0 } :> c4
    { t t t f } offset c4 v? :> offset'
    offset' { 3 3 3 0 } vshuffle { t f f t } vmask :> c1
    offset' { 3 3 3 1 } vshuffle { f t f t } vmask :> c2
    offset' { 3 3 3 2 } vshuffle { f f t t } vmask :> c3

    c1 c rows>> set-first
    c2 c rows>> set-second
    c3 c rows>> set-third
    c4 c rows>> set-fourth

    c ;

TYPED:: rotation-matrix4 ( axis: float-4 theta: float -- matrix: matrix4 )
    !   x*x + c*(1.0 - x*x)   x*y*(1.0 - c) - s*z   x*z*(1.0 - c) + s*y   0

    matrix4 (struct) :> c

    factors { t t t f } vmask :> factors'

    factors' { 0 3 3 3 } vshuffle
    factors' { 3 1 3 3 } vshuffle
    factors' { 3 3 2 3 } vshuffle
    float-4{ 0.0 0.0 0.0 1.0 }

    c set-rows ;

: ortho-matrix4 ( factors -- matrix )
    float-4{ 1.0 1.0 1.0 1.0 } swap v/ scale-matrix4 ; inline
