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

            李錦俊(mybios)的blog

            游戲開發(fā) C++ Cocos2d-x OpenGL DirectX 數(shù)學 計算機圖形學 SQL Server

              C++博客 :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
              86 Posts :: 0 Stories :: 370 Comments :: 0 Trackbacks

            公告

            QQ:30743734
            EMain:mybios@qq.com

            常用鏈接

            留言簿(16)

            我參與的團隊

            最新隨筆

            搜索

            •  

            積分與排名

            • 積分 - 370257
            • 排名 - 67

            最新評論

            閱讀排行榜

            評論排行榜

            左手坐標系的直觀表示:
            LH.JPG

            向量的表示(軸對齊包圍盒(AABB(axially aligned bounding box))):
            Vector.JPG

            2D向量的長度:||v|| = sqrt(vx*vx + vy*vy)
            3D向量的長度:||v|| = sqrt(vx*vx + vy*vy + vz*vz)

            標準化向量=此向量/此向量的長度=vx / ||v|| , vy / ||v|| , vz / ||v||

            標準化后的向量的頭接觸到圓心在原點的單位圓(單位圓的半徑為1)


            向量加法的幾何意義(三角形法則):
            vAdd.JPG

            計算一個點到另一個點的位移可以使用三角形法則和向量減法來解決這個問題:
            Vector1.JPG
            兩點間距離的公式:設(shè)兩點分別為3D向量a和b
            則距離(a,b)=||b-a||=sqrt((bx - ax)2 +(by - ay)2 +(bz - az)2 )

            向量點乘:點乘等于向量大小與向量夾角的cos值的積,其中c為兩點a和b的夾角:
            a點乘b=||a||*||b||*cos(c)

            計算向量的夾角:c =acos( (a*b)/(||a|| * ||b||))

            如果a和b是單位向量,則c=acos(a*b)

            當點乘結(jié)果大于0,則夾角小于90度
            當點乘結(jié)果等于0,則夾角等于90度
            當點乘結(jié)果小于0,則夾角大于90度


            向量差乘:
            Vector2.JPG

            向量的封裝類:
            /////////////////////////////////////////////////////////////////////////////
            //
            //?3D?Math?Primer?for?Games?and?Graphics?Development
            //
            //?Vector3.h?-?Declarations?for?3D?vector?class
            //
            //?Visit?gamemath.com?for?the?latest?version?of?this?file.
            //
            //?For?additional?comments,?see?Chapter?6.
            //
            /////////////////////////////////////////////////////////////////////////////

            #ifndef?__VECTOR3_H_INCLUDED__
            #define?__VECTOR3_H_INCLUDED__

            #include?
            <math.h>

            /////////////////////////////////////////////////////////////////////////////
            //
            //?class?Vector3?-?a?simple?3D?vector?class
            //
            /////////////////////////////////////////////////////////////////////////////

            class?Vector3?{
            public:

            //?Public?representation:??Not?many?options?here.

            ????
            float?x,y,z;

            //?Constructors

            ????
            //?Default?constructor?leaves?vector?in
            ????
            //?an?indeterminate?state

            ????Vector3()?
            {}

            ????
            //?Copy?constructor

            ????Vector3(
            const?Vector3?&a)?:?x(a.x),?y(a.y),?z(a.z)?{}

            ????
            //?Construct?given?three?values

            ????Vector3(
            float?nx,?float?ny,?float?nz)?:?x(nx),?y(ny),?z(nz)?{}

            //?Standard?object?maintenance

            ????
            //?Assignment.??We?adhere?to?C?convention?and
            ????
            //?return?reference?to?the?lvalue

            ????Vector3?
            &operator?=(const?Vector3?&a)?{
            ????????x?
            =?a.x;?y?=?a.y;?z?=?a.z;
            ????????
            return?*this;
            ????}


            ????
            //?Check?for?equality

            ????
            bool?operator?==(const?Vector3?&a)?const?{
            ????????
            return?x==a.x?&&?y==a.y?&&?z==a.z;
            ????}


            ????
            bool?operator?!=(const?Vector3?&a)?const?{
            ????????
            return?x!=a.x?||?y!=a.y?||?z!=a.z;
            ????}



            //?Vector?operations

            ????
            //?Set?the?vector?to?zero

            ????
            void?zero()?{?x?=?y?=?z?=?0.0f;?}

            ????
            //?Unary?minus?returns?the?negative?of?the?vector

            ????Vector3?
            operator?-()?const?{?return?Vector3(-x,-y,-z);?}

            ????
            //?Binary?+?and?-?add?and?subtract?vectors

            ????Vector3?
            operator?+(const?Vector3?&a)?const?{
            ????????
            return?Vector3(x?+?a.x,?y?+?a.y,?z?+?a.z);
            ????}


            ????Vector3?
            operator?-(const?Vector3?&a)?const?{
            ????????
            return?Vector3(x?-?a.x,?y?-?a.y,?z?-?a.z);
            ????}


            ????
            //?Multiplication?and?division?by?scalar

            ????Vector3?
            operator?*(float?a)?const?{
            ????????
            return?Vector3(x*a,?y*a,?z*a);
            ????}


            ????Vector3?
            operator?/(float?a)?const?{
            ????????
            float????oneOverA?=?1.0f?/?a;?//?NOTE:?no?check?for?divide?by?zero?here
            ????????return?Vector3(x*oneOverA,?y*oneOverA,?z*oneOverA);
            ????}


            ????
            //?Combined?assignment?operators?to?conform?to
            ????
            //?C?notation?convention

            ????Vector3?
            &operator?+=(const?Vector3?&a)?{
            ????????x?
            +=?a.x;?y?+=?a.y;?z?+=?a.z;
            ????????
            return?*this;
            ????}


            ????Vector3?
            &operator?-=(const?Vector3?&a)?{
            ????????x?
            -=?a.x;?y?-=?a.y;?z?-=?a.z;
            ????????
            return?*this;
            ????}


            ????Vector3?
            &operator?*=(float?a)?{
            ????????x?
            *=?a;?y?*=?a;?z?*=?a;
            ????????
            return?*this;
            ????}


            ????Vector3?
            &operator?/=(float?a)?{
            ????????
            float????oneOverA?=?1.0f?/?a;
            ????????x?
            *=?oneOverA;?y?*=?oneOverA;?z?*=?oneOverA;
            ????????
            return?*this;
            ????}


            ????
            //?Normalize?the?vector

            ????
            void????normalize()?{
            ????????
            float?magSq?=?x*x?+?y*y?+?z*z;
            ????????
            if?(magSq?>?0.0f)?{?//?check?for?divide-by-zero
            ????????????float?oneOverMag?=?1.0f?/?sqrt(magSq);
            ????????????x?
            *=?oneOverMag;
            ????????????y?
            *=?oneOverMag;
            ????????????z?
            *=?oneOverMag;
            ????????}

            ????}


            ????
            //?Vector?dot?product.??We?overload?the?standard
            ????
            //?multiplication?symbol?to?do?this

            ????
            float?operator?*(const?Vector3?&a)?const?{
            ????????
            return?x*a.x?+?y*a.y?+?z*a.z;
            ????}

            }
            ;

            /////////////////////////////////////////////////////////////////////////////
            //
            //?Nonmember?functions
            //
            /////////////////////////////////////////////////////////////////////////////

            //?Compute?the?magnitude?of?a?vector

            inline?
            float?vectorMag(const?Vector3?&a)?{
            ????
            return?sqrt(a.x*a.x?+?a.y*a.y?+?a.z*a.z);
            }


            //?Compute?the?cross?product?of?two?vectors

            inline?Vector3?crossProduct(
            const?Vector3?&a,?const?Vector3?&b)?{
            ????
            return?Vector3(
            ????????a.y
            *b.z?-?a.z*b.y,
            ????????a.z
            *b.x?-?a.x*b.z,
            ????????a.x
            *b.y?-?a.y*b.x
            ????);
            }


            //?Scalar?on?the?left?multiplication,?for?symmetry

            inline?Vector3?
            operator?*(float?k,?const?Vector3?&v)?{
            ????
            return?Vector3(k*v.x,?k*v.y,?k*v.z);
            }


            //?Compute?the?distance?between?two?points

            inline?
            float?distance(const?Vector3?&a,?const?Vector3?&b)?{
            ????
            float?dx?=?a.x?-?b.x;
            ????
            float?dy?=?a.y?-?b.y;
            ????
            float?dz?=?a.z?-?b.z;
            ????
            return?sqrt(dx*dx?+?dy*dy?+?dz*dz);
            }


            //?Compute?the?distance?between?two?points,?squared.??Often?useful
            //?when?comparing?distances,?since?the?square?root?is?slow

            inline?
            float?distanceSquared(const?Vector3?&a,?const?Vector3?&b)?{
            ????
            float?dx?=?a.x?-?b.x;
            ????
            float?dy?=?a.y?-?b.y;
            ????
            float?dz?=?a.z?-?b.z;
            ????
            return?dx*dx?+?dy*dy?+?dz*dz;
            }


            /////////////////////////////////////////////////////////////////////////////
            //
            //?Global?variables
            //
            /////////////////////////////////////////////////////////////////////////////

            //?We?provide?a?global?zero?vector?constant

            extern?const?Vector3?kZeroVector;

            /////////////////////////////////////////////////////////////////////////////
            #endif?//?#ifndef?__VECTOR3_H_INCLUDED__

            posted on 2006-11-17 17:09 李錦俊(mybios) 閱讀(3729) 評論(5)  編輯 收藏 引用 所屬分類: 數(shù)學、幾何和圖形學

            Feedback

            # re: 【原創(chuàng)】《3D數(shù)學基礎(chǔ):圖形與游戲開發(fā)》讀書筆記1 2006-11-17 17:40 李錦俊
            請別在我這發(fā)廣告!謝謝!  回復  更多評論
              

            # re: 【原創(chuàng)】《3D數(shù)學基礎(chǔ):圖形與游戲開發(fā)》讀書筆記1 2006-11-18 17:52 sea
            3D完全自己寫這些變化效率怎么樣?   回復  更多評論
              

            # re: 【原創(chuàng)】《3D數(shù)學基礎(chǔ):圖形與游戲開發(fā)》讀書筆記1 2006-11-18 22:21 李錦俊
            你是說代替D3DXMatrixxxxx之類的函數(shù)嗎?那效率不會低下的。都是CPU來處理,只要算法不是很差就可以。  回復  更多評論
              

            # re: 【原創(chuàng)】《3D數(shù)學基礎(chǔ):圖形與游戲開發(fā)》讀書筆記1[未登錄] 2007-11-15 11:32 YY
            哈哈,這本書我也有,是本好書  回復  更多評論
              

            # re: 【原創(chuàng)】《3D數(shù)學基礎(chǔ):圖形與游戲開發(fā)》讀書筆記1 2008-04-08 18:05 秋蕭世
            我只看的懂數(shù)學部分代碼就暈了  回復  更多評論
              

            久久国产精品免费| 精品国产青草久久久久福利| 国产毛片久久久久久国产毛片| 国产视频久久| 久久精品国产亚洲AV影院| 99久久精品毛片免费播放| 色99久久久久高潮综合影院| 久久精品国产久精国产思思| 婷婷久久综合九色综合九七| 91精品国产9l久久久久| 亚洲国产日韩欧美综合久久| 热久久这里只有精品| 久久天天躁狠狠躁夜夜avapp| 狠狠色丁香久久综合婷婷| 国产精品一区二区久久精品涩爱| 国内精品久久久久| 久久久婷婷五月亚洲97号色| 久久午夜免费视频| 久久久久国产日韩精品网站| 1000部精品久久久久久久久| 亚洲级αV无码毛片久久精品| 欧美性猛交xxxx免费看久久久| 亚洲国产精品热久久| 99久久99久久| 精品久久久久久亚洲精品| 日产精品久久久久久久| 久久亚洲精品国产精品婷婷| 久久免费大片| 欧美与黑人午夜性猛交久久久| 久久久人妻精品无码一区| 国产精品va久久久久久久| 中文精品久久久久国产网址| 久久99国产精品尤物| 久久精品水蜜桃av综合天堂| 久久久久AV综合网成人| 国产精品女同久久久久电影院| 亚洲国产精品高清久久久| 无码久久精品国产亚洲Av影片| 午夜精品久久久久久中宇| 久久久久AV综合网成人| 精品久久久久久亚洲|