?? snow.cpp
字號:
//////////////////////////////////////////////////////////////////////////////////////////////////
//
// File: snow.cpp
//
// Author: Frank Luna (C) All Rights Reserved
//
// System: AMD Athlon 1800+ XP, 512 DDR, Geforce 3, Windows XP, MSVC++ 7.0
//
// Desc: Demonstrates the PSystem::Snow system.
//
//////////////////////////////////////////////////////////////////////////////////////////////////
#include "d3dUtility.h"
#include "psystem.h"
#include "camera.h"
#include <cstdlib>
#include <ctime>
//
// Globals
//
IDirect3DDevice9* Device = 0;
const int Width = 640;
const int Height = 480;
psys::PSystem* Sno = 0;
Camera TheCamera(Camera::AIRCRAFT);
//
// Framework Functions
//
bool Setup()
{
// seed random number generator
srand((unsigned int)time(0));
//
// Create Snow System.
//
d3d::BoundingBox boundingBox;
boundingBox._min = D3DXVECTOR3(-10.0f, -10.0f, -10.0f);
boundingBox._max = D3DXVECTOR3( 10.0f, 10.0f, 10.0f);
Sno = new psys::Snow(&boundingBox, 5000);
Sno->init(Device, "snowflake.dds");
//
// Create basic scene.
//
d3d::DrawBasicScene(Device, 1.0f);
//
// Set projection matrix.
//
D3DXMATRIX proj;
D3DXMatrixPerspectiveFovLH(
&proj,
D3DX_PI / 4.0f, // 45 - degree
(float)Width / (float)Height,
1.0f,
5000.0f);
Device->SetTransform(D3DTS_PROJECTION, &proj);
return true;
}
void Cleanup()
{
d3d::Delete<psys::PSystem*>( Sno );
d3d::DrawBasicScene(0, 1.0f);
}
bool Display(float timeDelta)
{
if( Device )
{
//
// Update the scene:
//
if( ::GetAsyncKeyState(VK_UP) & 0x8000f )
TheCamera.walk(4.0f * timeDelta);
if( ::GetAsyncKeyState(VK_DOWN) & 0x8000f )
TheCamera.walk(-4.0f * timeDelta);
if( ::GetAsyncKeyState(VK_LEFT) & 0x8000f )
TheCamera.yaw(-1.0f * timeDelta);
if( ::GetAsyncKeyState(VK_RIGHT) & 0x8000f )
TheCamera.yaw(1.0f * timeDelta);
if( ::GetAsyncKeyState('N') & 0x8000f )
TheCamera.strafe(-4.0f * timeDelta);
if( ::GetAsyncKeyState('M') & 0x8000f )
TheCamera.strafe(4.0f * timeDelta);
if( ::GetAsyncKeyState('W') & 0x8000f )
TheCamera.pitch(1.0f * timeDelta);
if( ::GetAsyncKeyState('S') & 0x8000f )
TheCamera.pitch(-1.0f * timeDelta);
D3DXMATRIX V;
TheCamera.getViewMatrix(&V);
Device->SetTransform(D3DTS_VIEW, &V);
Sno->update(timeDelta);
//
// Draw the scene:
//
Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);
Device->BeginScene();
D3DXMATRIX I;
D3DXMatrixIdentity(&I);
Device->SetTransform(D3DTS_WORLD, &I);
d3d::DrawBasicScene(Device, 1.0f);
// order important, render snow last.
Device->SetTransform(D3DTS_WORLD, &I);
Sno->render();
Device->EndScene();
Device->Present(0, 0, 0, 0);
}
return true;
}
//
// WndProc
//
LRESULT CALLBACK d3d::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch( msg )
{
case WM_DESTROY:
::PostQuitMessage(0);
break;
case WM_KEYDOWN:
if( wParam == VK_ESCAPE )
::DestroyWindow(hwnd);
break;
}
return ::DefWindowProc(hwnd, msg, wParam, lParam);
}
//
// WinMain
//
int WINAPI WinMain(HINSTANCE hinstance,
HINSTANCE prevInstance,
PSTR cmdLine,
int showCmd)
{
if(!d3d::InitD3D(hinstance,
Width, Height, true, D3DDEVTYPE_HAL, &Device))
{
::MessageBox(0, "InitD3D() - FAILED", 0, 0);
return 0;
}
if(!Setup())
{
::MessageBox(0, "Setup() - FAILED", 0, 0);
return 0;
}
d3d::EnterMsgLoop( Display );
Cleanup();
Device->Release();
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -