[Nel] proposed control changes

Dan Erikson derikson@montana.com
Thu, 12 Apr 2001 20:49:18 -0600


Hi all, this is kind of long, sorry.  I had some thoughts that I'd like to
get some feedback on, and some code that you might find useful.

I've put together a patch that changes the mouse control in snowballs so
that the mouse is normally free, and you have to click on the window
and move the mouse in order to move the view around.  This is a change
from the current behavior where the mouse is always locked by the
application.  This allows one to use other applications while the game
is running.  I've even used it to have two instances of snowball running at
the same time, which should be useful for testing reasons.  It'll also alow
for using the mouse in the future for clicking on controls on other parts of
the screen.  The only thing I'm not sure about is how well it will work on
windows.  It looks like it'll work, but it would be nice if someone 
would test it.

I used the right mouse button because the left mouse button is already 
in use
for throwing a snowball, but I think these changes to the controls would
work better:

* Left mouse button to move the view around
* Right mouse button to move forward
* Space button to throw a snowball
* Enter button to enter chat mode
     After text is typed and enter is pressed, return from chat mode
* Mousewheel forward to zoom in
* Mousewheel backwards to zoom out
* Left button turns the view left normally
* If control+left or left_mouse+left, then strafe left
* Right button turns the view right normally
* If control+right or left_mouse+right, then strafe right

The normal mode/chat mode allows us to use the keys for functionality rather
than F1-F12, which is a little harder to remember than something like 
'r' for
toggle radar.  Also, there are a limited number of function buttons, so I
think having access to all the other keys would allow good future expansion.

The changes to the mouse buttons allows one to move around the world using
only the mouse.

It would also be nice to have the ability to customize these keys, but 
that's
something for a little later.

If anyone has any comments about this stuff, I'd love to hear them.

Patch to use right mouse button to move the heading around:

