I'm building a function at the moment in C++ that will let me create a directional ray in my 3D application when I click on the screen. I'm working on some x's and y's calculation at the moment, but the problem is that I do a std::cout
on x and y, the values stay the same. If I remove the static
keyword this works fine, but I want to keep it as a static local variable as I will be using this function many times, so what exactly is the problem or what exactly am I doing wrong that's making it print the same value out all the time?
Heres the function:
void Mouse::GetClickDirection(D3DXMATRIX projMatrix)
{
static POINT mousePoint;
GetCursorPos(&mousePoint);
ScreenToClient(hwnd, &mousePoint);
static float width = (float)backBufferWidth;
static float height = (float)backBufferHeight;
static float x = (2.0f * mousePoint.x / width - 1.0f) / projMatrix(0, 0);
static float y = (-2.0f * mousePoint.y / height + 1.0f) / projMatrix(1,1);
D3DXVECTOR3 origin(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 dir(x, y, 1.0f);
system("CLS");
std::cout << "X: " << x << std::endl;
std::cout << "Y: " << y << std::endl;
}