HRESULT Camera::HandleMessages(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { case WM_KEYDOWN: { switch( wParam ) { case 'A': case VK_LEFT: Strafe(-0.1f) ; return TRUE ; case 'D': case VK_RIGHT: Strafe(0.1f) ; return TRUE ; case 'W': case VK_UP: Walk(0.1f) ; return TRUE ; case 'S': case VK_DOWN: Walk(-0.1f) ; return TRUE ; } } } return FALSE ; }
void Camera::Move3D() { if (m_moveState.forward) { Walk(m_speed * m_msec); } if (m_moveState.back) { Walk(-m_speed * m_msec); } if (m_moveState.left) { Strafe(m_speed * m_msec); } if (m_moveState.right) { Strafe(-m_speed * m_msec); } if (m_moveState.up) { Lift(m_speed * m_msec); } if (m_moveState.down) { Lift(-m_speed * m_msec); } }
void FPS_Cam::UpdateInput(double dt) //update if inputs available { /* Strafe */ if (CU::input.IsKeyPressed(Input::A) && !CU::input.IsKeyPressed(Input::D)) { Strafe(-dt); } if (!CU::input.IsKeyPressed(Input::A) && CU::input.IsKeyPressed(Input::D)) { Strafe(dt); } /* walk */ if (CU::input.IsKeyPressed(Input::W) && !CU::input.IsKeyPressed(Input::S)) { Walk(dt); } if (!CU::input.IsKeyPressed(Input::W) && CU::input.IsKeyPressed(Input::S)) { Walk(-dt); } /* Fly */ if (CU::input.IsKeyPressed(Input::K)) { Fly(dt); } else if (CU::input.IsKeyPressed(Input::L)) { Fly(-dt); } }
void Camera3::Update(double dt, bool* myKeys) {/* Vector3 view = (target - position).Normalized(); Vector3 right = view.Cross(up); right.y = 0; Inertia: instant dir change * strafe */ if(myKeys[KEY_A] && !myKeys[KEY_D]) Strafe(-dt); else if(straftMovingLeft) DecelerateLeft(-dt); if(myKeys[KEY_D] && !myKeys[KEY_A]) Strafe(dt); else if(straftMovingRight) DecelerateRight(dt); /* walk */ if(myKeys[KEY_W] && !myKeys[KEY_S]) Walk(dt); else if(walkMovingForward) DecelerateForward(dt); if(myKeys[KEY_S] && !myKeys[KEY_W]) Walk(-dt); else if(walkMovingBackward) DecelerateBackward(-dt); if(myKeys[KEY_C] && !croutching) croutching = true; croutch(dt); /* fly */ if(myKeys[KEY_K]) Fly(dt); if(myKeys[KEY_L]) Fly(-dt); if(myKeys[KEY_SPACE] && !jump) //com runs too fast, spacebar 2 times setJump(dt); if(myKeys[KEY_T]) //reset { Reset(); } /** update jump **/ if(jump) Jump(dt); /** mouse **/ Yaw(dt); Pitch(dt); }
void Camera::KeyboardWASD(InputManager &input, float factor) { //Unreal Tournament style keyboard setup if(input.KeyCheck(KEY_W)) Move(-factor); if(input.KeyCheck(KEY_S)) Move(factor); if(input.KeyCheck(KEY_A)) Strafe(factor); if(input.KeyCheck(KEY_D)) Strafe(-factor); }
void Entity::GoBackAndForth(float dt) { if (mGoUp) { Strafe(dt*movementMult); if (mPosition.x > mOrigX + mHeightToGo){ mGoUp = false; mGoDown = true; } } if (mGoDown) { Strafe(-dt*movementMult); if (mPosition.x < mOrigX - mHeightToGo){ mGoUp = true; mGoDown = false; } } }
void Camera::Update(float deltaTime, SDL_Event e) { if (e.type == SDL_KEYDOWN) { switch (e.key.keysym.sym) { case SDLK_a: Yaw(-kAngleToTurn); break; case SDLK_d: Yaw(kAngleToTurn); break; case SDLK_s: Pitch(-kAngleToTurn); break; case SDLK_w: Pitch(kAngleToTurn); break; case SDLK_q: Roll(kAngleToTurn); break; case SDLK_e: Roll(-kAngleToTurn); break; case SDLK_DOWN: MoveForward(-kMoveDistance); break; case SDLK_UP: MoveForward(kMoveDistance); break; case SDLK_LEFT: Strafe(kMoveDistance); break; case SDLK_RIGHT: Strafe(-kMoveDistance); break; } } }
void XM_CALLCONV Camera::Update( float deltaTime ) { if( GetAsyncKeyState( VK_HOME ) ) { SetCamType(); } if( GetCamType()==1 ) { if( GetAsyncKeyState( VK_LEFT ) ) { RotateY( 5.0f * deltaTime ); } if( GetAsyncKeyState( VK_RIGHT ) ) { RotateY( -5.0f * deltaTime ); } if( GetAsyncKeyState( VK_UP ) ) { Walk( -15.0f * deltaTime ); } if( GetAsyncKeyState( VK_DOWN ) ) { Walk( 15.0f * deltaTime ); } if( GetAsyncKeyState( VK_PRIOR ) ) { Pitch( 1.0f * deltaTime ); } if( GetAsyncKeyState( VK_NEXT ) ) { Pitch( -1.0f * deltaTime ); } if( GetAsyncKeyState( VK_OEM_COMMA ) ) { Strafe( -15.0f * deltaTime ); } if( GetAsyncKeyState( VK_OEM_PERIOD ) ) { Strafe( 15.0f * deltaTime ); } } else { // default camera //XMStoreFloat3( &target1, goblin1Pos); //XMVECTOR posV = XMLoadFloat3( &pos ); //XMVECTOR targetV = goblin1Pos; //XMVECTOR upV = GetUpXM(); //LookAt( posV, targetV, upV ); } UpdateViewMatrix(); }
void EulerCamera::Collided(ObjectType colltype) { if (colltype == ObjectType::ENEMY) { printf("Enemy collision"); } else if (colltype == ObjectType::OBJECT) { printf("Object \n"); if (LastMove==Moves::Forward) Walk(-0.1f); else if (LastMove == Moves::Backward) Walk(0.1f); else if (LastMove == Moves::Left) Strafe(0.1f); else if (LastMove == Moves::Right) Strafe(-0.1f); } }
void Active_SendReset(Packet* p, EncodeFlags ef) { int i; uint32_t flags = (GetFlags() | ef) & ~ENC_FLAG_VAL; uint32_t value = ef & ENC_FLAG_VAL; for ( i = 0; i < s_attempts; i++ ) { uint32_t len = 0; const uint8_t* rej; value = Strafe(i, value, p); rej = Encode_Reject(ENC_TCP_RST, flags|value, p, &len); if ( !rej ) return; s_send(p->pkth, !(ef & ENC_FLAG_FWD), rej, len); } }
/*** Procesamiento de la lógica del juego ***/ void Logic( float elapsed ) { // ACC = MulVector(ACC, 5); vTerrain = GetHeight( &terrain , cam.pos.x, cam.pos.z ) + altura; // sprintf(fpstex, "%d fps", CalculateFPS(elapsed)); /*Cámara*/ // correr if (Brun && (cam.pos.y <= vTerrain || under)){ // MulVector(VEL, 1.5f); run = 3.5f; } else if (Brun == GL_FALSE && (cam.pos.y <= vTerrain || under)){ run = 1.0f; } // confirma si esta debajo del agua if (cam.pos.y <= vWater) under = GL_TRUE; else under = GL_FALSE; //debajo del agua if (under){ velocityAgua = 0.3f; if (abs(VEL.x) <velocity * 0.3){ //VEL.x = 10.0; ACC.x = 0.0f; //aqui agrego la corriente } else ACC.x = 0.0f; } else{ velocityAgua = 1.0f; // VEL.z = 150.0f; ACC.x = 0.0f; VEL.x = 0.0f; } /* //bool (runState ? 0.5f : 1.0f) */ if( cam.walk ){ //VEL.z = velocity * run * velocityAgua; Walk( &cam,velocity * run * velocityAgua * elapsed, GL_TRUE); } if( cam.walkinv ){ //VEL.z = -velocity * 0.5 * run * velocityAgua; Walk( &cam, -velocity * 0.5 * run * velocityAgua* elapsed, GL_TRUE); } if( cam.strafe ){ //VEL.x = velocity * 0.8 * run * velocityAgua; Strafe( &cam, velocity * 0.8 * run * velocityAgua * elapsed, GL_TRUE); } if( cam.strafeinv ){ // VEL.x = -velocity * 0.8 * run * velocityAgua; Strafe( &cam, -velocity * 0.8 * run * velocityAgua * elapsed, GL_TRUE); } /* if( cam.walk ){ VEL.z = velocity * run * velocityAgua; Walk( &cam,VEL.z * elapsed, GL_TRUE); }else if (cam.pos.y <= vTerrain) VEL.z = 0.0f; if( cam.walkinv ){ VEL.z = -velocity * run * velocityAgua; Walk( &cam,VEL.z * elapsed, GL_TRUE); }else if (cam.pos.y <= vTerrain) VEL.z = 0.0f; if( cam.strafe ){ VEL.x = velocity * run * velocityAgua; Strafe( &cam, VEL.x * elapsed, GL_TRUE); }else if (cam.pos.y <= vTerrain) VEL.x = 0.0f; if( cam.strafeinv ){ VEL.x = -velocity * run * velocityAgua; Strafe( &cam, VEL.x * elapsed, GL_TRUE); }else if (cam.pos.y <= vTerrain) VEL.x = 0.0f; */ // LOCALIZACION EN MAPA dotX = mapWidth * (cam.pos.x / ( 64.0f * 50.0f)); dotZ = mapHeight * (cam.pos.z / ( 64.0f * 50.0f)); //fisicas VEL = SumVector ( VEL, MulVector ( ACC , elapsed ) ); //POS = SumVector ( POS, MulVector ( VEL , elapsed ) ); cam.pos.x = ( cam.pos.x + (VEL.x * elapsed ) ); //cam.pos.y = ( cam.pos.y + (VEL.y * elapsed ) ); // caidas y corriente if (under){ cam.pos.y = cam.pos.y + (VEL.y * 0.03 * run * elapsed ); cam.pos.x = cam.pos.x + (VEL.x * elapsed); } else{ cam.pos.y = cam.pos.y + (VEL.y * velocityAgua * run * elapsed ); //cam.pos.z = cam.pos.z + (VEL.z * elapsed); } if (jump && cam.pos.y<= vTerrain) { VEL.y = 40.0f; jump = GL_FALSE; }else if (jump && (cam.pos.y <= vWater + (altura * 0.1)) ){ // VEL.x = -velocity * 0.8 * run * velocityAgua; Fly( &cam, velocity * 0.2 * run * elapsed, GL_TRUE); VEL.y = 0.0f; if (cam.pos.y > vWater) cam.pos.y = vWater + (altura * 0.1f); /* if (cam.pos.y > vWater - altura){ VEL.y = 0.0f; cam.pos.y = vWater; }*/ } //OXIGENO if ((( (Brun && (cam.walk || cam.walkinv || cam.strafe || cam.strafeinv))) || under) && !oxIn) ox -= elapsed; else ox += 0.2 * elapsed; if ( ox < 0.0f || oxIn) oxIn = GL_FALSE; if (ox < 0.0f) { oxIn = GL_FALSE; ox = 0.0f; } if (ox > oxlevel){ oxIn = GL_FALSE; ox = oxlevel; } //ATAQUES CON LA ESPADA... if (atk1){ if (angX > -70) { angX -= 360.0f* elapsed; } if (angZ < 90) { angZ += 360.0f* elapsed; }else{ angX=0.0f; angZ = 0.0f; atk1= GL_FALSE; } /* if (angZ > 500) { angZ -= 360.0f* elapsed; }*/ } //mueve textura movWater += 0.4f * (elapsed); //no sobrepasa el limite del suelo if (cam.pos.y <= vTerrain) cam.pos.y = vTerrain; }
void Camera::HandleInput() { double deltaTime = GLOBAL::GetInstance().GetDeltaTime(); // Start moving the camera with the C key. if (InputManager::GetInstance()->IsKeyClicked(VkKeyScan('l')) && !GLOBAL::GetInstance().CAMERA_FLYING && FLAG_DEBUG == 1) { GLOBAL::GetInstance().CAMERA_FLYING = true; POINT position; GetCursorPos(&position); m_oldMouseX = (float)position.x; m_oldMouseY = (float)position.y; m_upVector = DirectX::XMFLOAT3(0.0f, 20.0f, 10.0f); DirectX::XMStoreFloat3(&m_upVector, DirectX::XMVector3Normalize(DirectX::XMLoadFloat3(&m_upVector))); m_look = DirectX::XMFLOAT3(0.0f, -20.0f, 10.0f); DirectX::XMStoreFloat3(&m_look, DirectX::XMVector3Normalize(DirectX::XMLoadFloat3(&m_look))); m_right = DirectX::XMFLOAT3(1.0f, 0.0f, 0.0f); DirectX::XMStoreFloat3(&m_right, DirectX::XMVector3Normalize(DirectX::XMLoadFloat3(&m_right))); } if (GLOBAL::GetInstance().CAMERA_FLYING) { // Rotate and pitch the camera. POINT position; GetCursorPos(&position); float dx = DirectX::XMConvertToRadians(0.25f * static_cast<float>(position.x - m_oldMouseX)); float dy = DirectX::XMConvertToRadians(0.25f * static_cast<float>(position.y - m_oldMouseY)); Pitch(dy); Rotate(dx); SetCursorPos((int)m_oldMouseX, (int)m_oldMouseY); // Move the camera using W, S, A, D keys. if (InputManager::GetInstance()->IsKeyPressed(VK_UP)) { Walk(10.0f * (float)deltaTime); } if (InputManager::GetInstance()->IsKeyPressed(VK_DOWN)) { Walk(-10.0f * (float)deltaTime); } if (InputManager::GetInstance()->IsKeyPressed(VK_LEFT)) { Strafe(-10.0f * (float)deltaTime); } if (InputManager::GetInstance()->IsKeyPressed(VK_RIGHT)) { Strafe(10.0f * (float)deltaTime); } // Update the camera. UpdateMovedCamera(); // Set shader variables from the camera. GraphicsEngine::SetViewAndProjection(GetViewMatrix(), GetProjectionMatrix()); // Reset the camera when BACKSPACE key is pressed. if (GetAsyncKeyState(VK_BACK)) { GLOBAL::GetInstance().CAMERA_FLYING = false; ResetCamera(); } } }
//----------------------------------------------------------------------------- // Updates the player object. //----------------------------------------------------------------------------- void PlayerObject::Update( float elapsed, bool addVelocity ) { // Allow the base animated object to update. AnimatedObject::Update( elapsed, addVelocity ); // Override the object's forward vector to take the view tilt into account. // This will allow the forward vector to move up and down as well instead // of just remaining horizontal. This is not important for movement since // the player can not fly, but for things like shooting it is. m_forward.x = (float)sin( GetRotation().y ); m_forward.y = (float)-tan( m_viewTilt ); m_forward.z = (float)cos( GetRotation().y ); D3DXVec3Normalize( &m_forward, &m_forward ); // Set the player's view point. This is done every frame because as the // mesh is animated, the reference point in the mesh may move. This // will allow the view point to move with the mesh's animations. m_viewPoint = GetMesh()->GetReferencePoint( "rp_view_point" )->GetTranslation(); // Ensure that the view movement is relative to the rotation. D3DXVec3TransformCoord( &m_viewPoint, &m_viewPoint, GetRotationMatrix() ); // Only calculate the correct view matrix if it is being used. if( m_isViewing == true ) { // Create the x axis rotation matrix. D3DXMATRIX rotationXMatrix; D3DXMatrixRotationX( &rotationXMatrix, m_viewTilt ); // Create the combined rotation matrix (i.e. y axis rotation from the // scene object plus the x axis rotation from the player object). D3DXMATRIX combinedRotation; D3DXMatrixMultiply( &combinedRotation, &rotationXMatrix, GetRotationMatrix() ); // Build a translation matrix that represents the final view point. D3DXMATRIX viewPointTranslationMatrix; D3DXVECTOR3 finalViewPointTranslation = GetTranslation() + m_viewPoint; D3DXMatrixTranslation( &viewPointTranslationMatrix, finalViewPointTranslation.x, finalViewPointTranslation.y, finalViewPointTranslation.z ); // Override the object's view matrix using the combined rotation and // the position of the final view point translation. D3DXMatrixMultiply( &m_viewMatrix, &combinedRotation, &viewPointTranslationMatrix ); D3DXMatrixInverse( &m_viewMatrix, NULL, &m_viewMatrix ); } // Ignore the rest if the player is dying (or dead) if( m_dying == true ) return; // Drive and strafe the player accordingly. if( m_drive != 0.0f ) Drive( m_drive * 8000.0f * elapsed ); if( m_strafe != 0.0f ) Strafe( m_strafe * 4000.0f * elapsed ); // Update the step audio paths. m_leftStepAudioPath->SetPosition( GetTranslation() + GetMesh()->GetReferencePoint( "rp_left_foot" )->GetTranslation() ); m_leftStepAudioPath->SetVelocity( GetVelocity() ); m_rightStepAudioPath->SetPosition( GetTranslation() + GetMesh()->GetReferencePoint( "rp_right_foot" )->GetTranslation() ); m_rightStepAudioPath->SetVelocity( GetVelocity() ); // Check if the player is changing their weapon (local player only). static float move = 0.0f; if( m_changingWeapon > 0.0f ) { m_changingWeapon -= elapsed; if( m_changingWeapon > 1.0f ) { // Lower the old weapon. move -= 100.0f * elapsed; m_weapons[m_oldWeapon]->RaiseLowerWeapon( elapsed, this, move ); } else if( m_changingWeapon < 0.0f ) { // The new weapon is in place. m_changingWeapon = 0.0f; move = 0.0f; // Send a message to inform the other players the weapon is ready. PlayerWeaponChangeMsg pwcm; pwcm.msgid = MSGID_PLAYER_WEAPON_CHANGE; pwcm.dpnid = g_engine->GetNetwork()->GetLocalID(); pwcm.weapon = m_currentWeapon; g_engine->GetNetwork()->Send( &pwcm, sizeof( PlayerWeaponChangeMsg ), DPNID_ALL_PLAYERS_GROUP, DPNSEND_NOLOOPBACK ); } else { // Raise the new weapon. move += 100.0f * elapsed; m_weapons[m_currentWeapon]->RaiseLowerWeapon( elapsed, this, move ); } } else { // Update the player's current weapon, when not changing weapons. if( m_weaponChanging == false ) m_weapons[m_currentWeapon]->Update( elapsed, m_fire, this, m_viewPoint.y ); } }
/******************************************************************************** Update the camera ********************************************************************************/ void TPCamera::Update(double dt) { // WASD movement if (myKeys['w'] == true) { Walk(dt); } else { MoveVel_W = 0.0f; } if (myKeys['s'] == true) { Walk(-dt); } else { MoveVel_S = 0.0f; } if (myKeys['a'] == true) { Strafe(-dt); } else { MoveVel_A = 0.0f; } if (myKeys['d'] == true) { Strafe(dt); } else { MoveVel_D = 0.0f; } // Rotation if (myKeys[VK_UP] == true) { LookUp(dt); } if (myKeys[VK_DOWN] == true) { LookUp(-dt); } if (myKeys[VK_LEFT] == true) { TurnLeft(-dt); } if (myKeys[VK_RIGHT] == true) { TurnRight(dt); } // Jump if (myKeys[32] == true) { Jump(dt); myKeys[32] = false; } UpdateJump(dt); //Update the camera direction based on mouse move // left-right rotate /*if (Application::camera_yaw != 0) Yaw(dt); if (Application::camera_pitch != 0) Pitch(dt); if (Application::IsKeyPressed('R')) { Reset(); }*/ }
void FPcamera::Update(double dt, float heightOffset) { if(myKeys['w']) { if(myKeys['z']) { if (!m_bJumping) { Run(dt, heightOffset); } else { Walk(dt, heightOffset); } myKeys['z'] = false; } else { Walk(dt, heightOffset); } myKeys['w'] = false; } if(myKeys['s']) { if(myKeys['z']) { Run(-dt, heightOffset); myKeys['z'] = false; } else { Walk(-dt, heightOffset); } myKeys['s'] = false; } if(myKeys['a']) { Strafe(-dt, heightOffset); myKeys['a'] = false; } if(myKeys['d']) { Strafe(dt, heightOffset); myKeys['d'] = false; } if(myKeys['q']) { moveUp(dt, 5.f); myKeys['q'] = false; } if(myKeys['e']) { moveDown(dt, 5.f); myKeys['e'] = false; } if(myKeys[32]) { Jump(dt); myKeys[32] = false; } if(myKeys['c']) { m_bCrouching = true; Crouch(dt, heightOffset); myKeys['c'] = false; } else { m_bCrouching = false; Crouch(-dt, heightOffset); } if(m_bRecoil) { static float timer = 0.f; lookUp(dt, 20.f); timer += (float)dt; if (timer >= 0.1f) { m_bRecoil = false; timer = 0.f; } } else if (!m_bRecoil && recoil > 0.f) { lookDown(dt, 20.f); } UpdateJump(dt, heightOffset); if(Application::camera_pitch != 0) { Pitch(dt); } if(Application::camera_yaw != 0) { Yaw(dt); } if(myKeys['r']) { Reset(); myKeys['r'] = false; } }