• <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)  編輯 收藏 引用

            日韩人妻无码一区二区三区久久| 无码专区久久综合久中文字幕| 久久久久久久尹人综合网亚洲 | 午夜不卡久久精品无码免费| 久久午夜无码鲁丝片秋霞 | 91久久精品国产免费直播| 久久国产精品免费一区| 色偷偷91久久综合噜噜噜噜| 亚洲国产欧美国产综合久久 | 精品无码久久久久久尤物| 国产精品va久久久久久久| 亚洲AV无码久久精品蜜桃| 久久精品不卡| 久久精品国产精品亚洲毛片| 日韩中文久久| 97久久精品无码一区二区天美| 老司机午夜网站国内精品久久久久久久久| 亚洲中文久久精品无码ww16| 久久精品一区二区三区中文字幕| 日韩AV无码久久一区二区| 久久免费国产精品| 天天久久狠狠色综合| 亚洲国产精品久久电影欧美| 久久天天躁狠狠躁夜夜不卡 | 97精品伊人久久大香线蕉| 伊人久久精品线影院| 国产精品久久99| 精品久久久噜噜噜久久久 | 久久精品国产亚洲av瑜伽| 久久99国产乱子伦精品免费| 亚洲欧美伊人久久综合一区二区 | 久久性精品| 国产精品无码久久综合网| 国产精品九九九久久九九| 99久久免费国产特黄| 久久99热只有频精品8| 午夜精品久久久久久毛片| 亚洲狠狠婷婷综合久久蜜芽| 日韩人妻无码精品久久久不卡 | 美女写真久久影院| 99热热久久这里只有精品68|