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

            游戲開(kāi)發(fā) C++ Cocos2d-x OpenGL DirectX 數(shù)學(xué) 計(jì)算機(jī)圖形學(xué) SQL Server

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

            公告

            QQ:30743734
            EMain:mybios@qq.com

            常用鏈接

            留言簿(16)

            我參與的團(tuán)隊(duì)

            最新隨筆

            搜索

            •  

            積分與排名

            • 積分 - 372214
            • 排名 - 67

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            左手坐標(biāo)系的直觀表示:
            LH.JPG

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

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

            標(biāo)準(zhǔn)化向量=此向量/此向量的長(zhǎng)度=vx / ||v|| , vy / ||v|| , vz / ||v||

            標(biāo)準(zhǔn)化后的向量的頭接觸到圓心在原點(diǎn)的單位圓(單位圓的半徑為1)


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

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

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

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

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

            當(dāng)點(diǎn)乘結(jié)果大于0,則夾角小于90度
            當(dāng)點(diǎn)乘結(jié)果等于0,則夾角等于90度
            當(dāng)點(diǎn)乘結(jié)果小于0,則夾角大于90度


            向量差乘:
            Vector2.JPG

            向量的封裝類(lèi):
            /////////////////////////////////////////////////////////////////////////////
            //
            //?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) 閱讀(3745) 評(píng)論(5)  編輯 收藏 引用 所屬分類(lèi): 數(shù)學(xué)、幾何和圖形學(xué)

            Feedback

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

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

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

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

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

            久久93精品国产91久久综合| …久久精品99久久香蕉国产 | 亚洲AV无码久久精品蜜桃| 日韩欧美亚洲国产精品字幕久久久| 亚洲精品无码久久久久AV麻豆| 久久精品国产男包| 久久电影网一区| 欧美激情精品久久久久久| 久久精品99久久香蕉国产色戒| 91精品国产综合久久香蕉| 久久只这里是精品66| 久久综合丝袜日本网| 人妻精品久久久久中文字幕69| 青青草原1769久久免费播放| 97精品伊人久久大香线蕉| 91超碰碰碰碰久久久久久综合| 久久人人爽人人人人片av| 国产午夜福利精品久久| 久久精品国产99久久久古代 | 久久精品一区二区三区AV| 欧美亚洲日本久久精品| 久久r热这里有精品视频| 亚洲日本va中文字幕久久| 开心久久婷婷综合中文字幕| 久久91精品国产91久久小草| 久久久精品2019免费观看| 国产成人精品三上悠亚久久| 亚洲一区精品伊人久久伊人| 国产精品成人精品久久久 | 国产精品久久亚洲不卡动漫| 亚洲精品高清国产一线久久| 久久久国产99久久国产一| 少妇被又大又粗又爽毛片久久黑人| 99久久婷婷国产综合精品草原| 99久久777色| 国产精品久久久久无码av | 久久国产精品无码网站| 精品久久久久久无码中文野结衣| 97超级碰碰碰碰久久久久| 天天久久狠狠色综合| 91久久精品国产成人久久|