Exemplo n.º 1
0
static void handle_sdlevents_keyb() {
	for(int i = 0; i < KEY_MAX; ++i)
		key[i] = GetKeyboard()->KeyDown[sdlkeymap[i]] ? 1 : 0;
	
	for(int i = 0; i < GetKeyboard()->queueLength; ++i) {
		KeyboardEvent& ev = GetKeyboard()->keyQueue[i];
		if(ev.down) keyqueue.push_back( ev.sym );
	}
}
Exemplo n.º 2
0
/*
 *  ClearBreak - clear a break after it is pressed
 */
void ClearBreak( void )
{
    while( KeyboardHit() ) {
        GetKeyboard();
    }
    EditFlags.BreakPressed = false;

} /* ClearBreak */
Exemplo n.º 3
0
bool CObjectRotateCamera::Update()
{
    CMouseManager* mouse = GetMouse();
    bool down[2] = {mouse->IsPressed(0), mouse->IsPressed(1)};
    int x = mouse->GetX();
    int y = mouse->GetY();

    int dx = x - m_lastx;
    int dy = y - m_lasty;
    
    bool needUpdate = false;

    if (!GetKeyboard()->IsPressed(VK_SHIFT) && m_lastDown[0] && down[0] && (abs(dx) + abs(dy) > 0))
    {
        m_anglex += dx * 0.01f; // * elapsedTime;
        m_anglez += dy * 0.01f;// * elapsedTime;

        m_anglex = NormAngle(m_anglex);
        m_anglez = NormAngle(m_anglez);
        Point3 eye = Angle2Pos(m_anglex, m_anglez);
        SetEye(eye.x, eye.y, eye.z);         
        needUpdate = true;
    }

    if (GetMouse()->GetWheel() != 0)
    {
        m_radius *= max(0.01f, 1 - GetMouse()->GetWheel() * 0.0003f);
        Point3 eye = Angle2Pos(m_anglex, m_anglez);
        SetEye(eye.x, eye.y, eye.z);
        needUpdate = true;
    }

    m_lastDown[0] = down[0];
    m_lastDown[1] = down[1];
    m_lastx = x;
    m_lasty = y;
   
    return needUpdate;
}
Exemplo n.º 4
0
/*
 * LostFileCheck - check if there are any lost files out there
 */
bool LostFileCheck( void )
{
    char        path[FILENAME_MAX];
    vi_key      key;
    char        ch;
    int         off;
    int         handle;

    MakeTmpPath( path, lockFileName );
    off = strlen( path ) - 5;
    for( ch = START_CHAR; ch <= END_CHAR; ch++ ) {
        path[off] = ch;
        handle = sopen3( path, O_RDONLY | O_TEXT, SH_DENYRW );
        if( handle > 0 ) {
            MakeTmpPath( path, checkFileName );
            path[off] = ch;
            if( access( path, F_OK ) == -1 ) {
                MakeTmpPath( path, lockFileName );
                path[off] = ch;
                close( handle );
                handle = -1;
                remove( path );
            } else {
                break;
            }
        }
    }
    if( handle > 0 ) {
        close( handle );
        if( !EditFlags.RecoverLostFiles ) {
            if( !EditFlags.IgnoreLostFiles ) {
#ifdef __WIN__
                CloseStartupDialog();
                key = GetAutosaveResponse();
                handleKey( key );
                ShowStartupDialog();
                return( TRUE );
#else
                SetPosToMessageLine();
                MyPrintf( "Files have been lost since your last session, do you wish to:\n" );
                MyPrintf( "\ti)gnore\n\tr)ecover\n\tq)uit\n" );
                for( ;; ) {
                    key = GetKeyboard();
                    if( handleKey( key ) ) {
                        return( TRUE );
                    }
                }
#endif
            } else {
                remove( path );
                return( FALSE );
            }
        }
    } else {
        if( EditFlags.RecoverLostFiles ) {
            EditFlags.RecoverLostFiles = FALSE;
            EditFlags.NoInitialFileLoad = FALSE;
        }
    }
    return( FALSE );

} /* LostFileCheck */
Exemplo n.º 5
0
void CGUIDialog::Update( float elapsedTime )
{
	CMouseManager * mouse = GetMouse();
	//鼠标悬停在的控件
	CGUIControl * mouse_over = NULL;

	for (size_t i = 0; i < m_children.size(); i ++)
	{
		if (m_children[i]->GetVisible() && m_children[i]->IsInBound((float)mouse->GetX(), (float)mouse->GetY()))
		{
			mouse_over = m_children[i];
		}
		m_children[i]->BeforeUpdate(elapsedTime);
	}

	//鼠标移动,更新焦点控件
	if (mouse->MouseMoved())
	{
		SetFocusedControl(mouse_over);
	}
	
	if (mouse_over)
	{
		if (mouse->IsJustPressed(0))
		{
			SetFocusedControl(mouse_over);
			mouse_over->OnMouseDown();
		}else if (mouse->IsJustReleased(0))
		{
			SetFocusedControl(mouse_over);
			mouse_over->OnMouseUp();
		}
	}

	if (! m_children.empty())
	{
		if (GetKeyboard()->IsJustPressed(VK_DOWN))
		{
			int f = GetFocusIndex() + 1;
			if (f == m_children.size()) f = 0;
			SetFocusedControl(m_children[f]);
		}else if (GetKeyboard()->IsJustPressed(VK_UP))
		{
			int f = GetFocusIndex() - 1;
			if (f < 0) f = (int)m_children.size() - 1;
			SetFocusedControl(m_children[f]);
		}else if (GetKeyboard()->IsJustPressed(VK_RETURN) || GetKeyboard()->IsJustPressed(VK_SPACE))
		{
			if (m_focusedCtrl)
			{
				m_focusedCtrl->OnMouseDown();
			}
		}else if (GetKeyboard()->IsJustReleased(VK_RETURN) || GetKeyboard()->IsJustReleased(VK_SPACE))
		{
			if (m_focusedCtrl)
			{
				m_focusedCtrl->OnMouseUp();
			}
		}
	}

	for (size_t i = 0; i < m_children.size(); i ++)
	{
		m_children[i]->AfterUpdate(elapsedTime);
	}

}
Exemplo n.º 6
0
/*
 * GetKey - read a key from the keyboard
 */
