Sign in to follow this  
  • entries
    182
  • comments
    235
  • views
    188313

Struggles With Mice

Sign in to follow this  
mittens

49 views

I vaguely remember the last time I wrote my own demo framework entirely from scratch -- as in, I didn't base things off of old code, I didn't code off a third-party engine/framework, and I didn't just base a program on a skeleton template for simplistic. The memory based in such conditions is one wrought with sadness, pain, and, uh, more sadness. Sadness squared is probably a good way of putting it.

But this time, since I figured I'll start having a great deal more free-time on week nights and weekends, I figure that if I'm going to start nestling in for a long year's hobby development that I sure as hell better have a good framework. And, so far, this idea has been treating me well. As I said in one of yesterday's trio of posts, the last few days I've been working on replacing all of the DXUT functionality that I have come to rely on. This, too, has been treating me well. And then I finally bit the bullet and wrote the mouse input and camera code (my lease favorite things I've had to write so far). Writing a camera is actually kind of fun so long as you have well-working input routines and the rest of your framework isn't straight out of the womb. But writing a decent camera with mouse code that you haven't properly tweaked to work well within a window, what with capturing and such, is the opposite of fun. The antifun. The thing that sheeps hear and run away ba-ba-ba-ing in pain and agony kind of antifun.

I did, though, manage to get the stuff working to the point where I could, with a bit of difficulty, move up from zombiegroin to see Boney's normal-mapped face:



So that's that. I'm also not entirely sure about the overall design of the Input class. At the time it seemed like a good idea, since it was something that actually screamed for program-wide instance. But I know people like Josh and Washu lash out against singletons. So this was my horrible idea for a class design:

class CWin32Input
{
public:

//Input Management Methods.
static void Activate( );
static void Deactivate( );

//Input State Query Methods
//Keyboard.
static void HandleKeyboardMessage( UINT uiMsg, WPARAM wParam, LPARAM lParam );

static inline bool IsKeyboardActive( ) { return( m_bActiveKeyboard ); }

static inline bool IsKeyDown( long lChar ) { return( m_bKeyboardState[lChar] ); }
static inline bool IsKeyUp( long lChar ) { return( !m_bKeyboardState[lChar] ); }

static void SetKeyState( long lChar, bool isKeyDown );

//Mouse
static inline bool IsMouseActive( ) { return( m_bActiveMouse ); }
static void SetMouseClip( bool bClip, long lLeft = -1, long lTop = -1, long lRight = -1, long lBottom = -1 );

static void SetMouseButtonState( unsigned long ulMouseButton, bool isButtonDown );
static void SetMousePos( LPARAM lParam );
static void SetMouseWheel( WPARAM wParam );

static void HoldMouse( bool bHold, bool bHideCursor = false );

static inline void GetMousePos( long &x, long &y ) { x = m_lMousePosX; y = m_lMousePosY; }
static inline void GetMouseDelta( long &dx, long &dy ) { dx = m_lMouseDeltaX; dy = m_lMouseDeltaY; }

static bool IsMouseButtonDown( long lButton );
static bool IsMouseButtonUp( long lButton );

private:

CWin32Input( );
~CWin32Input( );

private:

//Keyboard Members.
static bool m_bKeyboardState[WIN32INPUT_NUM_KEYBOARD_STATES];
static long m_lKeyModifiers;
static bool m_bActiveKeyboard;

//Mouse Members.
static bool m_bMouseButtonState[MOUSE_BUTTON_COUNT];
static long m_lMousePosX, m_lMousePosY;
static long m_lMousePosXPrev, m_lMousePosYPrev;
static long m_lMouseDeltaX, m_lMouseDeltaY;
static long m_lMouseWheelDelta;
static bool m_bActiveMouse;

static RECT m_rectMouseClip;
static bool m_bClipMouse;
};

I'm very willing to change this, as it's getting fairly unwieldy in practice, but I need good reason to motivate my need-for-a-rewrite brain portions.
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

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