Take the 2-minute tour ×

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;


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!

share|improve this question
are you sure you should use XMMatrixRotationX(yMouseDelta / 100) and XMMatrixRotationY(xMouseDelta / 100) instead of XMMatrixRotationX(xMouseDelta / 100) and XMMatrixRotationY(yMouseDelta / 100) –  willywonka_dailyblah Apr 12 at 11:54
@willywonka_dailyblah I'm sure. –  user3476584 Apr 12 at 12:05

1 Answer 1

up vote 0 down vote accepted

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)
share|improve this answer
Thank you! Worked for me! –  user3476584 Apr 14 at 17:14

Your Answer


