亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ch12p1_simplewater.cpp

?? 游戲開發特殊技巧-special.effects.game.programming
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
/*
#############################################################################

  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];

      // dampen it!
      value = (int)((float)value / 1.05f);

      // store it in array
      newwater[(y*iWaterWidth)+x] = value;
    }
  }
  
  /* unremark this section of code to create a eastbound current
  for (y=0; y < iWaterHeight; y++) {
    for (int x=iWaterWidth-1; x >= 0; x--) {
      int xminus1 = x ? x-1 : iWaterWidth-1; // wrap around
      newwater[(y*iWaterWidth)+x] = newwater[(y*iWaterWidth)+xminus1];
    }
  }

  for (y=0; y < iWaterHeight; y++) {
    for (int x=iWaterWidth-1; x >= 1; x--) {
      int xminus1 = x ? x-1 : iWaterWidth-1; // wrap around
      oldwater[(y*iWaterWidth)+x] = oldwater[(y*iWaterWidth)+xminus1];
    }
  }
  */
}

void CreateWaterDroplet(int iX, int iY, int iSize, int iSplashStrength,
                        int *waterbuf, int iWaterWidth, int iWaterHeight)
{
  for (int x=iX-iSize; x <= iX+iSize; x++) {
    for (int y=iY-iSize; y <= iY+iSize; y++) {
      // make sure we're in bounds
      if (x < 0 || x >= iWaterWidth || y < 0 || y >= iWaterHeight) continue;
      
      // see if the point at (x,y) is within the circle of radius size
      int square_x    = (x-iX)*(x-iX);
      int square_y    = (y-iY)*(y-iY);
      int square_size = iSize*iSize;

      if (square_x+square_y <= square_size) {
        // it's within the size circle!  apply it to the water buffer.
        waterbuf[(y*iWaterWidth)+x] += (int)((float)iSplashStrength)*sqrt(square_x+square_y);
      }
    }
  }
}

