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

隨筆 - 505  文章 - 1034  trackbacks - 0
<2006年11月>
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789


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

常用鏈接

留言簿(94)

隨筆分類(649)

隨筆檔案(505)

相冊

BCB

Crytek

  • crymod
  • Crytek's Offical Modding Portal

Game Industry

OGRE

other

Programmers

Qt

WOW Stuff

搜索

  •  

積分與排名

  • 積分 - 918837
  • 排名 - 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>
            美日韩在线观看| 在线午夜精品自拍| 欧美激情在线观看| 欧美日本免费| 国产精品久久国产愉拍| 欧美三级免费| 国产日韩在线播放| 亚洲国产日韩欧美一区二区三区| 亚洲国产91| 99国产精品久久久久老师| 亚洲伊人一本大道中文字幕| 久久国产婷婷国产香蕉| 亚洲丝袜av一区| 久久精品在线| 国产日韩欧美中文| 狠狠入ady亚洲精品| 亚洲国产成人久久综合一区| 99国产精品久久久| 久久久视频精品| 亚洲国产另类精品专区| 亚洲精品久久久久久久久久久| 一区二区三区国产在线观看| 久久精品国产欧美亚洲人人爽| 欧美成人免费全部观看天天性色| 国产精品九色蝌蚪自拍| 亚洲第一中文字幕| 欧美一级片在线播放| 亚洲经典一区| 久久久久久伊人| 国产精品女主播| 日韩亚洲精品在线| 久久久久久自在自线| av成人免费在线观看| 美女主播一区| 国模 一区 二区 三区| 亚洲视频图片小说| 亚洲国产黄色| 久久天堂成人| 国产一区二区三区高清在线观看| 亚洲乱码日产精品bd| 久久先锋资源| 午夜视频一区二区| 国产欧美日韩在线播放| 亚洲一区二区欧美| 亚洲三级免费电影| 欧美a级片网站| 影音先锋成人资源站| 欧美在线日韩精品| 亚洲欧美日韩精品久久奇米色影视 | 久久精品一区二区三区不卡牛牛| 欧美日韩999| 亚洲国产精品va在看黑人| 久久国产精品99国产| 亚洲视频一二三| 国产精品成人免费视频| 国产精品99久久久久久久vr| 亚洲人成7777| 欧美日本在线一区| 日韩一区二区电影网| 亚洲国产免费看| 欧美freesex8一10精品| 亚洲人成绝费网站色www| 免费看av成人| 欧美77777| 99re在线精品| 亚洲深夜av| 国产日韩在线一区二区三区| 欧美中文字幕在线| 欧美综合国产| 亚洲精品韩国| 亚洲最新在线| 国产欧美一区二区在线观看| 久久久久久夜| 欧美xxx在线观看| 亚洲四色影视在线观看| 中文日韩在线| 国产亚洲一本大道中文在线| 快she精品国产999| 免费日韩av电影| 亚洲婷婷综合色高清在线| 亚洲一区二区在线播放| 国内精品写真在线观看| 亚洲黄色精品| 国产模特精品视频久久久久| 久久综合中文色婷婷| 欧美激情精品久久久久久久变态| 亚洲一区免费视频| 久久久久久夜| 午夜国产一区| 欧美成人精品激情在线观看| 午夜精品久久久| 免费不卡亚洲欧美| 欧美伊人影院| 欧美日本韩国一区| 六月婷婷一区| 国产精品欧美日韩| 亚洲国产精品福利| 国产一区91| 一区二区三区精品视频在线观看| 狠狠做深爱婷婷久久综合一区| 亚洲免费大片| 91久久综合| 久久精品中文| 性亚洲最疯狂xxxx高清| 欧美二区视频| 美日韩在线观看| 国产精品爽黄69| 亚洲精品九九| 亚洲黄色有码视频| 国产免费成人| 一色屋精品亚洲香蕉网站| 国产精品久久久久久久久久妞妞| 久久国产视频网站| 欧美另类在线观看| 久久影音先锋| 国产精品美女黄网| 亚洲经典在线看| 狠狠综合久久av一区二区小说 | 亚洲视频一区二区免费在线观看| 欧美一级专区免费大片| 午夜精品福利在线观看| 欧美日韩精品中文字幕| 亚洲大片在线观看| 永久免费精品影视网站| 欧美一区综合| 久久久国产91| 国模吧视频一区| 欧美一区二区免费观在线| 羞羞答答国产精品www一本| 欧美午夜不卡视频| 日韩视频精品| 亚洲一区二区三区四区视频| 欧美日韩激情小视频| 亚洲精品乱码久久久久久黑人| 亚洲黄色在线看| 欧美xxx成人| 日韩午夜激情| 亚洲尤物视频网| 国产精品欧美风情| 亚洲综合精品| 久久精品国产精品亚洲精品| 国产日产精品一区二区三区四区的观看方式| 亚洲裸体视频| 亚洲一区二区免费在线| 国产精品久久久久久亚洲调教| 99视频精品在线| 一区二区久久久久| 国产精品毛片a∨一区二区三区|国| 亚洲一区欧美激情| 久久嫩草精品久久久精品一| 激情成人在线视频| 欧美77777| 在线视频日本亚洲性| 久久精品国产成人| 亚洲国产激情| 欧美无乱码久久久免费午夜一区| 亚洲嫩草精品久久| 免费成人高清视频| 99综合精品| 国产午夜精品久久久久久久| 久久最新视频| 中文精品视频| 麻豆91精品| 一区二区日韩| 国产偷久久久精品专区| 欧美国产精品| 亚洲在线视频| 亚洲激情视频网站| 亚洲欧美另类综合偷拍| 亚洲福利视频专区| 国产精品成人久久久久| 久久久噜噜噜| 中国亚洲黄色| 欧美国产日本在线| 亚洲在线一区二区| 亚洲国产精品传媒在线观看| 欧美激情日韩| 亚洲欧美网站| 亚洲欧洲日本国产| 久久精品视频免费| 亚洲视频精选在线| 亚洲国产精品999| 国产欧美一区二区色老头| 欧美刺激性大交免费视频| 午夜在线视频观看日韩17c| 亚洲国产精品久久久久秋霞不卡| 香蕉久久夜色精品国产| 99国产精品久久久久久久成人热 | 欧美在线视频免费播放| 亚洲人成网站在线播| 久久国产综合精品| 亚洲婷婷在线| 一本大道久久a久久精品综合| 黄色成人av网| 国产一区二区你懂的| 国产精品久久久久久妇女6080 | 亚洲色诱最新| 亚洲欧洲精品天堂一级| 美日韩精品视频| 久久久无码精品亚洲日韩按摩|