Sparrott

Hi,

I'm quite new to DirectX, and C++...

I'll start with what I'm trying to acheive: I'm aiming to get a bunch of textured cubes on the screen, and for the user to be able to pick them up and move them around, using the mouse.

I've got the cubes (well, squares at the moment), and I can get input from the mouse so that when the mouse moves the camera moves. However, in order for the user to pick up a specific cube, I need to know which one the mouse is over at that point in time, therefore I need to get the screen coordinates of the mouse. All I seem to be able to get at the moment is the change in x and y of the mouse since the last poll for input.

If anyone can tell me how to do that that'd be great! I've read stuff about getting the mouse position from the form, but I'm not using .net and haven't got a form!

Thanks,
Sparrott



Re: Game Technologies: DirectX 101 Getting the mouse position in screen coordinates using C++ (no .net)

windozer_

Sparrott,

If you need to get the screen coords of the mouse position at any point in time you can call the Win32 function GetCursorPos in your message loop. This will return an LPPOINT (pointer to a structure of 2 longs which are the x and y coords). Is this what you are looking for Thanks.

Cale





Re: Game Technologies: DirectX 101 Getting the mouse position in screen coordinates using C++ (no .net)

Sparrott

That sounds about right, yes - cheers.
Sparrott




Re: Game Technologies: DirectX 101 Getting the mouse position in screen coordinates using C++ (no .net)

Sparrott

I think this is what I want, but when I try and use it I get an access violation. here is my code:

LPPOINT cursorPos = 0;
GetCursorPos(cursorPos);
float x = 0;
x = cursorPos->x;
float y = 0;
y = cursorPos->y;

char msg[50];

sprintf(msg, "x: %.2f\n"
"y : %.2f\n", x, y);

MessageBox(0, msg, "Mouse Position", 0);

In the watches window, the value is x= y=

Any ideas

Thanks.




Re: Game Technologies: DirectX 101 Getting the mouse position in screen coordinates using C++ (no .net)

Sparrott

Don't worry - sorted myself out. It works like so:

POINT cursorPos;
GetCursorPos(&cursorPos);
float x = 0;
x = cursorPos.x;
float y = 0;
y = cursorPos.y;

char msg[50];

sprintf(msg, "x: %.2f\n"
"y : %.2f\n", x, y);

MessageBox(0, msg, "Mouse Position", 0);

Cheers!




Re: Game Technologies: DirectX 101 Getting the mouse position in screen coordinates using C++ (no .net)

windozer_

Sparrott,

Cool, glad to see this worked for you. BTW. the sprintf has been deprecated and the safe version is sprintf_s

Cale