青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

天行健 君子當自強而不息

DirectX 9的一些數學計算函數:平面


平面

將三維物體表面剖分為一系列的三角形面,物體的光照亮度處理就轉化為對這些平面三角形的照明處理,從而可簡單地通過平面三角形的法向量與光的入射方向的夾角,來確定各種入射光對平面上每一點所貢獻的亮度值。

對于三角形3個頂點p0,p1,p2構成的平面,選取一個垂直于該平面的法向量n。假設點p為平面上的任意一點,由于n . (p - p0) = 0,從而n . p - n . p0 = 0,由此展開向量的點積運算可知,平面方程具有如下的一般形式:ax+by+cz+d=0。如果要具體求出平面的方程,可取n=(p1-p0) x (p2 - p0)計算出來。

因為平面的方程式由4個系數a, b, c, d就可確定,因此,DirectX提供了如下的D3DXPLANE結構體保存方程式的4個系數,當然結構體還提供了基于方程式系數的加減乘除等運算。
 
typedef struct D3DXPLANE
{
#ifdef __cplusplus
public:
    D3DXPLANE() {}
    D3DXPLANE( CONST FLOAT* );
    D3DXPLANE( CONST D3DXFLOAT16* );
    D3DXPLANE( FLOAT a, FLOAT b, FLOAT c, FLOAT d );

    
// casting
    operator FLOAT* ();
    
operator CONST FLOAT* () const;

    
// assignment operators
    D3DXPLANE& operator *= ( FLOAT );
    D3DXPLANE& 
operator /= ( FLOAT );

    
// unary operators
    D3DXPLANE operator + () const;
    D3DXPLANE 
operator - () const;

    
// binary operators
    D3DXPLANE operator * ( FLOAT ) const;
    D3DXPLANE 
operator / ( FLOAT ) const;

    friend D3DXPLANE 
operator * ( FLOAT, CONST D3DXPLANE& );

    BOOL 
operator == ( CONST D3DXPLANE& ) const;
    BOOL 
operator != ( CONST D3DXPLANE& ) const;

#endif //__cplusplus
    FLOAT a, b, c, d;
} D3DXPLANE, *LPD3DXPLANE;

DirectX還提供了基于三點的向量求平面的 D3DXPlaneFromPoints函數以及基于一點和一個法向量求平面的D3DXPlaneFromPointNormal函數。

Constructs a plane from three points.

D3DXPLANE * D3DXPlaneFromPoints(
D3DXPLANE * pOut,
CONST D3DXVECTOR3 * pV1,
CONST D3DXVECTOR3 * pV2,
CONST D3DXVECTOR3 * pV3
);

Parameters

pOut
[in, out] Pointer to the D3DXPLANE structure that is the result of the operation.
pV1
[in] Pointer to a D3DXVECTOR3 structure, defining one of the points used to construct the plane.
pV2
[in] Pointer to a D3DXVECTOR3 structure, defining one of the points used to construct the plane.
pV3
[in] Pointer to a D3DXVECTOR3 structure, defining one of the points used to construct the plane.

Return Values

Pointer to the D3DXPLANE structure constructed from the given points.

Remarks

The return value for this function is the same value returned in the pOut parameter. In this way, the D3DXPlaneFromPoints function can be used as a parameter for another function.

 

Constructs a plane from a point and a normal.

D3DXPLANE * D3DXPlaneFromPointNormal(
D3DXPLANE * pOut,
CONST D3DXVECTOR3 * pPoint,
CONST D3DXVECTOR3 * pNormal
);

Parameters

pOut
[in, out] Pointer to the D3DXPLANE structure that is the result of the operation.
pPoint
[in] Pointer to a D3DXVECTOR3 structure, defining the point used to construct the plane.
pNormal
[in] Pointer to a D3DXVECTOR3 structure, defining the normal used to construct the plane.

Return Values

Pointer to the D3DXPLANE structure constructed from the point and the normal.

Remarks

The return value for this function is the same value returned in the pOut parameter. In this way, the D3DXPlaneFromPointNormal function can be used as a parameter for another function.


要正確運行以下的示例程序,需要在工程中包含d3dx9.lib,或者在main函數前加入

#pragma comment(lib, "d3dx9.lib")

以指示編譯器鏈接d3dx9.lib。

代碼示例:

#include <stdio.h>
#include <D3DX9Math.h>

#pragma warning(disable : 4305)

int main()
{
    D3DXVECTOR3 P0(8.0,  -3.0, 6.0);
    D3DXVECTOR3 P1(2.0,  -3.0, -5.0);
    D3DXVECTOR3 P2(-1.0, -3.0, 10.0);

    D3DXPLANE plane;

    D3DXPlaneFromPoints(&plane, &P0, &P1, &P2);

    printf("Plane equation: %fx + %fy + %fz + %f = 0", plane.a, plane.b, plane.c, plane.d);
    printf("\n\n\n");

    
return 0;
}

