青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

隨筆 - 505  文章 - 1034  trackbacks - 0
<2007年2月>
28293031123
45678910
11121314151617
18192021222324
25262728123
45678910


子曾經曰過:編程無他,唯手熟爾!

常用鏈接

留言簿(94)

隨筆分類(649)

隨筆檔案(505)

相冊

BCB

Crytek

  • crymod
  • Crytek's Offical Modding Portal

Game Industry

OGRE

other

Programmers

Qt

WOW Stuff

搜索

  •  

積分與排名

  • 積分 - 918854
  • 排名 - 14

最新隨筆

最新評論

閱讀排行榜

評論排行榜

術語:
rotation period 旋轉周期
radians              弧度



//-----------------------------------------------------------------------------
// File: Matrices.cpp
//
// Desc: Now that we know how to create a device and render some 2D vertices,
//       this tutorial goes the next step and renders 3D geometry. To deal with
//       3D geometry we need to introduce the use of 4x4 matrices to transform
//       the geometry with translations, rotations, scaling, and setting up our
//       camera.
//
//       Geometry is defined in model space. We can move it (translation),
//       rotate it (rotation), or stretch it (scaling) using a world transform.
//       The geometry is then said to be in world space. Next, we need to
//       position the camera, or eye point, somewhere to look at the geometry.
//       Another transform, via the view matrix, is used, to position and
//       rotate our view. With the geometry then in view space, our last
//       transform is the projection transform, which "projects" the 3D scene
//       into our 2D viewport.
//
//       Note that in this tutorial, we are introducing the use of D3DX, which
//       is a set of helper utilities for D3D. In this case, we are using some
//       of D3DX's useful matrix initialization functions. To use D3DX, simply
//       include <d3dx9.h> and link with d3dx9.lib.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#include <Windows.h>
#include 
<mmsystem.h>
#include 
<d3dx9.h>
#pragma warning( disable : 
4996 ) // disable deprecated warning 
#include <strsafe.h>
#pragma warning( 
default : 4996 ) 




//-----------------------------------------------------------------------------
// Global variables
//-----------------------------------------------------------------------------
LPDIRECT3D9             g_pD3D       = NULL; // Used to create the D3DDevice
LPDIRECT3DDEVICE9       g_pd3dDevice = NULL; // Our rendering device
LPDIRECT3DVERTEXBUFFER9 g_pVB        = NULL; // Buffer to hold vertices

// A structure for our custom vertex type
struct CUSTOMVERTEX
{
    FLOAT x, y, z;      
// The untransformed, 3D position for the vertex
    DWORD color;        // The vertex color
};

// Our custom FVF, which describes our custom vertex structure
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE)




//-----------------------------------------------------------------------------
// Name: InitD3D()
// Desc: Initializes Direct3D
//-----------------------------------------------------------------------------
HRESULT InitD3D( HWND hWnd )
{
    
// Create the D3D object.
    if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
        
return E_FAIL;

    
// Set up the structure used to create the D3DDevice
    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory( 
&d3dpp, sizeof(d3dpp) );
    d3dpp.Windowed 
= TRUE;
    d3dpp.SwapEffect 
= D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat 
= D3DFMT_UNKNOWN;

    
// Create the D3DDevice
    if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
                                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                      
&d3dpp, &g_pd3dDevice ) ) )
    {
        
return E_FAIL;
    }

    
// Turn off culling, so we see the front and back of the triangle
    
// 關閉剔除,以便三角形的前后都能被我們看到
    g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );

    
// Turn off D3D lighting, since we are providing our own vertex colors
    
// 關閉D3D光照,因為我們提供我們自己的頂點顏色
    g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE );

    
return S_OK;
}




//-----------------------------------------------------------------------------
// Name: InitGeometry()
// Desc: Creates the scene geometry
//-----------------------------------------------------------------------------
HRESULT InitGeometry()
{
    
// Initialize three vertices for rendering a triangle
    CUSTOMVERTEX g_Vertices[] =
    {
        { 
-1.0f,-1.0f0.0f0xffff0000, },
        {  
1.0f,-1.0f0.0f0xff0000ff, },
        {  
0.0f1.0f0.0f0xffffffff, },
    };

    
// Create the vertex buffer.
    if( FAILED( g_pd3dDevice->CreateVertexBuffer( 3*sizeof(CUSTOMVERTEX),
                                                  
0, D3DFVF_CUSTOMVERTEX,
                                                  D3DPOOL_DEFAULT, 
&g_pVB, NULL ) ) )
    {
        
return E_FAIL;
    }

    
// Fill the vertex buffer.
    VOID* pVertices;
    
if( FAILED( g_pVB->Lock( 0sizeof(g_Vertices), (void**)&pVertices, 0 ) ) )
        
return E_FAIL;
    memcpy( pVertices, g_Vertices, 
sizeof(g_Vertices) );
    g_pVB
->Unlock();

    
return S_OK;
}




