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

            热99RE久久精品这里都是精品免费 | 国产午夜精品久久久久九九电影| 亚洲午夜精品久久久久久人妖| 久久99精品久久久久久齐齐| 少妇被又大又粗又爽毛片久久黑人 | 99久久er这里只有精品18| 青青青国产精品国产精品久久久久 | 91精品国产91久久综合| 久久精品无码一区二区日韩AV| 97精品依人久久久大香线蕉97| 岛国搬运www久久| 久久99精品久久久久久久不卡| 亚洲精品WWW久久久久久| 久久精品视频网| 伊人久久大香线蕉av不卡| 久久久久黑人强伦姧人妻| 国内精品久久久久影院一蜜桃| 亚洲国产成人久久笫一页| 欧美精品一区二区精品久久| 五月丁香综合激情六月久久| 亚洲国产天堂久久综合| 精品久久久久久久中文字幕| 国产精品99久久免费观看| 亚洲精品乱码久久久久久中文字幕 | 国产精自产拍久久久久久蜜| 久久久久亚洲AV片无码下载蜜桃| 亚洲国产精品综合久久网络| 精品久久久久久无码国产| 国产亚州精品女人久久久久久 | 亚洲国产另类久久久精品| 欧美一区二区久久精品| 久久久久无码精品| 人妻中文久久久久| 亚洲精品成人网久久久久久| 色综合久久久久综合99| 亚洲伊人久久综合影院| 亚洲国产精品无码久久九九| 2021国内久久精品| 无码国内精品久久人妻蜜桃| 久久超碰97人人做人人爱| 99精品久久精品一区二区|