Jump to content
Leadwerks Community

Recommended Posts

Posted

You have to check the mouse position Z component

 

class SomeClass
{
float _lastMZ;
...

void Init()
{
 _lastMZ = Window::GetCurrent()->GetMousePosition().z;
}

void UpdateWorld()
{
 auto mz = Window::GetCurrent()->GetMousePosition().z;
 if ( mz != _lastMZ )
 {
		 // mouse wheel moved
		 // distance is mz-_lastMZ
		 _lastMZ = mz;
 }
}
};

  • Like 1
  • Upvote 1

Roland Strålberg
Website: https://rstralberg.com

Posted
class MouseSensorListener
{
public:
   virtual void onmousewheelHit( float distance ) = 0;
};
class MouseSensor
{
private:
   float _lastMZ;
   MouseSensorListener _listener;
public:
   void init()
   {
    _listener = nullptr;
    _lastMZ = Window::GetCurrent()->GetMousePosition().z;
   }
   void register( MouseSensorListener* listener )
   {
    _listener = listener;
   }
   void unregister()
   {
    _listener = nullptr;
   }
   void update()
   {
    auto mz = Window::GetCurrent()->GetMousePosition().z;
    if ( mz != _lastMZ )
    {
	    // mouse wheel moved
	    // distance is mz-_lastMZ
	    if( _listener )
	    {
	    _listener->onmousewheelHit(mz-_lastMZ);
	    }
	    _lastMZ = mz;
    }
   }
};
class SomeClass :
   public MouseSensorListener
{
public:
   void init( MouseSensor* sensor )
   {
   sensor->register(this);
   }
   void onmousewheelHit( float distance )
   {
    // Mouse wheel moved 'distance'
   }
};

Roland Strålberg
Website: https://rstralberg.com

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...