本文整理汇总了C++中Waves::Update方法的典型用法代码示例。如果您正苦于以下问题:C++ Waves::Update方法的具体用法?C++ Waves::Update怎么用?C++ Waves::Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Waves
的用法示例。
在下文中一共展示了Waves::Update方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: UpdateScene
void LightDemo::UpdateScene(float dt)
{
DemoApp::UpdateScene(dt);
// Every quarter second, generate a random wave.
static float t_base = 0.0f;
if( (m_timer.TotalTime() - t_base) >= 0.25f )
{
t_base += 0.25f;
uint32 i = 5 + rand() % (m_waves.RowCount()-10);
uint32 j = 5 + rand() % (m_waves.ColumnCount()-10);
float r = MathHelper::RandF(1.0f, 2.0f);
m_waves.Disturb(i, j, r);
}
m_waves.Update(dt);
// Update the wave vertex buffer with the new solution.
D3D11_MAPPED_SUBRESOURCE mappedData;
HR(m_dxImmediateContext->Map(m_wavesVB.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedData));
Vertex* v = reinterpret_cast<Vertex*>(mappedData.pData);
for(UINT i = 0; i < m_waves.VertexCount(); ++i)
{
v[i].pos = m_waves[i];
v[i].normal = m_waves.Normal(i);
}
m_dxImmediateContext->Unmap(m_wavesVB.Get(), 0);
// Animate the lights.
// Circle light over the land surface.
m_pointLight.position.x = 70.0f*cosf( 0.2f*m_timer.TotalTime() );
m_pointLight.position.z = 70.0f*sinf( 0.2f*m_timer.TotalTime() );
m_pointLight.position.y = MathHelper::Max(GetHeight(m_pointLight.position.x,
m_pointLight.position.z), -3.0f) + 10.0f;
// The spotlight takes on the camera position and is aimed in the
// same direction the camera is looking. In this way, it looks
// like we are holding a flashlight.
m_spotLight.position = m_camPosition;
XMVECTOR pos = XMLoadFloat3(&m_camPosition);
XMVECTOR target = XMLoadFloat3(&m_camTarget);
XMStoreFloat3(&m_spotLight.direction, XMVector3Normalize(target - pos));
}
示例2: UpdateScene
void WavesApp::UpdateScene(float dt)
{
// Convert Spherical to Cartesian coordinates.
float x = m_fRadius * sinf(m_fPhi) * cosf(m_fTheta);
float z = m_fRadius * sinf(m_fPhi) * sinf(m_fTheta);
float y = m_fRadius*cosf(m_fPhi);
XMVECTOR pos = XMVectorSet(x, y, z, 1.0f);
XMVECTOR target = XMVectorZero();
XMVECTOR up = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
XMMATRIX V = XMMatrixLookAtLH(pos, target, up);
XMStoreFloat4x4(&m_viewMatrix, V);
//
// Every quarter second, generate a random wave.
//
static float s_baseT = 0.0f;
if ((mTimer.GetTotalTime() - s_baseT)>=0.25f)
{
s_baseT += 0.25f;
UINT i = 5 + rand() % 190;
UINT j = 5 + rand() % 190;
float r = MathHelper::RandF(1.0f, 2.0f);
m_waves.Disturb(i, j, r);//jingz 假设这个是生成浪花,数据变化时更新了什么内容呢?
}
m_waves.Update(dt);
//
// Update the wave vertex buffer with the new solution.
//
D3D11_MAPPED_SUBRESOURCE mappedData;
HR(m_pD3dImmediateContext->Map(m_pWavesVB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedData));
Vertex * vertices = reinterpret_cast<Vertex *>(mappedData.pData);
for (UINT i = 0; i < m_waves.GetVertexCount();++i)
{
vertices[i].Pos = m_waves[i];
vertices[i].Color = XMFLOAT4(0.0f, 0.0f, 0.0f, 1.0f);
}
m_pD3dImmediateContext->Unmap(m_pWavesVB,0);
}
示例3: UpdateScene
void BlendApp::UpdateScene(float dt)
{
// Convert Spherical to Cartesian coordinates.
float x = mRadius*sinf(mPhi)*cosf(mTheta);
float z = mRadius*sinf(mPhi)*sinf(mTheta);
float y = mRadius*cosf(mPhi);
mEyePosW = XMFLOAT3(x, y, z);
// Build the view matrix.
XMVECTOR pos = XMVectorSet(x, y, z, 1.0f);
XMVECTOR target = XMVectorZero();
XMVECTOR up = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
XMMATRIX V = XMMatrixLookAtLH(pos, target, up);
XMStoreFloat4x4(&mView, V);
//
// Every quarter second, generate a random wave.
//
static float t_base = 0.0f;
if( (mTimer.TotalTime() - t_base) >= 0.1f )
{
t_base += 0.1f;
DWORD i = 5 + rand() % (mWaves.RowCount()-10);
DWORD j = 5 + rand() % (mWaves.ColumnCount()-10);
float r = MathHelper::RandF(0.5f, 1.0f);
mWaves.Disturb(i, j, r);
}
mWaves.Update(dt);
//
// Update the wave vertex buffer with the new solution.
//
D3D11_MAPPED_SUBRESOURCE mappedData;
HR(md3dImmediateContext->Map(mWavesVB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedData));
Vertex* v = reinterpret_cast<Vertex*>(mappedData.pData);
for(UINT i = 0; i < mWaves.VertexCount(); ++i)
{
v[i].Pos = mWaves[i];
v[i].Normal = mWaves.Normal(i);
// Derive tex-coords in [0,1] from position.
v[i].Tex.x = 0.5f + mWaves[i].x / mWaves.Width();
v[i].Tex.y = 0.5f - mWaves[i].z / mWaves.Depth();
}
md3dImmediateContext->Unmap(mWavesVB, 0);
//
// Animate water texture coordinates.
//
// Tile water texture.
XMMATRIX wavesScale = XMMatrixScaling(5.0f, 5.0f, 0.0f);
// Translate texture over time.
mWaterTexOffset.y += 0.05f*dt;
mWaterTexOffset.x += 0.1f*dt;
XMMATRIX wavesOffset = XMMatrixTranslation(mWaterTexOffset.x, mWaterTexOffset.y, 0.0f);
// Combine scale and translation.
XMStoreFloat4x4(&mWaterTexTransform, wavesScale*wavesOffset);
//
// Switch the render mode based in key input.
//
if( GetAsyncKeyState('1') & 0x8000 )
mRenderOptions = RenderOptions::Lighting;
if( GetAsyncKeyState('2') & 0x8000 )
mRenderOptions = RenderOptions::Textures;
if( GetAsyncKeyState('3') & 0x8000 )
mRenderOptions = RenderOptions::TexturesAndFog;
}
示例4: UpdateScene
void TreeBillboardApp::UpdateScene(float dt)
{
DemoApp::UpdateScene(dt);
// Every quarter second, generate a random wave.
static float t_base = 0.0f;
if( (m_timer.TotalTime() - t_base) >= 0.1f )
{
t_base += 0.1f;
uint32 i = 5 + rand() % (m_waves.RowCount()-10);
uint32 j = 5 + rand() % (m_waves.ColumnCount()-10);
float r = MathHelper::RandF(0.5f, 1.0f);
m_waves.Disturb(i, j, r);
}
m_waves.Update(dt);
// Update the wave vertex buffer with the new solution.
D3D11_MAPPED_SUBRESOURCE mappedData;
HR(m_dxImmediateContext->Map(m_wavesVB.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedData));
Vertex::Basic32* v = reinterpret_cast<Vertex::Basic32*>(mappedData.pData);
for(UINT i = 0; i < m_waves.VertexCount(); ++i)
{
v[i].Pos = m_waves[i];
v[i].Normal = m_waves.Normal(i);
// Derive tex-coords in [0,1] from position.
v[i].Tex.x = 0.5f + m_waves[i].x / m_waves.Width();
v[i].Tex.y = 0.5f - m_waves[i].z / m_waves.Depth();
}
m_dxImmediateContext->Unmap(m_wavesVB.Get(), 0);
// Animate water texture coordinates.
// Tile water texture.
XMMATRIX wavesScale = XMMatrixScaling(5.0f, 5.0f, 0.0f);
// Translate texture over time (this animate the texture)
m_waterTexOffset.y += 0.05f*dt;
m_waterTexOffset.x += 0.1f*dt;
XMMATRIX wavesOffset = XMMatrixTranslation(m_waterTexOffset.x, m_waterTexOffset.y, 0.0f);
// Combine scale and translation.
XMStoreFloat4x4(&m_waterTexTransform, wavesScale*wavesOffset);
// Switch the render mode based in key input.
if( GetAsyncKeyState('1') & 0x8000 )
m_renderOptions = RenderOptions::Lighting;
if( GetAsyncKeyState('2') & 0x8000 )
m_renderOptions = RenderOptions::Textures;
if( GetAsyncKeyState('3') & 0x8000 )
m_renderOptions = RenderOptions::TexturesAndFog;
if( GetAsyncKeyState('R') & 0x8000 )
m_alphaToCoverageOn = true;
if( GetAsyncKeyState('T') & 0x8000 )
m_alphaToCoverageOn = false;
}
示例5: UpdateScene
void LightingApp::UpdateScene(float dt)
{
// Convert Spherical to Cartesian coordinates.
float x = mRadius*sinf(mPhi)*cosf(mTheta);
float z = mRadius*sinf(mPhi)*sinf(mTheta);
float y = mRadius*cosf(mPhi);
mEyePosW = XMFLOAT3(x, y, z);
// Build the view matrix.
XMVECTOR pos = XMVectorSet(x, y, z, 1.0f);
XMVECTOR target = XMVectorZero();
XMVECTOR up = XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f);
XMMATRIX V = XMMatrixLookAtLH(pos, target, up);
XMStoreFloat4x4(&mView, V);
//
// Every quarter second, generate a random wave.
//
static float t_base = 0.0f;
if( (mTimer.TotalTime() - t_base) >= 0.25f )
{
t_base += 0.25f;
DWORD i = 5 + rand() % (mWaves.RowCount()-10);
DWORD j = 5 + rand() % (mWaves.ColumnCount()-10);
float r = MathHelper::RandF(1.0f, 2.0f);
mWaves.Disturb(i, j, r);
}
mWaves.Update(dt);
//
// Update the wave vertex buffer with the new solution.
//
D3D11_MAPPED_SUBRESOURCE mappedData;
HR(md3dImmediateContext->Map(mWavesVB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedData));
Vertex* v = reinterpret_cast<Vertex*>(mappedData.pData);
for(UINT i = 0; i < mWaves.VertexCount(); ++i)
{
v[i].Pos = mWaves[i];
v[i].Normal = mWaves.Normal(i);
}
md3dImmediateContext->Unmap(mWavesVB, 0);
//
// Animate the lights.
//
// Circle light over the land surface.
mPointLight.Position.x = 70.0f*cosf( 0.2f*mTimer.TotalTime() );
mPointLight.Position.z = 70.0f*sinf( 0.2f*mTimer.TotalTime() );
mPointLight.Position.y = MathHelper::Max(GetHillHeight(mPointLight.Position.x,
mPointLight.Position.z), -3.0f) + 10.0f;
// The spotlight takes on the camera position and is aimed in the
// same direction the camera is looking. In this way, it looks
// like we are holding a flashlight.
mSpotLight.Position = mEyePosW;
XMStoreFloat3(&mSpotLight.Direction, XMVector3Normalize(target - pos));
}