Partial changes to ASS rotation code
This commit is contained in:
parent
f3255b57ac
commit
f1196e854f
|
@ -22,6 +22,7 @@ class MatrixTransform {
|
|||
return new MatrixTransform($scale, null, null);
|
||||
}
|
||||
|
||||
//TODO: check sin sign location
|
||||
public static function rotate(float $angle) : MatrixTransform{
|
||||
$cos = cos($angle);
|
||||
$sin = sin($angle);
|
||||
|
@ -36,26 +37,15 @@ class MatrixTransform {
|
|||
return new MatrixTransform(null, null, null);
|
||||
}
|
||||
|
||||
//TODO: skewX, skewY
|
||||
public static function skewX(float $angle) : MatrixTransform{
|
||||
return new MatrixTransform(null, new Vector2(tan($angle), 0), null);
|
||||
}
|
||||
|
||||
public static function skewY(float $angle) : MatrixTransform{
|
||||
return new MatrixTransform(null, new Vector2(0, tan($angle)), null);
|
||||
}
|
||||
|
||||
public function combine(MatrixTransform $other): MatrixTransform {
|
||||
/*
|
||||
return new MatrixTransform(
|
||||
new Vector2(
|
||||
$this->get_a() * $other->get_a() + $this->get_c() * $other->get_b(),
|
||||
$this->get_b() * $other->get_c() + $this->get_d() * $other->get_d(),
|
||||
),
|
||||
new Vector2(
|
||||
$this->get_b() * $other->get_a() + $this->get_d() * $other->get_b(),
|
||||
$this->get_a() * $other->get_c() + $this->get_c() * $other->get_d(),
|
||||
),
|
||||
new Vector2(
|
||||
$this->get_a() * $other->get_e() + $this->get_c() * $other->get_f() + $this->get_e(),
|
||||
$this->get_b() * $other->get_e() + $this->get_d() * $other->get_f() + $this->get_f()
|
||||
)
|
||||
);
|
||||
*/
|
||||
|
||||
$result = clone $this;
|
||||
$result->matrix = $other->matrix->multiply($this->matrix);
|
||||
return $result;
|
||||
|
|
|
@ -287,6 +287,39 @@ class matrixTransformTag implements ASSPositioningTag {
|
|||
|
||||
$scale_x = $scale_y = $frx = $fry = $frz = $fax = $fay = 0;
|
||||
|
||||
|
||||
//TODO: WiP, fix rotations on negative scales
|
||||
|
||||
$i = sqrt($a * $a + $c * $c);
|
||||
$j = sqrt($b * $b + $d * $d);
|
||||
|
||||
if($i >= $j){
|
||||
$n = $i;
|
||||
$frz = (180 / M_PI) * atan2($c, $a);
|
||||
|
||||
$scale_x = $n;
|
||||
$scale_y = ($a * $d - $b * $c) / $n;
|
||||
$fax = ($a * $b + $c * $d) / ($n * $n);
|
||||
$fay = 0;
|
||||
|
||||
if($scale_y < 0){
|
||||
$frx = 180;
|
||||
}
|
||||
}else{
|
||||
$n = $j;
|
||||
$frz = (180 / M_PI) * atan2(-$b, $d);
|
||||
|
||||
$scale_x = ($a * $d - $b * $c) / $n;
|
||||
$scale_y = $n;
|
||||
$fax = 0;
|
||||
$fay = ($a * $b + $c * $d) / ($n * $n);
|
||||
|
||||
if($scale_x < 0){
|
||||
$fry = 180;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if(
|
||||
!$isZero($a) and !$isZero($d)
|
||||
//!(($isZero($a) and !$isZero($b)) or (!$isZero($c) and $isZero($d)))
|
||||
|
@ -354,6 +387,7 @@ class matrixTransformTag implements ASSPositioningTag {
|
|||
echo $transform . "\n";
|
||||
throw new \Exception("Invalid transform state");
|
||||
}
|
||||
*/
|
||||
|
||||
$fscx = abs($scale_x) * 100;
|
||||
$fscy = abs($scale_y) * 100;
|
||||
|
|
Loading…
Reference in a new issue