??xml version="1.0" encoding="utf-8" standalone="yes"?>国产精品国产精品,亚洲精品自在久久,亚洲伊人伊色伊影伊综合网http://www.shnenglu.com/zybdebug/zh-cnSun, 24 Aug 2025 05:22:51 GMTSun, 24 Aug 2025 05:22:51 GMT60理解SkinWeights 骨骼动画http://www.shnenglu.com/zybdebug/archive/2009/09/17/96584.htmlzyb_debugzyb_debugThu, 17 Sep 2009 14:45:00 GMThttp://www.shnenglu.com/zybdebug/archive/2009/09/17/96584.htmlhttp://www.shnenglu.com/zybdebug/comments/96584.htmlhttp://www.shnenglu.com/zybdebug/archive/2009/09/17/96584.html#Feedback1http://www.shnenglu.com/zybdebug/comments/commentRss/96584.htmlhttp://www.shnenglu.com/zybdebug/services/trackbacks/96584.htmlhttp://hi.baidu.com/zyb_debug/blog/item/fbe409eeb8a8b5e5cf1b3e0b.html


阅读 Advanced Animation

谈到SkinWeights里面的TransformMatrix的时候一W带q,我始l不理解q个matrix有何用处Q因为我感觉所有的点变换都被 Frame里面的阶层体pd?那么SkinWeights里面的matrix有什么用?/p>

l过我一个晚上的思考,看了GameDev论坛的帖子,l于理解了?/p>

首先讲徏模,建模建出来的是一些顶点,q些点l成了最原始的mesh?/p>

最原始的mesh中有SkinWeights信息

SkinWeights

{

名字Q?/p>

影响的顶Ҏ(gu)Q?/p>

点的烦引;//是影响了几个顶?/p>

点权重Q?/乘以Frame TransformMatrix的百分比

最后就是一?*4的矩阵;

}

q个4*4矩阵是这旉骼在 Mesh中的位置的逆矩阵,也就是相对于 local坐标pR?/p>

我说的明白点Q手腕是个骨|手指是手腕影响的顶炏V就是一个点,vetexQ在自n坐标pM?/p>

那么?手指这个点 * SkinWeightsMatrix 得到的就是个位置Q什么位|?q当于把手腕连带指移到坐标原炏V当Ӟ手腕在坐标原点的位置?/p>

 

至于Frame中存储的阶层体系矩阵是现在骨骼的位|?/p>

扑ֈ现在手腕骨骼的矩? 手指Vertex* SkinWeighsMatrix*(肩膀的Matrix*背肘的matrix*手腕的matrix)Q?/p>

那么手指自然就变换C相应的位|?/p>

 

我说得这么通俗Q不知道传达到思想没?

参考链?/p>

http://www.gamedev.net/community/forums/topic.asp?topic_id=479158

http://www.gamedev.net/community/forums/topic.asp?topic_id=392242

最后感慨下QGameDev的论坛果然是好地?/p>

zyb_debug 2009-09-17 22:45 发表评论
]]>
在VS中如何部|?h?cpp文ghttp://www.shnenglu.com/zybdebug/archive/2009/09/15/96216.htmlzyb_debugzyb_debugTue, 15 Sep 2009 06:59:00 GMThttp://www.shnenglu.com/zybdebug/archive/2009/09/15/96216.htmlhttp://www.shnenglu.com/zybdebug/comments/96216.htmlhttp://www.shnenglu.com/zybdebug/archive/2009/09/15/96216.html#Feedback0http://www.shnenglu.com/zybdebug/comments/commentRss/96216.htmlhttp://www.shnenglu.com/zybdebug/services/trackbacks/96216.html以前写的l大多数E序都是把cpp,h一股脑儿放在当前目录下?/p>

q样明显是不好的Q前几天我开始构q点d3d库,构徏了些许类之后发现把它们都攑֜当前目录Q也是工程目录下市不好的,应该把它们分cM下?/p>

于是我试了下Q新Z个文件夹Q然后把。h丢进厅R?/p>

l果发现在cpp文g?#include “*****.h”不能~译通过。后来觉得VS里一定有讄L.h,路径的设|?/p>

于是?/p>

在property内看C相应讄Q如?/p>

看到 Additional那个选项没,在那里添加设|\径的地方Q将.h.cpp所在的文g夹包含进d行了?/p>

如图


后来遇到了个预编译头的问题,见上文章吧?

zyb_debug 2009-09-15 14:59 发表评论
]]>
Q{Q预~译头文?/title><link>http://www.shnenglu.com/zybdebug/archive/2009/09/15/96214.html</link><dc:creator>zyb_debug</dc:creator><author>zyb_debug</author><pubDate>Tue, 15 Sep 2009 06:35:00 GMT</pubDate><guid>http://www.shnenglu.com/zybdebug/archive/2009/09/15/96214.html</guid><wfw:comment>http://www.shnenglu.com/zybdebug/comments/96214.html</wfw:comment><comments>http://www.shnenglu.com/zybdebug/archive/2009/09/15/96214.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/zybdebug/comments/commentRss/96214.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/zybdebug/services/trackbacks/96214.html</trackback:ping><description><![CDATA[<p>今天在改一个很大的E序Q慢慢看Q慢慢改。突然发C?c文gQ里面什么也没有Q?/p> <p>几个头文gQ我一看,我靠Q这不是把简单的问题搞复杂了吗,随手删掉那个c文g?/p> <p>l果不能~译了,我靠Q?/p> <p>fatal error C1083: Cannot open precompiled header file: \'Debug/v13_3.pch\':</p> <p>No such file or directory</p> <p>怎么rebuild all都不行?/p> <p>上网查了一下,才搞懂了Q?/p> <p>Q-Q-Q-Q-Q-Q-Q-Q-ȝQ-Q-Q-</p> <p>如果工程很大Q头文g很多Q而有几个头文件又是经常要用的Q那?/p> <p>1。把q些头文件全部写C个头文g里面去,比如写到preh.h</p> <p>2。写一个preh.cQ里面只一句话Q?include "preh.h"</p> <p>3。对于preh.cQ在project setting里面讄creat precompiled headersQ对于其?/p> <p>.c文gQ设|use precompiled header file</p> <p>//</p> <p>哈哈</p> <p>我试了一下,效果很明显,不用precompiled headerQ编译一ơ我可以M个厕所Q用</p> <p>precompiled headerQ编译的时候,我可以站h怸懒腰Q活动活动就差不多啦</p> <p>Q-Q-Q-Q-Q{载的文章Q-Q-Q-Q-Q-</p> <p>预编译头的概念:(x)</p> <p>所谓的预编译头是把一个工E中的那一部分代码,预先~译好放在一个文仉(通常?/p> <p>?pch为扩展名?Q这个文件就UCؓ(f)预编译头文gq些预先~译好的代码可以是Q何的</p> <p>C/C++代码--------甚至是inline的函敎ͼ但是必须是稳定的Q在工程开发的q程中不?/p> <p>被经常改变。如果这些代码被修改Q则需要重新编译生成预~译头文件。注意生成预~?/p> <p>译头文g是很耗时间的。同时你得注意预~译头文仉常很大Q通常?-7M大。注意及(qing)</p> <p>时清理那些没有用的预~译头文件?/p> <p>也许你会(x)问:(x)现在的编译器都有Time stamp的功能,~译器在~译整个工程的时候,?/p> <p>只会(x)~译那些l过修改的文Ӟ而不?x)去~译那些从上ơ编译过Q到现在没有被修改过</p> <p>的文件。那么ؓ(f)什么还要预~译头文件呢Q答案在q里Q我们知道编译器是以文g为单</p> <p>位编译的Q一个文件经q修改后Q会(x)重新~译整个文gQ当然在q个文g里包含的所?/p> <p>头文件中的东西(.eg Macro, Preprocesser Q都要重新处理一遍。VC的预~译头文?/p> <p>保存的正是这部分信息。以避免每次都要重新处理q些头文件?/p> <p>预编译头的作用:(x)</p> <p>Ҏ(gu)上文介绍Q预~译头文件的作用当然是提高便宜速度了,有了它你没有必要每次</p> <p>都编译那些不需要经常改变的代码。编译性能当然提高了?/p> <p>预编译头的用:(x)</p> <p>要用预~译_(d)我们必须指定一个头文gQ这个头文g包含我们不会(x)l常改变?/p> <p>代码和其他的头文Ӟ然后我们用这个头文g来生成一个预~译头文Ӟ.pch文gQ?/p> <p>惛_大家都知?StdAfx.hq个文g。很多h都认是VC提供的一?#8220;pȝU别”?/p> <p>Q编译器带的一个头文g。其实不是的Q这个文件可以是M名字的。我们来考察一?/p> <p>典型的由AppWizard生成的MFC Dialog Based E序的预~译头文件。(因ؓ(f)AppWizard</p> <p>?x)?f)我们指定好如何用预~译头文Ӟ默认的是StdAfx.hQ这是VCL(fng)名字Q。我?/p> <p>?x)发现这个头文g里包含了以下的头文gQ?/p> <p>#include <afxwin.h> // MFC core and standard components</p> <p>#include <afxext.h> // MFC extensions</p> <p>#include <afxdisp.h> // MFC Automation classes</p> <p>#include <afxdtctl.h> // MFC support for Internet Explorer 4</p> <p>Common Controls</p> <p>#include <afxcmn.h></p> <p>q些正是使用MFC的必d含的头文Ӟ当然我们不太可能在我们的工程中修改这些头?/p> <p>件的Q所以说他们是稳定的?/p> <p>那么我们如何指定它来生成预编译头文g。我们知道一个头文g是不能编译的。所以我</p> <p>们还需要一个cpp文g来生?pch 文g。这个文仉认的是StdAfx.cpp。在q个文g</p> <p>里只有一句代码就是:(x)#include “Stdafx.h”。原因是理所当然的,我们仅仅是要它能</p> <p>够编译而已?D?D?D也就是说Q要的只是它?cpp的扩展名。我们可以用/Yc~译开x?/p> <p>定StdAfx.cpp来生成一?pch文gQ通过/Fp~译开x指定生成的pch文g的名字。打</p> <p>开project ->Setting->C/C++ 对话框。把Category指向Precompiled Header。在左边?/p> <p>?wi)Ş视图里选择整个工程 </p> <p>Project Options(右下角的那个白的地方)可以看到 /Fp “debug/PCH.pch”Q这是?/p> <p>定生成的.pch文g的名字,默认的通常是 <工程?gt;.pchQ我的示例工E名是PCHQ?/p> <p>然后Q在左边的树(wi)形视N选择StdAfx.cpp.//q时只能选一个cpp文gQ?/p> <p>q时原来的Project Option变成?Source File OptionQ原来是工程Q现在是一个文?/p> <p>Q当然变了)。在q里我们可以看到 /Yc开养I/Yc的作用就是指定这个文件来创徏一?/p> <p>Pch文g?Yc后面的文件名是那个包含了E_代码的头文gQ一个工E里只能有一个文</p> <p>件的可以有YC开兟뀂VC根据这个选项?StdAfx.cpp~译成一个Obj文g和一个PCH文g</p> <p>?/p> <p>然后我们再选择一个其它的文g来看看,//其他cpp文g</p> <p>在这里,Precomplier 选择?Use ⋯⋯⋯一,头文件是我们指定创徏PCH 文g的stda</p> <p>fx.h</p> <p>文g。事实上Q这里是使用工程里的讄Q(如图1Q?Yu”stdafx.h”?/p> <p>q样Q我们就讄好了预编译头文g。也是_(d)我们可以使用预编译头功能了。以</p> <p>下是注意事项Q?/p> <p>1):如果使用?YuQ就是说使用了预~译Q我们在每个.cpp文g的最开_(d)我强调一?/p> <p>是最开_(d)包含 你指定生pch文g?h文gQ默认是stdafx.hQ不然就?x)有问题。如</p> <p>果你没有包含q个文gQ就告诉你Unexpected file end. 如果你不是在最开头包含的Q?/p> <p>你自p以下q道了Q绝Ҏ(gu)很惊人的效果?.</p> <p>fatal error C1010: unexpected end of file while looking for precompiled</p> <p>header directive</p> <p>Generating Code...</p> <p>2Q如果你把pch文g不小心丢了,~译的时候就?x)生很多的不正常的行?f)。根据以?/p> <p>的分析,你只要让~译器生成一个pch文g。也是说把 stdafx.cppQ即指定/Yc的那?/p> <p>cpp文gQ从新编译一遍。当然你可以d?Rebuild All。简单一点就是选择那个cpp</p> <p>文gQ按一下Ctrl + F7可以了。不然可是很费旉的哦?/p> <p>//</p> <p>呵呵Q如果你居然耐着性子看到了这里,那么再回到帖子最开始看看我的ȝ吧!</p> <img src ="http://www.shnenglu.com/zybdebug/aggbug/96214.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/zybdebug/" target="_blank">zyb_debug</a> 2009-09-15 14:35 <a href="http://www.shnenglu.com/zybdebug/archive/2009/09/15/96214.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>完善Camerac?/title><link>http://www.shnenglu.com/zybdebug/archive/2009/09/14/96159.html</link><dc:creator>zyb_debug</dc:creator><author>zyb_debug</author><pubDate>Mon, 14 Sep 2009 12:59:00 GMT</pubDate><guid>http://www.shnenglu.com/zybdebug/archive/2009/09/14/96159.html</guid><wfw:comment>http://www.shnenglu.com/zybdebug/comments/96159.html</wfw:comment><comments>http://www.shnenglu.com/zybdebug/archive/2009/09/14/96159.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/zybdebug/comments/commentRss/96159.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/zybdebug/services/trackbacks/96159.html</trackback:ping><description><![CDATA[//=========================================<br>   /**<br>   ơ计方?br>   right向量的y分量始终?<br>   */<br>//=========================================<br><br>在Cameracd了一个,以自w位|和目标位置计算look,up,right向量的函?br>void zybCamera::setPositionAndTarget(D3DXVECTOR3* pos,D3DXVECTOR3* target)<br>{<br>   _pos = *pos;<br>   D3DXVECTOR3 look = *target - *pos;<br>   D3DXVec3Normalize(&look,&look);<br>   _look = look; <p>   _right.y = 0;<br>   //正向旋{90°Q想惌己前Ҏ(gu)前向量,又向量自然ؓ(f)前向量旋?0<br>   _right.x = look.z;<br>   _right.z = -look.x;<br>   D3DXVec3Normalize(&_right,&_right);</p> <p>   D3DXVec3Cross(&_up, &_look, &_right);<br>   D3DXVec3Normalize(&_up, &_up);</p> <p><br>}</p> <img src ="http://www.shnenglu.com/zybdebug/aggbug/96159.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/zybdebug/" target="_blank">zyb_debug</a> 2009-09-14 20:59 <a href="http://www.shnenglu.com/zybdebug/archive/2009/09/14/96159.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>扩充完\径库http://www.shnenglu.com/zybdebug/archive/2009/09/14/96100.htmlzyb_debugzyb_debugMon, 14 Sep 2009 03:56:00 GMThttp://www.shnenglu.com/zybdebug/archive/2009/09/14/96100.htmlhttp://www.shnenglu.com/zybdebug/comments/96100.htmlhttp://www.shnenglu.com/zybdebug/archive/2009/09/14/96100.html#Feedback8http://www.shnenglu.com/zybdebug/comments/commentRss/96100.htmlhttp://www.shnenglu.com/zybdebug/services/trackbacks/96100.htmlhttp://hi.baidu.com/zyb_debug/blog/item/87a5d6c3072f8c3fe4dd3b2a.html
׃一个早上的旉Q终于将路径库扩充完毕?/p>

再次感叹一下Animation 那本书实在是太好了?/p>

途中的茶壶会(x)按照自己在外部文件中定义的\径走Q有直线Q有曲线?/p>

外部txt是这样定义的

xof 0303txt 0032

template Path {
<F8569BED-53B6-4923-AF0B-59A09271D556>
DWORD Type;        // 0=straight, 1=curved
Vector Start;
Vector Point1;
Vector Point2;
Vector End;
}

template Route {
<18AA1C92-16AB-47a3-B002-6178F9D2D12F>
DWORD NumPaths;
array Path Paths[NumPaths];
}

Route Robot {
5; // 5 paths

0; // Straight path type
0.0, 10.0,   0.0; // Start
0.0, 10.0,   0.0; // Unused
0.0, 10.0,   0.0; // Unused
0.0, 10.0, 150.0;, // End

1; // Curved path type
    0.0, 10.0, 150.0; // Start
   75.0, 10.0, 150.0; // Point1
150.0, 10.0, 75.0; // Point2
150.0, 10.0,   0.0;, // End

1; // Curved path type
150.0, 10.0,    0.0; // Start
150.0, 10.0, -75.0; // Point1
   75.0, 10.0, -150.0; // Point2
    0.0, 10.0, -150.0;, // End

0; // Straight path type
     0.0, 10.0, -150.0; // Start
     0.0, 10.0,    0.0; // Unused
     0.0, 10.0,    0.0; // Unused
-150.0, 10.0,   75.0;, // End

0; // Straight path type
-150.0, 10.0, 75.0; // Start
     0.0, 10.0,   0.0; // Unused
     0.0, 10.0,   0.0; // Unused
     0.0, 10.0,   0.0;; // End
}

然后用个c解析,Ҏ(gu)旉插值就行了?br>



zyb_debug 2009-09-14 11:56 发表评论
]]>
LoadMesh and DrawMeshhttp://www.shnenglu.com/zybdebug/archive/2009/09/12/96004.htmlzyb_debugzyb_debugSat, 12 Sep 2009 08:04:00 GMThttp://www.shnenglu.com/zybdebug/archive/2009/09/12/96004.htmlhttp://www.shnenglu.com/zybdebug/comments/96004.htmlhttp://www.shnenglu.com/zybdebug/archive/2009/09/12/96004.html#Feedback1http://www.shnenglu.com/zybdebug/comments/commentRss/96004.htmlhttp://www.shnenglu.com/zybdebug/services/trackbacks/96004.htmlhttp://hi.baidu.com/zyb_debug/blog/item/d2ee04171d48ab5bf2de32d7.html
利用上篇文章的D3DXMESHCONTAINER_EXQLoadMesh和DrawMesh都是单的基础cd敎ͼ
以后׃用每ơ蝲入的时候都写那一大堆q_的代码?br>

