It is currently Sat Sep 23, 2017 9:44 am

All times are UTC - 5 hours




 Page 1 of 1 [ 8 posts ] 
Author Message
 Post subject: Caligari VMK 3 Workflow and Hotkeys setup
PostPosted: Tue Feb 13, 2007 7:05 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
This VMK shows you how to handle the mouse input to allow you to look around in the 3D world.


Offline
 Profile  
 
 Post subject: Re: GameDev VMK 10 - Mouse Control
PostPosted: Wed Aug 01, 2007 6:49 pm 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
In VMK37 we revisit how the mouse is handled so that it is easy to implement a Graphical User Interface.


Last edited by Marek on Sat Aug 16, 2008 8:50 pm, edited 1 time in total.

Offline
 Profile  
 
 Post subject:
PostPosted: Sat Aug 16, 2008 6:16 pm 

Joined: Fri Aug 08, 2008 6:50 am
Posts: 9
Location: Norway
I just want to notify that on my 24" lcd monitor at resolution at 1920x1200, I did experience that the mouse cursor was placed outside the application resulting the mouse to flicker. :?

I did fix the problem by modifying to this (the four first lines in function is modified):
void GameOGL::HandleMouse()
{
   int cx = GetSystemMetrics(SM_CXSCREEN);
   int cy = GetSystemMetrics(SM_CYSCREEN);
   static int iMouseX = (cx>>1) ;//(m_iWidth>>1);
   static int iMouseY = (cy>>1) ;//(m_iHeight>>1);
   static float fScaleFactor = 0.001f;

   POINT mousePosition;
   GetCursorPos(&mousePosition);

   m_Camera.Move(LOOK_RIGHT, (mousePosition.x-iMouseX)*fScaleFactor);
   m_Camera.Move(LOOK_UP,    (mousePosition.y-iMouseY)*fScaleFactor);

   //move mouse back to middle of the screen
   SetCursorPos(iMouseX, iMouseY);

} // HandleMouse


But I think there should be a smarter solution to solve this, i.e what whould happen if someone manage to move the application.
(I managed by pressing ALT then down, select move and so on)
Then the mouse would be visible again (flickering) at the center of screen.
So it still ain't foul proff.

Any suggestions :?:

EDIT: Please look at VMK037 :arrow:


Offline
 Profile  
 
 Post subject:
PostPosted: Sun Sep 07, 2008 2:32 am 

Joined: Wed Aug 06, 2008 7:53 pm
Posts: 182
Location: Russia
To MindProse and all
There is another solution indeed. The idea is to use window position on the screen instead of screen resolution. Functions GetCursorPos() / SetCursorPos() work actually in screen coordinates, not in current window coordinates. Here is an updated version of HandleMouse(). Note, that mouse cursor now is pinned to the actual center of the game’s window.
// in GameOGL.h – declaration
void HandleMouse( bool centerCursor = false );

// in GameOGL.cpp – definition
void GameOGL::HandleMouse( bool centerCursor /* = false */ )
{
    RECT rect;
    ::GetWindowRect(m_WND, &rect);

    const int windowCenterX = rect.left + m_wndParam.width / 2;
    const int windowCenterY = rect.top + m_wndParam.height / 2;

    if ( !centerCursor )
    {
        const float scaleFactor = 0.001F;
        POINT mousePosition;
        ::GetCursorPos( &mousePosition );
        m_camera.Move( LOOK_RIGHT, scaleFactor * (mousePosition.x - windowCenterX) );
        m_camera.Move( LOOK_UP, scaleFactor * (mousePosition.y - windowCenterY) );
    }

    ::SetCursorPos(windowCenterX, windowCenterY);
}

I use a slightly different naming style, but the solution should be intelligible. An argument ‘bool centerCursor’ is used to select the action: full mouse-handling or only cursor centering. To move cursor in the center of the window during initialization I do an invocation:
HandleMouse( true );

Ok, this solution is transitional anyway. Shall see what Marek says in VMK37. ;)


Last edited by BugHunter on Tue Oct 14, 2008 6:41 am, edited 1 time in total.

Offline
 Profile  
 
 Post subject: Multiple Mouse Buttons
PostPosted: Wed Oct 08, 2008 9:03 pm 

Joined: Sun Sep 21, 2008 5:27 am
Posts: 16
Can anyone display any code on how to use more than the three mouse buttons?

I have Six buttons that I want to use 1st for fire, 2nd Alternate Fire, Middle for Jump, 4 for reload, 5 for Grenade, maybe 6 to enter zoom.

I only use the keyboard for up, down, left, right and general stuff like map, console ect...

MA


Offline
 Profile  
 
 Post subject:
PostPosted: Sat Oct 11, 2008 4:25 am 
Site Admin

Joined: Sun Feb 11, 2007 8:59 am
Posts: 1105
Location: Ontario Canada
Have you tried using WM_XBUTTONDOWN?
Quote:
msdn url: msdn.microsoft.com/en-us/library/ms646245(VS.85).aspx


Offline
 Profile  
 
 Post subject: DirectInput handles Multiple Button Mouse
PostPosted: Tue Oct 14, 2008 6:32 am 

Joined: Wed Aug 06, 2008 7:53 pm
Posts: 182
Location: Russia
Hi, Bukaroo7000.
If you still are not satisfied with WM_XBUTTONDOWN, another possibility is to utilize DirectX::DirectInput.

