2010-08-21 129 views
-1

我有這個算法,我發現這裏只有一兩件事讓我爲難一下:幫助理解這一點?

Clear the stencil buffer to 1. 
    Pick an arbitrary vertex v0, probably somewhere near the polygon to reduce floating-point errors. 
    For each vertex v[i] of the polygon in clockwise order: 
     let s be the segment v[i]->v[i+1] (where i+1 will wrap to 0 when the last vertex is reached) 
     if v0 is to the "right" of s: 
      draw a triangle defined by s, v[i], v[i+1] that adds 1 to the stencil buffer 
     else 
      draw a triangle defined by s, v[i], v[i+1] that subtracts 1 from the stencil buffer 
    end for 
    fill the screen with the desired color/texture, testing for stencil buffer values >= 2. 

By "right of s" I mean from the perspective of someone standing on v[i] and facing v[i+1]. This can be tested by using a cross product: 

cross(v0 - v[i], v[i+1] - v[i]) > 0 

是困惑我的是,我需要繪製由S,V [I],V [定義的三角形的部分我+ 1]。如果S是段v [i] - > v [i + 1]那麼這是如何實現的?

感謝

+1

是的,它看起來像一個錯誤,因爲* s *是由v [i]和[i + 1]定義的段。我的鏡頭是應該有* v0 *而不是* s *。如果你已經提供了關於這個算法應該做什麼的更多信息,它也會有很大的幫助。它有影子卷嗎? – Rekin 2010-08-21 15:16:35

+0

不,我正在嘗試使用模具而不是GLUTESS繪製凹面多邊形 – jmasterx 2010-08-21 15:18:20

回答

1

如果我沒有記錯,你必須繪製三角形分別是V0 - v [I] - v [I + 1]

+0

完美謝謝! – jmasterx 2010-08-21 15:22:00

0

如果我正確地讀你的榜樣,s是間段2個頂點是三角形的邊緣。所以它以順時針的方式在三角形周圍「散步」,填充頂點。

「卷繞」 - 順時針或逆時針 - 確定三角形的法線。

0

燁,它看起來像一個錯誤,因爲s的段由v [I]v [I + 1]定義。這在繪製凹多邊形的情況下是有意義的。用v0,v [i],v [i + 1]