HRESULT LoadMesh(
        D3DXMESHCONTAINER_EX 
**ppMesh, 
        IDirect3DDevice9 
*pDevice, 
        
char *Filename, char *TexturePath /* =  */,
        DWORD NewFVF 
/* = 0 */, DWORD LoadFlags /* = D3DXMESH_SYSTEMMEM */
        )
    {

        ID3DXMesh 
*pLoadMesh = NULL;
        HRESULT hr;

        
// Error checking
        if(!ppMesh || !pDevice || !Filename || !TexturePath)
            
return E_FAIL;

        
// Use system memory if converting FVF
        DWORD TempLoadFlags = LoadFlags;
        
if(NewFVF)
            TempLoadFlags 
= D3DXMESH_SYSTEMMEM;

        
// Load the mesh using D3DX routines
        ID3DXBuffer *MaterialBuffer = NULL, *AdjacencyBuffer = NULL;
        DWORD NumMaterials;
        
if(FAILED(hr=D3DXLoadMeshFromXA(Filename, TempLoadFlags,
            pDevice, 
&AdjacencyBuffer,
            
&MaterialBuffer, NULL,
            
&NumMaterials, &pLoadMesh)))
            
return hr;

        
// Convert to new FVF first as needed
        if(NewFVF) {
            ID3DXMesh 
*pTempMesh;

            
// Use CloneMeshFVF to convert mesh
            if(FAILED(hr=pLoadMesh->CloneMeshFVF(LoadFlags, NewFVF, pDevice, &pTempMesh))) {
                ReleaseCOM(AdjacencyBuffer);
                ReleaseCOM(MaterialBuffer);
                ReleaseCOM(pLoadMesh);
                
return hr;
            }

            
// Free prior mesh and store new pointer
            ReleaseCOM(pLoadMesh);
            pLoadMesh 
= pTempMesh; pTempMesh = NULL;
        }

        
// Allocate a D3DXMESHCONTAINER_EX structure
        D3DXMESHCONTAINER_EX *pMesh = new D3DXMESHCONTAINER_EX();
        
*ppMesh = pMesh;

        
// Store mesh name (filename), type, and mesh pointer
        pMesh->Name = _strdup(Filename);
        pMesh
->MeshData.Type = D3DXMESHTYPE_MESH;
        pMesh
->MeshData.pMesh = pLoadMesh; pLoadMesh = NULL;

        
// Store adjacency buffer
        DWORD AdjSize = AdjacencyBuffer->GetBufferSize();
        
if(AdjSize) {
            pMesh
->pAdjacency = new DWORD[AdjSize];
            memcpy(pMesh
->pAdjacency, AdjacencyBuffer->GetBufferPointer(), AdjSize);
        }
        ReleaseCOM(AdjacencyBuffer);

        
// Build material list
        if(!(pMesh->NumMaterials = NumMaterials)) {

            
// Create a default material
            pMesh->NumMaterials = 1;
            pMesh
->pMaterials   = new D3DXMATERIAL[1];
            pMesh
->pTextures    = new IDirect3DTexture9*[1];

            ZeroMemory(pMesh
->pMaterials, sizeof(D3DXMATERIAL));
            pMesh
->pMaterials[0].MatD3D.Diffuse.r = 1.0f;
            pMesh
->pMaterials[0].MatD3D.Diffuse.g = 1.0f;
            pMesh
->pMaterials[0].MatD3D.Diffuse.b = 1.0f;
            pMesh
->pMaterials[0].MatD3D.Diffuse.a = 1.0f;
            pMesh
->pMaterials[0].MatD3D.Ambient   = pMesh->pMaterials[0].MatD3D.Diffuse;
            pMesh
->pMaterials[0].MatD3D.Specular  = pMesh->pMaterials[0].MatD3D.Diffuse;
            pMesh
->pMaterials[0].pTextureFilename = NULL;
            pMesh
->pTextures[0]                   = NULL;

        } 
else {

            
// Load the materialsx

            D3DXMATERIAL 
*Materials = (D3DXMATERIAL*)MaterialBuffer->GetBufferPointer();
            pMesh
->pMaterials = new D3DXMATERIAL[pMesh->NumMaterials];
            pMesh
->pTextures  = new IDirect3DTexture9*[pMesh->NumMaterials];

            
for(DWORD i=0;i<pMesh->NumMaterials;i++) {
                pMesh
->pMaterials[i].MatD3D = Materials[i].MatD3D;
                pMesh
->pMaterials[i].MatD3D.Ambient = pMesh->pMaterials[i].MatD3D.Diffuse;

                
// Load the texture if one exists
                pMesh->pTextures[i] = NULL;
                
if(Materials[i].pTextureFilename) {
                    
char TextureFile[MAX_PATH];
                    sprintf_s(TextureFile,MAX_PATH, 
"%s%s", TexturePath, 
                        Materials[i].pTextureFilename);
                    D3DXCreateTextureFromFileA(pDevice,
                        TextureFile,
                        
&pMesh->pTextures[i]);
                }
            }
        }
        ReleaseCOM(MaterialBuffer);

        
// Optimize the mesh for better attribute access
        pMesh->MeshData.pMesh->OptimizeInplace(D3DXMESHOPT_ATTRSORT, NULL, NULL, NULL, NULL);

        
// Clear pMesh pointer just in case
        pMesh = NULL;

        
return S_OK;

    }

    
// Draw the first mesh in a linked list of objects
    HRESULT DrawMesh(D3DXMESHCONTAINER_EX *pMesh)
    {

        IDirect3DDevice9 
*pD3DDevice;
        DWORD LastState, OldAlphaState, OldSrcBlend, OldDestBlend;

        
// Error checking
        if(!pMesh)
            
return E_FAIL;
        
if(!pMesh->MeshData.pMesh)
            
return E_FAIL;
        
if(!pMesh->NumMaterials || !pMesh->pMaterials)
            
return E_FAIL;

        
// Get the device interface
        pMesh->MeshData.pMesh->GetDevice(&pD3DDevice);

        
// Release vertex shader if being used
        pD3DDevice->SetVertexShader(NULL);
        pD3DDevice
->SetVertexDeclaration(NULL);

        
// Save render states
        pD3DDevice->GetRenderState(D3DRS_ALPHABLENDENABLE, &OldAlphaState);
        pD3DDevice
->GetRenderState(D3DRS_SRCBLEND, &OldSrcBlend);
        pD3DDevice
->GetRenderState(D3DRS_DESTBLEND, &OldDestBlend);
        LastState 
= OldAlphaState;

        
// Setup pointer for mesh to draw, either regular or skinned
        ID3DXMesh *pDrawMesh = (!pMesh->pSkinMesh)?pMesh->MeshData.pMesh:pMesh->pSkinMesh;

        
// Look through all subsets
        for(DWORD i=0;i<pMesh->NumMaterials;i++) {

            
// Set material and texture
            pD3DDevice->SetMaterial(&pMesh->pMaterials[i].MatD3D);
            pD3DDevice
->SetTexture(0, pMesh->pTextures[i]);

            
// Enable or disable alpha blending per material
            if(pMesh->pMaterials[i].MatD3D.Diffuse.a != 1.0f) {
                
if(LastState != TRUE) {
                    LastState 
= TRUE;
                    pD3DDevice
->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
                    pD3DDevice
->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);//SRCCOLOR);
                    pD3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_DESTCOLOR);
                }
            } 
