zoukankan      html  css  js  c++  java
  • 使用OpenGL绘制圆环体(Torus)

    本篇介绍一下使用OpenGL绘制圆环体的方法。程序是在C#和OpenTK环境下编译的。

    代码:

    /// <summary>
    /// 绘制圆环体
    /// </summary>
    /// <param name="Radius">圆环体半径</param>
    /// <param name="TubeRadius">圆环体段半径</param>
    /// <param name="Sides">圆环体段的侧面数</param>
    /// <param name="Rings">圆环体段数</param>
    void DrawTorus(double Radius = 50, double TubeRadius= 10, int Sides = 20, int Rings = 30)
    {
        double sideDelta = 2.0 * Math.PI / Sides;
        double ringDelta = 2.0 * Math.PI / Rings;
        double theta = 0;
        double cosTheta = 1.0;
        double sinTheta = 0.0;
    
        double phi, sinPhi, cosPhi;
        double dist;
    
        GL.Color3(1.00f, 0.0f, 0.0f);
    
        for (int i = 0; i < Rings; i++)
        {
            double theta1 = theta + ringDelta;
            double cosTheta1 = Math.Cos(theta1);
            double sinTheta1 = Math.Sin(theta1);
            
            GL.Begin(BeginMode.QuadStrip);
            phi = 0;
            for (int j = 0; j <= Sides; j++)
            {
                phi = phi + sideDelta;
                cosPhi = Math.Cos(phi);
                sinPhi = Math.Sin(phi);
                dist = Radius + (TubeRadius * cosPhi);
    
                GL.Normal3(cosTheta * cosPhi, sinTheta * cosPhi, sinPhi);
                GL.Vertex3(cosTheta * dist, sinTheta * dist, TubeRadius * sinPhi);
    
                GL.Normal3(cosTheta1 * cosPhi, sinTheta1 * cosPhi, sinPhi);
                GL.Vertex3(cosTheta1 * dist, sinTheta1 * dist, TubeRadius * sinPhi);
            }
            GL.End();
            theta = theta1;
            cosTheta = cosTheta1;
            sinTheta = sinTheta1;
    
        }
    
    
    }
  • 相关阅读:
    Python 音视频方面资源大全
    MD5( 信息摘要算法)的概念原理及python代码的实现
    base64编解码学习及python代码实现
    操作系统下cache的几个概念
    scp 跨机远程拷贝
    VIM -小技巧汇总
    python中的进制转换
    linux目录跳转快捷方式——z武器
    ubuntu 16.04 清空log文件的方法
    【linux】crontab失效
  • 原文地址:https://www.cnblogs.com/xpvincent/p/2913544.html
Copyright © 2011-2022 走看看