結果輸出:

Plane equation: 0.000000x + 1.000000y + 0.000000z + 3.000000 = 0



直線與平面的交點

Finds the intersection between a plane and a line.

D3DXVECTOR3 * D3DXPlaneIntersectLine(
D3DXVECTOR3 * pOut,
CONST D3DXPLANE * pP,
CONST D3DXVECTOR3 * pV1,
CONST D3DXVECTOR3 * pV2
);

Parameters

pOut
[in, out] Pointer to a D3DXVECTOR3 structure, identifying the intersection between the specified plane and line.
pP
[in] Pointer to the source D3DXPLANE structure.
pV1
[in] Pointer to a source D3DXVECTOR3 structure, defining a line starting point.
pV2
[in] Pointer to a source D3DXVECTOR3 structure, defining a line ending point.

Return Values

Pointer to a D3DXVECTOR3 structure that is the intersection between the specified plane and line.

Remarks

If the line is parallel to the plane, NULL is returned.

The return value for this function is the same value returned in the pOut parameter. In this way, the D3DXPlaneIntersectLine function can be used as a parameter for another function.


代碼示例
 
#include <stdio.h>
#include <D3DX9Math.h>

#pragma comment(lib, "d3dx9.lib")
#pragma warning(disable : 4305)

int main()
{
    D3DXVECTOR3 A(0, 0, 0);
    D3DXVECTOR3 B(5, 5, 5);

    D3DXPLANE plane(0, 1, 0, -1);   
// equation: x = 1

    D3DXVECTOR3 intersect_point;

    D3DXPlaneIntersectLine(&intersect_point, &plane, &A, &B);

    
// intersect point must be: (1, 1, 1)
    printf("Intersect point: (%f, %f, %f)\n\n", intersect_point.x, intersect_point.y, intersect_point.z);

    
return 0;
}

輸出:

Intersect point: (1.000000, 1.000000, 1.000000)



點和平面的位置關系

對于1個給定了法向量n和內部一點p0的平面,任意1點p與該平面的位置關系可用兩向量的點積n . (p - p0) 進行判斷,分為如下的3種情形:
(1) 點p在法向量n的同一側,即n . (p - p0) > 0
(2) 點p在平面上,即n . (p - p0) = 0
(3) 點p在法向量n的反側,即n . (p - p0) < 0

對于以方程式ax+by+cz+d=0給出的平面,由系數a, b和c構成的向量(a, b, c)必然是1個垂直于該平面的向量法向量。

(證明如下:設平面上任意兩個點(x1,y1,z1), (x2,y2,z2),代入方程:
  ax1+by1+cz1+d=0;     ax2+by2+cz2+d=0 ;
  ====>
  a(x1-x2)+b(y1-y2)+c(z1-z2)=0
  ====>
  (a,b,c)(x1-x2, y1-y2, z1-z2)=0

即點積為0,因為兩點是任意的,所以具有一般性,即向量垂直與平面內任意一條直線。)
稱向量(a, b, c)為平面ax + by + cz +d = 0的默認法向量。

判斷一點p(x0, y0, z0)與ax+by+z+d=0平面的位置關系,可以直接利用ax0+by0+cz0+d的符號來決定。
 ax0 +by0+cz0+d > 0表示點p在默認法向量的一側,也可以說是位于平面的前方。
 ax0+by0+cz0+d = 0表示點p在平面上。
 ax0+by0+cz0+d < 0表示點p在默認法向量的另一側,也可以說是位于平面的后方。

平面(a, b, c, d)與任意點(x0, y0, z0)的ax0 + by0 + cz0值,可用DirectX提供的D3DXPlaneDotCoord函數計算出來,利用該函數返回值的符號可決定點在平面的那一側。

Computes the dot product of a plane and a 3D vector. The w parameter of the vector is assumed to be 1.

FLOAT D3DXPlaneDotCoord(
CONST D3DXPLANE * pP,
CONST D3DXVECTOR3 * pV
);

Parameters

pP
[in] Pointer to a source D3DXPLANE structure.
pV
[in] Pointer to a source D3DXVECTOR3 structure.

Return Values

The dot product of the plane and 3D vector.

Remarks

Given a plane (a, b, c, d) and a 3D vector (x, y, z) the return value of this function is a*x + b*y + c*z + d*1. The D3DXPlaneDotCoord function is useful for determining the plane's relationship with a coordinate in 3D space.


