Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cursor::Delta() が (Cursor::Pos() - Cursor::PreviousPos()) と一致しない #1119

Open
Raclamusi opened this issue Oct 26, 2023 · 0 comments

Comments

@Raclamusi
Copy link
Member

Cursor::Delta() のコメントに

Cursor::Pos() - Cursor::PreviousPos() と同値です。

とありますが、この2つの式の値が一致しないことがあります。

この問題は、Transformer2D でマウスカーソルの座標系を拡大したときに発生します。

次のコードを実行してマウスカーソルを動かしてみると、Cursor::Pos() - Cursor::PreviousPos() はカーソル座標の整数部が変化するフレームで一瞬大きさを持つのに対し、Cursor::Delta() は(ゆっくり動かしていると)ずっと Point{ 0, 0 } のままです。

# include <Siv3D.hpp> // Siv3D v0.6.12

void Main()
{
	constexpr double Scale = 100;

	while (System::Update())
	{
		const Transformer2D transformer{ Mat3x2::Scale(Scale), TransformCursor::Yes };

		ClearPrint();
		Print << Cursor::Delta();
		Print << (Cursor::Pos() - Cursor::PreviousPos());

		for (int32 x = 0; x < (Scene::Width() / Scale + 1); ++x)
		{
			for (int32 y = 0; y < (Scene::Height() / Scale + 1); ++y)
			{
				if ((x + y) % 2 == 0)
				{
					Rect{ x, y, 1 }.draw(ColorF{ 0.3, 0.9, 0.6 });
				}
			}
		}
	}
}

この問題の原因としては、Cursor::Delta() の実装が Cursor::Pos() - Cursor::PreviousPos() ではなく Cursor::DeltaF().asPoint() のような実装になっていることが考えられます。
実際に、すべてのプラットフォームの Cursor の実装で、Vec2 で求めたマウスカーソルの移動量を Point に変換しているようなコードが見られました。
以下の permalink はその1つです。

m_state.point.delta = m_state.vec2.delta.asPoint();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant