• <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>

            天行健 君子當(dāng)自強而不息

            D3D中的光照(3)

            平行光示例:

            The GetAsyncKeyState function determines whether a key is up or down at the time the function is called, and whether the key was pressed after a previous call to GetAsyncKeyState.

            Syntax

            SHORT GetAsyncKeyState(      
                int vKey
            );

            Parameters

            vKey
            [in] Specifies one of 256 possible virtual-key codes. For more information, see Virtual-Key Codes.

            Return Value

            If the function succeeds, the return value specifies whether the key was pressed since the last call to GetAsyncKeyState, and whether the key is currently up or down. If the most significant bit is set, the key is down, and if the least significant bit is set, the key was pressed after the previous call to GetAsyncKeyState. However, you should not rely on this last behavior; for more information, see the Remarks.

            截圖:

            源代碼:

            /**************************************************************************************
              Demonstrates using a directional light with D3DX objects.  
              You can orbit the scene using the left and right arrow keys.  
              In addition you can elevate the camera with the up and down arrow keys.  
             *************************************************************************************
            */

            #include 
            "d3dUtility.h"

            #pragma warning(disable : 
            4100)

            #define MESH_TEAPOT        0
            #define MESH_SPHERE        1
            #define MESH_TORUS        2
            #define MESH_CYLINDER    3
            #define NUM_MESH        4

            const int WIDTH  = 640;
            const int HEIGHT = 480;

            IDirect3DDevice9
            *        g_d3d_device  = NULL;
            ID3DXMesh
            *                g_object_meshes[NUM_MESH];
            D3DXMATRIX                g_world_matrices[NUM_MESH];
            D3DMATERIAL9            g_materials[NUM_MESH];

            ////////////////////////////////////////////////////////////////////////////////////////////////////

            bool setup()
            {    
                
            // create objects
                D3DXCreateTeapot(g_d3d_device, &g_object_meshes[MESH_TEAPOT], NULL);
                D3DXCreateSphere(g_d3d_device, 
            1.0f2020&g_object_meshes[MESH_SPHERE], NULL);
                D3DXCreateTorus(g_d3d_device, 
            0.5f1.0f2020&g_object_meshes[MESH_TORUS], NULL);
                D3DXCreateCylinder(g_d3d_device, 
            0.5f1.0f2.0f2020&g_object_meshes[MESH_CYLINDER], NULL);

                
            // build world matrices - position the objects in world space
                D3DXMatrixTranslation(&g_world_matrices[MESH_TEAPOT],     0.0f,  2.0f0.0f);
                D3DXMatrixTranslation(
            &g_world_matrices[MESH_SPHERE],     0.0f-2.0f0.0f);
                D3DXMatrixTranslation(
            &g_world_matrices[MESH_TORUS],    -3.0f,  0.0f0.0f);
                D3DXMatrixTranslation(
            &g_world_matrices[MESH_CYLINDER],     3.0f,  0.0f0.0f);

                
            // setup the object's materials
                g_materials[MESH_TEAPOT]   = RED_MATERIAL;
                g_materials[MESH_SPHERE]   
            = BLUE_MATERIAL;
                g_materials[MESH_TORUS]    
            = GREEN_MATERIAL;
                g_materials[MESH_CYLINDER] 
            = YELLOW_MATERIAL;

                
            // setup a directional light
                D3DXVECTOR3 light_direction(1.0f-0.0f0.25f);
                D3DXCOLOR   color 
            = WHITE;
                D3DLIGHT9   dir_light 
            = init_directional_light(&light_direction, &color);

                
            // set and enable the light
                g_d3d_device->SetLight(0&dir_light);
                g_d3d_device
            ->LightEnable(0, TRUE);

                
            // turn off specular lighting and instruct Direct3D to renormalize normals
                g_d3d_device->SetRenderState(D3DRS_NORMALIZENORMALS, TRUE);
                g_d3d_device
            ->SetRenderState(D3DRS_SPECULARENABLE, FALSE);

                
            // set the projection matrix
                D3DXMATRIX proj;
                D3DXMatrixPerspectiveFovLH(
            &proj, D3DX_PI * 0.25f, (float)WIDTH/HEIGHT, 1.0f1000.0f);
                g_d3d_device
            ->SetTransform(D3DTS_PROJECTION, &proj);
                
                
            return true;
            }

            void cleanup()
            {
                
            for(int i = 0; i < NUM_MESH; i++)
                    safe_release
            <ID3DXMesh*>(g_object_meshes[i]);
            }

            bool display(float time_delta)
            {
                
            // update the scene: update camera position

                
            static float angle = (3.0f * D3DX_PI) / 2.0f;
                
            static float height = 5.0f;

                
            if(GetAsyncKeyState(VK_LEFT) & 0x8000f)
                    angle 
            -= 0.5f * time_delta;

                
            if(GetAsyncKeyState(VK_RIGHT) & 0x8000f)
                    angle 
            += 0.5f * time_delta;

                
            if(GetAsyncKeyState(VK_UP) & 0x8000f)
                    height 
            += 5.0f * time_delta;

                
            if(GetAsyncKeyState(VK_DOWN) & 0x8000f)
                    height 
            -= 5.0f * time_delta;

                D3DXVECTOR3 position(cosf(angle) 
            * 7.0f, height, sinf(angle) * 7.0f);
                D3DXVECTOR3 target(
            0.0f0.0f0.0f);
                D3DXVECTOR3 up(
            0.0f1.0f0.0f);

                D3DXMATRIX view_matrix;
                D3DXMatrixLookAtLH(
            &view_matrix, &position, &target, &up);

                g_d3d_device
            ->SetTransform(D3DTS_VIEW, &view_matrix);

                
            // draw the scene

                g_d3d_device
            ->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x000000001.0f0);

                g_d3d_device
            ->BeginScene();

                
            for(int i = 0; i < NUM_MESH; i++)
                {
                    
            // set material and world matrix for ith object, then render the ith object.
                    g_d3d_device->SetMaterial(&g_materials[i]);
                    g_d3d_device
            ->SetTransform(D3DTS_WORLD, &g_world_matrices[i]);
                    g_object_meshes[i]
            ->DrawSubset(0);
                }
                
                g_d3d_device
            ->EndScene();

                g_d3d_device
            ->Present(NULL, NULL, NULL, NULL);

                
            return true;
            }

            LRESULT CALLBACK wnd_proc(HWND hwnd, UINT msg, WPARAM word_param, LPARAM long_param)
            {
                
            switch(msg)
                {
                
            case WM_DESTROY:
                    PostQuitMessage(
            0);
                    
            break;

                
            case WM_KEYDOWN:
                    
            if(word_param == VK_ESCAPE)
                        DestroyWindow(hwnd);
                    
            break;
                }

                
            return DefWindowProc(hwnd, msg, word_param, long_param);
            }

            int WINAPI WinMain(HINSTANCE inst, HINSTANCE, PSTR cmd_line, int cmd_show)
            {
                
            if(! init_d3d(inst, WIDTH, HEIGHT, true, D3DDEVTYPE_HAL, &g_d3d_device))
                {
                    MessageBox(NULL, 
            "init_d3d() - failed."0, MB_OK);
                    
            return 0;
                }

                
            if(! setup())
                {
                    MessageBox(NULL, 
            "Steup() - failed."0, MB_OK);
                    
            return 0;
                }

                enter_msg_loop(display);

                cleanup();
                g_d3d_device
            ->Release();

                
            return 0;
            }


            下載源程序

            posted on 2008-03-16 19:35 lovedday 閱讀(597) 評論(0)  編輯 收藏 引用


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            公告

            導(dǎo)航

            統(tǒng)計

            常用鏈接

            隨筆分類(178)

            3D游戲編程相關(guān)鏈接

            搜索

            最新評論

            久久综合狠狠色综合伊人| 久久婷婷色综合一区二区| 久久精品国产清自在天天线| 久久热这里只有精品在线观看| 色婷婷噜噜久久国产精品12p| 精品久久人人妻人人做精品 | 精品久久久久久无码不卡| 久久久久免费精品国产| 97精品国产91久久久久久| 99久久国产热无码精品免费| 亚洲AV无码成人网站久久精品大| 中文无码久久精品| 精品人妻伦九区久久AAA片69| 国产精品嫩草影院久久| 91精品国产91热久久久久福利 | 久久久无码精品午夜| 成人亚洲欧美久久久久| 国产精品va久久久久久久| 色综合久久88色综合天天 | 亚洲伊人久久成综合人影院| 色欲综合久久中文字幕网| 国产精品毛片久久久久久久 | 欧美无乱码久久久免费午夜一区二区三区中文字幕 | 国产精品一久久香蕉产线看| 国产精品久久自在自线观看| 久久久久夜夜夜精品国产| 国产精自产拍久久久久久蜜| 久久久久久久91精品免费观看| 99久久精品日本一区二区免费| 久久99国产精品久久99果冻传媒| 久久e热在这里只有国产中文精品99| 欧美激情精品久久久久久久九九九 | 伊人久久精品无码二区麻豆| 人妻少妇久久中文字幕一区二区 | 国产成人久久精品麻豆一区| 欧美日韩成人精品久久久免费看| 蜜臀av性久久久久蜜臀aⅴ| 亚洲狠狠久久综合一区77777| 欧美一区二区久久精品| 99re久久精品国产首页2020| 亚洲精品久久久www|