📄 scene1.cpp
字号:
#include "stdafx.h"
#include "scene1.h"
IDirect3DTexture9* Texture_Splash;
extern HMODULE resDll;
bool LoadScene1()
{/*
if (FAILED(D3DXCreateTextureFromFile(
Device,
TEXT("maze.png"),
&Texture_Splash)))
{
ERMSG("D3DXCreateTexture -- FAILED");
return false;
}
*/
if (FAILED(D3DXCreateTextureFromResource(
Device,
resDll,
MAKEINTRESOURCE(101),
&Texture_Splash)))
{
ERMSG("D3DXCreateTextureFromResource(101) - FAILED");
return false;
}
return true;
}
void CleanScene1()
{
d3d::Release(Texture_Splash);
}
bool Scene1(float timeDelta)
{
if( Device )
{
//
// Update: Update the camera.
//
/*
if( ::GetAsyncKeyState('W') & 0x8000f )
TheCamera.walk(4.0f * timeDelta);
if( ::GetAsyncKeyState('S') & 0x8000f )
TheCamera.walk(-4.0f * timeDelta);
if( ::GetAsyncKeyState('A') & 0x8000f )
TheCamera.strafe(-4.0f * timeDelta);
if( ::GetAsyncKeyState('D') & 0x8000f )
TheCamera.strafe(4.0f * timeDelta);
if( ::GetAsyncKeyState('R') & 0x8000f )
TheCamera.fly(4.0f * timeDelta);
if( ::GetAsyncKeyState('F') & 0x8000f )
TheCamera.fly(-4.0f * timeDelta);
if( ::GetAsyncKeyState(VK_UP) & 0x8000f )
TheCamera.pitch(1.0f * timeDelta);
if( ::GetAsyncKeyState(VK_DOWN) & 0x8000f )
TheCamera.pitch(-1.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.roll(1.0f * timeDelta);
if( ::GetAsyncKeyState('M') & 0x8000f )
TheCamera.roll(-1.0f * timeDelta);
TheCamera.getViewMatrix(&V);
Device->SetTransform(D3DTS_VIEW, &V);
*/
//
// Draw the scene:
//
Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0, 1.0f, 0);
Device->BeginScene();
IDirect3DVertexBuffer9 *SplashV = 0;
if (FAILED(Device->CreateVertexBuffer(
16*sizeof(VertexRHWTEX),
D3DUSAGE_WRITEONLY,
FVF_VERTEXRHWTEX,
D3DPOOL_MANAGED,
&SplashV,
0)))
{
ERMSG("Device->CreateVertexBuffer(SplashV) -- FAILED");
return false;
}
static float widthL1 = ScreenWidth/5.0f*3.0f, widthL2 = ScreenWidth/5.0f*2.0f;
static float widthR1 = ScreenWidth/5.0f*3.0f, widthR2 = ScreenWidth/5.0f*2.0f;
static float Left = 0.0f, Right = ScreenWidth;
static float y = 20 * timeDelta;
static float x = 0.0f;
static float z = 0.0f;
if (y < 0)
{
x += ScreenWidth * 0.1f + z;
z += 0.2f;
}
else
{
y -= timeDelta;
}
if (Left<= -ScreenWidth*0.4f)
{
PostMessage(GetActiveWindow(), UM_SCENE1_ENDED, 0, 0);
}
VertexRHWTEX* v;
SplashV->Lock(0, 16*sizeof(VertexRHWTEX), (void**)&v, 0);
v[0] = VertexRHWTEX(Left-=timeDelta*80.0f, ScreenHeight, 0.0f, 1.0f, 0.0f, 1.0f);
v[1] = VertexRHWTEX(Left-=timeDelta*80.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f);
v[2] = VertexRHWTEX(widthL1-=timeDelta*80.0f, 0.0f, 0.0f, 1.0f, 0.6f, 0.0f);
v[3] = VertexRHWTEX(widthL2-=timeDelta*80.0f, ScreenHeight*1.0f/5.0f, 0.0f, 1.0f, 0.4f, 1.0f/5.0f);
v[4] = VertexRHWTEX(widthL1-=timeDelta*80.0f, ScreenHeight*2.0f/5.0f, 0.0f, 1.0f, 0.6f, 2.0f/5.0f);
v[5] = VertexRHWTEX(widthL2-=timeDelta*80.0f, ScreenHeight*3.0f/5.0f, 0.0f, 1.0f, 0.4f, 3.0f/5.0f);
v[6] = VertexRHWTEX(widthL1-=timeDelta*80.0f, ScreenHeight*4.0f/5.0f, 0.0f, 1.0f, 0.6f, 4.0f/5.0f);
v[7] = VertexRHWTEX(widthL2-=timeDelta*80.0f, ScreenHeight*5.0f/5.0f, 0.0f, 1.0f, 0.4f, 5.0f/5.0f);
v[8] = VertexRHWTEX(Right+=timeDelta*80.0f, ScreenHeight, 0.0f, 1.0f, 1.0f, 1.0f);
v[9] = VertexRHWTEX(Right+=timeDelta*80.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f);
v[10] = VertexRHWTEX(widthR1+=timeDelta*80.0f, 0.0f, 0.0f, 1.0f, 0.6f, 0.0f);
v[11] = VertexRHWTEX(widthR2+=timeDelta*80.0f, ScreenHeight*1.0f/5.0f, 0.0f, 1.0f, 0.4f, 1.0f/5.0f);
v[12] = VertexRHWTEX(widthR1+=timeDelta*80.0f, ScreenHeight*2.0f/5.0f, 0.0f, 1.0f, 0.6f, 2.0f/5.0f);
v[13] = VertexRHWTEX(widthR2+=timeDelta*80.0f, ScreenHeight*3.0f/5.0f, 0.0f, 1.0f, 0.4f, 3.0f/5.0f);
v[14] = VertexRHWTEX(widthR1+=timeDelta*80.0f, ScreenHeight*4.0f/5.0f, 0.0f, 1.0f, 0.6f, 4.0f/5.0f);
v[15] = VertexRHWTEX(widthR2+=timeDelta*80.0f, ScreenHeight*5.0f/5.0f, 0.0f, 1.0f, 0.4f, 5.0f/5.0f);
SplashV->Unlock();
IDirect3DIndexBuffer9 *SplashI = 0;
if (FAILED(Device->CreateIndexBuffer(
36*sizeof(WORD),
D3DUSAGE_WRITEONLY,
D3DFMT_INDEX16,
D3DPOOL_MANAGED,
&SplashI,
0)))
{
ERMSG("Device->CreateVertexBuffer(SpalshI) -- FAILED");
return false;
}
WORD *i;
SplashI->Lock(0, 36*sizeof(WORD), (void**)&i, 0);
// 左边
i[0] = 3; i[1] = 1; i[2] = 2;
i[3] = 4; i[4] = 1; i[5] = 3;
i[6] = 5; i[7] = 1; i[8] = 4;
i[9] = 6; i[10] = 1; i[11] = 5;
i[12] = 7; i[13] = 1; i[14] = 6;
i[15] = 0; i[16] = 1; i[17] = 7;
// 右边
i[18] = 9; i[19] = 11; i[20] = 10;
i[21] = 9; i[22] = 12; i[23] = 11;
i[24] = 9; i[25] = 13; i[26] = 12;
i[27] = 9; i[28] = 14; i[29] = 13;
i[30] = 9; i[31] = 15; i[32] = 14;
i[33] = 9; i[34] = 8; i[35] = 15;
SplashI->Unlock();
Device->SetTexture(0, Texture_Splash);
Device->SetStreamSource(0, SplashV, 0, sizeof(VertexRHWTEX));
Device->SetIndices(SplashI);
Device->SetFVF(FVF_VERTEXRHWTEX);
Device->DrawIndexedPrimitive(
D3DPT_TRIANGLELIST,
0,
0,
16,
0,
12);
Device->EndScene();
Device->Present(0, 0, 0, 0);
SplashV->Release();
SplashI->Release();
}
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -