c++ - 帮助理解这一点?

标签 c++ c algorithm opengl

我在这里找到了这个算法,只有一件事让我困惑:

    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[i + 1] 定义的三角形。如果 S 是段 v[i]->v[i+1] 那么这怎么可能?

谢谢

最佳答案

如果我没记错的话,你必须绘制的三角形是 v0 - v[i] - v[i+1]

关于c++ - 帮助理解这一点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3538001/

相关文章:

c++ - 是否可以根据 C++20 中稍后的运行时决定存在不同的隐式对象?

c - 从文件中读取()返回什么?

c - 使用多个进程读取文件并通过pipe()发送数字

c - 此优化代码中调用的内容

algorithm - 插入排序与选择排序

c++ - 这个结构试图做什么?

c++ - 时间类问题

c++ - 如何避免由于内存不足导致的 gcc 崩溃

algorithm - 在网格中移动的机器人

algorithm - 分析时间复杂度时log base 2等于log base 3?