else {
                
if(LastState != FALSE) {
                    LastState 
= FALSE;
                    pD3DDevice
->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
                }
            }

            
// Draw the mesh subset
            pDrawMesh->DrawSubset(i);
        }

        
// Restore alpha blending states
        if(LastState != OldAlphaState) {
            pD3DDevice
->SetRenderState(D3DRS_ALPHABLENDENABLE, OldAlphaState);
            pD3DDevice
->SetRenderState(D3DRS_SRCBLEND, OldSrcBlend);
            pD3DDevice
->SetRenderState(D3DRS_DESTBLEND, OldDestBlend);
        }

        
// Make sure to release the device object!
        pD3DDevice->Release();

        
// Return success
        return S_OK;

    }


zyb_debug 2009-09-12 16:04 发表评论
]]>
扩充D3DXMESHCONTAINER和D3DXFramehttp://www.shnenglu.com/zybdebug/archive/2009/09/11/95962.htmlzyb_debugzyb_debugFri, 11 Sep 2009 13:51:00 GMThttp://www.shnenglu.com/zybdebug/archive/2009/09/11/95962.htmlhttp://www.shnenglu.com/zybdebug/comments/95962.htmlhttp://www.shnenglu.com/zybdebug/archive/2009/09/11/95962.html#Feedback0http://www.shnenglu.com/zybdebug/comments/commentRss/95962.htmlhttp://www.shnenglu.com/zybdebug/services/trackbacks/95962.htmlhttp://hi.baidu.com/zyb_debug/blog/item/cb3fe2ca9ca3f015bf09e682.html

