コード例 #1
0
	void PlayerBehavior::MovePlayer() {
		float ElapsedTime = App::GetApp()->GetElapsedTime();
		Vec3 Angle = GetMoveVector();
		//Rigidbodyを取り出す
		auto PtrRedit = GetGameObject()->GetComponent<Rigidbody>();
		auto Velo = PtrRedit->GetVelocity();
		if (Angle.length() <= 0.0f && Velo.y == 0.0f) {
			//コントローラを離したとき対策
			Velo *= GetDecel();
			PtrRedit->SetVelocity(Velo);
			return;
		}
		//Transform
		auto PtrTransform = GetGameObject()->GetComponent<Transform>();
		//現在の速度を取り出す
		//目的地を最高速度を掛けて求める
		auto Target = Angle * GetMaxSpeed();
		//目的地に向かうために力のかける方向を計算する
		//Forceはフォースである
		auto Force = Target - Velo;
		//yは0にする
		Force.y = 0;
		//加速度を求める
		auto Accel = Force / GetMass();
		//ターン時間を掛けたものを速度に加算する
		Velo += (Accel * ElapsedTime);
		//速度を設定する
		PtrRedit->SetVelocity(Velo);
		//回転の計算
		if (Angle.length() > 0.0f) {
			auto UtilPtr = GetGameObject()->GetBehavior<UtilBehavior>();
			UtilPtr->RotToHead(Angle, 1.0f);
		}
	}
コード例 #2
0
ファイル: Player.cpp プロジェクト: WiZFramework/BaseCross
	void Player::OnUpdate() {
		//1つ前の位置を取っておく
		m_BeforePos = m_Pos;
		//前回のターンからの経過時間を求める
		float ElapsedTime = App::GetApp()->GetElapsedTime();
		//コントローラの取得
		auto CntlVec = App::GetApp()->GetInputDevice().GetControlerVec();
		if (CntlVec[0].bConnected) {
			if (!m_JumpLock) {
				//Aボタン
				if (CntlVec[0].wPressedButtons & XINPUT_GAMEPAD_A) {
					m_BeforePos.y += 0.01f;
					m_Pos.y += 0.01f;
					m_GravityVelocity = Vec3(0, 4.0f, 0);
					m_JumpLock = true;
				}
			}
			Vec3 Direction = GetMoveVector();
			if (length(Direction) < 0.1f) {
				m_Velocity *= 0.9f;
			}
			else {
				m_Velocity = Direction * 5.0f;
			}
		}
		m_Pos += (m_Velocity * ElapsedTime);
		m_GravityVelocity += m_Gravity * ElapsedTime;
		m_Pos += m_GravityVelocity * ElapsedTime;
		if (m_Pos.y <= m_BaseY) {
			m_Pos.y = m_BaseY;
			m_GravityVelocity = Vec3(0, 0, 0);
			m_JumpLock = false;
		}
		RotToHead(0.1f);
	}
コード例 #3
0
/* Traces the outline of the block structures of a repositioning move
 */
static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPositon,
                                     bool aErase )
{
    auto screen = aPanel->GetScreen();
    auto block = &screen->m_BlockLocate;

    if( aErase )
    {
        block->Draw( aPanel, aDC, block->GetMoveVector(), g_XorMode, block->GetColor() );
        DrawMovingItems( aPanel, aDC );
    }

    block->SetMoveVector( aPanel->GetParent()->GetCrossHairPosition() - block->GetLastCursorPosition() );
    block->Draw( aPanel, aDC, block->GetMoveVector(), g_XorMode, block->GetColor() );
    DrawMovingItems( aPanel, aDC );
}
コード例 #4
0
ファイル: Player.cpp プロジェクト: WiZFramework/BaseCross
	//後更新
	void Player::OnUpdate2() {
		auto PtrPs = GetComponent<PsSphereBody>();
		auto Ptr = GetComponent<Transform>();
		Ptr->SetPosition(PtrPs->GetPosition());
		//回転の計算
		Vec3 Angle = GetMoveVector();
		if (Angle.length() > 0.0f) {
			auto UtilPtr = GetBehavior<UtilBehavior>();
			//補間処理を行わない回転。補間処理するには以下1.0を0.1などにする
			UtilPtr->RotToHead(Angle, 1.0f);
		}
		//文字列の表示
		DrawStrings();
	}