//-----------------------------------------------------------------------------
// Name: Cleanup()
// Desc: Releases all previously initialized objects
//-----------------------------------------------------------------------------
VOID Cleanup()
{
    
if( g_pVB != NULL )
        g_pVB
->Release();

    
if( g_pd3dDevice != NULL )
        g_pd3dDevice
->Release();

    
if( g_pD3D != NULL )
        g_pD3D
->Release();
}

下面是最關鍵的函數:
//-----------------------------------------------------------------------------
// Name: SetupMatrices()
// Desc: Sets up the world, view, and projection transform matrices.
//-----------------------------------------------------------------------------
VOID SetupMatrices()
{
    
// For our world matrix, we will just rotate the object about the y-axis.
    
// 物件只圍繞y軸旋轉
    D3DXMATRIXA16 matWorld;

    
// Set up the rotation matrix to generate 1 full rotation (2*PI radians) every 1000 ms. 
    
// 配置旋轉矩陣為每1000ms一整圈(2*PI 弧度)
    
// To avoid the loss of precision inherent in very high floating point numbers,
    
// 為了避免高浮點數固有的精度損失,
    
// the system time is modulated by the rotation period before conversion to a radian angle.
    
// 系統時間被旋轉周期求模,在它被轉化成弧度角前
    UINT  iTime  = timeGetTime() % 1000;
    FLOAT fAngle 
= iTime * (2.0f * D3DX_PI) / 1000.0f;
    D3DXMatrixRotationY( 
&matWorld, fAngle );
    g_pd3dDevice
->SetTransform( D3DTS_WORLD, &matWorld );
設置視圖矩陣,看圖:



    // Set up our view matrix. 
    
// 設置視圖矩陣
    
// A view matrix can be defined given an eye point,
    
// a point to lookat, and a direction for which way is up. Here, we set the
    
// eye five units back along the z-axis and up three units, look at the
    
// origin, and define "up" to be in the y-direction.
    D3DXVECTOR3 vEyePt( 0.0f3.0f,-5.0f );
    D3DXVECTOR3 vLookatPt( 
0.0f0.0f0.0f );
    D3DXVECTOR3 vUpVec( 
0.0f1.0f0.0f );
    D3DXMATRIXA16 matView;
    D3DXMatrixLookAtLH( 
&matView, &vEyePt, &vLookatPt, &vUpVec );
    g_pd3dDevice
->SetTransform( D3DTS_VIEW, &matView );
投影矩陣:
    // For the projection matrix, we set up a perspective transform (which
    
// transforms geometry from 3D view space to 2D viewport space, with
    
// a perspective divide making objects smaller in the distance). 
    
// 投影矩陣,我們配置一個透視轉化(把圖形從3D視圖空間轉化到2D視口空間,透視劃分使得遠的物件小)
    
// To build a perpsective transform, we need the field of view (1/4 pi is common),
    
// the aspect ratio, and the near and far clipping planes (which define at
    
// what distances geometry should be no longer be rendered).
    
// 構建透視轉化,四個參數(1)the field of view (2)the aspect ratio (3)the near clipping plane (4)the far clipping plane
    D3DXMATRIXA16 matProj;
    D3DXMatrixPerspectiveFovLH( 
&matProj, D3DX_PI/41.0f1.0f100.0f );
    g_pd3dDevice
->SetTransform( D3DTS_PROJECTION, &matProj );
}

//-----------------------------------------------------------------------------
// Name: Render()
// Desc: Draws the scene
//-----------------------------------------------------------------------------
VOID Render()
{
    
// Clear the backbuffer to a black color
    g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f0 );

    
