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

            的筆記

            隨時隨地編輯

            法線、平面、頂點、數學

            第一天,神說要有math,要計算法線,于是就有了Ogre::math,有了法線計算。

                    /** Calculate a face normal, including the w component which is the offset from the origin. */
                    
            static Vector4 calculateFaceNormal(const Vector3& v1, const Vector3& v2, const Vector3& v3);
                    
            /** Calculate a face normal, no w-information. */
                    
            static Vector3 calculateBasicFaceNormal(const Vector3& v1, const Vector3& v2, const Vector3& v3);
                    
            /** Calculate a face normal without normalize, including the w component which is the offset from the origin. */
                    
            static Vector4 calculateFaceNormalWithoutNormalize(const Vector3& v1, const Vector3& v2, const Vector3& v3);
                    
            /** Calculate a face normal without normalize, no w-information. */
                    
            static Vector3 calculateBasicFaceNormalWithoutNormalize(const Vector3& v1, const Vector3& v2, const Vector3& v3);
            文如其名,四個上帝之子是同胞胎,只為了一個目的:得到法線,和一個附加長度。
                //-----------------------------------------------------------------------
                Vector4 Math::calculateFaceNormal(const Vector3& v1, const Vector3& v2, const Vector3& v3)
                
            {
                    Vector3 normal 
            = calculateBasicFaceNormal(v1, v2, v3);
                    
            // Now set up the w (distance of tri from origin
                    return Vector4(normal.x, normal.y, normal.z, -(normal.dotProduct(v1)));
                }

                
            //-----------------------------------------------------------------------
                Vector3 Math::calculateBasicFaceNormal(const Vector3& v1, const Vector3& v2, const Vector3& v3)
                
            {
                    Vector3 normal 
            = (v2 - v1).crossProduct(v3 - v1);
                    normal.normalise();
                    
            return normal;
                }

                
            //-----------------------------------------------------------------------
                Vector4 Math::calculateFaceNormalWithoutNormalize(const Vector3& v1, const Vector3& v2, const Vector3& v3)
                
            {
                    Vector3 normal 
            = calculateBasicFaceNormalWithoutNormalize(v1, v2, v3);
                    
            // Now set up the w (distance of tri from origin)
                    return Vector4(normal.x, normal.y, normal.z, -(normal.dotProduct(v1)));
                }

                
            //-----------------------------------------------------------------------
                Vector3 Math::calculateBasicFaceNormalWithoutNormalize(const Vector3& v1, const Vector3& v2, const Vector3& v3)
                
            {
                    Vector3 normal 
            = (v2 - v1).crossProduct(v3 - v1);
                    
            return normal;
                }
            上帝是多么的英明,在你千辛萬苦google后卻還是無果的時候,卻發現圣書上古老的筆跡是最好的詮釋。

            第二天,上帝走在水面上,說要有一個面,于是就有了平面。

                Ogre::MeshManager::getSingleton().createPlane("floor", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
                    Plane(Vector3::UNIT_Y, 
            0), 2002001010true11010, Vector3::UNIT_Z);

                
            // create a floor entity, give it a material, and place it at the origin
                Ogre::Entity* floor = mSceneMgr->createEntity("Floor""floor");
                floor
            ->setMaterialName("Examples/Rockwall");
                floor
            ->setCastShadows(false);
                mSceneMgr
            ->getRootSceneNode()->attachObject(floor);

            第三天,神說要有點、也要有叉。點點叉叉才像世界。

            1).點積
            維基:http://en.wikipedia.org/wiki/Dot_product
            點積沒有其他的幾何意義,除了表示2個向量的角度:


            同時在ogre代碼中:
                    inline Real Vector3::dotProduct(const Vector3& vec) const
                    
            {
                        
            return x * vec.x + y * vec.y + z * vec.z;
                    }

            這里也可以看到一個互動效果的點積圖形程序:
            http://xahlee.org/SpecialPlaneCurves_dir/ggb/Vector_Dot_Product.html

            也可以看到在其他領域點積還是有意義的,例如物理


            2).叉積
            維基:http://en.wikipedia.org/wiki/Cross_product
            叉積的結果正好是面的法線向量。這個向量的絕對值正好是向量包圍體的體積\面積。
            叉積的結果表示:
             

            同時在ogre代碼中:
                    inline Vector3::Vector3 crossProduct( const Vector3& rkVector ) const
                    
            {
                        
            return Vector3(
                            y 
            * rkVector.z - z * rkVector.y,
                            z 
            * rkVector.x - x * rkVector.z,
                            x 
            * rkVector.y - y * rkVector.x);
                    }

            3).四元數
            一個四元數可以對應一個4*4矩陣,這是上帝的法則,作為它的子民,只有依其言行事。
            這里你可以看到四元數---對應矩陣---模型的互動操作,I love It!當然,只板檣才可以讓演示程序跑起來,I 罰克中國恭饞褲襠。
            http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToMatrix/program/index.htm
            這個站還有四元數相關運算的詳細推導,例如四元數轉4*4矩陣。

            4).矩陣

            第四天,上帝想考驗世人的信仰,想看看每一顆心是不是紅的。

            Entity *ent = NULL;
            // mesh data to retrieve         
            size_t vertex_count;
            size_t index_count;
            Ogre::Vector3 
            *vertices;
            unsigned 
            long *indices;

            // get the mesh information
            GetMeshInformation(ent->getMesh(), vertex_count, vertices, index_count, indices,             
                ent
            ->getParentNode()->_getDerivedPosition(),
                ent
            ->getParentNode()->_getDerivedOrientation(),
                ent
            ->getParentNode()->getScale());

            // test for hitting individual triangles on the mesh
            for (int i = 0; i < static_cast<int>(index_count); i += 3)
            {
                
            // check for a hit against this triangle
                
            //std::pair<bool, Ogre::Real> hit = Ogre::Math::intersects(ray, vertices[indices[i]],
                
            //    vertices[indices[i+1]], vertices[indices[i+2]], true, false);
                Vector3 noraml =  Ogre::Math::calculateBasicFaceNormalWithoutNormalize (vertices[indices[i]], vertices[indices[i+1]], vertices[indices[i+2]] ); 
                Vector3 center 
            = (vertices[indices[i]] + vertices[indices[i+1]])/2;
                center 
            = (center+vertices[indices[i+2]] )/2;
                mPoints.push_back(center);
                mPoints.push_back(center 
            + noraml );
            }


            // free the verticies and indicies memory
            delete[] vertices;
            delete[] indices;

            ///////////////////////////////////////////////////////////////////////
            // Get the mesh information for the given mesh.
            // Code found on this forum link: http://www.ogre3d.org/wiki/index.php/RetrieveVertexData
            void DynLine::GetMeshInformation(const Ogre::MeshPtr mesh,
                                                    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)

            如此,上帝一一查明了世上的每一個生命,不管這個點式多么的渺小或微不足道,上帝均能一一檢視。這里,在每一個面上都計算出了法線向量。

            第五天,修改了Node要記得update。

            void Node::needUpdate(bool forceParentUpdate)

             
             

            posted on 2011-06-20 14:57 的筆記 閱讀(702) 評論(0)  編輯 收藏 引用

            2021国产精品久久精品| 国产成人精品久久综合| 久久久久亚洲AV无码观看| 噜噜噜色噜噜噜久久| 一本色道久久88精品综合| 99久久99久久| 亚洲伊人久久成综合人影院| 色婷婷综合久久久久中文| 亚洲精品国产成人99久久| 97精品国产97久久久久久免费| 国产韩国精品一区二区三区久久| 久久久WWW成人免费毛片| 欧美喷潮久久久XXXXx| 日本精品久久久久中文字幕| 久久天天躁夜夜躁狠狠躁2022| 嫩草影院久久99| 久久久精品国产sm调教网站| 久久综合给合综合久久| 成人a毛片久久免费播放| 亚洲精品乱码久久久久久蜜桃不卡| 国产高潮久久免费观看| 国产精品无码久久综合| 亚洲AV无码成人网站久久精品大| 久久久久久一区国产精品| 久久99国产精品久久99| 人妻精品久久无码专区精东影业| 综合久久给合久久狠狠狠97色| 国产99久久久久久免费看| 99久久99这里只有免费的精品| 亚洲精品蜜桃久久久久久| 久久夜色精品国产噜噜亚洲a| 99热成人精品免费久久| 色成年激情久久综合| 亚洲国产精品久久66| 国产精品久久久99| 久久婷婷五月综合97色直播| 久久精品成人影院| 久久无码人妻精品一区二区三区 | 久久精品一区二区三区不卡| 久久精品午夜一区二区福利| 国产亚洲精品自在久久|