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

            国产精品VIDEOSSEX久久发布| 久久精品人妻中文系列| 无码伊人66久久大杳蕉网站谷歌 | 人妻久久久一区二区三区| 亚洲va久久久噜噜噜久久男同 | 亚洲va久久久噜噜噜久久男同| 亚洲精品国产字幕久久不卡 | 99久久综合国产精品二区| 久久99精品国产麻豆不卡| 99久久精品免费看国产一区二区三区 | 东京热TOKYO综合久久精品| 国内精品久久久久久久影视麻豆 | 无码国内精品久久人妻麻豆按摩| 久久亚洲春色中文字幕久久久| 狠狠精品久久久无码中文字幕| 国产99久久久国产精品小说| 久久这里只精品国产99热| 精品国产乱码久久久久久呢| 精品无码久久久久久久动漫| 久久精品人人做人人爽电影蜜月 | 亚洲精品午夜国产va久久| 亚洲国产成人久久综合碰碰动漫3d| 日韩精品久久久久久久电影| 91精品国产高清久久久久久91| 日韩久久久久久中文人妻 | 久久久久久久综合日本| 国产一级持黄大片99久久 | 精品国产乱码久久久久久浪潮| 久久婷婷成人综合色综合| 久久亚洲精品无码aⅴ大香| 伊人伊成久久人综合网777| 精品久久国产一区二区三区香蕉| 国内精品伊人久久久久av一坑 | 99久久国产免费福利| 精品国际久久久久999波多野| 久久SE精品一区二区| 亚洲国产精品成人久久蜜臀| 亚洲精品无码久久毛片| 亚洲精品国产综合久久一线| 亚洲精品99久久久久中文字幕| 午夜精品久久久久久影视777|