// Begin the scene
    if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
    {
        
// Setup the world, view, and projection matrices
        SetupMatrices();

        
// Render the vertex buffer contents
        g_pd3dDevice->SetStreamSource( 0, g_pVB, 0sizeof(CUSTOMVERTEX) );
        g_pd3dDevice
->SetFVF( D3DFVF_CUSTOMVERTEX );
        g_pd3dDevice
->DrawPrimitive( D3DPT_TRIANGLESTRIP, 01 );

        
// End the scene
        g_pd3dDevice->EndScene();
    }

    
// Present the backbuffer contents to the display
    g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}




//-----------------------------------------------------------------------------
// Name: MsgProc()
// Desc: The window's message handler
//-----------------------------------------------------------------------------
LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
    
switch( msg )
    {
        
case WM_DESTROY:
            Cleanup();
            PostQuitMessage( 
0 );
            
return 0;
    }

    
return DefWindowProc( hWnd, msg, wParam, lParam );
}




//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: The application's entry point
//-----------------------------------------------------------------------------
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )
{
    
// Register the window class
    WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L0L,
                      GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
                      
"D3D Tutorial", NULL };
    RegisterClassEx( 
&wc );

    
// Create the application's window
    HWND hWnd = CreateWindow( "D3D Tutorial""D3D Tutorial 03: Matrices",
                              WS_OVERLAPPEDWINDOW, 
100100256256,
                              NULL, NULL, wc.hInstance, NULL );

    
// Initialize Direct3D
    if( SUCCEEDED( InitD3D( hWnd ) ) )
    {
        
// Create the scene geometry
        if( SUCCEEDED( InitGeometry() ) )
        {
            
// Show the window
            ShowWindow( hWnd, SW_SHOWDEFAULT );
            UpdateWindow( hWnd );

            
// Enter the message loop
            MSG msg;
            ZeroMemory( 
&msg, sizeof(msg) );
            
while( msg.message!=WM_QUIT )
            {
                
if( PeekMessage( &msg, NULL, 0U0U, PM_REMOVE ) )
                {
                    TranslateMessage( 
&msg );
                    DispatchMessage( 
&msg );
                }
                
else
                    Render();
            }
        }
    }

    UnregisterClass( 
"D3D Tutorial", wc.hInstance );
    