开始了Advanced Animation with DirectX的阅?br>基础cd的构建是重要?q后打算把它们加入我的zybToos的Framework里?br>代码来自书中

#ifndef ZYBANIMATIONTOOLS_H

#define ZYBANIMATIONTOOLS_H

#include 
"DXUT.h"

//=========================================
    /**
    扩充D3DXMESHCONTAINER
    扩充D3DXFrame
    
*/
//=========================================


namespace zyb
{

    
#define ReleaseCOM(x) { if(x!=NULL) x->Release(); x=NULL; }

    
// Declare an extended version of D3DXFRAME
    
// that contains a constructor and destructor
    
// as well as a combined transformation matrix
    struct D3DXFRAME_EX : D3DXFRAME 
    {
        D3DXMATRIX matCombined;   
// Combined matrix
        D3DXMATRIX matOriginal;   // Original transformation from .X

        D3DXFRAME_EX()
        {
            Name 
= NULL;
            pMeshContainer 
= NULL;
            pFrameSibling 
= pFrameFirstChild = NULL;
            D3DXMatrixIdentity(
&matCombined);
            D3DXMatrixIdentity(
&matOriginal);
            D3DXMatrixIdentity(
&TransformationMatrix);
        }

        
~D3DXFRAME_EX()
        { 
            delete [] Name;          Name 
= NULL;
            delete pFrameSibling;    pFrameSibling 
= NULL;
            delete pFrameFirstChild; pFrameFirstChild 
= NULL;
        }

        
// Function to scan hierarchy for matching frame name
        D3DXFRAME_EX *Find(const char *FrameName)
        {
            D3DXFRAME_EX 
*pFrame, *pFramePtr;

            
// Return this frame instance if name matched
            if(Name && FrameName && !strcmp(FrameName, Name))
                
return this;

            
// Scan siblings
            if((pFramePtr = (D3DXFRAME_EX*)pFrameSibling)) {
                
if((pFrame = pFramePtr->Find(FrameName)))
                    
return pFrame;
            }

            
// Scan children
            if((pFramePtr = (D3DXFRAME_EX*)pFrameFirstChild)) {
                
if((pFrame = pFramePtr->Find(FrameName)))
                    
return pFrame;
            }

            
// Return none found
            return NULL;
        }

        
// Reset transformation matrices to originals
        void Reset()
        {
            
// Copy original matrix
            TransformationMatrix = matOriginal;

            
// Reset sibling frames
            D3DXFRAME_EX *pFramePtr;
            
if((pFramePtr = (D3DXFRAME_EX*)pFrameSibling))
                pFramePtr
->Reset();

            
// Reset child frames
            if((pFramePtr = (D3DXFRAME_EX*)pFrameFirstChild))
                pFramePtr
->Reset();
        }

        
// Function to combine matrices in frame hiearchy
        void UpdateHierarchy(D3DXMATRIX *matTransformation = NULL)
        {
            D3DXFRAME_EX 
*pFramePtr;
            D3DXMATRIX matIdentity;

            
// Use an identity matrix if none passed
            if(!matTransformation) {
                D3DXMatrixIdentity(
&matIdentity);
                matTransformation 
= &matIdentity;
            }

            
// Combine matrices w/supplied transformation matrix
            matCombined = TransformationMatrix * (*matTransformation);

            
// Combine w/sibling frames
            if((pFramePtr = (D3DXFRAME_EX*)pFrameSibling))
                pFramePtr
->UpdateHierarchy(matTransformation);

            
// Combine w/child frames
            if((pFramePtr = (D3DXFRAME_EX*)pFrameFirstChild))
                pFramePtr
->UpdateHierarchy(&matCombined);
        }

        
void Count(DWORD *Num)
        {
            
// Error checking
            if(!Num)
                
return;

            
// Increase count of frames
            (*Num)+=1;

            
// Process sibling frames
            D3DXFRAME_EX *pFrame;
            
if((pFrame=(D3DXFRAME_EX*)pFrameSibling))
                pFrame
->Count(Num);

            
// Process child frames
            if((pFrame=(D3DXFRAME_EX*)pFrameFirstChild))
                pFrame
->Count(Num);
        }
    };

    
// Declare an extended version of D3DXMESHCONTAINER
    
// that contains a constructor and destructor
    
// as well as an array of textures, a mesh object
    
// that contains the generated skin mesh, and 
    
// matrices that map to the frame hierarchy's and
    
// for updating bones.
    struct D3DXMESHCONTAINER_EX : D3DXMESHCONTAINER
    {
        IDirect3DTexture9 
**pTextures;
        ID3DXMesh          
*pSkinMesh;

