Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

neonoblivion

dinput mouse problem

This topic is 5566 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m getting all zero''s for my mouse data. this is my init code.
GIB_API int ginit(float r, float g, float b){
	//dsound

 	if(DirectSoundCreate(NULL,&lpds,NULL)!=DS_OK)
      return (1);
	
	if(FAILED(lpds->SetCooperativeLevel(hwnd,DSSCL_NORMAL)))
      return (1);

	if (DirectInputCreate(hin,DIRECTINPUT_VERSION,&lpdi,NULL)!=DI_OK)
      return (1);
   //keyboard

	if (lpdi->CreateDevice(GUID_SysKeyboard, &lpdikey, NULL)!=DI_OK)
      return (1);

	if (lpdikey->SetCooperativeLevel(hwnd, 
                DISCL_NONEXCLUSIVE | DISCL_BACKGROUND)!=DI_OK)
      return (1);

	if (lpdikey->SetDataFormat(&c_dfDIKeyboard)!=DI_OK)
      return (1);

   if (lpdikey->Acquire()!=DI_OK)
      return (1);
   ///

   ///

   //mouse

   ///

   ///

   if (lpdi->CreateDevice(GUID_SysMouse, &lpdimouse, NULL)!=DI_OK)
      return (1);

	if (lpdimouse->SetCooperativeLevel(hwnd,
                DISCL_NONEXCLUSIVE | DISCL_BACKGROUND)!=DI_OK)
      return (1);

	if (lpdimouse->SetDataFormat(&c_dfDIMouse)!=DI_OK)
      return (1);

   if (lpdimouse->Acquire()!=DI_OK)
      return (1);
   ///

   ///

   //end mouse

   ///

   ///


	glShadeModel(GL_SMOOTH);
	glClearColor(r, g, b, 0.5f);
   glClearDepth(1.0f);
	glEnable(GL_DEPTH_TEST);				
	glDepthFunc(GL_LEQUAL);
   glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();

	return(0);
}
this is the update code.
GIB_API void startinput(){
   if(lpdikey->GetDeviceState(sizeof(char)*256,keystate)==DIERR_INPUTLOST){
      lpdikey->Acquire();
      lpdikey->GetDeviceState(sizeof(char)*256,keystate);
   }
   if(lpdimouse->GetDeviceState(sizeof(DIMOUSESTATE),(LPVOID)&mousestate)==DIERR_INPUTLOST){
      lpdimouse->Acquire();
      lpdimouse->GetDeviceState(sizeof(DIMOUSESTATE),(LPVOID)&mousestate);
   }
   ShowCursor(FALSE);
}
the structure i get back has only 0''s for the xyz. I''ve never done this before so it''s probably somthing stupid, please help, Klaus.

Share this post


Link to post
Share on other sites
Advertisement
I think your problem is as follows:

You need to create a mouse device as well as a keyboard device:

//Create the mouse device object
if(FAILED(m_pDirectInput->CreateDevice(GUID_SysMouse, &m_pMouse, NULL)))
{
CleanUpDirectInput();
//LogError("
  • Unable to create DirectInput mouse device interface.");
    return false;
    }

    Also, I think you should aquire (both keyboard and mouse) after the creation (and only once), not in the update code.

    Share this post


    Link to post
    Share on other sites
    Stupid question: your init function return 0 or 1 ?
    Also why you assume in function that checks input that after an Aquire the GetDeviceState will not fail again? Check for that too(use a while or just a single if and retry next frame).
    Also, cooperative level should not be NONEXCLUSIVE | FOREGROUND ?
    Petru.

    Share this post


    Link to post
    Share on other sites
    hey Petru, my init function returns 0. i assume that the GetDeviceState will not fail because, the tutorials I''ve read say that the reason that it would fail is that the hold the program has on the mouse has been lost. sorry i didn''t say i call startinput() every frame. FOREGROUND just means that the prog only takes input when in focus rather than BACKGROUND which is always, i think ;b.

    Share this post


    Link to post
    Share on other sites
    Always check return codes. It is very likely that if you''re getting all 0s, the function is not returning success. It may be that you need check for DIERR_NOTACQUIRED in addition to DIERR_INPUTLOST. I think they mean about the same. But check what error you''re getting and then you can fix it.

    Share this post


    Link to post
    Share on other sites

    • Advertisement
    ×

    Important Information

    By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

    GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

    Sign me up!