0

このトピックに近い他の質問は、私がそれを理解するのにあまり役立たないようです。Visual Studio と Direct2D を使用してプログラミングを始めたばかりで、楕円の中にある楕円である 2 つの「目」をマウスに追従させる方法がわかりません。

void MainWindow::CalculateLayout()私が使用している関数の内部

    const float radius3=radius/4;
    const float radius3_2=radius/5;
    const float x3=x-100;
    const float y3=y-150;
    ellipse3 = D2D1::Ellipse(D2D1::Point2F(x3, y3), radius3, radius3_2);
        //left eye

    const float radius4=radius/4;
    const float radius4_2=radius/5;
    const float x4=x+100;
    const float y4=y-150;
    ellipse4 = D2D1::Ellipse(D2D1::Point2F(x4, y4), radius4, radius4_2);
        //right eye

    const float radius5=radius/8;
    const float radius5_2=radius5/2;
    const float x5=x-100;
    const float y5=y-150;
    ellipse5 = D2D1::Ellipse(D2D1::Point2F(x5, y5), radius5, radius5_2);    
    // left eyeball

    const float radius6=radius/8;
    const float radius6_2=radius6/2;
    const float x6=x+100;
    const float y6=y-150;
    ellipse6 = D2D1::Ellipse(D2D1::Point2F(x6, y6), radius6, radius6_2);    
    // right eyeball

目と眼球の位置を設定します。これに沿ったものを使用して、マウスの位置を制御する必要があると思います。フォームからではなく、空のプロジェクトからこれを実行しようとしています。const float x5=x-100X値に単純に置き換える解決策はありMouseMoveますか?

4

1 に答える 1

0

の定義を置き換える必要がx5ありますが、眼球内にとどまるようにバインドする式でそれを行う必要があります。

数式は次のようになります。

// compute the angle from the eyes to the mouse
angle = arctan( (mouseY - y) / (mouseX - x) );
// x-100 and y-150 are assumed to be the origins (center) of the eyeball
// eyeballRadius should be the radius of the eyeball, or slightly smaller (so the eyes do not extend outside of it)
x5 = (x-100) + cos(angle) * eyeballRadius;
y5 = (y-150) + sin(angle) * eyeballRadius;

お役に立てれば。

カーソルが非常に近くにあるときに寄り目効果を得るには、各眼球に独自の角度を計算させる必要があります。leftAngle = arctan( (mouseY - (y-150)) / (mouseX - (x-100)) )

于 2012-02-14T00:43:07.607 に答える