如果要計算平面法線和另一法線的夾角,可使用D3DXPlaneDotNormal。

Computes the dot product of a plane and a 3D vector. The w parameter of the vector is assumed to be 0.

FLOAT D3DXPlaneDotNormal(
CONST D3DXPLANE * pP,
CONST D3DXVECTOR3 * pV
);

Parameters

pP
[in] Pointer to a source D3DXPLANE structure.
pV
[in] Pointer to a source D3DXVECTOR3 structure.

Return Values

The dot product of the plane and 3D vector.

Remarks

Given a plane (a, b, c, d) and a 3D vector (x, y, z) the return value of this function is a*x + b*y + c*z + d*0. The D3DXPlaneDotNormal function is useful for calculating the angle between the normal of the plane, and another normal.


平面單位化:

如果平面ax+by+cz+d=0的默認法向量n =(a,b,c)為單位向量,那么該平面稱為單位化平面。

Normalizes the plane coefficients so that the plane normal has unit length.

D3DXPLANE * D3DXPlaneNormalize(
D3DXPLANE * pOut,
CONST D3DXPLANE * pP
);

Parameters

pOut
[in, out] Pointer to the D3DXPLANE structure that is the result of the operation.
pP
[in] Pointer to the source D3DXPLANE structure.

Return Values

Pointer to a D3DXPLANE structure that represents the normal of the plane.

Remarks

This function normalizes a plane so that |a,b,c| == 1.

The return value for this function is the same value returned in the pOut parameter. In this way, this function can be used as a parameter for another function.


代碼示例:

#include <stdio.h>
#include <D3DX9Math.h>

#pragma warning(disable : 4305)

int main()
{
    D3DXPLANE plane(1, 0, 0, -1);

    D3DXVECTOR3 p(5, 0, 0);

    
float dot = D3DXPlaneDotCoord(&plane, &p);
    printf("dot = %f\n\n", dot);

    dot = D3DXPlaneDotNormal(&plane, &p);
    printf("dot = %f\n\n", dot);

    D3DXPLANE plane2(3, 4, 0, 0);
    D3DXPlaneNormalize(&plane2, &plane2);
    printf("After normalize: (%f, %f, %f, %f)\n\n", plane2.a, plane2.b, plane2.c, plane2.d);

    
return 0;
}

輸出:

dot = 4.000000

dot = 5.000000

After normalize: (0.600000, 0.800000, 0.000000, 0.000000)

posted on 2007-05-04 01:18 lovedday 閱讀(1936) 評論(1)  編輯 收藏 引用 所屬分類: ■ DirectX 9 Program

評論

# re: DirectX 9的一些數學計算函數:平面 2008-11-19 05:42 Z. Yao

平面與平面的交線怎么計算  回復  更多評論   

公告

導航

統計

常用鏈接

隨筆分類(178)