        D3DXMATRIX        
**ppFrameMatrices;
        D3DXMATRIX         
*pBoneMatrices;

        D3DXMESHCONTAINER_EX()
        {
            Name               
= NULL;
            MeshData.pMesh     
= NULL;
            pMaterials         
= NULL;
            pEffects           
= NULL;
            NumMaterials       
= 0;
            pAdjacency         
= NULL;
            pSkinInfo          
= NULL;
            pNextMeshContainer 
= NULL;
            pTextures          
= NULL;
            pSkinMesh          
= NULL;
            ppFrameMatrices    
= NULL;
            pBoneMatrices      
= NULL;
        }

        
~D3DXMESHCONTAINER_EX()
        {
            
if(pTextures && NumMaterials) {
                
for(DWORD i=0;i<NumMaterials;i++)
                    ReleaseCOM(pTextures[i]);
            }
            delete [] pTextures;       pTextures 
= NULL;
            NumMaterials 
= 0;

            delete [] Name;            Name 
= NULL;
            delete [] pMaterials;      pMaterials 
= NULL;
            delete pEffects;           pEffects 
= NULL;

            delete [] pAdjacency;      pAdjacency 
= NULL;
            delete [] ppFrameMatrices; ppFrameMatrices 
= NULL;
            delete [] pBoneMatrices;   pBoneMatrices 
= NULL;

            ReleaseCOM(MeshData.pMesh);
            ReleaseCOM(pSkinInfo);
            ReleaseCOM(pSkinMesh);

            delete pNextMeshContainer; pNextMeshContainer 
= NULL;
        }

        D3DXMESHCONTAINER_EX 
*Find(char *MeshName)
        {
            D3DXMESHCONTAINER_EX 
*pMesh, *pMeshPtr;

            
// Return this mesh instance if name matched
            if(Name && MeshName && !strcmp(MeshName, Name))
                
return this;

            
// Scan next in list
            if((pMeshPtr = (D3DXMESHCONTAINER_EX*)pNextMeshContainer)) {
                
if((pMesh = pMeshPtr->Find(MeshName)))
                    
return pMesh;
            }

            
// Return none found
            return NULL;
        }
    };

    

    








}


#endif


