在OpenGL中创建直角三棱柱

发布于 2024-09-27 06:43:34 字数 168 浏览 0 评论 0原文

我正在学习 OpenGL(具体来说,使用 JOGL)并且我正在尝试创建一个直角三棱柱。我了解到您可以使用 glutWire/SolidCylinder 和少量切片(显然,三角形为 3 个)创建一个等边棱柱。

所以我想知道是否有其他方法可以制作棱镜,或者是否有某种方法可以缩放等边三角形以将其变成直角三角形?

I'm learning OpenGL (specifically, using JOGL) and I'm trying to create a right-angled triangular prism. I learned you can create an equilateral prism with glutWire/SolidCylinder and a a low number of slices (3 for a triangle, obviously).

So I'm wondering if there's some other way to make a prism, or if there's some way to scale an equilateral triangle to turn it into a right triangle?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦过后 2024-10-04 06:43:34

我还发现(至少在 JOGL 中,不知道其他地方) glutSolidCylinder 无法正常工作 - 端板以与侧面不同的旋转方式绘制,给你一个非常奇怪的形状。

所以我最终只是提出了一种方法来创建一个单位直角三棱柱,然后您可以根据需要旋转和缩放它。可能有更好的方法可以做到这一点,因此欢迎发表评论:

 private void unitTriangularPrism(GL gl, boolean solid){
    // back endcap
    gl.glBegin(solid ? GL.GL_TRIANGLES : GL.GL_LINES);
    gl.glVertex3f(1f, 0f, 0f);
    gl.glVertex3f(0f, 0f, 0f);
    gl.glVertex3f(0f, 1f, 0f);
    gl.glEnd();

    // front endcap
    gl.glBegin(solid ? GL.GL_TRIANGLES : GL.GL_LINES);
    gl.glVertex3f(1f, 0f, 1f);
    gl.glVertex3f(0f, 0f, 1f);
    gl.glVertex3f(0f, 1f, 1f);
    gl.glEnd();

    // bottom
    gl.glBegin(solid ? GL.GL_QUADS : GL.GL_LINES);
    gl.glVertex3f(0f, 0f, 0f);
    gl.glVertex3f(1f, 0f, 0f);
    gl.glVertex3f(1f, 0f, 1f);
    gl.glVertex3f(0f, 0f, 1f);
    gl.glEnd();

    // back
    gl.glBegin(solid ? GL.GL_QUADS : GL.GL_LINES);
    gl.glVertex3f(0f, 0f, 0f);
    gl.glVertex3f(0f, 1f, 0f);
    gl.glVertex3f(0f, 1f, 1f);
    gl.glVertex3f(0f, 0f, 1f);
    gl.glEnd();

    // top
    gl.glBegin(solid ? GL.GL_QUADS : GL.GL_LINES);
    gl.glVertex3f(0f, 1f, 0f);
    gl.glVertex3f(1f, 0f, 0f);
    gl.glVertex3f(1f, 0f, 1f);
    gl.glVertex3f(0f, 1f, 1f);
    gl.glEnd();
}

I additionally found that (at least in JOGL, no idea about elsewhere) glutSolidCylinder doesn't work correctly - the endplates are drawn at a different rotation than the sides, giving you a very strange looking shape.

So I ended up just making a method that creates a unit-right-triangular prism which you can then rotate and scale as necessary. There's likely much better ways to do this, so comments are welcome:

 private void unitTriangularPrism(GL gl, boolean solid){
    // back endcap
    gl.glBegin(solid ? GL.GL_TRIANGLES : GL.GL_LINES);
    gl.glVertex3f(1f, 0f, 0f);
    gl.glVertex3f(0f, 0f, 0f);
    gl.glVertex3f(0f, 1f, 0f);
    gl.glEnd();

    // front endcap
    gl.glBegin(solid ? GL.GL_TRIANGLES : GL.GL_LINES);
    gl.glVertex3f(1f, 0f, 1f);
    gl.glVertex3f(0f, 0f, 1f);
    gl.glVertex3f(0f, 1f, 1f);
    gl.glEnd();

    // bottom
    gl.glBegin(solid ? GL.GL_QUADS : GL.GL_LINES);
    gl.glVertex3f(0f, 0f, 0f);
    gl.glVertex3f(1f, 0f, 0f);
    gl.glVertex3f(1f, 0f, 1f);
    gl.glVertex3f(0f, 0f, 1f);
    gl.glEnd();

    // back
    gl.glBegin(solid ? GL.GL_QUADS : GL.GL_LINES);
    gl.glVertex3f(0f, 0f, 0f);
    gl.glVertex3f(0f, 1f, 0f);
    gl.glVertex3f(0f, 1f, 1f);
    gl.glVertex3f(0f, 0f, 1f);
    gl.glEnd();

    // top
    gl.glBegin(solid ? GL.GL_QUADS : GL.GL_LINES);
    gl.glVertex3f(0f, 1f, 0f);
    gl.glVertex3f(1f, 0f, 0f);
    gl.glVertex3f(1f, 0f, 1f);
    gl.glVertex3f(0f, 1f, 1f);
    gl.glEnd();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文