3D游戲編程相關鏈接

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            亚洲国产一区二区三区在线播 | 欧美国产精品人人做人人爱| 亚洲美女黄网| 亚洲国产精品久久久久婷婷884| 亚洲精品中文字幕在线观看| 亚洲九九爱视频| 午夜视频一区二区| 一二三区精品福利视频| 欧美一区成人| 久久久国产精品亚洲一区 | 欧美一级黄色网| 亚洲高清免费| 欧美激情网站在线观看| 亚洲欧洲久久| 国产色婷婷国产综合在线理论片a| 亚洲日本aⅴ片在线观看香蕉| 国产精品夜夜夜| 久久国产一区| 久久亚洲一区| 国产视频久久久久久久| 另类专区欧美制服同性| 免费日韩av电影| 亚洲日本激情| 亚洲国产一区二区精品专区| 欧美噜噜久久久xxx| 久久精品视频免费观看| 亚洲国产成人午夜在线一区| 久久精品国产第一区二区三区最新章节| 另类欧美日韩国产在线| 这里只有精品丝袜| 亚洲免费成人av电影| 巨乳诱惑日韩免费av| 亚洲一区二区三区久久| 精品不卡在线| 国产精品亚洲视频| 国产精品ⅴa在线观看h| 国产欧美日韩不卡免费| 国产一区二区三区在线观看视频| 欧美日韩123| 亚洲一区二区网站| 国产精品外国| 欧美国产日本在线| 欧美在线视频免费| 久久国产99| 国产精品qvod| 亚洲电影第三页| 最新国产成人在线观看| 一本色道久久综合亚洲二区三区| 一区二区三区免费网站| 亚洲黄色性网站| 亚洲欧美成人网| 国产精品视频福利| 好吊一区二区三区| 一本久久a久久免费精品不卡| 性欧美大战久久久久久久久| 久久九九99视频| 日韩一级不卡| 性做久久久久久久久| 欧美精品一区二区三区一线天视频| 欧美一区二区三区精品| 久久久99国产精品免费| 国产一区二区日韩| 亚洲第一网站免费视频| 国产精品a久久久久| 最新国产精品拍自在线播放| 欧美一级午夜免费电影| av成人国产| 欧美成熟视频| 亚洲第一中文字幕在线观看| 亚洲主播在线播放| 亚洲高清视频一区| 男人插女人欧美| 亚洲第一精品夜夜躁人人爽| 模特精品裸拍一区| 亚洲免费在线视频一区 二区| 9久re热视频在线精品| 99成人在线| 欧美日韩视频一区二区三区| 亚洲欧洲日夜超级视频| 中文av一区特黄| 国产欧美日韩在线| 亚洲无线观看| 久久综合中文字幕| 亚洲欧美日韩视频二区| 欧美日韩国内| 午夜激情综合网| 午夜视频在线观看一区二区| 伊人一区二区三区久久精品| 亚洲欧洲精品一区二区| 欧美乱大交xxxxx| 久久人人97超碰国产公开结果| 欧美成人69av| 一区二区三区国产精华| 亚洲另类春色国产| 欧美午夜电影一区| 老妇喷水一区二区三区| 欧美一区二区视频97| 国产精品香蕉在线观看| 欧美不卡福利| 久久精品国产一区二区三区免费看| 国产精品麻豆成人av电影艾秋| 亚洲国产综合在线| 激情亚洲一区二区三区四区| 日韩视频一区二区| 国产亚洲欧美另类中文| 99re6热只有精品免费观看| 国产一区日韩欧美| 亚洲男人av电影| 国产精品99久久久久久久女警| 国产一区二区三区最好精华液| 一本色道久久综合狠狠躁篇怎么玩 | 玖玖在线精品| 午夜在线一区| 欧美日韩国产精品一区| 国产精品免费看| 亚洲激情二区| 国产亚洲欧美日韩在线一区| 亚洲午夜精品网| 亚洲一二三四区| 亚洲精品日韩精品| 欧美日韩免费观看一区三区| 99热这里只有成人精品国产| 国产精品人成在线观看免费| 久久久999精品免费| 久久精品电影| 亚洲第一在线综合网站| 欧美日韩色一区| 99国产精品| 欧美电影资源| 亚洲特级毛片| 欧美日韩国产电影| 久久躁狠狠躁夜夜爽| 欧美激情精品久久久久久| 亚洲欧美日韩在线不卡| 国产精品私人影院| 久久精品观看| 亚洲一区二区三| 免费成人在线视频网站| 欧美在线看片| 亚洲女人小视频在线观看| 亚洲网址在线| 国产色产综合产在线视频| 欧美激情一区二区在线| 136国产福利精品导航网址应用| 欧美色网在线| 欧美+亚洲+精品+三区| 欧美在线免费观看视频| 国产精品看片资源| 国产日韩精品综合网站| 精品av久久久久电影| 激情视频一区| 日韩亚洲欧美高清| 亚洲电影免费在线| 亚洲第一福利视频| 亚洲三级视频| 亚洲毛片在线观看| 亚洲精品一区二区在线| 欧美插天视频在线播放| 免费成人高清视频| 亚洲一二三区精品| 日韩视频在线免费| 亚洲欧美日韩国产一区二区| 欧美呦呦网站| 欧美日韩高清在线观看| 免费亚洲电影| 国产片一区二区| 亚洲裸体在线观看| 一区二区三区四区在线| 亚洲欧美中文日韩v在线观看| 免费成人黄色片| 亚洲欧美另类中文字幕| 久久一区二区三区国产精品 | 久久精品亚洲国产奇米99| 欧美在线视频免费| 老司机一区二区| 亚洲无限av看| 欧美日韩福利在线观看| 噜噜噜噜噜久久久久久91| 欧美性猛片xxxx免费看久爱 | 性伦欧美刺激片在线观看| 欧美在线观看视频在线| 一本综合久久| 欧美人与性动交α欧美精品济南到| 国产精品毛片一区二区三区| 亚洲国产日韩欧美| 久久午夜电影网| 麻豆成人av| 狠狠狠色丁香婷婷综合久久五月| 午夜精品福利视频| 欧美成年人视频| 亚洲欧美日韩高清| 欧美婷婷久久| 亚洲免费一级电影| 毛片基地黄久久久久久天堂| 久久亚洲欧美| 亚洲视频国产视频| 亚洲一区三区电影在线观看| 国产区日韩欧美| 久久久99免费视频| 亚洲福利视频三区|