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

posts - 311, comments - 0, trackbacks - 0, articles - 0
  C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

(搬運工)Ogre動畫拾取函數

Posted on 2011-09-20 14:22 點點滴滴 閱讀(758) 評論(0)  編輯 收藏 引用 所屬分類: 08 游戲SDK
IEntity* GraphicalWorld::pickEntity(const Ray& ray, uint32 mask)
    {
        WS_ASSERT( msCore );
// 
//         const unsigned long mask = 0xFFFFFFFF;
        Ogre::Ray ogreRay( VEC_WS2OGRE(ray.getOrigin()), VEC_WS2OGRE(ray.getDirection()) );
        
if (!mpRaySceneQuery)
        {
            mpRaySceneQuery 
= msCore->getSceneMgr()->createRayQuery( ogreRay, mask );            
        }
        
else
        {
            mpRaySceneQuery
->setRay(ogreRay );    
            mpRaySceneQuery
->setQueryMask(mask);
        }        
        mpRaySceneQuery
->setSortByDistance(true);
        
        Ogre::Real closest_distance 
= 99999.0f;
        Ogre::RaySceneQueryResult 
&query_result = mpRaySceneQuery->execute();
        Ogre::MovableObject
* movable;
        IEntity
* pEntity = NULL;


        
for (size_t qr_idx = 0; qr_idx < query_result.size(); qr_idx++)
        {
            
// stop checking if we have found a raycast hit that is closer
            
// than all remaining entities
            if ((closest_distance >= 0.0f&& (closest_distance < query_result[qr_idx].distance))
                
break;

            
// only check this result if its a hit against an entity
            movable = query_result[qr_idx].movable;            
            
if (( movable != NULL) && (movable->getMovableType().compare("Entity"== 0&& movable->isVisible())
            {
                
                EntityMap::const_iterator itFind 
= mEntityMap.find( static_cast<Ogre::Entity*>(movable));
                
if (itFind == mEntityMap.end())
                    
continue;

                
// get the entity to check
                Ogre::Entity *pentity = static_cast<Ogre::Entity*>(movable);

                
// mesh data to retrieve
                size_t vertex_count;
                size_t index_count;

                pentity
->_getSkelAnimVertexData();
                
// get the mesh information
                GetMeshInformation(pentity, vertex_count, index_count, 
                    pentity
->getParentNode()->_getDerivedPosition(),
                    pentity
->getParentNode()->_getDerivedOrientation(),
                    pentity
->getParentNode()->_getDerivedScale());

                
// test for hitting individual triangles on the mesh
                bool new_closest_found = false;
                
for (int i = 0; i < static_cast<int>(index_count); i += 3)
                {
                    assert(mIndexBuffer[i] 
< vertex_count);
                    assert(mIndexBuffer[i 
+ 1< vertex_count);
                    assert(mIndexBuffer[i 
+ 2< vertex_count);
                    
// check for a hit against this triangle

                    std::pair
<bool, Ogre::Real> hit = Ogre::Math::intersects(ogreRay, mVertexBuffer[mIndexBuffer[i]],
                        mVertexBuffer[mIndexBuffer[i
+1]], mVertexBuffer[mIndexBuffer[i+2]], truefalse);

                    
// if it was a hit check if its the closest
                    if (hit.first)
                    {
                        
if ((closest_distance < 0.0f|| (hit.second < closest_distance))
                        {
                            
// this is the closest so far, save it off
                            closest_distance = hit.second;
                            new_closest_found 
= true;
                        }
                    }
                }

                
// if we found a new closest raycast for this object, update the
                
// closest_result before moving on to the next object.
                if (new_closest_found)
                {
                    pEntity 
= itFind->second;
                }
            }
        }


//         Ogre::RaySceneQueryResult &result = mpRaySceneQuery->execute();
//         Ogre::RaySceneQueryResult::iterator it = result.begin();
//         if (it != result.end())
//         {
//             //it->distance
//             //if (it->worldFragment)
//             if (it->movable)
//             {
//                 //Ogre::UserDefinedObject* udo = Ogre::MovableObject::getUserObject();
//                 if (it->movable->getMovableType() == "Entity")
//                 {
//                     EntityMap::const_iterator itFind = mEntityMap.find( static_cast<Ogre::Entity*>( it->movable ) );
//                     if (itFind != mEntityMap.end())
//                         return itFind->second;
//                 }
//             }
//         }
        return pEntity;
    }

取得動畫頂點數據
void GetMeshInformation(const Entity *entity,
                                size_t 
&vertex_count,
                                Ogre::Vector3
* &vertices,
                                size_t 
&index_count,
                                unsigned 
long* &indices,
                                
const Ogre::Vector3 &position,
                                
const Ogre::Quaternion &orient,
                                
const Ogre::Vector3 &scale)
{
    
bool added_shared = false;
    size_t current_offset 
= 0;
    size_t shared_offset 
= 0;
    size_t next_offset 
= 0;
    size_t index_offset 
= 0;
    vertex_count 
= index_count = 0;
 
   Ogre::MeshPtr mesh 
= entity->getMesh();
 
 
   
bool useSoftwareBlendingVertices = entity->hasSkeleton();
 
   
if (useSoftwareBlendingVertices)
   {
      entity
->_updateAnimation();
   }
 
    
// Calculate how many vertices and indices we're going to need
    for (unsigned short i = 0; i < mesh->getNumSubMeshes(); ++i)
    {
        Ogre::SubMesh
* submesh = mesh->getSubMesh( i );
 
        
// We only need to add the shared vertices once
        if(submesh->useSharedVertices)
        {
            
if!added_shared )
            {
                vertex_count 
+= mesh->sharedVertexData->vertexCount;
                added_shared 
= true;
            }
        }
        
else
        {
            vertex_count 
+= submesh->vertexData->vertexCount;
        }
 
        
// Add the indices
        index_count += submesh->indexData->indexCount;
    }
 
 
    
// Allocate space for the vertices and indices
    vertices = new Ogre::Vector3[vertex_count];
    indices 
= new unsigned long[index_count];
 
    added_shared 
= false;
 
    
// Run through the submeshes again, adding the data into the arrays
    for ( unsigned short i = 0; i < mesh->getNumSubMeshes(); ++i)
    {
        Ogre::SubMesh
* submesh = mesh->getSubMesh(i);
 
      
//----------------------------------------------------------------
      
// GET VERTEXDATA
      
//----------------------------------------------------------------
 
        
//Ogre::VertexData* vertex_data = submesh->useSharedVertices ? mesh->sharedVertexData : submesh->vertexData;
      Ogre::VertexData* vertex_data;
 
      
//When there is animation:
      if(useSoftwareBlendingVertices)
#ifdef BUILD_AGAINST_AZATHOTH
         vertex_data 
= submesh->useSharedVertices ? entity->_getSharedBlendedVertexData() : entity->getSubEntity(i)->_getBlendedVertexData();
#else
         vertex_data 
= submesh->useSharedVertices ? entity->_getSkelAnimVertexData() : entity->getSubEntity(i)->_getSkelAnimVertexData();
#endif
      
else
         vertex_data 
= submesh->useSharedVertices ? mesh->sharedVertexData : submesh->vertexData;
 
 
        
if((!submesh->useSharedVertices)||(submesh->useSharedVertices && !added_shared))
        {
            
if(submesh->useSharedVertices)
            {
                added_shared 
= true;
                shared_offset 
= current_offset;
            }
 
            
const Ogre::VertexElement* posElem =
                vertex_data
->vertexDeclaration->findElementBySemantic(Ogre::VES_POSITION);
 
            Ogre::HardwareVertexBufferSharedPtr vbuf 
=
                vertex_data
->vertexBufferBinding->getBuffer(posElem->getSource());
 
            unsigned 
char* vertex =
                static_cast
<unsigned char*>(vbuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
 
            
// There is _no_ baseVertexPointerToElement() which takes an Ogre::Real or a double
            
//  as second argument. So make it float, to avoid trouble when Ogre::Real will
            
//  be comiled/typedefed as double:
            
//      Ogre::Real* pReal;
            float* pReal;
 
            
for( size_t j = 0; j < vertex_data->vertexCount; ++j, vertex += vbuf->getVertexSize())
            {
                posElem
->baseVertexPointerToElement(vertex, &pReal);
 
                Ogre::Vector3 pt(pReal[
0], pReal[1], pReal[2]);
 
                vertices[current_offset 
+ j] = (orient * (pt * scale)) + position;
            }
 
            vbuf
->unlock();
            next_offset 
+= vertex_data->vertexCount;
        }
 
 
        Ogre::IndexData
* index_data = submesh->indexData;
        size_t numTris 
= index_data->indexCount / 3;
        Ogre::HardwareIndexBufferSharedPtr ibuf 
= index_data->indexBuffer;
 
        
bool use32bitindexes = (ibuf->getType() == Ogre::HardwareIndexBuffer::IT_32BIT);
 
        unsigned 
long*  pLong = static_cast<unsigned long*>(ibuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
        unsigned 
short* pShort = reinterpret_cast<unsigned short*>(pLong);
 
 
        size_t offset 
= (submesh->useSharedVertices)? shared_offset : current_offset;
        size_t index_start 
= index_data->indexStart;
        size_t last_index 
= numTris*3 + index_start;
 
        
if (use32bitindexes)
            
for (size_t k = index_start; k < last_index; ++k)
            {
                indices[index_offset
++= pLong[k] + static_cast<unsigned long>( offset );
            }
 
        
else
            
for (size_t k = index_start; k < last_index; ++k)
            {
                indices[ index_offset
++ ] = static_cast<unsigned long>( pShort[k] ) +
                    static_cast
<unsigned long>( offset );
            }
 
        ibuf
->unlock();
        current_offset 
= next_offset;
    }
}




青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            国产亚洲一区在线播放| 午夜久久福利| 欧美在线免费| 欧美一区三区二区在线观看| 亚洲综合不卡| 欧美一区二区| 欧美黄色一区| 在线性视频日韩欧美| 一本在线高清不卡dvd| 亚洲视频欧美在线| 欧美在线视频a| 男女激情视频一区| 欧美日一区二区在线观看 | 久久久久久久999| 欧美电影专区| 在线亚洲自拍| 久久久精彩视频| 欧美日韩国产在线播放| 国产精品一区在线观看| 18成人免费观看视频| 99精品免费| 久久久99国产精品免费| 亚洲精品乱码久久久久久按摩观| 亚洲作爱视频| 久久婷婷人人澡人人喊人人爽| 欧美激情一区二区三区| 国产日韩精品视频一区| 日韩一级网站| 久久夜色精品国产欧美乱| 日韩亚洲成人av在线| 久久久免费av| 国产精品午夜在线| 99国产麻豆精品| 蜜桃av综合| 性色av一区二区三区在线观看| 欧美精品导航| 亚洲国产精品999| 久久久久久久综合| 亚洲中无吗在线| 欧美日韩四区| 亚洲精品乱码久久久久久蜜桃91| 久久xxxx精品视频| 亚洲一级黄色片| 欧美日本精品| 亚洲精品一区在线| 欧美黄色成人网| 久久久www成人免费毛片麻豆| 国产精品日韩久久久| 亚洲一卡久久| 一区二区三区欧美视频| 欧美日韩国产综合久久| 亚洲区国产区| 欧美激情综合色| 欧美aa在线视频| 亚洲人www| 亚洲国产欧美一区二区三区同亚洲| 久久岛国电影| 影院欧美亚洲| 欧美成人精品三级在线观看| 久久精品视频在线| 亚洲综合电影| 亚洲欧美激情在线视频| 国产精品第一页第二页第三页| 99国产精品| 亚洲美女黄网| 欧美性猛交xxxx乱大交退制版| 99视频+国产日韩欧美| 亚洲欧洲日夜超级视频| 欧美精品国产一区| 亚洲图片激情小说| 日韩一二三在线视频播| 欧美午夜精品久久久久久浪潮 | 欧美激情欧美狂野欧美精品| 久久综合电影| 亚洲免费观看高清完整版在线观看熊| 欧美国产成人在线| 欧美精品久久久久久久| 亚洲天天影视| 欧美一区免费视频| 亚洲国产精品成人精品| 亚洲精品欧美专区| 国产精品美女久久久免费| 久久久久久久999精品视频| 久久久久在线观看| 99视频精品在线| 亚洲欧美日韩国产一区| 亚洲第一区在线| 一本不卡影院| 亚洲第一精品在线| 99国产精品久久久| 好吊成人免视频| 日韩手机在线导航| 国产尤物精品| 亚洲美女视频在线观看| 国产亚洲毛片| 亚洲精品国产精品乱码不99| 国产精品区一区二区三| 欧美成人小视频| 国产精品久久毛片a| 免费日韩精品中文字幕视频在线| 欧美日韩ab片| 欧美成人精品在线播放| 国产精品欧美一区二区三区奶水| 欧美.www| 国产亚洲欧洲| 亚洲午夜久久久| 日韩视频亚洲视频| 久久久在线视频| 欧美在线免费一级片| 欧美日韩国产专区| 欧美韩日一区二区三区| 国产亚洲一级| 亚洲永久免费观看| 一区二区三区四区精品| 六月丁香综合| 久久久久久欧美| 国产麻豆成人精品| 亚洲视频精品| 亚洲综合三区| 欧美视频精品在线| 亚洲精品一品区二品区三品区| 伊人成人在线| 国语自产精品视频在线看抢先版结局 | 欧美 日韩 国产精品免费观看| 欧美日韩一区三区四区| 免费在线国产精品| 国产中文一区| 欧美一区二区三区四区视频| 亚洲欧美日韩高清| 欧美性事在线| 夜夜精品视频| 亚洲欧美日韩另类| 国产精品久久久久久久浪潮网站| 亚洲免费观看高清完整版在线观看熊 | 美女视频网站黄色亚洲| 国产精品免费视频观看| 亚洲视频在线观看一区| 在线亚洲欧美| 国产精品久久久久久久久久免费| 日韩亚洲精品视频| 亚洲天堂网在线观看| 欧美视频久久| 亚洲一区二区在线观看视频| 午夜精品亚洲| 国产香蕉久久精品综合网| 久久成人免费日本黄色| 暖暖成人免费视频| 亚洲乱码精品一二三四区日韩在线 | 欧美成人在线影院| 最新亚洲视频| 欧美日韩一二三区| 亚洲欧美日本国产专区一区| 久久久91精品国产一区二区精品| 很黄很黄激情成人| 久久中文字幕导航| 亚洲乱码一区二区| 欧美一区网站| 亚洲福利视频免费观看| 欧美激情一区二区三区全黄| 一区二区欧美精品| 久久另类ts人妖一区二区| 亚洲人成人77777线观看| 欧美日韩精品欧美日韩精品| 一区二区三区产品免费精品久久75 | 欧美日韩中国免费专区在线看| 一个人看的www久久| 久久久国产精品亚洲一区| 亚洲国产精品一区二区久| 欧美日本一区| 国产一区二区精品| 欧美激情一区二区三区高清视频| 亚洲精品国产精品国自产观看| 欧美日韩国产综合在线| 亚洲一级黄色| 蜜乳av另类精品一区二区| 宅男精品导航| 伊人久久综合97精品| 欧美日韩中文另类| 久久免费99精品久久久久久| 一区二区三区欧美在线| 美国十次了思思久久精品导航| 99在线观看免费视频精品观看| 国产人久久人人人人爽| 欧美精品粉嫩高潮一区二区 | 精品动漫一区二区| 欧美四级电影网站| 麻豆精品传媒视频| 午夜精品短视频| 亚洲九九爱视频| 欧美1区视频| 久久国产一区二区| 亚洲一区二区三区免费观看| 亚洲高清一区二区三区| 欧美99在线视频观看| 性做久久久久久久免费看| 亚洲卡通欧美制服中文| 激情欧美一区二区三区在线观看 | 国产欧美精品一区aⅴ影院| 欧美伦理影院| 欧美精品一区二区久久婷婷|