Below is a quick and dirty console sample. It uses the simplest non-buffered method. I don’t have the time right now to polish it.
If you can please report whether all your mouse buttons give a response.

(in VC create a console app and put in this code).
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0500
#endif

#ifndef DIRECTINPUT_VERSION
#define DIRECTINPUT_VERSION 0x0800
#endif

#include <conio.h>
#include <tchar.h>
#include <dinput.h>
#include <iostream>

using namespace std;

//
// link direct-input libraries
//
#pragma comment( lib, "dxguid.lib" )
#pragma comment( lib, "dinput8.lib" )


//------------------------------------------------------------------------------
// Mouse handler uses DirectX::DirectInput.
// MouseHandlerDX can handle up to 8 mouse buttons.
// The simplest non-buffered method is used.
// Read MSDN::DirectX for more information.
// BugHunter.
//------------------------------------------------------------------------------
class MouseHandlerDX
{
public:
    MouseHandlerDX() : m_directInput(0), m_mouse(0) { }
    ~MouseHandlerDX() { DeInitialize(); }
   
    bool Initialize( HWND hWnd );
    void DeInitialize();
    void Update(); // call me each Game::Frame()
    bool IsButtonPressed( size_t button ) const;
    bool operator[] (size_t button) const { return IsButtonPressed(button); }
   
    const DIMOUSESTATE2 & GetRawMouseState() const { return m_mouseState; }

private:
    LPDIRECTINPUT8          m_directInput;
    LPDIRECTINPUTDEVICE8    m_mouse;
    DIMOUSESTATE2           m_mouseState;
};

inline bool MouseHandlerDX::Initialize( HWND hWnd )
{
    if (FAILED(DirectInput8Create( GetModuleHandle(0), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&m_directInput, NULL))
        ) return false;
    if (FAILED(m_directInput->CreateDevice( GUID_SysMouse, &m_mouse, NULL))
        ) return false;
    if (FAILED(m_mouse->SetCooperativeLevel( hWnd, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE ))
        ) return false;
    if (FAILED(m_mouse->SetDataFormat( &c_dfDIMouse2 ))
        ) return false;
    if (FAILED(m_mouse->Acquire())
        ) return false;
    return true;
}

inline void MouseHandlerDX::Update()
{
    if (m_mouse)
    {
        if (DIERR_INPUTLOST == m_mouse->GetDeviceState(sizeof(DIMOUSESTATE2), (LPVOID)&m_mouseState))
        {
            m_mouse->Acquire(); // reacquisition
            m_mouse->GetDeviceState(sizeof(DIMOUSESTATE2), (LPVOID)&m_mouseState);
        }
    }
}

inline void MouseHandlerDX::DeInitialize(void)
{
    if ( m_mouse )
    {
        m_mouse->Unacquire();
        m_mouse->Release();
        m_mouse = NULL;
    }
    if ( m_directInput )
    {
        m_directInput->Release();
        m_directInput = NULL;
    }
}

inline bool MouseHandlerDX::IsButtonPressed( size_t button ) const
{
    if ( button > 7 ) return false;
    return 0 != ( m_mouseState.rgbButtons[ button ] & 0x80 );
}







int _tmain(int argc, _TCHAR* argv[])
{
    MouseHandlerDX mouse;

    if ( !mouse.Initialize( GetConsoleWindow() ) )
    {
        cout << "MouseHandlerDX::Initialize() failed" << endl;
        _getch();
        return 1;
    }
    cout
        << "=-------------------------------------------------------=" << endl
        << " Hi guys, Bukaroo7000, Marek, MindProse and all          " << endl
        << "=-------------------------------------------------------=" << endl
        << " That's a quick sample of DirectInput for mouse.         " << endl
        << " Press any mouse button to see feedback on the screen.   " << endl
        << " Press any key to exit.                                  " << endl
        << "=-------------------------------------------------------=" << endl;

    do // start main loop
    {
        mouse.Update();

        for (size_t t = 0; t < 8; ++t)
            if ( mouse[ t ] ) // ( mouse.IsButtonPressed( t ) )
                cout << "Mouse button [" << t << "] is pressed" << endl;

        Sleep( 50 );
    }
    while ( !_kbhit() );

    _getch(); // clear keyboard buffer to see last message

    cout << "Bye now!..." << endl;
    _getch();
    return 0;
}


Offline
 Profile  
 
 Post subject: Re: GameDev VMK 10 - Mouse Control
PostPosted: Thu Aug 28, 2014 7:08 pm 

Joined: Fri Aug 22, 2014 3:54 pm
Posts: 17
I've come across a bug for my computer, I'm not sure if anyone has the issue. When moving your mouse, SetCursorPos seems to be "about" correct. It sometimes will set the mouse to 401 or 399 instead of 400 for my width causing the camera to continue to rotate either up or right until I move the mouse again and it sets it back correctly to 400,300... I'm not sure why it does this, but below solves the issue for me.

Add this line of code before the first Camer.Move() function.
I use a different naming convention. mp is MousePosition. iMX is iMousePositionX and iMY is iMousePositionY.
if((mp.x == iMX && mp.y == iMY)||(mp.x == iMX-1 || mp.x == iMX+1 || mp.y == iMY-1 || mp.y== iMY+1)) return;


Offline
 Profile  
 
Display posts from previous:  Sort by  
 Page 1 of 1 [ 8 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  

cron