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;
    
        }
    
    
    }
  • 相关阅读:
    MVC Form
    The way to learn english
    Test FastThree
    C#中Trim()、TrimStart()、TrimEnd()的用法
    c# Dictionary 简介
    visual studio快捷键大全
    ASP.NET MVC 中 ActionResult
    MVC4中使用 Ninject
    MVC Chapter 12 Overview of MVC Projects
    ASP.NET Razor
  • 原文地址:https://www.cnblogs.com/xpvincent/p/2913544.html
Copyright © 2011-2022 走看看