关键帧做的立方体动画

论坛 期权论坛     
选择匿名的用户   2021-5-30 03:14   260   0
<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 &#34;stdafx.h&#34;<br> #include &#34;关键帧动画实现月亮地球.h&#34;<br> #include&lt;d3d9.h&gt;<br> #include&lt;d3dx9.h&gt;<br> #include&lt;Windows.h&gt;<br> #pragma comment(lib, &#34;d3d9.lib&#34;)<br> #pragma comment(lib, &#34;d3dx9.lib&#34;)<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         &#61; NULL ;<br> LPDIRECT3DDEVICE9        g_pd3dDevice   &#61; NULL ;<br> LPDIRECT3DVERTEXBUFFER9  g_pVB          &#61; NULL ;<br> LPDIRECT3DINDEXBUFFER9   g_pIB          &#61; 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 &#61;&#61; ( g_pD3D &#61;Direct3DCreate9 ( D3D_SDK_VERSION ) ))<br>   return E_FAIL;<br>  //创建设备的结构体<br>  D3DPRESENT_PARAMETERS d3dpp;<br>  ZeroMemory(&amp;d3dpp ,sizeof(d3dpp));<br>  d3dpp.Windowed                 &#61; TRUE;<br>  d3dpp.SwapEffect               &#61; D3DSWAPEFFECT_DISCARD;<br>  d3dpp.BackBufferFormat         &#61; D3DFMT_UNKNOWN;<br>  d3dpp.EnableAutoDepthStencil   &#61; TRUE;<br>  d3dpp.AutoDepthStencilFormat   &#61; D3DFMT_D16;</span></p>
<p><span style="font-family:Microsoft YaHei; font-size:12px; background-color:#99ffff">  if( FAILED( g_pD3D-&gt;CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,<br>                                       D3DCREATE_SOFTWARE_VERTEXPROCESSING,<br>                                       &amp;d3dpp, &amp;g_pd3dDevice ) ) )<br>      return E_FAIL;</span></p>
<p><span style="font-family:Microsoft YaHei; font-size:12px; background-color:#99ffff">  //实现卷起功能<br>   g_pd3dDevice-&gt;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-&gt;SetRenderState(D3DRS_ZENABLE , TRUE );</span></p>
<p><span style="font-family:Microsoft YaHei; font-size:12px; background-color:#99ffff">  //顶点具有颜色,能起到光源的功能<br>   g_pd3dDevice-&gt;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[] &#61;<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-&gt;CreateVertexBuffer( 8*sizeof(CUSTOMVERTEX),<br>                                                   0, D3DFVF_CUSTOMVERTEX,<br>                                                   D3DPOOL_DEFAULT, &amp;g_pVB, NULL ) ) )<b
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP