/*
#############################################################################
Ch12p1_SimpleWater.cpp: a program that demonstrates the water algorithm,
without any annoying bells and/or whistles.
#############################################################################
*/
// include files ////////////////////////////////////////////////////////////
#define STRICT
#include <stdio.h>
#include <math.h>
#include <D3DX8.h>
#include "D3DApp.h"
#include "D3DFile.h"
#include "D3DFont.h"
#include "D3DUtil.h"
#include "DXUtil.h"
#include "D3DHelperFuncs.h"
#include "Ch12p1_resource.h"
#include "CommonFuncs.h"
// A structure for our custom vertex type.
struct CUSTOMVERTEX
{
D3DXVECTOR3 position; // The position
D3DCOLOR color; // The color
FLOAT tu, tv; // The texture coordinates
};
const int TEXTURESIZE = 256; // size of the fire texture
// Our custom FVF, which describes our custom vertex structure
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1)
//-----------------------------------------------------------------------------
// Name: class CMyD3DApplication
// Desc: Application class. The base class (CD3DApplication) provides the
// generic functionality needed in all Direct3D samples. CMyD3DApplication
// adds functionality specific to this sample program.
//-----------------------------------------------------------------------------
class CMyD3DApplication : public CD3DApplication
{
// Font for drawing text
CD3DFont* m_pFont;
CD3DFont* m_pFontSmall;
// Scene
LPDIRECT3DVERTEXBUFFER8 m_pVB;
DWORD m_dwNumVertices;
// Texture
LPDIRECT3DTEXTURE8 m_pImageTex; // this texture will go "underwater"...
LPDIRECT3DTEXTURE8 m_pWaterTex; // ... and will appear on this texture.
// Texture Palette
char m_strTextureSurfFormat[256];
int m_iWaterField[TEXTURESIZE*TEXTURESIZE]; // first water array
int m_iWaterField2[TEXTURESIZE*TEXTURESIZE]; // second water array
int *m_pWaterActive; // we use these two pointers to flip
int *m_pWaterScratch; // the active water array back and forth.
char m_lutDisplacement[512]; // displacement lookup table (to optimize calculations)
protected:
HRESULT OneTimeSceneInit();
HRESULT InitDeviceObjects();
HRESULT RestoreDeviceObjects();
HRESULT InvalidateDeviceObjects();
HRESULT DeleteDeviceObjects();
HRESULT FinalCleanup();
HRESULT Render();
HRESULT FrameMove();
HRESULT ConfirmDevice( D3DCAPS8* pCaps, DWORD dwBehavior, D3DFORMAT Format );
LRESULT MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
public:
CMyD3DApplication();
};
//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: Entry point to the program. Initializes everything, and goes into a
// message-processing loop. Idle time is used to render the scene.
//-----------------------------------------------------------------------------
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )
{
CMyD3DApplication d3dApp;
if( FAILED( d3dApp.Create( hInst ) ) )
return 0;
return d3dApp.Run();
}
//-----------------------------------------------------------------------------
// Name: CMyD3DApplication()
// Desc: Application constructor. Sets attributes for the app.
//-----------------------------------------------------------------------------
CMyD3DApplication::CMyD3DApplication()
{
m_strWindowTitle = _T("Ch12p1_SimpleWater");
m_bUseDepthBuffer = TRUE;
m_pFont = new CD3DFont( _T("Arial"), 12, D3DFONT_BOLD );
m_pFontSmall = new CD3DFont( _T("Arial"), 9, D3DFONT_BOLD );
m_pVB = NULL;
m_dwNumVertices = 6;
m_pImageTex = NULL;
m_pWaterTex = NULL;
}
/****************************************************************************
MakeDisplacementLookupTable: populates our m_cDisplacement map with valid
values based on a refraction index. The refraction index of water is 2.0.
****************************************************************************/
void MakeDisplacementLookupTable(char *pDisplacement, int iArraySize,
float fRefractionIndex,
float fDepth)
{
for (int i=-iArraySize/2; i < (iArraySize/2)-1; i++) {
float heightdiff = i*fDepth;
// the angle is the arctan of the height difference
float angle = (float)atan(heightdiff);
// now, calculate the angle of the refracted beam.
float beamangle = (float)asin(sin(angle) / fRefractionIndex);
// finally, calculate the displacement, based on the refracted beam
// and the height difference.
pDisplacement[i+(iArraySize/2)] = (int)(tan(beamangle) * heightdiff);
}
}
/****************************************************************************
ProcessWater: this function processes our water. It takes two input buffers,
the water dimensions, and the cooling amount. It calculates the new water
values from waterfield1 and puts them into waterfield2.
****************************************************************************/
void ProcessWater(int *oldwater, int *newwater,
int iWaterWidth, int iWaterHeight, float fDampValue)
{
// loop through all the water values...
for (int y=0; y < iWaterHeight; y++) {
for (int x=0; x < iWaterWidth; x++) {
// add up the values of all the neighboring water values...
int value;
int xminus1 = x-1; if (xminus1 < 0) xminus1 = 0;
int xminus2 = x-2; if (xminus2 < 0) xminus2 = 0;
int yminus1 = y-1; if (yminus1 < 0) yminus1 = 0;
int yminus2 = y-2; if (yminus2 < 0) yminus2 = 0;
int xplus1 = x+1; if (xplus1 >= iWaterWidth) xplus1 = iWaterWidth-1;
int xplus2 = x+2; if (xplus2 >= iWaterWidth) xplus2 = iWaterWidth-1;
int yplus1 = y+1; if (yplus1 >= iWaterHeight) yplus1 = iWaterHeight-1;
int yplus2 = y+2; if (yplus2 >= iWaterHeight) yplus2 = iWaterHeight-1;
//////////////////////////
//
// Blending methods: uncomment one of these two methods.
//
//////////////////////////
// Method 1: Slower but yields slightly better looking water
{
/*
value = (float)oldwater[((y) *iWaterWidth)+xminus1];
value += (float)oldwater[((y) *iWaterWidth)+xminus2];
value += (float)oldwater[((y) *iWaterWidth)+xplus1];
value += (float)oldwater[((y) *iWaterWidth)+xplus2];
value += (float)oldwater[((yminus1)*iWaterWidth)+x];
value += (float)oldwater[((yminus2)*iWaterWidth)+x];
value += (float)oldwater[((yplus1) *iWaterWidth)+x];
value += (float)oldwater[((yplus2) *iWaterWidth)+x];
value += (float)oldwater[((yminus1)*iWaterWidth)+xminus1];
value += (float)oldwater[((yminus1)*iWaterWidth)+xplus1];
value += (float)oldwater[((yplus1) *iWaterWidth)+xminus1];
value += (float)oldwater[((yplus1) *iWaterWidth)+xplus1];
// average them
value /= 6;
*/
}
// Method 2: This method is faster but doesn't look as good (IMHO)
{
value = oldwater[((y) *iWaterWidth)+xminus1];
value += oldwater[((y) *iWaterWidth)+xplus1];
value += oldwater[((yminus1)*iWaterWidth)+x];
value += oldwater[((yplus1) *iWaterWidth)+x];
// average them (/4) then multiply by two
// so they don't die off as quickly.
value /= 2;
}
////////////////////////
//
// regardless of the blending method we choose, we still must
// do this stuff.
//
////////////////////////
// subtract the previous water value
value -= newwater[(y*iWaterWidth)+x];
// dam
没有合适的资源?快使用搜索试试~ 我知道了~
Samples11-17.rar_directx 11_game_特效
共117个文件
h:27个
cpp:24个
ico:10个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 136 浏览量
2022-09-22
17:25:18
上传
评论
收藏 3.88MB RAR 举报
温馨提示
DirectX特效游戏程序设计11-17章实例源码。
资源推荐
资源详情
资源评论
收起资源包目录
Samples11-17.rar_directx 11_game_特效 (117个子文件)
Ch14p1_WarpImage.bmp 192KB
Ch13p1_trippy256.bmp 144KB
Ch13p1_FeedbackImage.bmp 144KB
Ch17p2_trippy256.bmp 144KB
Ch11p2_GreenFirePalette.bmp 1KB
Ch11p2_FirePalette.bmp 1KB
Ch12p1_SimpleWater.cpp 22KB
Ch15p1_SimpleClouds.cpp 22KB
Ch14p1_SimpleWarp.cpp 21KB
Ch13p1_SimpleFeedback.cpp 20KB
Ch11p1_SimpleFire.cpp 18KB
Ch17p2_TransitionPageant.cpp 17KB
Ch17p1_AlphaBlendFade.cpp 15KB
Ch16p1_SimpleBlur.cpp 14KB
Ch11p3_OrthoProj.cpp 12KB
Ch11p2_FireClass.cpp 11KB
Ch11p2_TextureFire.cpp 10KB
Ch17p2_WipeTransition.cpp 5KB
Ch17p2_StaticDissolveTransition.cpp 5KB
Ch17p2_WarpDissolveTransition.cpp 4KB
Ch17p2_CrunchTransition.cpp 4KB
Ch17p2_ConstSpeedCrunchTransition.cpp 4KB
Ch17p2_MeltTransition.cpp 3KB
Ch17p2_TileTransition.cpp 3KB
Ch17p2_DissolveTransition.cpp 3KB
Ch17p2_SolidFadeTransition.cpp 3KB
Ch16p1_ImageManipulator.cpp 3KB
Ch16p1_ImageManipulatorKernels.cpp 2KB
Ch17p2_TileTransition_OneVB.cpp 1KB
Ch17p2_ConstSpeedMeltTransition.cpp 1006B
Ch17p2_TransitionPageant.dsp 7KB
Ch16p1_SimpleBlur.dsp 6KB
Ch12p1_SimpleWater.dsp 5KB
Ch11p2_FireClass.dsp 5KB
Ch13p1_SimpleFeedback.dsp 5KB
Ch17p1_AlphaBlendFade.dsp 5KB
Ch11p1_SimpleFire.dsp 5KB
Ch15p1_SimpleClouds.dsp 5KB
Ch14p1_SimpleWarp.dsp 5KB
Ch11p3_OrthoProj.dsp 5KB
Ch17p2_TransitionPageant.dsw 571B
Ch17p1_AlphaBlendFade.dsw 565B
Ch13p1_SimpleFeedback.dsw 565B
Ch15p1_SimpleClouds.dsw 561B
Ch12p1_SimpleWater.dsw 559B
Ch14p1_SimpleWarp.dsw 557B
Ch11p1_SimpleFire.dsw 557B
Ch16p1_SimpleBlur.dsw 557B
Ch11p2_FireClass.dsw 555B
Ch11p3_OrthoProj.dsw 555B
Ch17p2_Transitionpageant.exe 244KB
Ch16p1_SimpleBlur.exe 224KB
Ch14p1_SimpleWarp.exe 220KB
Ch17p1_AlphaBlendFade.exe 220KB
Ch12p1_SimpleWater.exe 220KB
Ch11p2_FireClass.exe 220KB
Ch13p1_SimpleFeedback.exe 220KB
Ch11p3_OrthoProj.exe 216KB
Ch15p1_SimpleClouds.exe 108KB
Ch11p1_SimpleFire.exe 108KB
Ch17p2_TileTransition.h 7KB
Ch17p2_TileTransition_OneVB.h 7KB
Ch11p1_FirePalette.h 3KB
Ch11p2_FirePalette.h 3KB
Ch11p2_TextureFire.h 2KB
Ch16p1_ImageManipulatorKernels.h 1KB
Ch17p2_resource.h 1KB
Ch17p1_resource.h 1KB
Ch13p1_resource.h 1KB
Ch15p1_resource.h 1KB
Ch12p1_resource.h 1KB
Ch16p1_resource.h 1KB
Ch11p1_resource.h 1KB
Ch14p1_resource.h 1KB
Ch11p2_resource.h 1KB
Ch11p3_resource.h 1KB
Ch16p1_ImageManipulator.h 947B
Ch17p2_MeltTransition.h 757B
Ch17p2_CrunchTransition.h 752B
Ch17p2_ConstSpeedCrunchTransition.h 741B
Ch17p2_WarpDissolveTransition.h 662B
Ch17p2_Transition.h 645B
Ch17p2_StaticDissolveTransition.h 638B
Ch17p2_WipeTransition.h 618B
Ch17p2_ConstSpeedMeltTransition.h 515B
Ch17p2_DissolveTransition.h 458B
Ch17p2_SolidFadeTransition.h 449B
Ch15p1_MainIcon.ico 1KB
Ch12p1_MainIcon.ico 1KB
Ch17p1_MainIcon.ico 1KB
Ch16p1_MainIcon.ico 1KB
Ch11p1_MainIcon.ico 1KB
Ch17p2_MainIcon.ico 1KB
Ch13p1_MainIcon.ico 1KB
Ch14p1_MainIcon.ico 1KB
Ch11p3_MainIcon.ico 1KB
Ch11p2_MainIcon.ico 1KB
Ch16p1_Island.png 454KB
Ch17p1_Island.png 454KB
Ch17p2_Island.png 454KB
共 117 条
- 1
- 2
资源评论
刘良运
- 粉丝: 66
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功