本文整理汇总了C++中CFirstPersonCamera类的典型用法代码示例。如果您正苦于以下问题:C++ CFirstPersonCamera类的具体用法?C++ CFirstPersonCamera怎么用?C++ CFirstPersonCamera使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CFirstPersonCamera类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: renderSprites
// Render the given sprites. They must already be sorted into back-to-front order.
void SpriteRenderer::renderSprites(ID3D11DeviceContext* context, const std::vector<SpriteVertex>& sprites, const CFirstPersonCamera& camera) {
HRESULT hr;
if (sprites.size() > 1) {
std::cout;
}
D3D11_BOX box;
box.left = 0; box.right = sprites.size() * sizeof(SpriteVertex);
box.top = 0; box.bottom = 1; box.front = 0; box.back = 1;
context->UpdateSubresource(m_pVertexBuffer, 0, &box, sprites.data(), 0, 0);
// Bind the vertex buffer to the input assembler stage
unsigned int strides[] = { sizeof(SpriteVertex), }, offsets[] = { 0, };
context->IASetVertexBuffers(0, 1, &m_pVertexBuffer, strides, offsets);
// Set the Input Layout
context->IASetInputLayout(m_pInputLayout);
context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
// Load variables to shader
SAFE_GET_MATRIX(m_pEffect, "g_ViewProjection", g_ViewProjection);
SAFE_GET_VECTOR(m_pEffect, "g_CamRVec", camRightVec);
SAFE_GET_VECTOR(m_pEffect, "g_CamUVec", camUpVec);
SAFE_GET_RESOURCE(m_pEffect, "g_SprTexGatling", sprTexGatling);
SAFE_GET_RESOURCE(m_pEffect, "g_SprTexPlasma", sprTexPlasma);
SAFE_GET_RESOURCE(m_pEffect, "g_SprTexBoom", sprTexBoom);
// Set view and projection transformations to get sprites to the right positions in world space
DirectX::XMMATRIX viewProj = camera.GetViewMatrix() * camera.GetProjMatrix();
V(g_ViewProjection->SetMatrix((float*)&viewProj));
// Set Textures
V(sprTexGatling->SetResource(m_spriteSRV[0]));
V(sprTexPlasma->SetResource(m_spriteSRV[1]));
V(sprTexBoom->SetResource(m_spriteSRV[2]));
// Get camera's right and up vector
V(camRightVec->SetFloatVector((float*)&camera.GetWorldRight()));
V(camUpVec->SetFloatVector((float*)&camera.GetWorldUp()));
// Apply the pass from the effect
V(m_pEffect->GetTechniqueByName("sRender")->GetPassByName("P0")->Apply(0, context));
// Draw
context->Draw(sprites.size(), 0);
}
示例2: OnFrameMove
//--------------------------------------------------------------------------------------
// Handle updates to the scene. This is called regardless of which D3D API is used
//--------------------------------------------------------------------------------------
void CALLBACK OnFrameMove( double fTime, FLOAT fElapsedTime, void* pUserContext )
{
UNREFERENCED_PARAMETER(pUserContext);
UNREFERENCED_PARAMETER(fTime);
// Update the camera's position based on user input
g_LightCamera.FrameMove( fElapsedTime );
g_ViewerCamera.FrameMove( fElapsedTime );
}
示例3: MouseProc
void CALLBACK MouseProc( bool bLeftButtonDown, bool bRightButtonDown, bool bMiddleButtonDown, bool bSideButton1Down,
bool bSideButton2Down, int nMouseWheelDelta, int xPos, int yPos, void* pUserContext )
{
bool bOldLeftButtonDown = g_bLeftButtonDown;
bool bOldRightButtonDown = g_bRightButtonDown;
bool bOldMiddleButtonDown = g_bMiddleButtonDown;
g_bLeftButtonDown = bLeftButtonDown;
g_bMiddleButtonDown = bMiddleButtonDown;
g_bRightButtonDown = bRightButtonDown;
//*
if( bOldLeftButtonDown && !g_bLeftButtonDown )
{
// Disable movement
g_Camera.SetEnablePositionMovement( false );
}
else if( !bOldLeftButtonDown && g_bLeftButtonDown )
{
// Enable movement
g_Camera.SetEnablePositionMovement( true );
}
else if( !bOldRightButtonDown && g_bRightButtonDown )
{
// Enable movement
g_Camera.SetEnablePositionMovement( false );
}
else if( !bOldMiddleButtonDown && g_bMiddleButtonDown )
{
// Enable movement
g_Camera.SetEnablePositionMovement( false );
}
// If no mouse button is down at all, enable camera movement.
if( !g_bLeftButtonDown && !g_bRightButtonDown && !g_bMiddleButtonDown )
g_Camera.SetEnablePositionMovement( true );
//*/
/*
if( bRightButtonDown )
{
float dx = (xPos - g_ptSourisPosition.x)/5.f;
float dy = (yPos - g_ptSourisPosition.y)/5.f;
g_ptSourisPosition.x = xPos;
g_ptSourisPosition.y = yPos;
//if ( g_bSourisDroite )
{
g_pCamera->m_fAngleH += -dx;
g_pCamera->m_fAngleV += dy;
}
}
//*/
}
示例4: InitApp
//--------------------------------------------------------------------------------------
// Initialize the app
//--------------------------------------------------------------------------------------
void InitApp()
{
#ifdef CONSOLE
std::cout << "InitApp" << std::endl;
#endif
g_SettingsDlg.Init( &g_DialogResourceManager );
g_HUD.Init( &g_DialogResourceManager );
g_SampleUI.Init( &g_DialogResourceManager );
g_HUD.SetCallback( OnGUIEvent ); int iY = 10;
g_HUD.AddButton( IDC_TOGGLEFULLSCREEN, L"Toggle full screen", 35, iY, 125, 22 );
g_HUD.AddButton( IDC_TOGGLEREF, L"Toggle REF (F3)", 35, iY += 24, 125, 22, VK_F3 );
g_HUD.AddButton( IDC_CHANGEDEVICE, L"Change device (F2)", 35, iY += 24, 125, 22, VK_F2 );
g_SampleUI.SetCallback( OnGUIEvent ); iY = 10;
g_Camera.SetRotateButtons( true, false, false );
//g_pCamera = new CGlobalCamera();
D3DVECTOR Vdir={0,-1,0};
memset(&g_light,0,sizeof(D3DLIGHT9));
g_light.Type = D3DLIGHT_DIRECTIONAL;
g_light.Diffuse.r = 1.0f;
g_light.Diffuse.g = 1.0f;
g_light.Diffuse.b = 1.0f;
g_light.Diffuse.a = 1.0f;
g_light.Direction = Vdir;
// Inits Particle Engine
}
示例5: OnFrameMove
void CALLBACK OnFrameMove( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
{
// Update the camera's position based on user input
g_Camera.FrameMove( fElapsedTime );
OnMyAppFrameMove( pd3dDevice, fTime, fElapsedTime, pUserContext );
}
示例6: MsgProc
//--------------------------------------------------------------------------------------
// Handle messages to the application
//--------------------------------------------------------------------------------------
LRESULT CALLBACK MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool* pbNoFurtherProcessing,
void* pUserContext )
{
UNREFERENCED_PARAMETER(pUserContext);
// Pass messages to dialog resource manager calls so GUI state is updated correctly
*pbNoFurtherProcessing = g_DialogResourceManager.MsgProc( hWnd, uMsg, wParam, lParam );
if( *pbNoFurtherProcessing )
return 0;
// Pass messages to settings dialog if its active
if( g_D3DSettingsDlg.IsActive() )
{
g_D3DSettingsDlg.MsgProc( hWnd, uMsg, wParam, lParam );
return 0;
}
// Give the dialogs a chance to handle the message first
*pbNoFurtherProcessing = g_HUD.MsgProc( hWnd, uMsg, wParam, lParam );
if( *pbNoFurtherProcessing )
return 0;
*pbNoFurtherProcessing = g_SampleUI.MsgProc( hWnd, uMsg, wParam, lParam );
if( *pbNoFurtherProcessing )
return 0;
// Pass all remaining windows messages to camera so it can respond to user input
g_ViewerCamera.HandleMessages( hWnd, uMsg, wParam, lParam );
return 0;
}
示例7: XMVectorGetByIndex
//--------------------------------------------------------------------------------------
// Create any D3D11 resources that depend on the back buffer
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnD3D11ResizedSwapChain( ID3D11Device* pd3dDevice, IDXGISwapChain* pSwapChain,
const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext )
{
UNREFERENCED_PARAMETER(pSwapChain);
UNREFERENCED_PARAMETER(pUserContext);
HRESULT hr;
XMVECTOR vMeshExtents = g_Scene.GetSceneAABBMax() - g_Scene.GetSceneAABBMin();
XMVECTOR vMeshLength = XMVector3Length( vMeshExtents );
FLOAT fMeshLength = XMVectorGetByIndex( vMeshLength, 0);
V_RETURN( g_DialogResourceManager.OnD3D11ResizedSwapChain( pd3dDevice, pBackBufferSurfaceDesc ) );
V_RETURN( g_D3DSettingsDlg.OnD3D11ResizedSwapChain( pd3dDevice, pBackBufferSurfaceDesc ) );
g_fAspectRatio = pBackBufferSurfaceDesc->Width / ( FLOAT ) pBackBufferSurfaceDesc->Height;
g_ViewerCamera.SetProjParams( XM_PI / 4, g_fAspectRatio, 0.05f, fMeshLength);
g_Scene.OnResize(pBackBufferSurfaceDesc->Width, pBackBufferSurfaceDesc->Height);
g_HUD.SetLocation( pBackBufferSurfaceDesc->Width - 170, 0 );
g_HUD.SetSize( 170, 170 );
g_SampleUI.SetLocation( pBackBufferSurfaceDesc->Width - 170, pBackBufferSurfaceDesc->Height - 300 );
g_SampleUI.SetSize( 170, 300 );
return S_OK;
}
示例8: UpdateViewerCameraNearFar
//--------------------------------------------------------------------------------------
// Calcaulte the camera based on size of the current scene
//--------------------------------------------------------------------------------------
void UpdateViewerCameraNearFar()
{
XMVECTOR vMeshExtents = g_CascadedShadow.GetSceneAABBMax() - g_CascadedShadow.GetSceneAABBMin();
XMVECTOR vMeshLength = XMVector3Length(vMeshExtents);
FLOAT fMeshLength = XMVectorGetByIndex(vMeshLength, 0);
g_ViewerCamera.SetProjParams(XM_PI / 4, g_fAspectRatio, 0.05f, fMeshLength);
}
示例9: DXUTTRACE
//--------------------------------------------------------------------------------------
// SwapChain has changed and may have new attributes such as size.
// Create any D3D11 resources that depend on the back buffer
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnD3D11ResizedSwapChain(ID3D11Device* pd3dDevice, IDXGISwapChain *pSwapChain, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext)
{
HRESULT hr;
DXUTTRACE(L"OnD3D11ResizedSwapChain called\n");
V_RETURN( g_DialogResourceManager.OnD3D11ResizedSwapChain(pd3dDevice, pBackBufferSurfaceDesc) );
V_RETURN( g_SettingsDlg.OnD3D11ResizedSwapChain(pd3dDevice, pBackBufferSurfaceDesc) );
g_BackBufferWidth = pBackBufferSurfaceDesc->Width;
g_BackBufferHeight = pBackBufferSurfaceDesc->Height;
g_FullViewport.TopLeftX = 0.f;
g_FullViewport.TopLeftY = 0.f;
g_FullViewport.MinDepth = 0.f;
g_FullViewport.MaxDepth = 1.f;
g_FullViewport.Width = (FLOAT)g_BackBufferWidth;
g_FullViewport.Height = (FLOAT)g_BackBufferHeight;
// Setup the camera's projection parameters
float AspectRatio = (float)g_BackBufferWidth / (float)g_BackBufferHeight;
g_OrbitalCamera.SetProjParams (FOVY, AspectRatio, ZNEAR, ZFAR);
g_OrbitalCamera.SetWindow (g_BackBufferWidth, g_BackBufferHeight);
g_OrbitalCamera.SetButtonMasks(MOUSE_LEFT_BUTTON, MOUSE_WHEEL, 0);
g_FirstPersonCamera.SetProjParams (FOVY, AspectRatio, ZNEAR, ZFAR);
g_FirstPersonCamera.SetRotateButtons( 1, 1, 1 );
UINT HudWidth = 256;
float HudOpacity = 0.32f;
g_HUD.SetLocation(g_BackBufferWidth - HudWidth, 0);
g_HUD.SetSize (HudWidth, g_BackBufferHeight);
g_HUD.SetBackgroundColors(D3DCOLOR_COLORVALUE(0,0,0,HudOpacity));
// Allocate our own screen-sized buffers, as the SwapChain only contains a non-MSAA color buffer.
ResizeScreenSizedBuffers(pd3dDevice);
return hr;
}
示例10: vecEye
//--------------------------------------------------------------------------------------
// Create any D3D11 resources that aren't dependant on the back buffer
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnD3D11CreateDevice(ID3D11Device* pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext)
{
HRESULT hr;
DXUTTRACE(L"OnD3D11CreateDevice called\n");
SetCursor(LoadCursor(0, IDC_ARROW));
ID3D11DeviceContext* pd3dImmediateContext = DXUTGetD3D11DeviceContext(); // does not addref
V_RETURN( g_DialogResourceManager.OnD3D11CreateDevice(pd3dDevice, pd3dImmediateContext) );
V_RETURN( g_SettingsDlg.OnD3D11CreateDevice(pd3dDevice) );
g_pTxtHelper = new CDXUTTextHelper(pd3dDevice, pd3dImmediateContext, &g_DialogResourceManager, g_TextLineHeight);
// Setup orbital camera
D3DXVECTOR3 vecEye(0.0f, 2.0f, 0.0f);
D3DXVECTOR3 vecAt (0.0f, 0.0f, 0.0f);
g_OrbitalCamera.SetViewParams(&vecEye, &vecAt);
g_OrbitalCamera.SetRadius(1.5f, 0.01f);
// Setup first-person camera
D3DXVECTOR3 sibenikVecEye(0.0960150138f, 0.0273544509f, -0.0185411610f);
D3DXVECTOR3 sibenikVecAt (-0.623801112f, -0.649074197f, -0.174454257f);
g_FirstPersonCamera.SetViewParams(&sibenikVecEye, &sibenikVecAt);
g_FirstPersonCamera.SetEnablePositionMovement(1);
g_FirstPersonCamera.SetScalers(0.001f, 0.05f);
// Load Scene3D.fx
g_pSceneRenderer.OnCreateDevice(pd3dDevice);
// Load meshes and bin files
LoadScenes(pd3dDevice);
GFSDK_SSAO_Status status;
status = g_AORenderer.Create(pd3dDevice);
assert(status == GFSDK_SSAO_OK);
return S_OK;
}
示例11: OnFrameMove
//--------------------------------------------------------------------------------------
// Handle updates to the scene. This is called regardless of which D3D API is used
//--------------------------------------------------------------------------------------
void CALLBACK OnFrameMove(double fTime, float fElapsedTime, void* pUserContext)
{
SceneMesh *pSceneMesh = g_Scenes[g_CurrentSceneId].pMesh;
g_UseOrbitalCamera = pSceneMesh && pSceneMesh->UseOrbitalCamera();
if (g_UseOrbitalCamera)
{
g_OrbitalCamera.FrameMove(fElapsedTime);
}
else
{
g_FirstPersonCamera.FrameMove(fElapsedTime);
}
}
示例12: InitApp
//--------------------------------------------------------------------------------------
// Initialize the app
//--------------------------------------------------------------------------------------
void InitApp()
{
// Initialize dialogs
g_D3DSettingsDlg.Init( &g_DialogResourceManager );
g_HUD.Init( &g_DialogResourceManager );
g_SampleUI.Init( &g_DialogResourceManager );
g_HUD.SetCallback( OnGUIEvent ); int iY = 20;
g_HUD.AddButton( IDC_TOGGLEFULLSCREEN, L"Toggle full screen", 0, iY, 170, 22 );
g_HUD.AddButton( IDC_TOGGLEREF, L"Toggle REF (F3)", 0, iY += 26, 170, 22, VK_F3 );
g_HUD.AddButton( IDC_CHANGEDEVICE, L"Change device (F2)", 0, iY += 26, 170, 22, VK_F2 );
g_SampleUI.SetCallback( OnGUIEvent ); iY = 10;
WCHAR sz[100];
iY += 24;
swprintf_s( sz, L"Patch Divisions: %2.1f", g_fSubdivs );
g_SampleUI.AddStatic( IDC_PATCH_SUBDIVS_STATIC, sz, 10, iY += 26, 150, 22 );
g_SampleUI.AddSlider( IDC_PATCH_SUBDIVS, 10, iY += 24, 150, 22, 10 * MIN_DIVS, 10 * MAX_DIVS, (int)(g_fSubdivs * 10) );
iY += 24;
g_SampleUI.AddCheckBox( IDC_TOGGLE_LINES, L"Toggle Wires", 20, iY += 26, 150, 22, g_bDrawWires );
iY += 24;
g_SampleUI.AddRadioButton( IDC_PARTITION_INTEGER, IDC_PARTITION_MODE, L"Integer", 20, iY += 26, 170, 22 );
g_SampleUI.AddRadioButton( IDC_PARTITION_FRAC_EVEN, IDC_PARTITION_MODE, L"Fractional Even", 20, iY += 26, 170, 22 );
g_SampleUI.AddRadioButton( IDC_PARTITION_FRAC_ODD, IDC_PARTITION_MODE, L"Fractional Odd", 20, iY += 26, 170, 22 );
g_SampleUI.GetRadioButton( IDC_PARTITION_INTEGER )->SetChecked( true );
// Setup the camera's view parameters
static const XMVECTORF32 s_vecEye = { 5.0f, 3.0f, -10.0f, 0.f };
static const XMVECTORF32 s_vecAt = { 5.0f, 0.0f, 0.0f, 0.f };
g_Camera.SetViewParams( s_vecEye, s_vecAt );
g_Camera.SetEnablePositionMovement(true);
g_Camera.SetEnableYAxisMovement(true);
}
示例13: MouseProc
//--------------------------------------------------------------------------------------
// Handle mouse buttons
//--------------------------------------------------------------------------------------
void CALLBACK MouseProc( bool bLeftButtonDown, bool bRightButtonDown,
bool bMiddleButtonDown, bool bSideButton1Down,
bool bSideButton2Down, int nMouseWheelDelta,
int xPos, int yPos, void* pUserContext )
{
bool bOldLeftButtonDown = g_bLeftButtonDown;
bool bOldRightButtonDown = g_bRightButtonDown;
bool bOldMiddleButtonDown = g_bMiddleButtonDown;
g_bLeftButtonDown = bLeftButtonDown;
g_bMiddleButtonDown = bMiddleButtonDown;
g_bRightButtonDown = bRightButtonDown;
if( bOldLeftButtonDown && !g_bLeftButtonDown )
g_Camera.SetEnablePositionMovement( false );
else if( !bOldLeftButtonDown && g_bLeftButtonDown )
g_Camera.SetEnablePositionMovement( true );
if( !bOldRightButtonDown && g_bRightButtonDown )
{
g_Camera.SetEnablePositionMovement( false );
}
if( bOldMiddleButtonDown && !g_bMiddleButtonDown )
{
g_LCamera.SetEnablePositionMovement( false );
}
else if( !bOldMiddleButtonDown && g_bMiddleButtonDown )
{
g_LCamera.SetEnablePositionMovement( true );
g_Camera.SetEnablePositionMovement( false );
}
// If no mouse button is down at all, enable camera movement.
if( !g_bLeftButtonDown && !g_bRightButtonDown && !g_bMiddleButtonDown )
g_Camera.SetEnablePositionMovement( true );
}
示例14: OnFrameMove
//--------------------------------------------------------------------------------------
// Handle updates to the scene. This is called regardless of which D3D API is used
//--------------------------------------------------------------------------------------
void CALLBACK OnFrameMove( double fTime, float fElapsedTime, void* pUserContext )
{
// g_fElapsedTime = fElapsedTime;
// Update the camera's position based on user input
g_Camera.FrameMove( fElapsedTime );
//g_pCamera->Move();
// Updates particle system
particleSystem.update( fElapsedTime );
// Changes the color of the model over time
step += fElapsedTime * 0.5f;
particleModel->setParam(PARAM_RED,0.6f + 0.4f * sin(step));
particleModel->setParam(PARAM_GREEN,0.6f + 0.4f * sin(step + D3DX_PI * 2.0f / 3.0f));
particleModel->setParam(PARAM_BLUE,0.6f + 0.4f * sin(step + D3DX_PI * 4.0f / 3.0f));
}
示例15:
//--------------------------------------------------------------------------------------
// Create any D3D11 resources that depend on the back buffer
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnD3D11ResizedSwapChain( ID3D11Device* pd3dDevice, IDXGISwapChain* pSwapChain,
const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext )
{
HRESULT hr;
V_RETURN( g_DialogResourceManager.OnD3D11ResizedSwapChain( pd3dDevice, pBackBufferSurfaceDesc ) );
V_RETURN( g_D3DSettingsDlg.OnD3D11ResizedSwapChain( pd3dDevice, pBackBufferSurfaceDesc ) );
// Setup the camera's projection parameters
float fAspectRatio = pBackBufferSurfaceDesc->Width / ( FLOAT )pBackBufferSurfaceDesc->Height;
g_Camera.SetProjParams( D3DX_PI / 4, fAspectRatio, 2.0f, 4000.0f );
// g_Camera.SetWindow( pBackBufferSurfaceDesc->Width, pBackBufferSurfaceDesc->Height );
// g_Camera.SetButtonMasks( MOUSE_MIDDLE_BUTTON, MOUSE_WHEEL, MOUSE_LEFT_BUTTON );
D3DXVECTOR3 vMin = D3DXVECTOR3( -1000.0f, -1000.0f, -1000.0f );
D3DXVECTOR3 vMax = D3DXVECTOR3( 1000.0f, 1000.0f, 1000.0f );
g_Camera.SetRotateButtons(TRUE, FALSE, FALSE);
g_Camera.SetScalers( 0.01f, 30.0f );
g_Camera.SetDrag( true );
g_Camera.SetEnableYAxisMovement( true );
g_Camera.SetClipToBoundary( TRUE, &vMin, &vMax );
g_Camera.FrameMove( 0 );
g_HUD.SetLocation( pBackBufferSurfaceDesc->Width - 170, 0 );
g_HUD.SetSize( 170, 170 );
g_SampleUI.SetLocation( pBackBufferSurfaceDesc->Width - 170, pBackBufferSurfaceDesc->Height - 300 );
g_SampleUI.SetSize( 170, 300 );
//Turn off backface culling
D3D11_RASTERIZER_DESC rsDesc;
ZeroMemory(&rsDesc,sizeof(D3D11_RASTERIZER_DESC) );
rsDesc.CullMode = D3D11_CULL_NONE;
rsDesc.FillMode = D3D11_FILL_SOLID;
//rsDesc.FillMode = D3D11_FILL_WIREFRAME;
ID3D11RasterizerState *pRasterizerState = NULL;
pd3dDevice->CreateRasterizerState(&rsDesc, &pRasterizerState);
DXUTGetD3D11DeviceContext()->RSSetState(pRasterizerState);
SAFE_RELEASE(pRasterizerState);
return S_OK;
}