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

            的筆記

            隨時隨地編輯

            相機坐標(biāo)、視景體、變換矩陣

            引子
            有這樣一個問題,動態(tài)顯示當(dāng)前實體的世界坐標(biāo)、相機坐標(biāo)、透視投影坐標(biāo),以及當(dāng)前視圖坐標(biāo)變換矩陣、透視投影矩陣。

            code:
             1/**
             2* This little snippet gets the Transformatio coordinates for a MovableObject
             3*
             4* @param   object   The object to retrieve the coordidnates of.
             5* @param   camera   The active camera
             6* @param   viewPosition   The Vector3 to store the view position in
             7* @param   ProjectionPosition   The Vector3 to store the projection position in
             8*
             9* @return   Returns true if the object is visible and the coordinates were
            10*         retrieved, false otherwise.
            11*/

            12bool getTransformationCoords(Ogre::MovableObject* object, Ogre::Camera* camera, Ogre::Vector3&viewPosition  , Ogre::Vector3&ProjectionPosition)
            13{
            14
            15    if(!object->isInScene())
            16        return false;
            17
            18    const Ogre::AxisAlignedBox &AABB = object->getWorldBoundingBox(true);
            19    /**
            20    * If you need the point above the object instead of the center point:
            21    * This snippet derives the average point between the top-most corners of the bounding box
            22    * Ogre::Vector3 point = (AABB.getCorner(AxisAlignedBox::FAR_LEFT_TOP)
            23    *    + AABB.getCorner(AxisAlignedBox::FAR_RIGHT_TOP)
            24    *    + AABB.getCorner(AxisAlignedBox::NEAR_LEFT_TOP)
            25    *    + AABB.getCorner(AxisAlignedBox::NEAR_RIGHT_TOP)) / 4;
            26    */

            27
            28
            29    // Get the center point of the object's bounding box
            30    const Ogre::Vector3& point = AABB.getCenter();
            31
            32    // Is the camera facing that point? If not, return false
            33    Ogre::Plane cameraPlane = Plane(Vector3(camera->getDerivedOrientation().zAxis()), camera->getDerivedPosition());
            34
            35    if(cameraPlane.getSide(point) != Plane::NEGATIVE_SIDE)
            36        return false;
            37
            38    // Transform the 3D point into screen space
            39    //point = camera->getProjectionMatrix() * (camera->getViewMatrix() * point);
            40    viewPosition = camera->getViewMatrix() * point;
            41    ProjectionPosition = camera->getProjectionMatrix() * viewPosition;
            42
            43
            44    // Transform from coordinate space [-1, 1] to [0, 1] and update in-value
            45    ProjectionPosition.x = (ProjectionPosition.x / 2+ 0.5f;
            46    ProjectionPosition.y = 1 - ((ProjectionPosition.y / 2+ 0.5f);
            47
            48    return true;
            49}

            示意圖:


            分析:
            1. view坐標(biāo)顯示的是鼠標(biāo)所在實體的中心點在相機坐標(biāo)系中的坐標(biāo)。看代碼的line40,視圖矩陣乘以點的世界坐標(biāo),得到了這個點的在相機坐標(biāo)系中的坐標(biāo)。

            2. projection坐標(biāo)(0.2,0.2,1.0)表示的是屏幕坐標(biāo)系的坐標(biāo)。代碼的line41,透視投影矩陣乘以點的相機坐標(biāo),得到了這個點的透視變換坐標(biāo)。這個坐標(biāo)的范圍是[-1,1],需要變換到[0,1],代碼line45、46完成了這項映射變換。

            3.矩陣窗口顯示的是當(dāng)前視圖變換矩陣和投影變換矩陣。動態(tài)運行后可以發(fā)現(xiàn)投影矩陣一直不變。視圖矩陣隨著相機的移動、選擇在動態(tài)變換。
            視圖矩陣變換規(guī)律:
            相機沿著front方向變化:row3的z項變化,其他項均不變。
            相機沿著left方向變化,row0的z項目變化,其他項均不變。
            相機沿著top方向變化,row2的z項變化,其他項均不變。
            相機yaw?pitch?roll?
            任何時候row3都不變:{0 ,0 , 0 , 1}

            posted on 2011-06-20 21:51 的筆記 閱讀(1368) 評論(0)  編輯 收藏 引用


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


            久久天堂电影网| 久久久久亚洲av无码专区 | 久久久久亚洲av无码专区导航| 欧美亚洲国产精品久久| 伊人久久综合精品无码AV专区| 久久亚洲欧美国产精品| 久久99精品国产99久久6| 亚洲日本va午夜中文字幕久久| 久久人人爽人人爽人人av东京热| 久久国产精品无码一区二区三区| 久久久精品久久久久久 | 精品多毛少妇人妻AV免费久久| 久久婷婷五月综合97色| 99久久成人18免费网站| 狠狠色综合网站久久久久久久高清 | 青青草国产97免久久费观看| 亚洲AV无码久久精品成人| 久久99精品国产99久久6男男| 亚洲国产成人久久一区WWW| 狠狠狠色丁香婷婷综合久久俺| 久久精品免费一区二区| 久久久久国产精品麻豆AR影院| 精品精品国产自在久久高清| 伊人情人综合成人久久网小说| 国产精品久久久久影院嫩草| 久久精品国产AV一区二区三区| 91精品免费久久久久久久久| 久久精品人人做人人妻人人玩| 日韩电影久久久被窝网| 99久久国产亚洲高清观看2024| 久久亚洲日韩精品一区二区三区| 久久免费香蕉视频| 国产精品免费看久久久香蕉| 久久香蕉综合色一综合色88| 久久久久免费看成人影片| 久久亚洲精品成人AV| 久久精品人人槡人妻人人玩AV| 精品永久久福利一区二区| 久久精品国产亚洲AV麻豆网站| 久久天天躁狠狠躁夜夜96流白浆 | 久久精品18|