vi_key GetKey( bool usemouse )
{
    bool        hit;
    vi_key      key;

    clearSpin();
    for( ;; ) {
        if( EditFlags.NoCapsLock ) {
            TurnOffCapsLock();
        }
        LastMouseEvent = GetMouseEvent();
        if( LastMouseEvent != VI_MOUSE_NONE ) {
            RedrawMouse( MouseRow, MouseCol );
            DisplayMouse( true );
            if( TestMouseEvent( usemouse ) ) {
                return( VI_KEY( MOUSEEVENT ) );
            }
        }
        /*
         * could get set by mouse handler or IDEGetKeys
         */
        if( EditFlags.KeyOverride ) {
            key = getOverrideKey();
#ifndef __WIN__
            if( key == VI_KEY( CTRL_C ) ) {
                ExitWithVerify();
                clearSpin();
                continue;
            }
#endif
            return( key );
        }
        hit = KeyboardHit();
        if( !hit ) {
            DoAutoSave();
#ifdef __IDE__
            IDEGetKeys();
#endif
#ifdef __QNX__
            WaitForProxy();
            if( !KeyboardHit() ) {
                continue;
            }
#endif
        }
#if defined( BUSYWAIT )
        else {
#endif
            key = GetKeyboard();
#if defined( __NT__ )
            if( key == VI_KEY( MOUSEEVENT ) ) {
                continue;
            }
#endif
            DisplayMouse( false );
#ifndef __WIN__
            if( EditFlags.EscapedInsertChar )
                break;
#endif
            if( key == VI_KEY( NULL ) ) {
                GetKeyboard();
                ExitWithVerify();
                clearSpin();
                continue;
            }
#ifndef __WIN__
            if( key == VI_KEY( CTRL_C ) ) {
                ExitWithVerify();
                clearSpin();
                continue;
            }
#endif
            break;
#if defined( BUSYWAIT )
        }
#endif
#if defined( __DOS__ )
        DosIdleCall();
#elif defined( __OS2__ )
        DosSleep( 1 );
#endif
    }

    if( EditFlags.Spinning ) {
        EditFlags.SpinningOurWheels = true;
    }
    return( key );

} /* GetKey */
Exemplo n.º 7
0
void input_init(void)
{
  /* Enable Unicode to be able to grab what letter the user actually
     typed, taking the keyboard layout/language into account. Used for
     the console (game) and the input dialogs (editor). */
  SDL_EnableUNICODE(1);

  /* Clear keyboard/joystick buffer */
  memset(&sjoy,0,sizeof(sjoy));
  {
    int k = 0;
    for (k = 0; k < 256; k++)
      GetKeyboard(k);
    
    int a = ACTION_FIRST;
    for (a = ACTION_FIRST; a < ACTION_LAST; a++) 
      sjoy.joybitold[a] = 0;
  }
  sjoy.rightold = 0;
  sjoy.leftold  = 0;
  sjoy.upold    = 0;
  sjoy.downold  = 0;

  /* Define default button->action mapping */
  input_set_default_buttons();

  /* JOY */
  /* Joystick initialization never makes Dink fail for now. */
  /* Note: joystick is originaly only used by the game, not the
     editor. */
  if (joystick == 1)
    {
      if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1)
	{
	  log_error("Error initializing joystick, skipping: %s", SDL_GetError());
	  joystick = 0;
	}
      else
	{
	  /* first tests if a joystick driver is present */
	  /* if TRUE it makes certain that a joystick is plugged in */
	  if (SDL_NumJoysticks() > 0)
	    {
	      int i;
	      log_info("%i joysticks were found.", SDL_NumJoysticks());
	      log_info("The names of the joysticks are:");
	      for (i=0; i < SDL_NumJoysticks(); i++)
		log_info("    %s", SDL_JoystickName(i));
	      log_info("Picking the first one...");
	      jinfo = SDL_JoystickOpen(0);
	      /* Don't activate joystick events, Dink polls joystick
		 manually.  Plus events would pile up in the queue. */
	      SDL_JoystickEventState(SDL_IGNORE);
	      
	      if (jinfo) {
		log_info("Name: %s", SDL_JoystickName(0));
		log_info("Number of axes: %d", SDL_JoystickNumAxes(jinfo));
		log_info("Number of buttons: %d", SDL_JoystickNumButtons(jinfo));
		log_info("Number of balls: %d", SDL_JoystickNumBalls(jinfo));
		log_info("Number of hats: %d", SDL_JoystickNumHats(jinfo));
		
		/* Flush stacked joystick events */
		{
		  SDL_Event event;
		  while (SDL_PollEvent(&event));
		}
		
		joystick = 1;
	      } else {
		log_error("Couldn't open Joystick #0");
		joystick = 0;
	      }
	    }
	}
    }
}
Exemplo n.º 8
0
///////////////////
// Waits for any input (used in a loop)
int CInput::Wait(std::string& strText)
{
	mouse_t *Mouse = GetMouse();
	keyboard_t *kb = GetKeyboard();

	// First check the mouse
	for(uint n = 0; n < MAX_MOUSEBUTTONS; n++) {
		uint i = n;
		if(Mouse->Up & SDL_BUTTON(n)) {
			// Swap rmb id wih mmb (mouse buttons)
			switch (n)  {
			case 2: i=3; break;
			case 3: i=2; break;
			}
			strText = "ms"+itoa(i);
			return true;
		}
	}

	// Keyboard
	for(int i = 0; i < kb->queueLength; ++i) {
		if(kb->keyQueue[i].down) continue;
		
		for(uint n = 0; n<sizeof(Keys) / sizeof(keys_t); n++) {
			if(kb->keyQueue[i].sym == Keys[n].value) {
#ifdef WIN32
				// TODO: does this hack also work for keyup?
				// TODO: remove this hack here
				// Workaround for right alt key which is reported as LCTRL + RALT on windib driver
				if (i+1 < kb->queueLength && kb->keyQueue[i].sym == SDLK_LCTRL)  {
					if (kb->keyQueue[i+1].sym == SDLK_RALT)  {
						strText = "ralt";
						return true;
					}
				}
#endif

				strText = Keys[n].text;
				return true;
			}
		}

		// Our description is not enough, let's call SDL for help
		// We use SDL only for the left unknown keys to stay backward and forward compatible.
		if (kb->keyQueue[i].sym != SDLK_ESCAPE)  {
			strText = SDL_GetKeyName((SDLKey)kb->keyQueue[i].sym);
			return true;
		}
	}

#ifdef HAVE_JOYSTICK
	// joystick
	// TODO: more joysticks
	for(uint n = 0; n < sizeof(Joysticks) / sizeof(joystick_t); n++) {
		int i = Joysticks[n].text[3] - '1'; // at pos 3, there is the number ("joy1_...")

		// Check if any of the axes has been moved or a button press occured
		if(joys[i] != NULL && checkJoystickState(Joysticks[n].value, Joysticks[n].extra, i)) {
			strText = Joysticks[n].text;
			return true;
		}
	}
#endif
	
	return false;
}
Exemplo n.º 9
0
static void KeyboardCommands(void)
{
  int is_shift, is_alt;

  keys=GetKeyboard(); 

  if(InputType[2]==SIFC_FKB)	// Family Keyboard (FKB)
  {
   if(keyonly(SCROLLLOCK)) 
   {
    cidisabled^=1;
    FCEUI_DispMessage("Family Keyboard %sabled.",cidisabled?"en":"dis");
   }
   #ifdef SDL
   	SDL_WM_GrabInput( cidisabled? SDL_GRAB_ON: SDL_GRAB_OFF );
   #endif
   if(cidisabled) return;
  }

  is_shift = KEY(LEFTSHIFT) | KEY(RIGHTSHIFT);
  is_alt = KEY(LEFTALT) | KEY(RIGHTALT);

   #ifdef SDL
	if(keyonly(F4))
	{
		if(is_shift)
			FCEUI_SetRenderDisable(-1, 2);
		else
			FCEUI_SetRenderDisable(2, -1);
	}
	#endif
	
	#if defined(SDL) && !defined(FLASH)
		if(keyonly(ENTER) && is_alt) ToggleFS();
	#endif


// Disable most keyboard shortcuts in Flash
#ifndef FLASH

	NoWaiting &=~ 1;
	
	if(KEY(GRAVE))
	{
		NoWaiting|=1;
	}
	
	if(gametype==GIT_FDS)
	{
		if(keyonly(F6)) FCEUI_FDSSelect();
		if(keyonly(F8)) FCEUI_FDSInsert(0);
	}
	
	if(keyonly(F9))
	{
		FCEUI_SaveSnapshot();
	}

	if(gametype!=GIT_NSF)
	{
		#ifndef EXTGUI
		if(keyonly(F2))
		{
			DoCheatSeq();
		}
		#endif
		
		if(keyonly(F5)) 
		{
			if(is_shift)
				FCEUI_SaveMovie(NULL);
			else
				FCEUI_SaveState(NULL);
		}
		
		if(keyonly(F7)) 
		{
			if(is_shift)
				FCEUI_LoadMovie(NULL);
			else
				FCEUI_LoadState(NULL);
		}
	}

  if(keyonly(F1)) FCEUI_ToggleTileView();

  if(keyonly(F10)) FCEUI_ResetNES();
  if(keyonly(F11)) FCEUI_PowerNES();

  #ifdef EXTGUI
  if(keyonly(F3)) GUI_Hide(-1);
  if(KEY(F12)) GUI_RequestExit();
  if(KEY(ESCAPE)) CloseGame();
  #else
  if(KEY(F12) || KEY(ESCAPE)) CloseGame();
  #endif

  if(gametype==GIT_VSUNI)
  {
	if(keyonly(F8)) FCEUI_VSUniCoin();
	if(keyonly(F6))
        {
	 DIPS^=1;
	 FCEUI_VSUniToggleDIPView();
	}
	if(!(DIPS&1)) goto DIPSless;
	if(keyonly(1)) FCEUI_VSUniToggleDIP(0);
	if(keyonly(2)) FCEUI_VSUniToggleDIP(1);
	if(keyonly(3)) FCEUI_VSUniToggleDIP(2);
	if(keyonly(4)) FCEUI_VSUniToggleDIP(3);
	if(keyonly(5)) FCEUI_VSUniToggleDIP(4);
	if(keyonly(6)) FCEUI_VSUniToggleDIP(5);
	if(keyonly(7)) FCEUI_VSUniToggleDIP(6);
	if(keyonly(8)) FCEUI_VSUniToggleDIP(7);
  }
  else
  {
   static uint8 bbuf[32];
   static int bbuft;
   static int barcoder = 0;

   if(keyonly(H)) FCEUI_NTSCSELHUE();
   if(keyonly(T)) FCEUI_NTSCSELTINT();
   if(KEY(KP_MINUS) || KEY(MINUS)) FCEUI_NTSCDEC();
   if(KEY(KP_PLUS) || KEY(EQUAL)) FCEUI_NTSCINC();

   if((InputType[2] == SIFC_BWORLD) || (cspec == SIS_DATACH))
   {
    if(keyonly(F8)) 
    {
     barcoder ^= 1;
     if(!barcoder)
     {
      if(InputType[2] == SIFC_BWORLD)
      {
       strcpy(&BWorldData[1],bbuf);
       BWorldData[0]=1;
      }
      else
       FCEUI_DatachSet(bbuf);
      FCEUI_DispMessage("Barcode Entered");
     } 
     else { bbuft = 0; FCEUI_DispMessage("Enter Barcode");}
    }
   } else barcoder = 0;

	#define SSM(x)		\
	{ if(barcoder) { if(bbuft < 13) {bbuf[bbuft++] = '0' + x; bbuf[bbuft] = 0;} FCEUI_DispMessage("Barcode: %s",bbuf);}	\
	else { 			\
	 if(is_shift) FCEUI_SelectMovie(x); 	\
	 else FCEUI_SelectState(x); 	\
	} }

   DIPSless:
   if(keyonly(0)) SSM(0);
   if(keyonly(1)) SSM(1);
   if(keyonly(2)) SSM(2);
   if(keyonly(3)) SSM(3);
   if(keyonly(4)) SSM(4);
   if(keyonly(5)) SSM(5);
   if(keyonly(6)) SSM(6);
   if(keyonly(7)) SSM(7);
   if(keyonly(8)) SSM(8);
   if(keyonly(9)) SSM(9);
   #undef SSM
 }
#endif
}
Exemplo n.º 10
0
static void KeyboardCommands(void) {
    int is_shift, is_alt;

    keys = GetKeyboard();

    if ((InputType[2] == SIFC_FKB) || (InputType[2] == SIFC_SUBORKB) || (InputType[2] == SIFC_PEC586KB)) {
        if (cidisabled) return;
    }

    is_shift = KEY(LEFTSHIFT) | KEY(RIGHTSHIFT);
    is_alt = KEY(LEFTALT) | KEY(RIGHTALT);

    if (keyonly(F4)) {
        if (is_shift) FCEUI_SetRenderDisable(-1, 2);
        else FCEUI_SetRenderDisable(2, -1);
    }

    {
        static int nocount = 0;

        NoWaiting &= ~1;
        if (KEY(GRAVE))	//&& nocount)
            NoWaiting |= 1;
        nocount = (nocount + 1) & 3;
    }

    if (gametype == GIT_FDS) {
        if (keyonly(F6)) FCEUI_FDSSelect();
        if (keyonly(F8)) FCEUI_FDSInsert(0);
    }

    if (keyonly(F9)) FCEUI_SaveSnapshot();
    if (gametype != GIT_NSF) {
        if (keyonly(F5)) {
            if (is_shift)
                FCEUI_SaveMovie(NULL);
            else
                FCEUI_SaveState(NULL);
        }
        if (keyonly(F7)) {
            if (is_shift)
                FCEUI_LoadMovie(NULL);
            else
                FCEUI_LoadState(NULL);
        }
    }

//  if(keyonly(F1)) FCEUI_ToggleTileView();

    if (gametype == GIT_VSUNI) {
        if (keyonly(F8)) FCEUI_VSUniCoin();
        if (keyonly(F6)) {
            DIPS ^= 1;
            FCEUI_VSUniToggleDIPView();
        }
        if (!(DIPS & 1)) goto DIPSless;
        if (keyonly(1)) FCEUI_VSUniToggleDIP(0);
        if (keyonly(2)) FCEUI_VSUniToggleDIP(1);
        if (keyonly(3)) FCEUI_VSUniToggleDIP(2);
        if (keyonly(4)) FCEUI_VSUniToggleDIP(3);
        if (keyonly(5)) FCEUI_VSUniToggleDIP(4);
        if (keyonly(6)) FCEUI_VSUniToggleDIP(5);
        if (keyonly(7)) FCEUI_VSUniToggleDIP(6);
        if (keyonly(8)) FCEUI_VSUniToggleDIP(7);
    } else {
        static uint8 bbuf[32];
        static int bbuft;
        static int barcoder = 0;

        if (keyonly(H)) FCEUI_NTSCSELHUE();
        if (keyonly(T)) FCEUI_NTSCSELTINT();
        if (KEY(KP_MINUS) || KEY(MINUS)) FCEUI_NTSCDEC();
        if (KEY(KP_PLUS) || KEY(EQUAL)) FCEUI_NTSCINC();

        if ((InputType[2] == SIFC_BWORLD) || (cspec == SIS_DATACH)) {
            if (keyonly(F8)) {
                barcoder ^= 1;
                if (!barcoder) {
                    if (InputType[2] == SIFC_BWORLD) {
                        strcpy(&BWorldData[1], bbuf);
                        BWorldData[0] = 1;
                    } else
                        FCEUI_DatachSet(bbuf);
                    FCEUI_DispMessage("Barcode Entered");
                } else {
                    bbuft = 0;
                    FCEUI_DispMessage("Enter Barcode");
                }
            }
        } else barcoder = 0;

#define SSM(x)				  \
	{ if (barcoder) { if (bbuft < 13) { bbuf[bbuft++] = '0' + x; bbuf[bbuft] = 0; } FCEUI_DispMessage("Barcode: %s", bbuf); }		 \
	  else {						 \
		  if (is_shift) FCEUI_SelectMovie(x);		  \
		  else FCEUI_SelectState(x);		 \
	  }	\
	}

DIPSless:
        if (keyonly(0)) SSM(0);
        if (keyonly(1)) SSM(1);
        if (keyonly(2)) SSM(2);
        if (keyonly(3)) SSM(3);
        if (keyonly(4)) SSM(4);
        if (keyonly(5)) SSM(5);
        if (keyonly(6)) SSM(6);
        if (keyonly(7)) SSM(7);
        if (keyonly(8)) SSM(8);
        if (keyonly(9)) SSM(9);
#undef SSM
    }
}
Exemplo n.º 11
0
/*
 * 功能: 场景相机状态自动更新
 * 摘要: 该函数功能主要实现,根据自身的当前状态自动更新相机内部数据,无须外部干预
 * 参数: -
 * 返回值: -
 * 作者: lpf
 * 创建日期: 2008.02.02
 * 修改日志:
 *	2008.03.08 - lpf
 *		修正了相机在执行水平旋转和垂直旋转,并到达目的位置时,会不停的震动问题
 *	2008.10.17 - lpf
 * 		暂时屏蔽了"处理垂直角度与距离的限制";
 */