zyb_debug 2009-09-11 21:51 发表评论
]]>
上自?/title><link>http://www.shnenglu.com/zybdebug/archive/2009/09/10/95857.html</link><dc:creator>zyb_debug</dc:creator><author>zyb_debug</author><pubDate>Thu, 10 Sep 2009 14:15:00 GMT</pubDate><guid>http://www.shnenglu.com/zybdebug/archive/2009/09/10/95857.html</guid><wfw:comment>http://www.shnenglu.com/zybdebug/comments/95857.html</wfw:comment><comments>http://www.shnenglu.com/zybdebug/archive/2009/09/10/95857.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.shnenglu.com/zybdebug/comments/commentRss/95857.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/zybdebug/services/trackbacks/95857.html</trackback:ping><description><![CDATA[<p><a >http://hi.baidu.com/zyb_debug/blog/item/e7072b10295eb074cb80c42a.html</a><br>ogre的强大让我忍不住想用它?/p> <p>q几天快要看完那本书了,q剩动态阴影和2D。明天应该就可以完结了?/p> <p>~程之美看了l论前面引言Q我发现2q来我忽视了一个重要的东西是法。幸好我在大三这一q刚开始发C?/p> <p>DirectX中基q有Animation不太懂,不过我已l打CAdvanced Animation with DirectX9?/p> <p>听着MP3中《音乐天堂》精选,学习(fn)完后走在大学的\上?/p> <p>感觉ȝ是如此的q?...</p> <img src ="http://www.shnenglu.com/zybdebug/aggbug/95857.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/zybdebug/" target="_blank">zyb_debug</a> 2009-09-10 22:15 <a href="http://www.shnenglu.com/zybdebug/archive/2009/09/10/95857.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>实作ADTvector2 vector3 vector4 matrix44 matrix33http://www.shnenglu.com/zybdebug/archive/2009/09/08/95543.htmlzyb_debugzyb_debugTue, 08 Sep 2009 02:46:00 GMThttp://www.shnenglu.com/zybdebug/archive/2009/09/08/95543.htmlhttp://www.shnenglu.com/zybdebug/comments/95543.htmlhttp://www.shnenglu.com/zybdebug/archive/2009/09/08/95543.html#Feedback4http://www.shnenglu.com/zybdebug/comments/commentRss/95543.htmlhttp://www.shnenglu.com/zybdebug/services/trackbacks/95543.html阅读全文

zyb_debug 2009-09-08 10:46 发表评论
]]>
关于while(cin)http://www.shnenglu.com/zybdebug/archive/2009/09/06/95409.htmlzyb_debugzyb_debugSun, 06 Sep 2009 06:38:00 GMThttp://www.shnenglu.com/zybdebug/archive/2009/09/06/95409.htmlhttp://www.shnenglu.com/zybdebug/comments/95409.htmlhttp://www.shnenglu.com/zybdebug/archive/2009/09/06/95409.html#Feedback3http://www.shnenglu.com/zybdebug/comments/commentRss/95409.htmlhttp://www.shnenglu.com/zybdebug/services/trackbacks/95409.htmlhttp://hi.baidu.com/zyb_debug/blog/item/cdfc2adf9b982451cdbf1a7e.html
streams定义了两个可用于布尔表达式的函数

operator void*()   意义Qstream是否出错Q相当于!fail()Q?br>operator !()       意义Qstream是否已出错(相当于fail()Q?/p>

我们可以q用operator void*()在控制结构中z测出stream的当前状?

while (std::cin)
{
}
控制l构中的布尔条g值ƈ不是非得直接转换为bool不可Q只要能够{换ؓ(f)某个整数型别或指针型别就够了?br>转换为void* 常常是ؓ(f)了在同一表达式中d对象q测试是否成功:(x)

if(std::cin>> x)
{
//reading x was successful
}
正如先前的讨论,表达?br>std::cin >> x
?x)返回cinQ所以读入x后,上述语句变ؓ(f)
if(std::cin)
{
}

此时的cin被用于条件判?所以cin?x)调?operator void*,q回"stream是否发生错误"

以上技术的几个典型应用是以@环读入对象ƈ处理
while(std::cin >> obj)
{
std:: cout << obj << std::endl;
}

如果failbit或badbit被设立,该@环就立即中止---出现错误或者读?end-of-file).

我们可以利用operator!q行相反试Q它?x)返?strean是否已发生错?Q也是说如果failbit 或badbit被设立就?x)返回true用法如下:
if(!std::cin)
{
//the stream is not OK
}

上述文字Z <<c++标准E序?自修教程与参考手?>>p600 侯捷-孟岩?/p>

׃几天旉l于这本书阅读完了Q里面的streambuf没有理解Q是我功底不够的~故?..
开学了Qh多了hQl静静的学习(fn)



zyb_debug 2009-09-06 14:38 发表评论
]]>
˳wwwþþ| þ붯aëƬ| Ů㽶þ**ëƬƷ| Ʒþˬۺ| ľƷ99þù| wwwþþcom| ҹƷþþþþþ| ޹Ʒþþ| 99þһ| Ļþҹ| ƷƵþþþ| þþþþۺһĻ| ޾ƷWWWþþþþ| ٸ޾þþþþ | 99鶹þþùƷ| ˶ݺɫۺϾþ| þĻƷ| ޹Ʒþþþ| ƷþĻ| þô̫㽶av| 99þóĻ| þ| پþþƷþ| þŷƷ| þþֻоƷձ| þþþ뾫Ʒ| Ʒۺþþþþ| Ʒþþþþ| þùĻ| þ99Ʒ| ҹҹݺݾþAV| 99ξþþŷƷվ| ŷƷ˿þþĻ| þ㽶߿ۿ| þ97þ97Ʒӿ| þ91ƷۺϹҳ| þþ޾Ʒһ| ŷƷһþĻ| һŷƬþ| 鶹þ| ޵һƷƷþ|