direct input and mouse relative positioning

Started by
4 comments, last by Evil Steve 15 years, 8 months ago
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 ==========
Advertisement
What line is the first error on? What on earth are you doing with that typedef in the middle of your detect_mousepos function?

Also, you really shouldn't use DirectInput for any keyboard or mouse input, and I'd strongly recommend chucking that code out and using window messages.
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?
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}
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
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".

This topic is closed to new replies.

Advertisement