void CRegionCamera::Update(void)
{
	CClientRegion * c = GetGame()->GetRegion();
	if (c == NULL) /*&& GetGame()->GetSetup()->bSound*/ 
		return;

	// 处理场景3D音效
	D3DXVECTOR3 * pos;
	D3DXVECTOR3	  face;
	D3DXVECTOR3   right;
	D3DXVECTOR3   up;

	pos = c->GetCamera()->GetPosition();

	//pos->z = -pos->z;
	GetGame()->GetAudioList()->SetListenerPosition(*pos);

	//pos->z = -pos->z;
	face = (*c->GetCamera()->GetView()) - (*pos);

	Vector3 v = face;
	D3DXVec3Normalize(&face, &face);
	D3DXVec3Cross(&right, &Vector3(0, 1, 0), &face);
	D3DXVec3Normalize(&right, &right);
	D3DXVec3Cross(&up, &face, &right);

	//face.z = -face.z;
	//up.z   = -up.z;
	GetGame()->GetAudioList()->SetListenerOritation(face, up);

	if (g_bDebug)
	{
		if (GetKeyboard()->IsKeyDown(DIK_TAB))
		{
			char t[255];
			sprintf(t, "距离平方:%f", (v.x) * (v.x) + v.y * v.y + (v.z) * (v.z));
			GetGame()->OutPutText(140, 40, t, 255, D3DCOLOR_ARGB(255, 255, 255, 255));
		}
	}

	// 回到默认摄像机镜头角度H
	if (m_dwState & SCS_REPOS_H)
	{
		if (abs(m_iHoriAngle - m_iSourceHoriAngle) <= 5)
		{
			m_dwState	 &= ~SCS_REPOS_H;
			m_iHoriAngle = m_iSourceHoriAngle;
		}else
		{
			if (m_iHoriAngle > 180)
				m_iHoriAngle -= 360;
			else if(m_iHoriAngle < -180)
				m_iHoriAngle += 360;
			if (m_iHoriAngle > -45 && m_iHoriAngle < 135)
				m_iHoriAngle += 4;
			else if (m_iHoriAngle <= -45 || m_iHoriAngle >= 135)
				m_iHoriAngle -= 4;
		}
	}
	// 回到默认摄像机镜头角度V
	if (m_dwState & SCS_REPOS_V)
	{
		if (abs(m_iVertAngle - m_iSourceVertAngle) <= 5)
		{
			m_dwState	 &= ~SCS_REPOS_V;
			m_iVertAngle = m_iSourceVertAngle;
		}else
		{
			m_iVertAngle += (m_iSourceVertAngle - m_iVertAngle)/abs(m_iSourceVertAngle - m_iVertAngle) * 4;
		}
	}
	// 回到默认摄像机镜头角度V
	if (m_dwState & SCS_REPOS_D)
	{
		if (abs(s_fDistance - 17.0f) <= 1.0f)
		{
			m_dwState	 &= ~SCS_REPOS_D;
			s_fDistance = 17.0f;
		}else
		{
			s_fDistance += (17.0f - s_fDistance)/abs(17.0f - s_fDistance) * 0.5f;
		}
	}

	// 处理相机移动
	if (m_dwState & SCS_MOVE)
	{
		if (D3DXVec3Length(&m_vMoveDis) < m_fMoveDis)
			m_vMoveDis += m_vMoveSpeed;
		//else
		//	m_dwState &= ~SCS_MOVE;
	}

	// 处理相机水平旋转
	if (m_dwState & SCS_ROTATE_H)
	{
		if (m_iHoriAngle > m_iHDesAngle)
		{
			m_fHCurAngle -= m_fHRotateSpeed;
			m_iHoriAngle = (int)m_fHCurAngle;

			if (m_iHoriAngle < m_iHDesAngle)
				m_iHoriAngle = m_iHDesAngle;
		}else if (m_iHoriAngle < m_iHDesAngle)
		{
			m_fHCurAngle += m_fHRotateSpeed;
			m_iHoriAngle = (int)m_fHCurAngle;

			if (m_iHoriAngle > m_iHDesAngle)
				m_iHoriAngle = m_iHDesAngle;
		}else
			m_dwState &= ~SCS_ROTATE_H;
	}

	// 处理相机垂直旋转
	if (m_dwState & SCS_ROTATE_V)
	{
		if (m_iVertAngle > m_iVDesAngle)
		{
			m_fVCurAngle -= m_fVRotateSpeed;
			m_iVertAngle = (int)m_fVCurAngle;

			if (m_iVertAngle < m_iVDesAngle)
				m_iVertAngle = m_iVDesAngle;
		}else if (m_iVertAngle < m_iVDesAngle)
		{
			m_fVCurAngle += m_fVRotateSpeed;
			m_iVertAngle = (int)m_fVCurAngle;

			if (m_iVertAngle > m_iVDesAngle)
				m_iVertAngle = m_iVDesAngle;
		}else
			m_dwState &= ~SCS_ROTATE_V;
	}

	// 处理相机缩放
	if (m_dwState & SCS_ZOOM)
	{
		if (m_fZoomSpeed > 0.0f)
		{
			if (s_fDistance < m_fZoomDesDis)
				s_fDistance += m_fZoomSpeed;
			else
				m_dwState &= ~SCS_ZOOM;
		}else if (m_fZoomSpeed < 0.0f)
		{
			if (s_fDistance > m_fZoomDesDis)
				s_fDistance += m_fZoomSpeed;
			else
				m_dwState &= ~SCS_ZOOM;
		}

		if (s_fDistance > s_fMaxDistance)
		{
			s_fDistance = s_fMaxDistance;
			m_dwState	&= ~SCS_ZOOM;
		}else if (s_fDistance < s_fMinDistance)
		{
			s_fDistance = s_fMinDistance;
			m_dwState	&= ~SCS_ZOOM;
		}
	}

	// 处理相机震动
	if (m_dwState & SCS_SHOCK)
	{
		static const float fOffsetArray[6] = { 1.0f, -0.6f, 0.8f, -0.2f, 0.4f, 0.0f };
		static int		   iOffPos		   = 0;
		
		DWORD dwCurrentTime = timeGetTime();
		DWORD dwTimeElapse  = dwCurrentTime - m_dwShockStartTime;
		if (dwTimeElapse > m_dwShockDelayTime)
		{
			m_fShcokrOffset = fOffsetArray[iOffPos] * m_fShockMaxRatio;
			if (dwTimeElapse > m_dwShockTimeLength)
			{
				iOffPos	  = 0;
				m_dwState &= ~SCS_SHOCK;
			}

			if (iOffPos > 4)
				iOffPos = 0;
			else
				++iOffPos;
		}
	}

	// 处理垂直角度与距离的限制
	//float angle = s_fDistance/17.0f * 43.0f;
	//m_fMinVAngle = angle > 43.0f?43.0f:angle;
	//if (m_iVertAngle < m_fMinVAngle)
	//{
	//	m_iVertAngle = m_fMinVAngle;
	//	m_fVCurAngle = m_iVertAngle;
	//}

	if (s_fDistance > 0.0f)
		m_fDistance = s_fDistance;
}
Exemplo n.º 12
0
/*
 * 功能: 场景相机玩家操作处理
 * 摘要: -
 * 参数: -
 * 返回值: -
 * 作者: lpf
 * 创建日期: 2008.02.02
 * 修改日志:
 *	2008.07.09- lpf
 *		增加了对摄象机旋转角度的锁定,主要针对玩家通过鼠标键盘控制摄象机时;
 *	2008.07.23- lpf
 *		恢复相机操作可以被键盘和鼠标中键的视距缩放操作中断;
 *	2008.07.30- lpf
 *		鼠标右键双击恢复视角的点击事件时,不恢复视距;
 *	2008.10.17 - lpf
 * 		增加了游戏垂直视角控制由鼠标右键按下上下拖动;
 *	2008.12.04 - lpf
 * 		增加了如果应用程序失去焦点,则清空鼠标信息的处理;
 *	2008.12.16 - lpf
 * 		取消了使用键盘水平旋转视角的过度处理.在收到键盘旋转消息时,直接改变旋转角度,然后就立即改变m_nScorll变量值为0,以停止旋转;
 */
