Matrix3x2F上的累积翻译

时间:2013-02-28 23:18:42

标签: c++ windows-runtime direct2d

我正在开发一个使用D2D显示位图的WinRT应用。我希望结合多点触控,以便能够平移和放大位图。

我正在使用OnManipulatedUpdated事件来更新累积转换。我找到了一种找到累积比例因子的方法,但似乎无法找到累积翻译因子(我不希望用户在缩放图像的大小之外进行平移。

有没有办法找出累积翻译是什么?

这是我的代码:

D2D1::Matrix3x2F m_mxTransform;

property float CurrentScaleFactor
    {
        float get() { return sqrt(fabs(m_mxTransform.Determinant())); }
    }

void OnManipulationUpdated(
_In_ Windows::UI::Input::GestureRecognizer^ recognizer,
_In_ Windows::UI::Input::ManipulationUpdatedEventArgs^ args)
{
Point position = args->Position;
Point positionDelta = args->Delta.Translation;

float currentScale = CurrentScaleFactor;
float preAdjustedScale = args->Delta.Scale;
ManipulationDelta adjustedDelta = LimitManipulationScale(args->Delta, currentScale);
float newScale = currentScale * adjustedDelta.Scale;

//Update the transformation to 
D2D1::Matrix3x2F transformDelta;
if (preAdjustedScale == adjustedDelta.Scale)
{
    transformDelta = 
        D2D1::Matrix3x2F::Scale(adjustedDelta.Scale, adjustedDelta.Scale, D2D1::Point2F(args->Position.X, args->Position.Y)) *
        D2D1::Matrix3x2F::Translation(args->Delta.Translation.X, args->Delta.Translation.Y);
}
else  // don't translate
{
    transformDelta = 
        D2D1::Matrix3x2F::Scale(adjustedDelta.Scale, adjustedDelta.Scale, D2D1::Point2F(args->Position.X, args->Position.Y));
}
m_mxTransform = m_mxTransform * transformDelta;

....
m_d2dContext->SetTransform(m_mxTransform);
}

1 个答案:

答案 0 :(得分:0)

我想我发现了......

    /* x-coordinate that we are currently translated by */
    property float CurrentTranslationX
    {
        float get() { return m_mxTransform._31; }
    }

    /* y-coordinate that we are currently translated by */
    property float CurrentTranslationY
    {
        float get() { return m_mxTransform._32; }
    }