<p><span style="font-family:Microsoft YaHei; font-size:12px; background-color:#99ffff">// 关键帧动画实现月亮地球.cpp : 定义应用程序的入口点。<br> //</span></p>
<p><span style="font-family:Microsoft YaHei; font-size:12px; background-color:#99ffff">#include "stdafx.h"<br> #include "关键帧动画实现月亮地球.h"<br> #include<d3d9.h><br> #include<d3dx9.h><br> #include<Windows.h><br> #pragma comment(lib, "d3d9.lib")<br> #pragma comment(lib, "d3dx9.lib")<br> //进行动画关键值插值的阵列</span></p>
<p><span style="font-family:Microsoft YaHei; font-size:12px; background-color:#99ffff"> </span></p>
<p><span style="font-family:Microsoft YaHei; font-size:12px; background-color:#99ffff">D3DXVECTOR3 g_aniPos[2]; //位置关键值<br> D3DXQUATERNION g_aniRot[2]; //旋转关键值</span></p>
<p><span style="font-family:Microsoft YaHei; font-size:12px; background-color:#99ffff"> </span></p>
<p><br> <span style="font-family:Microsoft YaHei; font-size:12px; background-color:#99ffff">LPDIRECT3D9 g_pD3D = NULL ;<br> LPDIRECT3DDEVICE9 g_pd3dDevice = NULL ;<br> LPDIRECT3DVERTEXBUFFER9 g_pVB = NULL ;<br> LPDIRECT3DINDEXBUFFER9 g_pIB = NULL ;</span></p>
<p><span style="font-family:Microsoft YaHei; font-size:12px; background-color:#99ffff">D3DXMATRIXA16 g_matTMParent ;<br> D3DXMATRIXA16 g_matRParent ;</span></p>
<p><span style="font-family:Microsoft YaHei; font-size:12px; background-color:#99ffff">D3DXMATRIXA16 g_matTMChild ;<br> D3DXMATRIXA16 g_matRChild ;</span></p>
<p><span style="font-family:Microsoft YaHei; font-size:12px; background-color:#99ffff"> </span></p>
<p><span style="font-family:Microsoft YaHei; font-size:12px; background-color:#99ffff"> </span></p>
<p><span style="font-family:Microsoft YaHei; font-size:12px; background-color:#99ffff">struct CUSTOMVERTEX<br> {<!-- --><br> FLOAT x,y,z;<br> DWORD color;<br> };</span></p>
<p><br> <span style="font-family:Microsoft YaHei; font-size:12px; background-color:#99ffff">#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ |D3DFVF_DIFFUSE)</span></p>
<p><span style="font-family:Microsoft YaHei; font-size:12px; background-color:#99ffff"> </span></p>
<p><span style="font-family:Microsoft YaHei; font-size:12px; background-color:#99ffff">struct MYINDEX<br> {<!-- --><br> WORD _0,_1,_2;<br> };</span></p>
<p><span style="font-family:Microsoft YaHei; font-size:12px; background-color:#99ffff"> </span></p>
<p><span style="font-family:Microsoft YaHei; font-size:12px; background-color:#99ffff">HRESULT InitD3D (HWND hWnd )<br> {<!-- --><br> //创建D3D对象<br> if(NULL == ( g_pD3D =Direct3DCreate9 ( D3D_SDK_VERSION ) ))<br> return E_FAIL;<br> //创建设备的结构体<br> D3DPRESENT_PARAMETERS d3dpp;<br> ZeroMemory(&d3dpp ,sizeof(d3dpp));<br> d3dpp.Windowed = TRUE;<br> d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;<br> d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;<br> d3dpp.EnableAutoDepthStencil = TRUE;<br> d3dpp.AutoDepthStencilFormat = D3DFMT_D16;</span></p>
<p><span style="font-family:Microsoft YaHei; font-size:12px; background-color:#99ffff"> if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,<br> D3DCREATE_SOFTWARE_VERTEXPROCESSING,<br> &d3dpp, &g_pd3dDevice ) ) )<br> return E_FAIL;</span></p>
<p><span style="font-family:Microsoft YaHei; font-size:12px; background-color:#99ffff"> //实现卷起功能<br> g_pd3dDevice->SetRenderState(D3DRS_CULLMODE , D3DCULL_NONE);<br> </span></p>
<p><span style="font-family:Microsoft YaHei; font-size:12px; background-color:#99ffff"> //起到z缓冲的功能<br> g_pd3dDevice->SetRenderState(D3DRS_ZENABLE , TRUE );</span></p>
<p><span style="font-family:Microsoft YaHei; font-size:12px; background-color:#99ffff"> //顶点具有颜色,能起到光源的功能<br> g_pd3dDevice->SetRenderState(D3DRS_LIGHTING ,FALSE);</span></p>
<p><span style="font-family:Microsoft YaHei; font-size:12px; background-color:#99ffff"> return S_OK;<br> }</span></p>
<p><br> <span style="font-family:Microsoft YaHei; font-size:12px; background-color:#99ffff">HRESULT InitVB()<br> {<!-- --><br> /// 渲染正方体(cube)的八个顶点声明<br> CUSTOMVERTEX vertices[] =<br> {<!-- --><br> { -1, 1, 1 , 0xffff0000 }, /// v0<br> { 1, 1, 1 , 0xff00ff00 }, /// v1<br> { 1, 1, -1 , 0xff0000ff }, /// v2<br> { -1, 1, -1 , 0xffffff00 }, /// v3</span></p>
<p><span style="font-family:Microsoft YaHei; font-size:12px; background-color:#99ffff"> { -1, -1, 1 , 0xff00ffff }, /// v4<br> { 1, -1, 1 , 0xffff00ff }, /// v5<br> { 1, -1, -1 , 0xff000000 }, /// v6<br> { -1, -1, -1 , 0xffffffff }, /// v7<br> };</span></p>
<p><span style="font-family:Microsoft YaHei; font-size:12px; background-color:#99ffff"> /// 创建顶点缓冲<br> /// 分配储存八个用户顶点的存储器.<br> /// 指定储存FVF的数据格式.<br> if( FAILED( g_pd3dDevice->CreateVertexBuffer( 8*sizeof(CUSTOMVERTEX),<br> 0, D3DFVF_CUSTOMVERTEX,<br> D3DPOOL_DEFAULT, &g_pVB, NULL ) ) )<b |
|