void AnimationPlayer::Update(const GameTime& gameTime) { if (mIsPlayingClip) { assert(mCurrentClip != nullptr); mCurrentTime += (static_cast<float>(gameTime.ElapsedGameTime().count()) / 1000.0f) * mCurrentClip->TicksPerSecond(); if (mCurrentTime >= mCurrentClip->Duration()) { if (mIsClipLooped) { mCurrentTime = 0.0f; } else { mIsPlayingClip = false; return; } } if (mInterpolationEnabled) { GetInterpolatedPose(mCurrentTime, *(mModel->RootNode())); } else { GetPose(mCurrentTime, *(mModel->RootNode())); } } }
void BlinnPhongDemo::UpdateDirectionalLight(const GameTime& gameTime) { static float directionalIntensity = 1.0f; float elapsedTime = (float)gameTime.ElapsedGameTime(); // Upddate directional light intensity if (glfwGetKey(mGame->Window(), GLFW_KEY_T) && directionalIntensity < 1.0f) { directionalIntensity += elapsedTime; directionalIntensity = glm::min(directionalIntensity, 1.0f); mDirectionalLight->SetColor(vec4((vec3)directionalIntensity, 1.0f)); } if (glfwGetKey(mGame->Window(), GLFW_KEY_G) && directionalIntensity > 0.0f) { directionalIntensity -= elapsedTime; directionalIntensity = glm::max(directionalIntensity, 0.0f); mDirectionalLight->SetColor(vec4((vec3)directionalIntensity, 1.0f)); } // Rotate directional light vec2 rotationAmount = Vector2Helper::Zero; if (glfwGetKey(mGame->Window(), GLFW_KEY_LEFT)) { rotationAmount.x += LightRotationRate.x * elapsedTime; } if (glfwGetKey(mGame->Window(), GLFW_KEY_RIGHT)) { rotationAmount.x -= LightRotationRate.x * elapsedTime; } if (glfwGetKey(mGame->Window(), GLFW_KEY_UP)) { rotationAmount.y += LightRotationRate.y * elapsedTime; } if (glfwGetKey(mGame->Window(), GLFW_KEY_DOWN)) { rotationAmount.y -= LightRotationRate.y * elapsedTime; } mat4 lightRotationMatrix; if (rotationAmount.x != 0) { lightRotationMatrix = glm::rotate(mat4(), rotationAmount.x, Vector3Helper::Up); } if (rotationAmount.y != 0) { lightRotationMatrix = rotate(lightRotationMatrix, rotationAmount.y, mDirectionalLight->Right()); } if (rotationAmount.x != 0.0f || rotationAmount.y != 0.0f) { mDirectionalLight->ApplyRotation(lightRotationMatrix); //mProxyModel->ApplyRotation(lightRotationMatrix); } }
void FirstPersonCamera::Update(const GameTime& gameTime) { XMFLOAT2 movementAmount = Vector2Helper::Zero; if (mKeyboard != nullptr) { if (mKeyboard->IsKeyDown(DIK_W)) { movementAmount.y = 1.0f; } if (mKeyboard->IsKeyDown(DIK_S)) { movementAmount.y = -1.0f; } if (mKeyboard->IsKeyDown(DIK_A)) { movementAmount.x = -1.0f; } if (mKeyboard->IsKeyDown(DIK_D)) { movementAmount.x = 1.0f; } } XMFLOAT2 rotationAmount = Vector2Helper::Zero; if ((mMouse != nullptr) && (mMouse->IsButtonHeldDown(MouseButtons::Left))) { LPDIMOUSESTATE mouseState = mMouse->CurrentState(); rotationAmount.x = -mouseState->lX * mMouseSensitivity; rotationAmount.y = -mouseState->lY * mMouseSensitivity; } float elapsedTime = (float)gameTime.ElapsedGameTime(); XMVECTOR rotationVector = XMLoadFloat2(&rotationAmount) * mRotationRate * elapsedTime; XMVECTOR right = XMLoadFloat3(&mRight); XMMATRIX pitchMatrix = XMMatrixRotationAxis(right, XMVectorGetY(rotationVector)); XMMATRIX yawMatrix = XMMatrixRotationY(XMVectorGetX(rotationVector)); ApplyRotation(XMMatrixMultiply(pitchMatrix, yawMatrix)); XMVECTOR position = XMLoadFloat3(&mPosition); XMVECTOR movement = XMLoadFloat2(&movementAmount) * mMovementRate * elapsedTime; XMVECTOR strafe = right * XMVectorGetX(movement); position += strafe; XMVECTOR forward = XMLoadFloat3(&mDirection) * XMVectorGetY(movement); position += forward; XMStoreFloat3(&mPosition, position); Camera::Update(gameTime); }
void BlinnPhongDemo::UpdateAmbientLight(const GameTime& gameTime) { static float ambientIntensity = 0.0f; if (glfwGetKey(mGame->Window(), GLFW_KEY_R) && ambientIntensity < 1.0f) { ambientIntensity += (float)gameTime.ElapsedGameTime(); ambientIntensity = glm::min(ambientIntensity, 1.0f); mAmbientLight->SetColor(vec4((vec3)ambientIntensity, 1.0f)); } if (glfwGetKey(mGame->Window(), GLFW_KEY_F) && ambientIntensity > 0.0f) { ambientIntensity -= (float)gameTime.ElapsedGameTime(); ambientIntensity = glm::max(ambientIntensity, 0.0f); mAmbientLight->SetColor(vec4((vec3)ambientIntensity, 1.0f)); } }
void BlinnPhongDemo::UpdateSpecularLight(const GameTime& gameTime) { static float specularIntensity = 1.0f; if (glfwGetKey(mGame->Window(), GLFW_KEY_Y) && specularIntensity < 1.0f) { specularIntensity += (float)gameTime.ElapsedGameTime(); specularIntensity = glm::min(specularIntensity, 1.0f); mSpecularColor = (vec4((vec3)specularIntensity, 1.0f)); } if (glfwGetKey(mGame->Window(), GLFW_KEY_H) && specularIntensity > 0.0f) { specularIntensity -= (float)gameTime.ElapsedGameTime(); specularIntensity = glm::max(specularIntensity, 0.0f); mSpecularColor = (vec4((vec3)specularIntensity, 1.0f)); } static float specularPower = mSpecularPower; if (glfwGetKey(mGame->Window(), GLFW_KEY_U) && specularPower < UCHAR_MAX) { specularPower += LightModulationRate * (float)gameTime.ElapsedGameTime(); specularPower = glm::min(specularPower, static_cast<float>(UCHAR_MAX)); mSpecularPower = specularPower; } if (glfwGetKey(mGame->Window(), GLFW_KEY_J) && specularPower > 0.0f) { specularPower -= LightModulationRate * (float)gameTime.ElapsedGameTime(); specularPower = glm::max(specularPower, 0.0f); mSpecularPower = specularPower; } }
void TransparencyDemo::UpdateSpecularLight(const GameTime& gameTime) { static float specularIntensity = 1.0f; float elapsedTime = static_cast<float>(gameTime.ElapsedGameTime().count()) / 1000.0f; Library::GamePadComponent* gp = mGame->GetGamePad(); if (gp->IsButtonDown(GamePadButton::DPadUp) && specularIntensity < 1.0f) { specularIntensity += elapsedTime; specularIntensity = min(specularIntensity, 1.0f); mPixelCBufferPerObjectData.SpecularColor = XMFLOAT3(specularIntensity, specularIntensity, specularIntensity); } if (gp->IsButtonDown(GamePadButton::DPadDown) && specularIntensity > 0.0f) { specularIntensity -= elapsedTime; specularIntensity = max(specularIntensity, 0.0f); mPixelCBufferPerObjectData.SpecularColor = XMFLOAT3(specularIntensity, specularIntensity, specularIntensity); } static float specularPower = mPixelCBufferPerObjectData.SpecularPower; if (gp->IsButtonDown(GamePadButton::DPadRight) && specularPower < UCHAR_MAX) { specularPower += LightModulationRate * elapsedTime; specularPower = min(specularPower, static_cast<float>(UCHAR_MAX)); mPixelCBufferPerObjectData.SpecularPower = specularPower; } if (gp->IsButtonDown(GamePadButton::DPadLeft) && specularPower > 1.0f) { specularPower -= LightModulationRate * elapsedTime; specularPower = max(specularPower, 1.0f); mPixelCBufferPerObjectData.SpecularPower = specularPower; } }
void TransparencyDemo::UpdateAmbientLight(const GameTime& gameTime) { static float ambientIntensity = 0.0f; float elapsedTime = static_cast<float>(gameTime.ElapsedGameTime().count()) / 1000.0f; Library::GamePadComponent* gp = mGame->GetGamePad(); if (gp->IsButtonDown(GamePadButton::A) && ambientIntensity < 1.0f) { ambientIntensity += elapsedTime; ambientIntensity = min(ambientIntensity, 1.0f); mPixelCBufferPerFrameData.AmbientColor = XMFLOAT4(ambientIntensity, ambientIntensity, ambientIntensity, 1.0f); } if (gp->IsButtonDown(GamePadButton::B) && ambientIntensity > 0.0f) { ambientIntensity -= elapsedTime; ambientIntensity = max(ambientIntensity, 0.0f); mPixelCBufferPerFrameData.AmbientColor = XMFLOAT4(ambientIntensity, ambientIntensity, ambientIntensity, 1.0f); } }
void TransparencyDemo::UpdateDirectionalLight(const GameTime& gameTime) { static float directionalIntensity = 1.0f; float elapsedTime = static_cast<float>(gameTime.ElapsedGameTime().count()) / 1000.0f; Library::GamePadComponent* gp = mGame->GetGamePad(); // Update directional light intensity if (gp->IsButtonDown(GamePadButton::Y) && directionalIntensity < 1.0f) { directionalIntensity += elapsedTime; directionalIntensity = min(directionalIntensity, 1.0f); mPixelCBufferPerFrameData.LightColor = XMFLOAT4(directionalIntensity, directionalIntensity, directionalIntensity, 1.0f); mDirectionalLight->SetColor(mPixelCBufferPerFrameData.LightColor); } if (gp->IsButtonDown(GamePadButton::X) && directionalIntensity > 0.0f) { directionalIntensity -= elapsedTime; directionalIntensity = max(directionalIntensity, 0.0f); mPixelCBufferPerFrameData.LightColor = XMFLOAT4(directionalIntensity, directionalIntensity, directionalIntensity, 1.0f); mDirectionalLight->SetColor(mPixelCBufferPerFrameData.LightColor); } // Rotate directional light XMFLOAT2 rotationAmount = Vector2Helper::Zero; if (gp->CurrentState().IsLeftThumbStickRight()) { rotationAmount.x += LightRotationRate.x * elapsedTime; } if (gp->CurrentState().IsLeftThumbStickLeft()) { rotationAmount.x -= LightRotationRate.x * elapsedTime; } if (gp->CurrentState().IsLeftThumbStickUp()) { rotationAmount.y += LightRotationRate.y * elapsedTime; } if (gp->CurrentState().IsLeftThumbStickDown()) { rotationAmount.y -= LightRotationRate.y * elapsedTime; } XMMATRIX lightRotationMatrix = XMMatrixIdentity(); if (rotationAmount.x != 0) { lightRotationMatrix = XMMatrixRotationY(rotationAmount.x); } if (rotationAmount.y != 0) { XMMATRIX lightRotationAxisMatrix = XMMatrixRotationAxis(mDirectionalLight->RightVector(), rotationAmount.y); lightRotationMatrix *= lightRotationAxisMatrix; } if (rotationAmount.x != 0.0f || rotationAmount.y != 0.0f) { mDirectionalLight->ApplyRotation(lightRotationMatrix); mProxyModel->ApplyRotation(lightRotationMatrix); const XMFLOAT3& lightdirection = mDirectionalLight->Direction(); mVertexCBufferPerFrameData.LightDirection = XMFLOAT4(lightdirection.x, lightdirection.y, lightdirection.z, 0.0f); } }