blob: 3573e4f981855bfb54c7a94f948ae925f2bfc372 [file] [log] [blame]
/*
* Copyright 2020 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "modules/skottie/src/Transform.h"
#include "modules/sksg/include/SkSGTransform.h"
namespace skottie {
namespace internal {
TransformAdapter2D::TransformAdapter2D(sk_sp<sksg::Matrix<SkMatrix>> matrix)
: fMatrixNode(std::move(matrix)) {}
TransformAdapter2D::~TransformAdapter2D() = default;
SkMatrix TransformAdapter2D::totalMatrix() const {
SkMatrix t = SkMatrix::MakeTrans(-fAnchorPoint.x(), -fAnchorPoint.y());
t.postScale(fScale.x() / 100, fScale.y() / 100); // 100% based
t.postRotate(fRotation);
t.postTranslate(fPosition.x(), fPosition.y());
// TODO: skew
return t;
}
void TransformAdapter2D::apply() {
fMatrixNode->setMatrix(this->totalMatrix());
}
TransformAdapter3D::Vec3::Vec3(const VectorValue& v) {
fX = v.size() > 0 ? v[0] : 0;
fY = v.size() > 1 ? v[1] : 0;
fZ = v.size() > 2 ? v[2] : 0;
}
TransformAdapter3D::TransformAdapter3D()
: fMatrixNode(sksg::Matrix<SkMatrix44>::Make(SkMatrix::I())) {}
TransformAdapter3D::~TransformAdapter3D() = default;
sk_sp<sksg::Transform> TransformAdapter3D::refTransform() const {
return fMatrixNode;
}
SkMatrix44 TransformAdapter3D::totalMatrix() const {
SkMatrix44 t;
t.setTranslate(-fAnchorPoint.fX, -fAnchorPoint.fY, -fAnchorPoint.fZ);
t.postScale(fScale.fX / 100, fScale.fY / 100, fScale.fZ / 100);
SkMatrix44 r;
r.setRotateDegreesAbout(0, 0, 1, fRotation.fZ);
t.postConcat(r);
r.setRotateDegreesAbout(0, 1, 0, fRotation.fY);
t.postConcat(r);
r.setRotateDegreesAbout(1, 0, 0, fRotation.fX);
t.postConcat(r);
t.postTranslate(fPosition.fX, fPosition.fY, fPosition.fZ);
return t;
}
void TransformAdapter3D::apply() {
fMatrixNode->setMatrix(this->totalMatrix());
}
} // namespace internal
} // namespace skottie