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

            的筆記

            隨時隨地編輯

            相機坐標、視景體、變換矩陣

            引子
            有這樣一個問題,動態顯示當前實體的世界坐標、相機坐標、透視投影坐標,以及當前視圖坐標變換矩陣、透視投影矩陣。

            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坐標顯示的是鼠標所在實體的中心點在相機坐標系中的坐標。看代碼的line40,視圖矩陣乘以點的世界坐標,得到了這個點的在相機坐標系中的坐標。

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

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

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

            国产精品99久久精品| 国产一级持黄大片99久久| 性欧美大战久久久久久久久| 国产精品久久久久久久久| 久久99久久99精品免视看动漫| 久久精品一区二区三区中文字幕| 亚洲va中文字幕无码久久| 亚洲国产精品成人久久蜜臀 | 国产高潮国产高潮久久久| 欧美一区二区精品久久| 狠狠色丁香婷婷综合久久来来去| 久久久久久极精品久久久| 国产精品亚洲美女久久久| 伊人久久大香线蕉亚洲五月天| 99国产精品久久久久久久成人热| 国产午夜福利精品久久2021| 99久久久精品免费观看国产| 亚洲国产精品人久久| 色老头网站久久网| 久久久无码一区二区三区| 深夜久久AAAAA级毛片免费看| 国内精品久久久久影院一蜜桃| 97久久精品国产精品青草| 国产午夜久久影院| 久久综合一区二区无码| 久久综合丝袜日本网| 四虎影视久久久免费观看| 亚洲综合伊人久久综合| 亚洲天堂久久精品| 精品久久人人爽天天玩人人妻 | 亚洲精品乱码久久久久久蜜桃不卡 | 成人综合久久精品色婷婷| 99热成人精品免费久久| 亚洲伊人久久综合影院| 精品蜜臀久久久久99网站| 久久久久亚洲精品男人的天堂 | 青草国产精品久久久久久 | 天堂无码久久综合东京热| 久久久久亚洲精品天堂| 久久天天躁狠狠躁夜夜av浪潮| 色欲综合久久中文字幕网|