コード例 #1
0
// Called once per frame.
void DynamicCubemapRenderer::Update(DX::StepTimer const& timer)
{
    m_controller->Update();

    // Update the view matrix based on the camera position.
    m_camera->SetViewParameters(
        m_controller->get_Position(),       // The point the camera is at.
        m_controller->get_LookPoint(),      // The point to look towards.
        float3(0, 1, 0)                     // The up-vector  (+Y).
    );

    // Update the position of the cube and sphere objects.
    XMStoreFloat4x4(
        &m_cubeRotation,
        XMMatrixTranspose(
            XMMatrixRotationY(static_cast<float>(timer.GetTotalSeconds()) / 4 * XM_PIDIV4)
        )
    );

    XMStoreFloat4x4(
        &m_cube2Rotation,
        XMMatrixTranspose(
            XMMatrixRotationX(static_cast<float>(timer.GetTotalSeconds()) / 4 * XM_PIDIV4)
        )
    );

    XMStoreFloat4x4(
        &m_sphereRotation,
        XMMatrixTranspose(XMMatrixTranslation(0.0f, 0.0f, 0.0f))
    );
}
コード例 #2
0
// Called once per frame. Rotates the cube, and calculates and sets the model matrix
// relative to the position transform indicated by hologramPositionTransform.
void SpinningCubeRenderer::Update(const DX::StepTimer& timer)
{
    float const deltaTime = static_cast<float>(timer.GetElapsedSeconds());
    float const lerpDeltaTime = deltaTime * c_lerpRate;

    float3 const prevPosition = m_position;
    m_position = lerp(m_position, m_targetPosition, lerpDeltaTime);

    m_velocity = (prevPosition - m_position) / deltaTime;

    // Rotate the cube.
    // Convert degrees to radians, then convert seconds to rotation angle.
    float const radiansPerSecond = XMConvertToRadians(m_degreesPerSecond);
    float const totalRotation    = static_cast<float>(timer.GetTotalSeconds()) * radiansPerSecond;

    // Scale the cube down to 10cm
    float4x4 const modelScale = make_float4x4_scale({ 0.1f });
    float4x4 const modelRotation = make_float4x4_rotation_y(totalRotation);
    float4x4 const modelTranslation = make_float4x4_translation(m_position);

    m_modelConstantBufferData.model = modelScale * modelRotation * modelTranslation;

    // Use the D3D device context to update Direct3D device-based resources.
    const auto context = m_deviceResources->GetD3DDeviceContext();

    // Update the model transform buffer for the hologram.
    context->UpdateSubresource(
        m_modelConstantBuffer.Get(),
        0,
        nullptr,
        &m_modelConstantBufferData,
        0,
        0
        );
}
コード例 #3
0
ファイル: Game.cpp プロジェクト: walbourn/directxtk-samples
// Updates the world.
void Game::Update(DX::StepTimer const& timer)
{
    Vector3 eye(0.0f, 0.7f, 1.5f);
    Vector3 at(0.0f, -0.1f, 0.0f);

    m_view = Matrix::CreateLookAt(eye, at, Vector3::UnitY);

    m_world = Matrix::CreateRotationY(float(timer.GetTotalSeconds() * XM_PIDIV4));

    m_batchEffect->SetView(m_view);
    m_batchEffect->SetWorld(Matrix::Identity);

#ifdef DXTK_AUDIO
    m_audioTimerAcc -= (float)timer.GetElapsedSeconds();
    if (m_audioTimerAcc < 0)
    {
        if (m_retryDefault)
        {
            m_retryDefault = false;
            if (m_audEngine->Reset())
            {
                // Restart looping audio
                m_effect1->Play(true);
            }
        }
        else
        {
            m_audioTimerAcc = 4.f;

            m_waveBank->Play(m_audioEvent++);

            if (m_audioEvent >= 11)
                m_audioEvent = 0;
        }
    }
#endif

    auto pad = m_gamePad->GetState(0);
    if (pad.IsConnected())
    {
        if (pad.IsViewPressed())
        {
            PostQuitMessage(0);
        }
    }

    auto kb = m_keyboard->GetState();
    if (kb.Escape)
    {
        PostQuitMessage(0);
    }
}
コード例 #4
0
// Called once per frame, creates a Y rotation based on elapsed time.
void ShadowSceneRenderer::Update(DX::StepTimer const& timer)
{
    // Convert degrees to radians, then convert seconds to rotation angle.
    float radiansPerSecond = XMConvertToRadians(m_degreesPerSecond);
    double totalRotation = timer.GetTotalSeconds() * radiansPerSecond;

    // Uncomment the following line of code to oscillate the cube instead of
    // rotating it. Useful for testing different margin coefficients in the
    // pixel shader.

    //totalRotation = 9.f + cos(totalRotation) *.2;

    float animRadians = (float)fmod(totalRotation, XM_2PI);

    // Prepare to pass the view matrix, and updated model matrix, to the shader.
    XMStoreFloat4x4(&m_rotatedModelBufferData.model, XMMatrixTranspose(XMMatrixRotationY(animRadians)));

    // If the shadow dimension has changed, recreate it.
    D3D11_TEXTURE2D_DESC desc = { 0 };
    if (m_shadowMap != nullptr)
    {
        m_shadowMap->GetDesc(&desc);
        if (m_shadowMapDimension != desc.Height)
        {
            InitShadowMap();
        }
    }
}
コード例 #5
0
//-----------------------------------------------------------------------------------------------------------------------------------
void Camera::Update(DX::StepTimer const& timer)
{
	// If the camera is fixed we should not do any more updating
	if (m_cameraMode == CameraMode::kFixed)
	{
		return;
	}

	KeyboardInput& keyboard = ScreenManager::GetKeyboardInput();
	Vector2 diff = Vector2::Zero;

	if (keyboard.IsKeyDown(Keyboard::Keys::Left))
	{
		diff.x = -1;
	}
	if (keyboard.IsKeyDown(Keyboard::Keys::Right))
	{
		diff.x = 1;
	}
	if (keyboard.IsKeyDown(Keyboard::Keys::Up))
	{
		diff.y = -1;
	}
	if (keyboard.IsKeyDown(Keyboard::Keys::Down))
	{
		diff.y = 1;
	}

	if (diff != Vector2::Zero)
	{
		diff.Normalize();
		m_position += diff * (float)timer.GetElapsedSeconds() * m_panSpeed;
	}
}
コード例 #6
0
// Updates the world.
void Sample::Update(DX::StepTimer const& timer)
{
    PIXBeginEvent(PIX_COLOR_DEFAULT, L"Update");

    float elapsedTime = float(timer.GetElapsedSeconds());

    auto pad = m_gamePad->GetState(0);
    if (pad.IsConnected())
    {
        m_gamePadButtons.Update(pad);

        if (!m_ui->Update(elapsedTime, pad))
        {
            if (pad.IsViewPressed())
            {
                Windows::ApplicationModel::Core::CoreApplication::Exit();
            }
            if (pad.IsMenuPressed())
            {
                Windows::Xbox::UI::SystemUI::ShowAccountPickerAsync(nullptr,Windows::Xbox::UI::AccountPickerOptions::None);
            }
        }
    }
    else
    {
        m_gamePadButtons.Reset();
    }

    PIXEndEvent();
}
コード例 #7
0
ファイル: Game.cpp プロジェクト: heatha7979/xbox-live-api
// Updates the world.
void Game::Update(DX::StepTimer const& timer)
{
    PIXBeginEvent(PIX_COLOR_DEFAULT, L"Update");

    float elapsedTime = float(timer.GetElapsedSeconds());
    UNREFERENCED_PARAMETER(elapsedTime);

    auto pad = m_gamePad->GetState(0);
    if (pad.IsConnected())
    {
        m_gamePadButtons.Update(pad);

        if (pad.IsViewPressed())
        {
            Windows::ApplicationModel::Core::CoreApplication::Exit();
        }
    }
    else
    {
        m_gamePadButtons.Reset();
    }

    UpdateGame();

    PIXEndEvent();
}
コード例 #8
0
// Updates the text to be displayed.
void SampleFpsTextRenderer::Update(DX::StepTimer const& timer)
{
	// Update display text.
	uint32 fps = timer.GetFramesPerSecond();

	m_text = (fps > 0) ? std::to_wstring(fps) + L" FPS" : L" - FPS";

	ComPtr<IDWriteTextLayout> textLayout;
	DX::ThrowIfFailed(
		m_deviceResources->GetDWriteFactory()->CreateTextLayout(
			m_text.c_str(),
			(uint32) m_text.length(),
			m_textFormat.Get(),
			240.0f, // Max width of the input text.
			50.0f, // Max height of the input text.
			&textLayout
			)
		);

	DX::ThrowIfFailed(
		textLayout.As(&m_textLayout)
		);

	DX::ThrowIfFailed(
		m_textLayout->GetMetrics(&m_textMetrics)
		);
}
コード例 #9
0
//-----------------------------------------------------------------------------------------------------------------------------------
void Button::Update(DX::StepTimer const& timer)
{
	UIObject::Update(timer);

	if (IsActive())
	{
		m_clickResetTimer += (float)timer.GetElapsedSeconds();
		if (m_clickResetTimer >= m_resetTime)
		{
			m_buttonState = ButtonState::kIdle;
		}

		// Lerp our current colour to the default one to create effect when mouse over button
		SetColour(Color::Lerp(GetColour(), m_defaultColour, (float)timer.GetElapsedSeconds() * 3));
	}
}
// Updates any time-based rendering resources (currently none).
// This method must be implemented for the Overlay class.
void SampleVirtualControllerRenderer::Update(DX::StepTimer const& timer)
{
    // Update the timers for fading out unused touch inputs.
    float frameTime = static_cast<float>(timer.GetElapsedSeconds());
    if (m_stickFadeTimer > 0)  m_stickFadeTimer -= frameTime;
    if (m_buttonFadeTimer > 0) m_buttonFadeTimer -= frameTime;
}
コード例 #11
0
ファイル: Game.cpp プロジェクト: Mixone-FinallyHere/MixSecond
// Called once per frame, updates the scene state.
void Game::Update(DX::StepTimer const& timer)
{
	auto timeDelta = static_cast<float>(timer.GetElapsedSeconds());

	// Update animated models.
	m_skinnedMeshRenderer.UpdateAnimation(timeDelta, m_meshModels);

	// Rotate scene.
	m_rotation = static_cast<float>(timer.GetTotalSeconds()) * 0.5f;

	// Update the "time" variable for the glow effect.
	for (float &time : m_time)
	{
		time = std::max<float>(0.0f, time - timeDelta);
	}
}
コード例 #12
0
ファイル: Game.cpp プロジェクト: zhiangf/sobriquet
// Updates the world.
void Game::Update(DX::StepTimer const& timer)
{
    float elapsedTime = float(timer.GetElapsedSeconds());

    // TODO: Add your game logic here.
    elapsedTime;
}
コード例 #13
0
ファイル: Game.cpp プロジェクト: ka-s/DTK_test
// Updates the world
void Game::Update(DX::StepTimer const& timer)
{
    float elapsedTime = float(timer.GetElapsedSeconds());

    // TODO: Add your game logic here
    elapsedTime;
    i_render_manager->update();
}
コード例 #14
0
ファイル: Game.cpp プロジェクト: AlanWills/SpinOut_Source
// Updates the world
void Game::Update(DX::StepTimer const& timer)
{
    float elapsedTime = float(timer.GetElapsedSeconds());

    // TODO: Add your game logic here
    m_screenManager->Update(elapsedTime);
    m_screenManager->HandleInput(elapsedTime);
}
コード例 #15
0
ファイル: Game.cpp プロジェクト: fixedFTGJ/Coursework
// Updates the world
void Game::Update(DX::StepTimer const& timer)
{
    float elapsedTime = float(timer.GetElapsedSeconds());

    // TODO: Add your game logic here
	XMMATRIX m = XMMatrixIdentity();
	m = XMMatrixMultiply(m, XMMatrixTranslation(0.0f, 0.0f, 0.0f));
	XMStoreFloat4x4(&m_constantBufferData.model, m);
    elapsedTime;
}
コード例 #16
0
// Updates the world.
void Sample::Update(DX::StepTimer const& timer)
{
    PIXBeginEvent(PIX_COLOR_DEFAULT, L"Update");

    float elapsedTime = float(timer.GetElapsedSeconds());

	// Update the rotation constant
	m_curRotationAngleRad += elapsedTime / 3.f;
	if (m_curRotationAngleRad >= XM_2PI)
	{
		m_curRotationAngleRad -= XM_2PI;
	}

	// Rotate the cube around the origin
	XMStoreFloat4x4(&m_worldMatrix, XMMatrixRotationY(m_curRotationAngleRad));

	// Setup our lighting parameters
	m_lightDirs[0] = XMFLOAT4(-0.577f, 0.577f, -0.577f, 1.0f);
	m_lightDirs[1] = XMFLOAT4(0.0f, 0.0f, -1.0f, 1.0f);

	m_lightColors[0] = XMFLOAT4(0.5f, 0.5f, 0.5f, 1.0f);
	m_lightColors[1] = XMFLOAT4(0.5f, 0.0f, 0.0f, 1.0f);

	// Rotate the second light around the origin
	XMMATRIX rotate = XMMatrixRotationY(-2.0f * m_curRotationAngleRad);
	XMVECTOR lightDir = XMLoadFloat4(&m_lightDirs[1]);
	lightDir = XMVector3Transform(lightDir, rotate);
	XMStoreFloat4(&m_lightDirs[1], lightDir);

	// Handle controller input for exit
    auto pad = m_gamePad->GetState(0);
    if (pad.IsConnected())
    {
        m_gamePadButtons.Update(pad);

        if (pad.IsViewPressed())
        {
            Windows::ApplicationModel::Core::CoreApplication::Exit();
        }
    }
    else
    {
        m_gamePadButtons.Reset();
    }

    auto kb = m_keyboard->GetState();
    m_keyboardButtons.Update(kb);

    if (kb.Escape)
    {
        Windows::ApplicationModel::Core::CoreApplication::Exit();
    }

    PIXEndEvent();
}
コード例 #17
0
void DirectXTK3DSceneRenderer::Update(DX::StepTimer const& timer)
{
    Vector3 eye(0.0f, 0.7f, 1.5f);
    Vector3 at(0.0f, -0.1f, 0.0f);

    m_view = Matrix::CreateLookAt(eye, at, Vector3::UnitY);

    m_world = Matrix::CreateRotationY( float(timer.GetTotalSeconds() * XM_PIDIV4) );

    m_batchEffect->SetView(m_view);
    m_batchEffect->SetWorld(Matrix::Identity);

    m_audioTimerAcc -= (float)timer.GetElapsedSeconds();
    if (m_audioTimerAcc < 0)
    {
        if (m_retryDefault)
        {
            m_retryDefault = false;
            if (m_audEngine->Reset())
            {
                // Restart looping audio
                m_effect1->Play(true);
            }
        }
        else
        {
            m_audioTimerAcc = 4.f;

            m_waveBank->Play(m_audioEvent++);

            if (m_audioEvent >= 11)
                m_audioEvent = 0;
        }
    }

    if (!m_audEngine->IsCriticalError() && m_audEngine->Update())
    {
        // Setup a retry in 1 second
        m_audioTimerAcc = 1.f;
        m_retryDefault = true;
    }
}
コード例 #18
0
void PointLightRenderer::UpdateSpecularLight(const DX::StepTimer& gameTime)
{
	static float specularIntensity = 1.0f;
	GamePad::State gamePadState = mGamePad->CurrentState();
	if (gamePadState.IsConnected())
	{
		if (gamePadState.IsLeftTriggerPressed() && specularIntensity <= 1.0f)
		{
			specularIntensity += static_cast<float>(gameTime.GetElapsedSeconds());
			specularIntensity = min(specularIntensity, 1.0f);

			mPixelCBufferPerObjectData.SpecularColor = XMFLOAT3(specularIntensity, specularIntensity, specularIntensity);
		}

		if (gamePadState.IsRightTriggerPressed() && specularIntensity >= 0.0f)
		{
			specularIntensity -= (float)gameTime.GetElapsedSeconds();
			specularIntensity = max(specularIntensity, 0.0f);

			mPixelCBufferPerObjectData.SpecularColor = XMFLOAT3(specularIntensity, specularIntensity, specularIntensity);
		}

		static float specularPower = mPixelCBufferPerObjectData.SpecularPower;

		if (mGamePad->IsButtonDown(GamePadButton::DPadUp) && specularPower < UCHAR_MAX)
		{
			specularPower += LightModulationRate * static_cast<float>(gameTime.GetElapsedSeconds());
			specularPower = min(specularPower, static_cast<float>(UCHAR_MAX));

			mPixelCBufferPerObjectData.SpecularPower = specularPower;
		}

		if (mGamePad->IsButtonDown(GamePadButton::DPadDown) && specularPower > 1.0f)
		{
			specularPower -= LightModulationRate * static_cast<float>(gameTime.GetElapsedSeconds());
			specularPower = max(specularPower, 1.0f);

			mPixelCBufferPerObjectData.SpecularPower = specularPower;
		}
	}
}
コード例 #19
0
//-----------------------------------------------------------------------------------------------------------------------------------
void UIObject::Update(DX::StepTimer const& timer)
{
	BaseObject::Update(timer);

	m_currentLifeTime += (float)timer.GetElapsedSeconds();
	if (m_currentLifeTime > m_lifeTime)
	{
		// This UIObject has been alive for longer than its lifetime so it dies
		// and will be cleared up by whatever manager is in charge of it
		Die();
	}
}
コード例 #20
0
ファイル: Game.cpp プロジェクト: TsubameDono/CCDK
// Updates the world
void Game::Update(DX::StepTimer const& timer)
{
    float elapsedTime = float(timer.GetElapsedSeconds());

    // TODO: Add your game logic here
    elapsedTime;

    for(auto & player: m_players)
    {
        player->Update();
    }
}
コード例 #21
0
//-----------------------------------------------------------------------------------------------------------------------------------
void RigidBody::Update(DX::StepTimer const& timer)
{
	float elapsedSeconds = (float)timer.GetElapsedSeconds();

	// Update the rotation and angular components
	m_angularVelocity += m_angularAcceleration * elapsedSeconds;
	m_parent->SetLocalRotation(m_angularVelocity * elapsedSeconds + m_parent->GetLocalRotation());

	// Update the position and linear components (it IS minus because of the screen coords
	m_linearVelocity += m_linearAcceleration * elapsedSeconds;
	m_parent->SetLocalPosition(m_parent->GetLocalPosition() - Vector2::Transform(m_linearVelocity, Matrix::CreateRotationZ(m_parent->GetLocalRotation())) * elapsedSeconds);
}
コード例 #22
0
// Called once per frame, rotates the cube and calculates the model and view matrices.
void Sample3DSceneRenderer::Update(DX::StepTimer const& timer)
{
	if (!m_tracking)
	{
		// Convert degrees to radians, then convert seconds to rotation angle
		float radiansPerSecond = XMConvertToRadians(m_degreesPerSecond);
		double totalRotation = timer.GetTotalSeconds() * radiansPerSecond;
		float radians = static_cast<float>(fmod(totalRotation, XM_2PI));

		Rotate(radians);
	}
}
コード例 #23
0
void PointLightRenderer::UpdateAmbientLight(const DX::StepTimer& gameTime)
{
	static float ambientIntensity = 0.0f;

	auto gamePadState = mGamePad->CurrentState();
	if (gamePadState.IsConnected())
	{
		if (mGamePad->IsButtonDown(GamePadButton::A) && ambientIntensity <= 1.0f)
		{
			ambientIntensity += static_cast<float>(gameTime.GetElapsedSeconds());
			ambientIntensity = min(ambientIntensity, 1.0f);

			mPixelCBufferPerFrameData.AmbientColor = XMFLOAT4(ambientIntensity, ambientIntensity, ambientIntensity, 1.0f);
		}

		if (mGamePad->IsButtonDown(GamePadButton::B) && ambientIntensity >= 0.0f)
		{
			ambientIntensity -= (float)gameTime.GetElapsedSeconds();
			ambientIntensity = max(ambientIntensity, 0.0f);

			mPixelCBufferPerFrameData.AmbientColor = XMFLOAT4(ambientIntensity, ambientIntensity, ambientIntensity, 1.0f);
		}
	}
}
コード例 #24
0
ファイル: Game.cpp プロジェクト: walbourn/directxtk12test
// Updates the world.
void Game::Update(DX::StepTimer const& timer)
{
    PIXBeginEvent(PIX_COLOR_DEFAULT, L"Update");

    float elapsedTime = float(timer.GetElapsedSeconds());
    elapsedTime;

    auto pad = m_gamePad->GetState(0);
    auto kb = m_keyboard->GetState();
    if (kb.Escape || (pad.IsConnected() && pad.IsViewPressed()))
    {
        ExitGame();
    }

    PIXEndEvent();
}
コード例 #25
0
// Called once per frame, rotates the cube and calculates the model and view matrices.
void Sample3DSceneRenderer::Update(DX::StepTimer const& timer)
{
	if (m_loadingComplete)
	{
		if (!m_tracking)
		{
			// Rotate the cube a small amount.
			m_angle += static_cast<float>(timer.GetElapsedSeconds()) * m_radiansPerSecond;

			Rotate(m_angle);
		}

		// Update the constant buffer resource.
		UINT8* destination = m_mappedConstantBuffer + (m_deviceResources->GetCurrentFrameIndex() * c_alignedConstantBufferSize);
		memcpy(destination, &m_constantBufferData, sizeof(m_constantBufferData));
	}
}
コード例 #26
0
// Called once per frame. Rotates the cube, and calculates and sets the model matrix
// relative to the position transform indicated by hologramPositionTransform.
void SpinningCubeRenderer::Update(DX::StepTimer const& timer)
{
    // Rotate the cube.
    // Convert degrees to radians, then convert seconds to rotation angle.
    const float    radiansPerSecond = XMConvertToRadians(m_degreesPerSecond);
    const double   totalRotation = timer.GetTotalSeconds() * radiansPerSecond;
    const float    radians = static_cast<float>(fmod(totalRotation, XM_2PI));
    const XMMATRIX modelRotation = XMMatrixRotationY(-radians);

    // Position the cube.
    const XMMATRIX modelTranslation = XMMatrixTranslationFromVector(XMLoadFloat3(&m_position));

    // Multiply to get the transform matrix.
    // Note that this transform does not enforce a particular coordinate system. The calling
    // class is responsible for rendering this content in a consistent manner.
    const XMMATRIX modelTransform = XMMatrixMultiply(modelRotation, modelTranslation);

    // The view and projection matrices are provided by the system; they are associated
    // with holographic cameras, and updated on a per-camera basis.
    // Here, we provide the model transform for the sample hologram. The model transform
    // matrix is transposed to prepare it for the shader.
    XMStoreFloat4x4(&m_modelConstantBufferData.model, XMMatrixTranspose(modelTransform));

    // Loading is asynchronous. Resources must be created before they can be updated.
    if (!m_loadingComplete)
    {
        return;
    }

    // Use the D3D device context to update Direct3D device-based resources.
    const auto context = m_deviceResources->GetD3DDeviceContext();

    // Update the model transform buffer for the hologram.
    context->UpdateSubresource(
        m_modelConstantBuffer.Get(),
        0,
        nullptr,
        &m_modelConstantBufferData,
        0,
        0
    );
}
コード例 #27
0
// 更新要显示的文本。
void SampleFpsTextRenderer::Update(DX::StepTimer const& timer)
{
	// 更新显示文本。
	uint32 fps = timer.GetFramesPerSecond();

	m_text = (fps > 0) ? std::to_wstring(fps) + L" FPS" : L" - FPS";

	DX::ThrowIfFailed(
		m_deviceResources->GetDWriteFactory()->CreateTextLayout(
			m_text.c_str(),
			(uint32) m_text.length(),
			m_textFormat.Get(),
			240.0f, // 输入文本的最大宽度。
			50.0f, // 输入文本的最大高度。
			&m_textLayout
			)
		);

	DX::ThrowIfFailed(
		m_textLayout->GetMetrics(&m_textMetrics)
		);
}
コード例 #28
0
// Called once per frame. Rotates the cube, and calculates and sets the model matrix
// relative to the position transform indicated by hologramPositionTransform.
void SpinningCubeRenderer::Update(DX::StepTimer const& timer)
{
    constexpr float degreesPerSecond = 45.f;
    constexpr float radiansPerSecond = XMConvertToRadians(degreesPerSecond);

    // Rotate the cube.
    const double yawRadiansDelta = timer.GetElapsedSeconds() * radiansPerSecond;
    m_orientation *= make_quaternion_from_yaw_pitch_roll((float)yawRadiansDelta, 0, 0);

    // Compute updated transform for model.
    const XMMATRIX modelRotation = XMMatrixRotationQuaternion(XMLoadQuaternion(&m_orientation));
    const XMMATRIX modelTranslation = XMMatrixTranslationFromVector(XMLoadFloat3(&m_position));
    const XMMATRIX modelScale = XMMatrixScaling(0.25f, 0.25f, 0.25f);

    // Multiply to get the transform matrix.
    // Note that this transform does not enforce a particular coordinate system. The calling
    // class is responsible for rendering this content in a consistent manner.
    const XMMATRIX modelTransform = XMMatrixMultiply(modelScale, XMMatrixMultiply(modelRotation, modelTranslation));

    // The view and projection matrices are provided by the system; they are associated
    // with holographic cameras, and updated on a per-camera basis.
    // Here, we provide the model transform for the sample hologram.
    m_cubeModel->GetNode(Pbr::RootNodeIndex).SetTransform(modelTransform);
}
コード例 #29
0
void PointLightRenderer::UpdatePointLight(const DX::StepTimer& gameTime)
{
 	static float pointLightIntensity = 1.0f;
	float elapsedTime = static_cast<float>(gameTime.GetElapsedSeconds());
 
	GamePad::State gamePadState = mGamePad->CurrentState();
	if (gamePadState.IsConnected())
	{
		// Update point light intensity		
		if (mGamePad->IsButtonDown(GamePadButton::X) && pointLightIntensity <= 1.0f)
		{
			pointLightIntensity += elapsedTime;
			pointLightIntensity = min(pointLightIntensity, 1.0f);

			mPixelCBufferPerFrameData.LightColor = XMFLOAT4(pointLightIntensity, pointLightIntensity, pointLightIntensity, 1.0f);
			mPointLight->SetColor(mPixelCBufferPerFrameData.LightColor);
		}
		if (mGamePad->IsButtonDown(GamePadButton::Y) && pointLightIntensity >= 0.0f)
		{
			pointLightIntensity -= elapsedTime;
			pointLightIntensity = max(pointLightIntensity, 0.0f);

			mPixelCBufferPerFrameData.LightColor = XMFLOAT4(pointLightIntensity, pointLightIntensity, pointLightIntensity, 1.0f);
			mPointLight->SetColor(mPixelCBufferPerFrameData.LightColor);
		}

		// Move point light
		XMFLOAT3 movementAmount = Vector3Helper::Zero;
		if (!bIsCameraControlled)
		{
			if (gamePadState.IsLeftThumbStickLeft())
			{
				movementAmount.x = -1.0f;
			}

			if (gamePadState.IsLeftThumbStickRight())
			{
				movementAmount.x = 1.0f;
			}

			if (gamePadState.IsLeftThumbStickUp())
			{
				movementAmount.y = 1.0f;
			}

			if (gamePadState.IsLeftThumbStickDown())
			{
				movementAmount.y = -1.0f;
			}

			if (gamePadState.IsRightThumbStickLeft())
			{
				movementAmount.z = -1.0f;
			}

			if (gamePadState.IsRightThumbStickRight())
			{
				movementAmount.z = 1.0f;
			}
		}
		XMVECTOR movement = XMLoadFloat3(&movementAmount) * LightMovementRate * elapsedTime;
		mPointLight->SetPosition(mPointLight->PositionVector() + movement);
		mProxyModel->SetPosition(mPointLight->Position());
		mVertexCBufferPerFrameData.LightPosition = mPointLight->Position();

		mPixelCBufferPerFrameData.LightPosition = mPointLight->Position();
	}

}
コード例 #30
0
ファイル: Game.cpp プロジェクト: walbourn/directxtk-samples
// Updates the world.
void Game::Update(DX::StepTimer const& timer)
{
    PIXBeginEvent(PIX_COLOR_DEFAULT, L"Update");

    Vector3 eye(0.0f, 0.7f, 1.5f);
    Vector3 at(0.0f, -0.1f, 0.0f);

    m_view = Matrix::CreateLookAt(eye, at, Vector3::UnitY);

    m_world = Matrix::CreateRotationY(float(timer.GetTotalSeconds() * XM_PIDIV4));

    m_lineEffect->SetView(m_view);
    m_lineEffect->SetWorld(Matrix::Identity);

    m_shapeEffect->SetView(m_view);

    m_audioTimerAcc -= (float)timer.GetElapsedSeconds();
    if (m_audioTimerAcc < 0)
    {
        if (m_retryDefault)
        {
            m_retryDefault = false;
            if (m_audEngine->Reset())
            {
                // Restart looping audio
                m_effect1->Play(true);
            }
        }
        else
        {
            m_audioTimerAcc = 4.f;

            m_waveBank->Play(m_audioEvent++);

            if (m_audioEvent >= 11)
                m_audioEvent = 0;
        }
    }

    auto pad = m_gamePad->GetState(0);
    if (pad.IsConnected())
    {
        m_gamePadButtons.Update(pad);

        if (pad.IsViewPressed())
        {
            PostQuitMessage(0);
        }
    }
    else
    {
        m_gamePadButtons.Reset();
    }

    auto kb = m_keyboard->GetState();
    m_keyboardButtons.Update(kb);

    if (kb.Escape)
    {
        PostQuitMessage(0);
    }

    auto mouse = m_mouse->GetState();
    mouse;

    PIXEndEvent();
}