Index: move_listener.cpp
===================================================================
RCS file: /home/cvsroot/code/client/src/move_listener.cpp,v
retrieving revision 1.23
diff -c -r1.23 move_listener.cpp
*** move_listener.cpp    2001/04/10 10:20:48    1.23
--- move_listener.cpp    2001/04/13 02:21:30
***************
*** 54,63 ****
  \****************************************************************/
  CMoveListener::CMoveListener()
  {
!     _MouseFree = false;
    
-     _CursorInit = false;
-
     _Width = 0;
     _Height = 0;
 
--- 54,61 ----
  \****************************************************************/
  CMoveListener::CMoveListener()
  {
!     _MouseFree = true;
    
     _Width = 0;
     _Height = 0;
 
***************
*** 184,190 ****
  \****************************************************************/
  void CMoveListener::operator()(const CEvent& event)
  {
!     static const float eps = 0.001f;
 
     // Rotation
     if (event==EventMouseMoveId)
--- 182,188 ----
  \****************************************************************/
  void CMoveListener::operator()(const CEvent& event)
  {
!     static const float eps = 0.002f;
 
     // Rotation
     if (event==EventMouseMoveId)
***************
*** 196,240 ****
 
         if(!_MouseFree)
         {
!             if(_CursorInit)
             {
!                 float difx =  0.5f-mouseEvent->X;
!                 float dify =  -(0.5f-mouseEvent->Y);
!                 if( (float)fabs(difx) > eps || (float)fabs(dify) > eps)
                 {
!                     if ( (float)fabs(difx) > eps)
!                     {
!                          LocalArea->User.yaw( _RotSpeed*(difx) );
                     }
!                     if ( (float)fabs(dify) > eps)
!                     {
!                          LocalArea->User.ViewPitch += _RotSpeed*(dify);
!                          if(LocalArea->User.ViewPitch>(float)Pi/2)
!                          {
!                              LocalArea->User.ViewPitch = (float)Pi/2;
!                          }
!                          if(LocalArea->User.ViewPitch<-(float)Pi/2)
!                          {
!                              LocalArea->User.ViewPitch = -(float)Pi/2;
!                          }
                     }
-                     _Scene->getDriver()->setMousePos(0.5,0.5);
                 }
               }
-               else
-               {
-                   _CursorInit = true;
-                 _Scene->getDriver()->setMousePos(0.5,0.5);
-               }
         }
     }
  
 
 
-     // Shoot with left mouse button
     if ( event==EventMouseDownId)
     {
         CEventMouse* mouseEvent=(CEventMouse*)&event;
         if(mouseEvent->Button==leftButton && CanShot)
         {
             if ( (ClientSocket!=NULL) && ClientSocket->connected() )
--- 194,230 ----
 
         if(!_MouseFree)
         {
!             float difx =  _MouseLockX-mouseEvent->X;
!             float dify =  -(_MouseLockY-mouseEvent->Y);
!             if( (float)fabs(difx) > eps || (float)fabs(dify) > eps)
             {
!                 if ( (float)fabs(difx) > eps)
!                 {
!                     LocalArea->User.yaw( _RotSpeed*(difx) );
!                 }
!                 if ( (float)fabs(dify) > eps)
                 {
!                     LocalArea->User.ViewPitch += _RotSpeed*(dify);
!                     if(LocalArea->User.ViewPitch>(float)Pi/2)
!                      {
!                         LocalArea->User.ViewPitch = (float)Pi/2;
                     }
!                     if(LocalArea->User.ViewPitch<-(float)Pi/2)
!                      {
!                         LocalArea->User.ViewPitch = -(float)Pi/2;
                     }
                 }
+                 _Scene->getDriver()->setMousePos(_MouseLockX,_MouseLockY);
               }
         }
     }
  
 
 
     if ( event==EventMouseDownId)
     {
         CEventMouse* mouseEvent=(CEventMouse*)&event;
+         // Shoot with left mouse button
         if(mouseEvent->Button==leftButton && CanShot)
         {
             if ( (ClientSocket!=NULL) && ClientSocket->connected() )
***************
*** 249,254 ****
--- 239,259 ----
                 }
             }
         }
+         if(mouseEvent->Button==rightButton && _MouseFree)
+         {
+             _MouseLockX = mouseEvent->X;
+             _MouseLockY = mouseEvent->Y;
+             changeControlMode();
+         }
+     }
+
+     if(event==EventMouseUpId)
+     {
+         CEventMouse* mouseEvent=(CEventMouse*)&event;
+         if(mouseEvent->Button==rightButton && !_MouseFree)
+         {
+             changeControlMode();
+         }
     }
  }
 
***************
*** 260,265 ****
--- 265,271 ----
  {
     server.addListener (EventMouseMoveId, this);
     server.addListener (EventMouseDownId, this);
+     server.addListener (EventMouseUpId, this);
  }
 
 
***************
*** 270,274 ****
--- 276,281 ----
  {
     server.removeListener (EventMouseMoveId, this);
     server.removeListener (EventMouseDownId, this);
+     server.removeListener (EventMouseUpId, this);
  }
 
Index: move_listener.h
===================================================================
RCS file: /home/cvsroot/code/client/src/move_listener.h,v
retrieving revision 1.15
diff -c -r1.15 move_listener.h
*** move_listener.h    2001/03/05 09:39:44    1.15
--- move_listener.h    2001/04/13 02:21:30
***************
*** 119,127 ****
     /// Internal use
     virtual void operator()(const NLMISC::CEvent& event);
    
-     /// true if first setMousePos done
-     bool _CursorInit;
-
     CScene * _Scene;
    
     /// screen width
--- 119,124 ----
***************
*** 155,160 ****
--- 152,160 ----
     float _MouseY;
 
     bool _Shot;
+
+     float _MouseLockX;
+     float _MouseLockY;
  };
 
 
Index: client.cpp
===================================================================
RCS file: /home/cvsroot/code/client/src/client.cpp,v
retrieving revision 1.177
diff -c -r1.177 client.cpp
*** client.cpp    2001/04/12 17:06:42    1.177
--- client.cpp    2001/04/13 02:22:13
***************
*** 1880,1893 ****
     LocalArea->setEntityMovedCallback( moveEntityInstance );
     LocalArea->setEntityRemovedCallback( deleteEntityInstance );
 
-     // hide mouse cursor
-     CNELU::Driver->showCursor(false);
- #ifdef NL_RELEASE
-     CNELU::Driver->setCapture(true);
- #endif
-
-
-
     // Load meshes
     /*
     vector<string>::iterator itshp;
--- 1880,1885 ----