コード例 #5
0
ファイル: Player.cpp プロジェクト: WiZFramework/BaseCross
	//更新
	void Player::OnUpdate() {

		auto Vec = GetMoveVector();
		auto PtrPs = GetComponent<PsSphereBody>();
		auto Velo = PtrPs->GetLinearVelocity();
		Velo.x = Vec.x * 5.0f;
		Velo.z = Vec.z * 5.0f;
		PtrPs->SetLinearVelocity(Velo);

		//コントローラの取得
		auto CntlVec = App::GetApp()->GetInputDevice().GetControlerVec();
		if (CntlVec[0].bConnected) {
			//Aボタン
			if (CntlVec[0].wPressedButtons & XINPUT_GAMEPAD_A) {
				OnPushA();
			}
			//Xボタン
			else if (CntlVec[0].wPressedButtons & XINPUT_GAMEPAD_X) {
				OnPushX();
			}
		}

	}
	void ControllerInput::Tick(double Tick, double Span)
    {	
		if (!IsInitialized)
			return;

		/********************* READ INPUT *********************/
		/*        This will raise the event handlers          */   
		/******************************************************/
		
		if (!oisKeyboard || !oisMouse)
			return;

		oisKeyboard->capture();
		oisMouse->capture();
				
		/********************* EXIT CASES *********************/
		/*        Don't go on if any of these match           */
		/******************************************************/
		
		if (OgreClient::Singleton->Data->IsWaiting ||
			!OgreClient::Singleton->RenderWindow ||
			!OgreClient::Singleton->RenderWindow->isVisible() ||
			!OgreClient::Singleton->RenderWindow->isActive() ||
			!OgreClient::Singleton->HasFocus ||
			Avatar == nullptr ||
			Avatar->SceneNode == nullptr)
			return;
		
		/*************** SELF TARGET MODIFIER *****************/
		/*         Process keydown of some specific keys      */
		/******************************************************/

		// update flag whether selftarget modifier key is down     
		OgreClient::Singleton->Data->SelfTarget = IsSelfTargetDown;

		/****************** CAMERA PITCH/YAW ******************/
		/*      Apply frame-based smooth camera pitch/yaw     */
		/******************************************************/	
		
		SceneNode* cameraNode = OgreClient::Singleton->CameraNode;
		Camera* camera = OgreClient::Singleton->Camera;

		if (cameraNode && camera)
		{
			// get cameranode orientation
			Quaternion orientation = cameraNode->_getDerivedOrientation();

			// save/update current pitch and yaw values
			cameraPitchCurrent = orientation.getPitch().valueRadians();
			cameraYawCurrent = orientation.getYaw().valueRadians();

			// calculate new pitch and yaw values for this step/frame
			float destPitch = cameraPitchCurrent + cameraPitchStep;
			float destYaw = cameraYawCurrent + cameraYawStep;			

			// 1. PITCH						
			if (cameraPitchDelta != 0.0f)
			{
				// apply pitchstep on camera
				cameraNode->pitch(Radian(-cameraPitchStep));	
				
				// verify pitchover
				Quaternion orientation = cameraNode->_getDerivedOrientation();
				float pitchOver = orientation.getPitch().valueRadians();
			
				// don't allow overpitching, so pitch back possibly
				if (pitchOver >= Math::HALF_PI ||
					pitchOver <= -Math::HALF_PI)
				{
					cameraNode->pitch(Radian(cameraPitchStep));
					cameraPitchDelta = 0.0f;
					cameraPitchStep = 0.0f;
				}
				else if (cameraPitchDelta > 0.0f)
				{
					cameraPitchDelta -= cameraPitchStep;
					cameraPitchDelta = ::System::Math::Max(cameraPitchDelta, 0.0f);
				}
				else if (cameraPitchDelta < 0.0f)
				{
					cameraPitchDelta -= cameraPitchStep;
					cameraPitchDelta = ::System::Math::Min(cameraPitchDelta, 0.0f);
				}			
			}
			
			// 2. YAW
			if (cameraYawDelta != 0.0f)
			{
				// apply yawstep on camera
				cameraNode->yaw(Radian(-cameraYawStep), Node::TransformSpace::TS_WORLD);

				if (cameraYawDelta > 0.0f)
				{
					cameraYawDelta -= cameraYawStep;
					cameraYawDelta = ::System::Math::Max(cameraYawDelta, 0.0f);
				}
				else if (cameraYawDelta < 0.0f)
				{
					cameraYawDelta -= cameraYawStep;
					cameraYawDelta = ::System::Math::Min(cameraYawDelta, 0.0f);
				}
			}

			// 3. ZOOM
			if (cameraZDelta != 0.0f)
			{	
				float destZ = camera->getPosition().z - cameraZStep;

				//
				if (destZ > 0.0f)
				{
					// mark as 3. person camera mode
					IsCameraFirstPerson = false;
					
					// hide 1. person overlays
					ControllerUI::PlayerOverlays::HideOverlays();

					// apply the move
					camera->moveRelative(::Ogre::Vector3(0.0f, 0.0f, -cameraZStep));
					camera->_notifyMoved();
 
					if (cameraZDelta > 0.0f)
					{									
						cameraZDelta -= cameraZStep;
						cameraZDelta = ::System::Math::Max(cameraZDelta, 0.0f);
					}
					else if (cameraZDelta < 0.0f)
					{
						cameraZDelta -= cameraZStep;
						cameraZDelta = ::System::Math::Min(cameraZDelta, 0.0f);
					}
				}
				else
				{
					// mark as 1. person camera mode
					IsCameraFirstPerson = true;

					// show 1. person overlays
					ControllerUI::PlayerOverlays::ShowOverlays();

					// apply the move to the 0.0f
					camera->moveRelative(::Ogre::Vector3(0.0f, 0.0f, -cameraZStep - destZ));
					camera->_notifyMoved();
 
					cameraZDelta = 0.0f;
				}
			}
		}

		/********************* AVATAR YAW *********************/
		/*         Apply frame-based smooth avatar yaw        */
		/******************************************************/	
		
		// YAW
		if (avatarYawDelta != 0.0f)
		{
			// apply yawstep on avatar
			OgreClient::Singleton->TryYaw(avatarYawStep);

			if (avatarYawDelta > 0.0f)
			{
				avatarYawDelta -= avatarYawStep;
				avatarYawDelta = ::System::Math::Max(avatarYawDelta, 0.0f);
			}
			else if (avatarYawDelta < 0.0f)
			{
				avatarYawDelta -= avatarYawStep;
				avatarYawDelta = ::System::Math::Min(avatarYawDelta, 0.0f);
			}
		}

		/********************* MOVEMENT INPUT *****************/
		/*  left, right, up, down keys or both mouse buttons  */
		/******************************************************/	
		
		bool isMoveByMouseOrKeysNotUsedByUI = 
			(IsMovementInput && (IsBothMouseDown || !ControllerUI::ProcessingInput));

		if (isAutoMove || isMoveByMouseOrKeysNotUsedByUI)
		{
			// get movespeed based on walk-modifier key
			MovementSpeed speed = (IsWalkKeyDown) ? MovementSpeed::Walk : MovementSpeed::Run;
			
			// get movement direction vector
			V2 direction = GetMoveVector();

			// get the height of the avatar in ROO format
			float playerheight = 0.9f * 16.0f * Avatar->SceneNode->_getWorldAABB().getSize().y;
				
			// try to do the move (might get blocked)				
			OgreClient::Singleton->TryMove(direction, (unsigned char)speed, playerheight);
		}
				
		/************** KEYBOARD ONLY FROM HERE ON ************/
		/*               exit if UI is reading it             */
		/******************************************************/

		if (ControllerUI::ProcessingInput)
			return;
		
		/******************** ROTATION KEYS *******************/
		/*             rotate left/right by keyboard          */
		/******************************************************/	
		
        // Update Angle in dataobject and possibly send a update packet                  
		if (IsRotateKeyDown)
        {									          
            // scaled base delta
            float diff = KEYROTATESPEED * (float)OgreClient::Singleton->Config->KeyRotateSpeed * (float)OgreClient::Singleton->GameTick->Span;
			
			// half rotation speed on walk
			if (IsWalkKeyDown)
				diff *= 0.5f;

            // left
            if (OISKeyboard->isKeyDown(ActiveKeyBinding->RotateLeft))
            {
				// try to yaw and yaw camera back internally if suceeded
                if (OgreClient::Singleton->TryYaw(-diff) && IsLeftMouseDown && !isMouseWentDownOnUI)
                    cameraNode->yaw(Radian(-diff), Node::TransformSpace::TS_WORLD);
            }

            // right
            if (OISKeyboard->isKeyDown(ActiveKeyBinding->RotateRight))
            {
                // try to yaw and yaw camera back internally if suceeded                   
                if (OgreClient::Singleton->TryYaw(diff) && IsLeftMouseDown && !isMouseWentDownOnUI)
                    cameraNode->yaw(Radian(diff), Node::TransformSpace::TS_WORLD);
            }
		}
		
		/**************** ACTION BUTTON KEYS ******************/
		/*       these will trigger the defined actions       */
		/******************************************************/	

		ActionButtonList^ actionButtons = OgreClient::Singleton->Data->ActionButtons;

		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton01))		
			actionButtons[0]->Activate();
					
		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton02))		
			actionButtons[1]->Activate();
					
		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton03))		
			actionButtons[2]->Activate();
			
		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton04))		
			actionButtons[3]->Activate();
			
		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton05))	
			actionButtons[4]->Activate();
			
		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton06))		
			actionButtons[5]->Activate();
					
		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton07))	
			actionButtons[6]->Activate();
					
		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton08))		
			actionButtons[7]->Activate();		
			
		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton09))		
			actionButtons[8]->Activate();
					
		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton10))		
			actionButtons[9]->Activate();
			
		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton11))		
			actionButtons[10]->Activate();
					
		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton12))		
			actionButtons[11]->Activate();
					
		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton13))
			actionButtons[12]->Activate();
				
		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton14))
			actionButtons[13]->Activate();
			
		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton15))		
			actionButtons[14]->Activate();
				
		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton16))		
			actionButtons[15]->Activate();	
			
		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton17))		
			actionButtons[16]->Activate();
					
		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton18))		
			actionButtons[17]->Activate();
				
		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton19))		
			actionButtons[18]->Activate();		
			
		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton20))		
			actionButtons[19]->Activate();		
			
		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton21))	
			actionButtons[20]->Activate();
			
		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton22))	
			actionButtons[21]->Activate();		
			
		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton23))
			actionButtons[22]->Activate();
			
		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton24))
			actionButtons[23]->Activate();

		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton25))
			actionButtons[24]->Activate();

		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton26))
			actionButtons[25]->Activate();

		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton27))
			actionButtons[26]->Activate();

		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton28))
			actionButtons[27]->Activate();

		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton29))
			actionButtons[28]->Activate();

		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton30))
			actionButtons[29]->Activate();

		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton31))
			actionButtons[30]->Activate();

		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton32))
			actionButtons[31]->Activate();

		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton33))
			actionButtons[32]->Activate();

		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton34))
			actionButtons[33]->Activate();

		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton35))
			actionButtons[34]->Activate();

		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton36))
			actionButtons[35]->Activate();

		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton37))
			actionButtons[36]->Activate();

		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton38))
			actionButtons[37]->Activate();

		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton39))
			actionButtons[38]->Activate();

		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton40))
			actionButtons[39]->Activate();

		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton41))
			actionButtons[40]->Activate();

		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton42))
			actionButtons[41]->Activate();

		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton43))
			actionButtons[42]->Activate();

		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton44))
			actionButtons[43]->Activate();

		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton45))
			actionButtons[44]->Activate();

		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton46))
			actionButtons[45]->Activate();

		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton47))
			actionButtons[46]->Activate();

		if (oisKeyboard->isKeyDown(ActiveKeyBinding->ActionButton48))
			actionButtons[47]->Activate();
    };