HRESULT PutWaterOntoTexture(int *waterbuf, int iWaterWidth, int iWaterHeight,
                            char *lutDisplacement,
                            LPDIRECT3DDEVICE8 pd3dDevice,
                            LPDIRECT3DTEXTURE8 pSrcTex, 
                            LPDIRECT3DTEXTURE8 pDestTex)
{
  HRESULT hr;

  // lock texture
  D3DLOCKED_RECT rect_src, rect_dest;
  ::ZeroMemory(&rect_src, sizeof(rect_src));
  ::ZeroMemory(&rect_dest, sizeof(rect_dest));
  
  if (FAILED(hr = pSrcTex->LockRect(0, &rect_src, NULL, 0))) return(hr);
  if (FAILED(hr = pDestTex->LockRect(0, &rect_dest, NULL, 0))) return(hr);
  
  // our texture surface is now locked, and we can use the pitch to traverse it.
  DWORD *pSrc = (DWORD *)(rect_src.pBits);
  DWORD *pDest= (DWORD *)(rect_dest.pBits);
  
  int dest_index=0;
  int src_pitch = rect_src.Pitch/4; // in DWORDS
  
  // this could be optimized a LOT.  It's this way so you can learn the technique.
  for (int y=0; y < iWaterHeight; y++) {
    for (int x=0; x < iWaterWidth; x++) {
      
      int xdiff = (x == iWaterWidth-1)  ? 0 : waterbuf[(y*iWaterWidth)+x+1]   - waterbuf[(y*iWaterWidth)+x];
      int ydiff = (y == iWaterHeight-1) ? 0 : waterbuf[((y+1)*iWaterWidth)+x] - waterbuf[(y*iWaterWidth)+x];
      
      int xdisp = lutDisplacement[(xdiff+256) % 512];
      int ydisp = lutDisplacement[(ydiff+256) % 512];

      if (xdiff < 0) {
        if (ydiff < 0) {
          if (y-ydisp < 0 || y-ydisp >= TEXTURESIZE || x-xdisp < 0 || x-xdisp >= TEXTURESIZE)
            pDest[dest_index++] = pSrc[0];    
          else
            pDest[dest_index++] = pSrc[((y-ydisp)*src_pitch)+x-xdisp];  
        }
        else {
          if (y+ydisp < 0 || y+ydisp >= TEXTURESIZE || x-xdisp < 0 || x-xdisp >= TEXTURESIZE)
            pDest[dest_index++] = pSrc[0];    
          else
            pDest[dest_index++] = pSrc[((y+ydisp)*src_pitch)+x-xdisp];  
        }

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
99热精品一区二区| 欧美一区二区三区免费视频| 综合色天天鬼久久鬼色| 97成人超碰视| 美腿丝袜亚洲一区| 国产精品三级在线观看| 欧美日韩激情在线| 日韩电影在线观看网站| 国产午夜精品久久久久久久 | 久久精品网站免费观看| 91在线视频免费观看| 蜜臀91精品一区二区三区| 国产精品国产馆在线真实露脸| 欧美亚洲国产怡红院影院| 国产精品456| 美女视频黄 久久| 亚洲成精国产精品女| 亚洲国产精品成人综合| 日韩精品一区二区三区视频在线观看| 不卡的av在线| 国产高清不卡一区| 韩国精品在线观看| 日本强好片久久久久久aaa| 亚洲激情五月婷婷| 亚洲男人都懂的| 国产精品久久久久久久久果冻传媒 | 成人精品一区二区三区四区| 免费观看在线色综合| 免费高清成人在线| 久久精品久久99精品久久| 日韩 欧美一区二区三区| 性欧美大战久久久久久久久| 一个色妞综合视频在线观看| 一级特黄大欧美久久久| 亚洲一线二线三线久久久| 亚洲一区二区三区免费视频| 亚洲女性喷水在线观看一区| 亚洲视频在线观看三级| 激情欧美一区二区| 国产精品久久久久毛片软件| 日本欧美一区二区| 99九九99九九九视频精品| 欧美性受极品xxxx喷水| 中文字幕在线视频一区| 国产在线不卡一区| 欧美精品一区二区三区视频| 调教+趴+乳夹+国产+精品| 日本高清不卡视频| 依依成人综合视频| 日本大香伊一区二区三区| 一区二区三区精品久久久| 99精品久久只有精品| 中文字幕在线一区二区三区| 国产成人夜色高潮福利影视| 久久久三级国产网站| 国产精品18久久久久久久久久久久| 欧美不卡123| 国产成人日日夜夜| 一区二区三区四区乱视频| 91精品国产全国免费观看 | 在线播放日韩导航| 日本欧美在线观看| 精品对白一区国产伦| 成人免费视频国产在线观看| 亚洲精品国产a久久久久久 | 亚洲在线免费播放| 日韩欧美在线影院| 国产成人丝袜美腿| 亚洲gay无套男同| 精品日产卡一卡二卡麻豆| 成人性色生活片免费看爆迷你毛片| 日韩理论片网站| 欧美成人一区二区三区片免费| 国产99久久久精品| 日韩av一二三| 一区二区三区久久久| 久久久亚洲精华液精华液精华液| 高清不卡一二三区| 亚洲欧美日韩电影| 日韩一二三区视频| 成人免费福利片| 日韩avvvv在线播放| 国产欧美视频一区二区三区| jizz一区二区| 日韩成人av影视| 国产精品美女久久久久久| 欧美日韩国产首页| 91官网在线观看| 国产成a人亚洲精品| 日韩不卡在线观看日韩不卡视频| 欧美国产激情二区三区 | 亚洲三级小视频| 久久先锋资源网| 日韩一区二区三区观看| 99精品视频在线免费观看| 青青草国产精品97视觉盛宴| 亚洲欧美一区二区视频| 久久精品无码一区二区三区| 欧美一级视频精品观看| 欧美一区二区三区在线观看| 91在线你懂得| 欧美日韩一级视频| 91久久一区二区| 欧美在线观看视频一区二区| 日本道在线观看一区二区| 日本韩国一区二区| 欧美日韩一二三| 欧美日韩和欧美的一区二区| 91精品欧美久久久久久动漫| 日韩手机在线导航| 精品久久久久一区二区国产| 国产亚洲欧美一级| 久久精品一级爱片| 中文字幕亚洲在| 亚洲一区在线看| 裸体歌舞表演一区二区| 国产精品一区二区在线看| 成人av在线网站| 欧美视频在线一区| 日韩欧美一区二区免费| 国产视频一区二区在线观看| 一区二区三区在线播放| 亚洲大片一区二区三区| 欧美色图在线观看| 日韩一区二区三区高清免费看看| 国产精品成人免费在线| 亚洲国产一区二区在线播放| 成人一区在线看| 久久影院午夜论| 激情小说欧美图片| 国产视频在线观看一区二区三区| 国产一区视频网站| 国产校园另类小说区| 粉嫩久久99精品久久久久久夜| 日韩精品一区二区三区swag | 久久久精品2019中文字幕之3| 久久久久国产成人精品亚洲午夜| 国产精品久久久久影院亚瑟 | 成人久久视频在线观看| 成人免费电影视频| 亚洲三级在线看| 精品一区二区三区香蕉蜜桃| 国产精品一色哟哟哟| 色乱码一区二区三区88| 欧美一区二区二区| 麻豆91精品91久久久的内涵| 一区二区三区四区在线| 成人性生交大片免费看中文| 国产精品热久久久久夜色精品三区| 无码av免费一区二区三区试看| 欧美精品一区二区不卡| 亚洲国产成人高清精品| 3atv一区二区三区| 日本女人一区二区三区| 欧美本精品男人aⅴ天堂| 国产在线精品一区二区三区不卡| 日本午夜一本久久久综合| 91精品国产欧美一区二区18| 91成人在线观看喷潮| 国产精品视频yy9299一区| 国产亚洲精品久| 亚洲一区二区三区中文字幕在线| 亚洲综合在线免费观看| 日本不卡视频在线| 国产酒店精品激情| 99久久国产综合精品女不卡| 亚洲天堂中文字幕| 亚洲狠狠爱一区二区三区| 久久99精品国产91久久来源| 91在线码无精品| 欧美老女人第四色| 国产丝袜美腿一区二区三区| 亚洲一级电影视频| 成人动漫av在线| 欧美一区二区在线免费观看| 欧美福利视频一区| 最新日韩av在线| 99视频超级精品| 欧美日韩大陆一区二区| 国产精品欧美极品| 韩国欧美一区二区| 久久久久国产免费免费| 国产99精品视频| 亚洲日本中文字幕区| 欧美在线观看一区| 国产白丝网站精品污在线入口| 在线播放欧美女士性生活| 亚洲超碰精品一区二区| 久久精品国产精品青草| 国产伦精品一区二区三区免费 | 国产精品毛片久久久久久久| 久久精品视频免费观看| 欧美精品国产精品| 狠狠色丁香久久婷婷综合丁香| 色天使色偷偷av一区二区| 国产无人区一区二区三区| 久久精品国产99| 制服丝袜av成人在线看| 亚洲美女偷拍久久| 国产成人精品综合在线观看|