0

我正在开发一个使用 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);
}
4

1 回答 1

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; }
    }
于 2013-03-01T20:35:03.710 回答