return 0;
}
posted on 2007-02-15 23:05 七星重劍 閱讀(950) 評論(0)  編輯 收藏 引用 所屬分類: Game Graphics
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            欧美少妇一区| 精品白丝av| 午夜欧美精品| 亚洲精品永久免费| 免费日韩av| 狠狠色狠狠色综合日日91app| 久久一区中文字幕| 欧美资源在线| 久久大逼视频| 久久视频一区二区| 亚洲在线电影| 午夜激情综合网| 性欧美video另类hd性玩具| 亚洲午夜精品久久| 国产老肥熟一区二区三区| 国产精品观看| 国产亚洲欧美aaaa| 在线播放国产一区中文字幕剧情欧美| 国产欧美精品国产国产专区| 国产精品美女久久久浪潮软件| 欧美日韩不卡| 欧美三级黄美女| 国产精品伦理| 国产亚洲欧美一区在线观看 | 亚洲欧洲一级| 欧美激情中文字幕在线| 亚洲三级毛片| 99国内精品久久久久久久软件| 夜夜嗨网站十八久久| 亚洲欧美激情视频| 久久久久久久综合色一本| 免费av成人在线| 国产精品亚洲激情| aa级大片欧美| 欧美激情精品久久久久久变态 | 久久综合久色欧美综合狠狠 | 欧美日韩一区二区三区在线视频| 国产一区二区三区久久悠悠色av | 亚洲天堂久久| 欧美大片在线观看| 欧美日韩免费高清| 午夜国产精品视频免费体验区| 日韩一级大片| 久久爱另类一区二区小说| 欧美久久久久久蜜桃| 国产一区二区三区在线免费观看 | 日韩亚洲视频在线| 麻豆精品在线视频| 国产亚洲一区二区在线观看 | 日韩一级大片在线| 欧美成人精品| 久久久久久久国产| 韩国一区电影| 久久国产精品一区二区三区| 亚洲视频第一页| 国产精品高潮在线| 亚洲一区二区三区精品动漫| 亚洲国产欧美一区| 久热精品视频| 亚洲国产一区二区在线| 欧美大片va欧美在线播放| 狂野欧美激情性xxxx| 亚洲国产精品传媒在线观看| 欧美激情精品久久久六区热门 | 国产精品青草综合久久久久99| 99国产欧美久久久精品| 亚洲麻豆一区| 国产精品99久久久久久久vr| 欧美日韩国产一区精品一区| 一区二区三区**美女毛片| 99成人免费视频| 国产精品免费在线| 久久久久女教师免费一区| 久久婷婷国产麻豆91天堂| 亚洲欧洲一区二区三区久久| 亚洲精品美女久久7777777| 欧美日韩精品免费看| 亚洲欧美日韩中文在线制服| 欧美一区二区三区免费观看| 精品成人一区二区| 亚洲国产精品传媒在线观看 | 亚洲国产mv| 亚洲国内自拍| 国产精品亚洲一区二区三区在线| 欧美自拍偷拍| 免费欧美在线视频| 一区二区三区久久| 亚洲第一精品在线| 一区二区三区四区蜜桃| 国产精品一区=区| 久久婷婷国产综合尤物精品| 蜜臀久久99精品久久久久久9| 一区二区三区 在线观看视| 亚洲综合社区| 亚洲激情婷婷| 亚洲字幕在线观看| 亚洲精品国产精品乱码不99| 在线亚洲欧美| 国模私拍一区二区三区| 日韩视频一区二区三区在线播放免费观看 | 老牛国产精品一区的观看方式| 亚洲激情成人| 亚洲视频成人| 最新国产成人在线观看| 亚洲无线一线二线三线区别av| 在线免费高清一区二区三区| 亚洲另类在线视频| 黄色成人在线观看| 在线一区二区日韩| 日韩视频一区| 久久久久久色| 亚洲欧美日韩国产一区二区三区| 另类激情亚洲| 久久综合久久综合九色| 国产乱码精品一区二区三区忘忧草| 欧美jizz19hd性欧美| 国产欧美一级| 在线视频中文亚洲| 亚洲乱码日产精品bd| 欧美一级久久| 午夜精品国产更新| 樱桃成人精品视频在线播放| 欧美精品www在线观看| 午夜精品免费| 欧美日本国产一区| 欧美激情国产日韩精品一区18| 国产亚洲精品自拍| 亚洲综合日韩中文字幕v在线| 99亚洲精品| 欧美国产综合一区二区| 你懂的视频一区二区| 在线高清一区| 久久久一区二区| 久久久免费精品视频| 国产精品自拍在线| 一区二区av| 亚洲一区二区三区四区五区午夜 | 欧美一区二区视频在线观看2020| 欧美高清视频一区| 欧美二区不卡| 亚洲日韩视频| 欧美一区二区播放| 国产日韩欧美中文| 亚洲欧美另类国产| 欧美在线免费观看亚洲| 国产精品一级久久久| 亚洲欧美影院| 久久亚洲欧美| 亚洲国产精品久久久久婷婷884| 久久久久国产精品午夜一区| 久久亚洲精选| 亚洲精品乱码久久久久久蜜桃麻豆| 免费成年人欧美视频| 91久久国产精品91久久性色| 夜夜嗨av一区二区三区中文字幕| 欧美精品国产一区| 夜夜嗨av色一区二区不卡| 午夜精品一区二区三区在线视| 国产日韩高清一区二区三区在线| 欧美一区二区观看视频| 美女网站久久| 日韩视频在线免费| 国产精品久久久久免费a∨| 欧美一区激情| 最新国产精品拍自在线播放| 亚洲欧美国产精品va在线观看| 国产精品毛片| 久久综合99re88久久爱| 一本综合精品| 免费在线看成人av| 一区二区日韩精品| 国产自产精品| 欧美日韩亚洲精品内裤| 亚洲欧美在线一区二区| 欧美激情2020午夜免费观看| 亚洲一区二区在线播放| 好吊色欧美一区二区三区四区| 欧美福利视频在线观看| 午夜一区不卡| 亚洲三级影院| 久久久久国产一区二区三区| 国产日韩欧美91| 免费精品视频| 午夜在线精品偷拍| 亚洲精品资源| 男人插女人欧美| 欧美主播一区二区三区| 99精品热6080yy久久| 国模叶桐国产精品一区| 欧美三级视频| 欧美二区在线观看| 久久av一区| 亚洲一区欧美| 99re6热只有精品免费观看| 欧美插天视频在线播放| 久久精品电影| 欧美在线啊v| 欧美亚洲网站| 午夜精品久久久久99热蜜桃导演| 亚洲久久视频|