user3476584
user3476584

Reputation: 15

C++ DirectX First Person Camera

I'm trying to make a first person camera. At the moment, I'm working on the x and y rotation. The rotation is defined by the mouse offset from the center of the window.

RECT rc;
GetWindowRect(g_hWnd, &rc);
UINT width = rc.left + (rc.right - rc.left) / 2;
UINT height = rc.top + (rc.bottom - rc.top) / 2;

POINT pt;
GetCursorPos(&pt);

int xMouseDelta = pt.x - width;
int yMouseDelta = pt.y - height;

g_View = XMMatrixTranslation(0.0f, 1.0f, -5.0f) *
    XMMatrixRotationX(yMouseDelta / 100) *
    XMMatrixRotationY(xMouseDelta / 100);

The problem is, when moving it falters. I don't know what I'm doing wrong.

If I change the "100" (the sensitivity) to a higher number I don't see anything at all.

I guess I'm doing something wrong with the matrices, but I'm not sure. Or maybe the "GetCursorPos()" function isn't that precise?

Excuse me for my bad English. Thank you for reading!

Upvotes: 0

Views: 861

Answers (1)

Nico Schertler
Nico Schertler

Reputation: 32667

You have defined the deltas as int. Therefore, delta / 100 is also an int which allows angles of 0, 1, 2, 3 radians and their negatives. Just convert them to float:

XMMatrixRotationX(yMouseDelta / 100.0f)

Upvotes: 0

Related Questions