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

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

?? ch12p1_simplewater.cpp

?? 實現2D水面效果的源程序
?? 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视频一区二区| 亚洲线精品一区二区三区| 日本一区二区三区四区在线视频 | 国产精品99久久久久久久vr| 视频一区二区国产| 午夜精品一区二区三区免费视频| 亚洲精品视频免费看| 亚洲黄色免费电影| 一区二区三区在线影院| 亚洲午夜电影在线| 首页国产欧美久久| 久久精品国产亚洲高清剧情介绍| 热久久久久久久| 激情综合色综合久久| 国产精品一区在线观看乱码 | 国产成人8x视频一区二区| 韩国三级在线一区| 国产福利91精品一区| 成人污污视频在线观看| 9色porny自拍视频一区二区| 色综合久久久久久久| 欧美三级蜜桃2在线观看| 欧美一区二区三区男人的天堂| 欧美一区二区三区男人的天堂| 欧美变态tickling挠脚心| 久久久91精品国产一区二区三区| 中文久久乱码一区二区| 亚洲一卡二卡三卡四卡| 蜜臀精品一区二区三区在线观看| 国产一区二区视频在线播放| 成人综合在线网站| 欧美精品xxxxbbbb| 久久美女高清视频| 一区二区高清免费观看影视大全| 日产国产高清一区二区三区| 狠狠色丁香久久婷婷综合丁香| 福利视频网站一区二区三区| 91极品美女在线| 精品噜噜噜噜久久久久久久久试看| 国产日韩欧美麻豆| 亚洲va欧美va人人爽| 国产成人免费xxxxxxxx| 欧美影院精品一区| 久久久精品蜜桃| 午夜久久久久久久久久一区二区| 国产麻豆视频精品| 欧美日本乱大交xxxxx| 中文字幕二三区不卡| 日韩精品免费视频人成| 99久久精品国产麻豆演员表| 欧美电视剧在线看免费| 亚洲自拍偷拍综合| 成人免费av在线| 日韩一区二区三区三四区视频在线观看 | 欧美日韩不卡在线| 亚洲欧美一区二区视频| 国产一区二区视频在线| 在线综合视频播放| 亚洲国产一区在线观看| 99麻豆久久久国产精品免费| 久久免费看少妇高潮| 日本中文一区二区三区| 欧美午夜电影网| 日韩一区在线免费观看| 国产成人在线影院| 久久久综合九色合综国产精品| 视频一区欧美精品| 欧美日韩成人一区| 日韩电影免费在线看| 欧美午夜电影网| 亚洲午夜视频在线观看| 色婷婷精品大视频在线蜜桃视频| 国产精品蜜臀av| 成人免费毛片app| 精品美女在线观看| 久久99精品久久久久久国产越南| 欧美一区二区三区在线观看视频| 亚洲成av人片在线观看无码| 在线观看av不卡| 亚洲图片欧美色图| 欧美精品在线一区二区三区| 亚洲一区二区欧美日韩| 欧美在线制服丝袜| 亚洲动漫第一页| 欧美日韩精品一区二区三区蜜桃| 亚洲成人先锋电影| 日韩视频免费观看高清在线视频| 视频一区视频二区在线观看| 日韩欧美一二三四区| 久久精品国产99久久6| 精品日韩一区二区三区免费视频| 韩国毛片一区二区三区| 亚洲精品一线二线三线无人区| 精品亚洲成a人在线观看| 久久亚洲二区三区| gogo大胆日本视频一区| 亚洲色图另类专区| 欧美精品在线一区二区三区| 毛片一区二区三区| 中文字幕精品一区二区精品绿巨人| 成人av在线资源网站| 亚洲国产裸拍裸体视频在线观看乱了| 欧美日韩成人综合天天影院 | 欧美国产日本视频| 色综合色狠狠综合色| 日韩影院精彩在线| 久久久久久毛片| 91成人在线观看喷潮| 蜜桃精品视频在线观看| 中文av字幕一区| 欧美日韩国产另类一区| 国产毛片一区二区| 亚洲午夜一区二区三区| 国产视频亚洲色图| 欧美视频在线一区| 国产福利精品一区二区| 亚洲宅男天堂在线观看无病毒| 56国语精品自产拍在线观看| 高清在线不卡av| 日韩成人av影视| 亚洲欧洲99久久| 精品免费国产二区三区| 91黄色激情网站| 国产91精品欧美| 日本欧美肥老太交大片| 亚洲欧美另类图片小说| 久久精品视频免费观看| 欧美久久婷婷综合色| 色婷婷综合五月| 国产91精品一区二区麻豆网站| 日本免费在线视频不卡一不卡二| 亚洲免费观看高清| 国产精品污污网站在线观看| 日韩欧美美女一区二区三区| 欧美三级电影在线观看| 97国产精品videossex| 国产在线视频不卡二| 日韩**一区毛片| 视频一区视频二区在线观看| 亚洲精品成人在线| 中文字幕中文乱码欧美一区二区| 精品久久久三级丝袜| 欧美一区二区黄色| 在线成人免费观看| 欧美日韩一区国产| 欧美伊人久久大香线蕉综合69| 成人少妇影院yyyy| 成人永久aaa| 国产成人精品免费视频网站| 精品一区二区在线播放| 麻豆免费精品视频| 免费成人在线观看视频| 午夜精品一区二区三区电影天堂| 亚洲一区二区视频在线| 亚洲高清免费视频| 亚洲va在线va天堂| 日韩精品一区第一页| 奇米精品一区二区三区在线观看一| 亚洲一级二级在线| 天天影视网天天综合色在线播放| 亚洲精品国产高清久久伦理二区| 一区二区三区欧美| 国产精品一二三区在线| 九九**精品视频免费播放| 美女脱光内衣内裤视频久久网站 | 26uuu欧美日本| 精品国产伦理网| 国产日韩综合av| 亚洲欧洲另类国产综合| 一区二区三区四区蜜桃| 亚洲成人www| 精品在线免费视频| 国产超碰在线一区| 99久久国产综合精品麻豆| 色婷婷av一区二区三区软件| 欧美午夜不卡视频| 欧美第一区第二区| 欧美国产欧美综合| 玉足女爽爽91| 日本成人中文字幕| 国产成人午夜片在线观看高清观看| 成人av在线播放网站| 欧美性受极品xxxx喷水| 制服丝袜国产精品| 久久九九影视网| 亚洲电影一区二区| 国产成人在线免费| 欧美日韩在线直播| 久久久综合激的五月天| 一区二区三区四区乱视频| 免费的国产精品| 色偷偷88欧美精品久久久| 日韩欧美中文字幕精品| 最好看的中文字幕久久| 久久99精品国产.久久久久| 成人一区二区三区视频| 欧美一区日本一区韩国一区| 中文幕一区二区三区久久蜜桃| 日韩精品福利网|