2017-05-24 4 views

答えて

0

ポリゴンの向きが反時計回り(つまり頂点がccwの場合)の場合、ポリゴンの法線ベクトルを計算し、ポリゴンがカメラを向いているかどうかを確認できます。

凸角を形成するポリゴンの連続する3つの頂点a、b、cを探し、法線ベクトル(b-a)x(c-b)を計算します。

1

あなたが通常の3D問題であるが、2d-gamesというタグで質問しているように、質問はやや曖昧です。しかし2Dはポリゴンクロックの方向(CW)または反時計回り(CCW)の方向が依然として2Dポリゴンの性質であるため有効です。 3Dソリューションのための2D又は3Dを

(投影変換後に適用されている)は、2次元座標(画面空間)内に3つの以上の頂点を有する多角形を有する

v1.x = ?; // vert x and y 
    v1.y = ?; 
    // v2, v3 same for two more verts on the polygon. 
    // polygon is drawn from v1, to v2, to v3 

    // long hand to show working clearly 

    // get the vector from v2 to v1 
    vec1.x = v1.x - v2.x; 
    vec1.y = v1.y - v2.y; 

    // get the vector from v2 to v3 
    vec2.x = v3.x - v2.x; 
    vec2.y = v3.y - v2.y; 

    // get the cross product of the 2 vectors 
    cross = vec1.x * vec2.y - vec1.y * vec2.x; 

    if(cross < 0) { /* polygon is CCW and facing away */ } 
    else if(cross > 0) { /* polygon is CW and facing */ } 
    else { /* cross is 0 means polygon is edge on */ } 

あなたにポリゴンを淘汰しますレンダリングの作業量をできるだけ早く減らすことができます。ほとんどの3Dパイプラインには、事前に計算されたポリゴンの法線(ポリゴンの面に垂直なベクトル)とメッシュジオメトリの一部が含まれます。

ポリゴンの法線は、まずワールド空間に変換する必要があります。ポリゴンのワールド空間法線とベクトルのドット積をカメラに使用して、<の値を0にするとポリゴンが離れ、ドット> 0がカメラに向い、ドット== 0のポリゴンがエッジに当たっていることを意味します。

または、単純化してワールド空間のビュー方向を定義するカメラのベクトルを定義できます。あなたは例のエッジを無視し、それらを処分することができますほとんどの場合

norm = {x,y,z}; // transformed world space polygon normal 
camNorm = {x,y,z}; //vector out from camera into world space 
// get the dot product of norm and camNorm 
dot = norm.x * camNorm.x + norm.y * camNorm.y + norm.z * camNorm.z 

// now if dot is negative (facing in the opposite direction of the camera direction) the polygon is facing the camera 
if(dot < 0) { /* polygon is CW and facing */ } 
else if(dot > 0) { /* polygon is CCW and facing away */ } 
else { /* dot is 0 means polygon is edge on */ } 

(ドットまたはクロス== 0)のポリゴンが非常に遅く、パイプライン内までに定義されていないとない場合がありますいくつかのケースでは

正常です。そのような場合は、投影変換を適用して2Dソリューションを使用することができます(最初のもの)

関連する問題