Results 1 to 2 of 2
  1. #1
    lvous's Avatar
    Join Date
    Dec 2013
    Gender
    male
    Posts
    63
    Reputation
    10
    Thanks
    348

    mouse sensitivity & direct input

    I want to slow down mouse sensitivity as soon as I'm aiming at the nearest target. How can I change mouse sensitivity of a game which is using direct input? I can display mousestate.lX and IY but changing it does not work.

    Code:
    #include <ddraw.h>
    #include <dinput.h>
    #pragma comment (lib, "dinput8.lib")
    #pragma comment(lib, "dxguid.lib")
    
    LPDIRECTINPUT8 din;		// pointer to the DirectInput interface
    LPDIRECTINPUTDEVICE8 dmouse;	// pointer to the mouse device
    DIMOUSESTATE mouse_state;	// pointer t about the mouse information
    
    void init_mouse(HINSTANCE hInstance, HWND hWnd){
    	// create a direct input interface
    	DirectInput8Create(hInstance,              // Handle to the application
    		DIRECTINPUT_VERSION,    // compatible version
    		IID_IDirectInput8,      // DirectInput interface version
    		(void**)&din,           // pointer to the interface
    		NULL);                  // COM, leave it NULL
    
    	//create device
    	din->CreateDevice(GUID_SysMouse,
    		&dmouse,
    		NULL);
    	//set format
    	dmouse->SetDataFormat(&c_dfDIMouse);
    
    	//set control you will have over the device
    	dmouse->SetCooperativeLevel(hWnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND);
    }
    
    float mouse_x, mouse_y, mouse_z;
    void detect_mouse(){
    	//access the the input if you dnt already have access
    	dmouse->Acquire();
    
    	//access mouse information
    	dmouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&mouse_state);
    
    	//mousestate.lX;           //movement on the X axis
    	//mousestate****;           //movement on the Y axis
    
    	//does NOT do crap
    	mouse_state.lX += (float)mouse_state.lX / 2;
    	mouse_state**** += (float)mouse_state**** / 2; //for inverse -=
    
    	
    	// ***** check for mouse movements *****
    	// this is done seperately so that you can adjust mouse sensitivity
    	// check if mouse is going forward - player looks up
    	if (mouse_state**** < 0)
    	{
    	// now what?
    	}
    
    	// check if mouse is going back - player looks down
    	if (mouse_state**** > 0)
    	{
    
    	}
    
    	// check if mouse is going left - player rotates left
    	if (mouse_state.lX < 0)
    	{
    
    	}
    
    	// check if mouse is going right - player rotates right
    	if (mouse_state.lX > 0)
    	{
    
    	}
    }
    
    void clean_mouse(){
    	dmouse->Unacquire();      // close mouse
    	din->Release();		// close directinput
    }
    Last edited by lvous; 07-16-2014 at 08:03 AM.

  2. #2
    topblast's Avatar
    Join Date
    Mar 2010
    Gender
    male
    Location
    Far from around you Programmer: C++ | VB | C# | JAVA
    Posts
    3,607
    Reputation
    149
    Thanks
    5,052
    My Mood
    Cool
    a solution to this is a pseudo position, that way sensitivity will be just a multiplication of the mouse position, change the location, would just be changing an offset for the mouse.
    I just like programming, that is all.

    Current Stuff:

    • GPU Programmer (Cuda)
    • Client/Server (Cloud Server)
    • Mobile App Development

Tags for this Thread