void CRegionCamera::Run(void)
{
	// 输入设备对象
	CMouse	  * pMouse	  = GetMouse();
	CKeyBoard * pKeyboard = GetKeyboard();

	// 鼠标到左右边缘,左右旋转
	POINT ptMouse;
	ptMouse.x = pMouse->GetMouseX();
	ptMouse.y = pMouse->GetMouseY();

	// 键盘控制转方向
	if (m_dwState & SCS_KEYBOARD_ABLE)
	{
		if (m_dwState & SCS_ROTATE_H_ABLE && !(m_dwState & SCS_LOCK_ROTATE))
		{
			if (pKeyboard->IsKeyDown(DIK_LEFT) && pKeyboard->IsKeyDown(DIK_LCONTROL))
			{
				//|| GetGame()->GetSetup()->lControl == 1 && pMouse->GetMouseX()<5 
				//&& pMouse->GetMouseY()>0 && pMouse->GetMouseY()<SCREEN_HEIGHT)
				m_nScorll =- 1;
				ResumeCamera();
			}

			if (m_nScorll < 0)
			{
				// left
				m_iHoriAngle -= 3;
				m_iHoriAngle = m_iHoriAngle % 360;

//				if (abs(m_iHoriAngle%10) <= 1)
					m_nScorll=0;
			}

			if (pKeyboard->IsKeyDown(DIK_RIGHT) && pKeyboard->IsKeyDown(DIK_LCONTROL))
			{
				//||	GetGame()->GetSetup()->lControl == 1 && pMouse->GetMouseX()>SCREEN_WIDTH-5
				//&&	pMouse->GetMouseY()>0 && pMouse->GetMouseY()<SCREEN_HEIGHT)
				m_nScorll = 1;
				ResumeCamera();
			}

			if (m_nScorll > 0)
			{
				// right
				m_iHoriAngle += 3;
				m_iHoriAngle = m_iHoriAngle % 360;

				//if (abs(m_iHoriAngle%45) <= 1)
					m_nScorll = 0;
			}

			if (pKeyboard->IsKeyDown(DIK_NEXT) && pKeyboard->IsKeyDown(DIK_LCONTROL))
			{
				++m_iVertAngle;
				if (m_iVertAngle > m_iMaxVertAngle)
					m_iVertAngle = m_iMaxVertAngle;

				ResumeCamera();
			}

			if (pKeyboard->IsKeyDown(DIK_PRIOR) && pKeyboard->IsKeyDown(DIK_LCONTROL))
			{
				--m_iVertAngle;
				if (m_iVertAngle < m_iMinVertAngle)
					m_iVertAngle = m_iMinVertAngle;

				ResumeCamera();
			}
		}

		// 有输入框时无效
		//IGUIRoot *pRoot = IGUIRoot::GetGUIInstance();
		//if(!pRoot->GetFocusComp())
		//{
		//	// 键盘放缩
		//	if (pKeyboard->IsKeyDown(DIK_SUBTRACT) || pKeyboard->IsKeyDown(DIK_UP))
		//	{
		//		s_fDistance -= 0.5f;

		//		if (s_fDistance > s_fMaxDistance)
		//			s_fDistance = s_fMaxDistance;
		//		else if (s_fDistance < s_fMinDistance)
		//			s_fDistance = s_fMinDistance;

		//		ResumeCamera();
		//		RemoveCameraState();
		//		m_dwState &= ~SCS_SMOOTH;
		//	}

		//	if (pKeyboard->IsKeyDown(DIK_ADD) || pKeyboard->IsKeyDown(DIK_DOWN))
		//	{
		//		s_fDistance += 0.5f;
		//		if (s_fDistance > s_fMaxDistance)
		//			s_fDistance = s_fMaxDistance;
		//		else if (s_fDistance < s_fMinDistance)
		//			s_fDistance = s_fMinDistance;

		//		ResumeCamera();
		//		RemoveCameraState();
		//		m_dwState &= ~SCS_SMOOTH;
		//	}
		//}
	}

	// 滚轮
	if ((m_dwState & SCS_MOUSE_WHEEL_ABLE) && pMouse->GetCurrentButton() == MB_WHEEL)
	{
		s_fDistance -= (float)((short)HIWORD(pMouse->GetWheelDelta())) * 0.01f;
		if (s_fDistance > s_fMaxDistance)
		{
			s_fDistance = s_fMaxDistance;	
		}
		else if (s_fDistance < s_fMinDistance)
		{
			s_fDistance = s_fMinDistance;
		}
		float fzDelta = (float)((short)HIWORD(pMouse->GetWheelDelta()));
		if (GetGame()->GetMainPlayer()->GetAction() != CShape::ACT_WALK&&GetGame()->GetMainPlayer()->GetAction() != CShape::ACT_RUN)
		{
			m_dwState &= ~SCS_SMOOTH;
		}
		
		ResumeCamera();
		RemoveCameraState();
	}

	extern bool g_bIsFocus;
	if (!g_bIsFocus)
		pMouse->ClearMessage();

	// 鼠标右键操作
	bool bRightUp = false;

	// 鼠标右键按下一次
	if (pMouse->GetCurrentButton() == RB_DOWN)
	{
		m_ptOldMouse.x  = pMouse->GetMouseX();
		m_ptOldMouse.y  = pMouse->GetMouseY();
		m_iOldHoriAngle = m_iHoriAngle;
		m_iOldVertAngle = m_iVertAngle;
		ResumeCamera();
	}

	// 鼠标右键弹起
	if (pMouse->GetCurrentButton() == RB_UP)
		bRightUp = true;

	// 鼠标右键按下不放
	if (pMouse->IsRightButtonDown() && !bRightUp)
	{
		if ((pMouse->GetMouseX() - m_ptOldMouse.x) > 1 || (pMouse->GetMouseX() - m_ptOldMouse.x) < -1)
		{
			if (!(m_dwState & SCS_LOCK_ROTATE))
			{
				m_iHoriAngle = (int)( m_iOldHoriAngle + (pMouse->GetMouseX() - m_ptOldMouse.x)*0.5 ) % 360;
				RemoveCameraState();
			}
			/*m_iVertAngle = (int)( m_iOldVertAngle + (pMouse->GetMouseX() - m_ptOldMouse.x)*0.5 ) % 360;
			m_dwState	 &= ~SCS_REPOS_V;*/
		}

		m_iVertAngle += (int)(((float)pMouse->GetMouseMoveY() * 0.5f));
		if (m_iVertAngle < m_iMinVertAngle)
			m_iVertAngle = m_iMinVertAngle;
		else if (m_iVertAngle > m_iMaxVertAngle)
			m_iVertAngle = m_iMaxVertAngle;

		ResumeCamera();
	}

	//IGUIRoot *pRoot = IGUIRoot::GetGUIInstance();
	//if(pRoot && pRoot->GetGUIComp())
	//{
	//	CComponent * pComp = pRoot->GetGUIComp()->GetComponentAt(pMouse->GetMouseX(),pMouse->GetMouseY());
	//	if(pComp && pComp->IsEnabled() && pComp->IsVisible() && 
	//		strcmp(pComp->GetName(),"ChatInfo")!=0 && strcmp(pComp->GetName(),"TeamPage")!=0 
	//		&& strcmp(pComp->GetName(),"MedalTipPage")!=0)
	//	{
	//		return;
	//	}
	//	// 鼠标右键双击
	//	if (pMouse->GetCurrentButton() == RB_DCLICK && !(m_dwState & SCS_LOCK_ROTATE))
	//	{
	//		m_dwState |= SCS_REPOS_H;
	//		m_dwState |= SCS_REPOS_V;
	//		//m_dwState |= SCS_REPOS_D;
	//	}
	//}
}