Sign in to follow this  
starfox5194

direct input and mouse relative positioning

Recommended Posts

im following the tutorials at http://www.directxtutorial.com/Tutorial9/E-DirectInput/dx9E2.aspx#still i am trying to make a value change when the mouse moves left or right I hope it is a stupid error. Here is the function. void detect_mousepos(void) { static DIMOUSESTATE mousestate; // create a static storage for the mouse-states typedef struct DIMOUSESTATE// store the mouse x/y/z position { LONG lX; LONG lY; LONG lZ; BYTE rgbButtons[4]; } DIMOUSESTATE, *LPDIMOUSESTATE; dinmouse->Acquire(); // get access if we don't have it already // fill the mousestate with values dinmouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&mousestate); if (LONG lX >= 1) { mousex = mousex + 0.03; } if (LONG lX <= -1) { mousex = mousex-0.03; } return; } and here are the compiling errors with visual studio 2008 Pro 32 Bit. 1>------ Build started: Project: First-Person-Shooter, Configuration: Release Win32 ------ 1>Compiling... 1>First-Person-Shooter.cpp 1>d:\Program Files\Microsoft Visual Studio 9.0\VC\include\dinput.h: DIRECTINPUT_VERSION undefined. Defaulting to version 0x0800 1>.\First-Person-Shooter.cpp(186) : error C2143: syntax error : missing ',' before '>=' 1>.\First-Person-Shooter.cpp(187) : error C2143: syntax error : missing ';' before '{' 1>.\First-Person-Shooter.cpp(190) : error C2143: syntax error : missing ',' before '<=' 1>.\First-Person-Shooter.cpp(191) : error C2143: syntax error : missing ';' before '{' 1>.\First-Person-Shooter.cpp(301) : warning C4244: 'argument' : conversion from 'double' to 'FLOAT', possible loss of data 1>Build log was saved at "file://d:\Documents and Settings\Admin\My Documents\Visual Studio 2008\Projects\First-Person-Shooter\First-Person-Shooter\Release\BuildLog.htm" 1>First-Person-Shooter - 4 error(s), 1 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Share this post


Link to post
Share on other sites
my bad the first error starts at the if statement.

I was just following the tutorials not really knowing what i was doing.

EDIT: can you point me to a mouse input tutorial?

Share this post


Link to post
Share on other sites
This isn't valid C++:
if (LONG lX >= 1)

I'd really recommend taking a step back and learning some more C++ before jumping in like this, or else you'll just find ourself getting into more and more problems. Most DirectX tutorials out there and the documentation assume a good grasp of C++, since it's pretty advanced stuff. Trying to jump in like this will just frustrate you and take you much longer to learn than slowing down a little.

I can answer your current question, but it won't really help you in the long run. I think your code should be:

void detect_mousepos(void)
{
DIMOUSESTATE mousestate; // Doesn't need to be static

// See if Acquire() fails, and bail out if it does
HRESULT hResult = dinmouse->Acquire();
if(FAILED(hResult)
return;

// fill the mousestate with values
hResult = dinmouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&mousestate);
if(FAILED(hResult))
return;

if (mousestate.lX >= 1)
{
mousex += 0.03;
}
else if (mousestate.lX <= -1)
{
mousex -= 0.03;
}
// The return here is redundant
}

Share this post


Link to post
Share on other sites
i knew the long wasn't supposed to be there but visual studio was saying that lx was an undeclared identifier.

Although i had no idea that the periods were supposed to be there.

I'm very new to directx and im just fooling around with it to see what it can do.

Thanks a lot for your help, the program works great now

Share this post


Link to post
Share on other sites
Quote:
Original post by starfox5194
i knew the long wasn't supposed to be there but visual studio was saying that lx was an undeclared identifier.

Although i had no idea that the periods were supposed to be there.
Without the LONG there, the compiler will look for a variable called lX. It won't look inside other structures, it'll only check local variables in the current scope, then keep going up scopes till it hits the global scope. If it still can't find a variable with that name, it'll give the error.
The period there tells the compiler "I want you to use the lX variable that's in the mousestate structure I defined above".

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this