0

私は Skia と C++ を使用していますが、問題は実際にはフレームワークと言語に依存しません。

Translation、Rotation、Scale を持つオブジェクトがあります。また、(0,0) ではないローカル原点を持つこともできます。たとえば、正方形は、左上隅ではなく中央に原点を持つことができます。

オブジェクトは子オブジェクトを持つことができ、それらの子は親に対して相対的に変換されます。行列は、階層に沿って移動するにつれて結合されます。

これは私が行っている方法のサンプルコードであり、期待どおりに機能しています。

しかし、私の質問は、原点にスケールを事前に乗算する必要がないように、これを変更するにはどうすればよいですか?

// C++
void MyObject::update( SkMatrix parentTransform ) {
    // Reset local transform to match parent
    localTransform.getIdentity();
    localTransform.postConcat( parentTransform );

    // Pre-multiply origin by scale (how can I avoid this?)
    ox = originX * scaleX;
    oy = originY * scaleY;

    // Now apply translation (taking origin in to account)
    localTransform = localTransform.preConcat( SkMatrix::Translate( x - ox, y - oy ) );
    // Rotate about the origin
    localTransform = localTransform.preConcat( SkMatrix::RotateDeg( rotation, SkPoint::Make( ox, oy ) ) );
    // Scale
    localTransform = localTransform.preConcat( SkMatrix::Scale( scaleX, scaleY ) );

    // Now update the children of this object recursively
    for ( auto& child : children ) {
        child.update( localTransform  );
    }
}

連結 (乗算) 前後の行列演算の順序がわかりません。

どんな助けでも大歓迎

4

0 に答える 0