螺旋线

代码如下:

#include <windows.h>
//#include <GLUT/glut.h>
#include <GL/glut.h>
#include <math.h>
#include <iostream>
using namespace std;

#define GL_PI 3.1415f

void RenderScene()
{
    GLfloat x,y,z,angle;

    glClear(GL_COLOR_BUFFER_BIT);

    glPushMatrix();
    glRotatef(45.0,1.0f,0.0f,0.0f);
    glRotatef(45.0,0.0f,1.0f,0.0f);

    glPointSize(5.0f);

    glBegin(GL_POINTS);
    z = -50.0f;
    for(angle = 0.0f;angle <= (2.0f*GL_PI)*3.0f;angle += 0.1f)
    {
        x = 50.0f*sin(angle);
        y = 50.0f*cos(angle);

        glVertex3f(x,y,z);
        z += 0.5f;
        cout<<"x: "<<x<<" ,y: "<<y<<" ,z: "<<z<<endl;
    }
    glEnd();

    glPopMatrix();
    glutSwapBuffers();
}

void ChangeSize(GLsizei w,GLsizei h)
{
    if(h==0)
        h = 1;

    GLfloat aspectRatio = (GLfloat)w/(GLfloat)h;

    glViewport(0,0,w,h);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    if(w<h)
    {
        glOrtho(-100.0,100.0,-100.0/aspectRatio,100.0/aspectRatio,100.0,-100.0);
        //windowWidth = 100;
        //windowHeight = 100/aspectRatio;
    }
    else
    {
        glOrtho(-100.0*aspectRatio,100.0*aspectRatio,-100.0,100.0,100.0,-100.0);
        //windowWidth = 100*aspectRatio;
        //windowHeight = 100;
    }

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    //glLookAt()
}

void SetupRC()
{
    glClearColor(0.0f,0.0f,0.0f,1.0f);
    glColor3f(0.0f,1.0f,0.0f);
}

int main(int argc, char *argv[])
{
   glutInit(&argc,argv);
   glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
   glutInitWindowSize(800,600);
   glutCreateWindow("Simple");

   glutDisplayFunc(RenderScene);
   glutReshapeFunc(ChangeSize);

   SetupRC();
   glutMainLoop();
   return 0;
}
时间: 2024-10-11 21:56:58

螺旋线的相关文章

用JS画斐波那契螺旋线(黄金螺旋线)

偶然看到斐波那契螺旋线(黄金螺旋线)的定义及画图方法,试着用JS画了一下,很漂亮,很好玩 具体定义及画法大家查一下就有了,很简单. 以下是代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>FibonacciSequence</title> </head> <body> <

点绘制螺旋线

/** * 缓冲区工具类 */public class BufferUtil { /**  * 将浮点数组转换成字节缓冲区  */ public static ByteBuffer arr2ByteBuffer(float[] arr){  ByteBuffer ibb = ByteBuffer.allocateDirect(arr.length * 4);  ibb.order(ByteOrder.nativeOrder());  FloatBuffer fbb = ibb.asFloatBu

OpenGl绘制螺旋线

/** * 缓冲区工具类 */public class BufferUtil { /**  * 将浮点数组转换成字节缓冲区  */ public static ByteBuffer arr2ByteBuffer(float[] arr){  ByteBuffer ibb = ByteBuffer.allocateDirect(arr.length * 4);  ibb.order(ByteOrder.nativeOrder());  FloatBuffer fbb = ibb.asFloatBu

(转)maya螺旋线脚本(mel)

1 string $curve=`curve -d 3 -p 0 0 0`; 2 rename $curve ("newCurve"); 3 for($i=0;$i<100;$i++) 4 { 5 currentTime $i; 6 float $a=sin ($i)*(sin($i/32.0)); 7 float $b=cos ($i)*(sin($i/32.0)); 8 float $c=($i/55.0); 9 curve -a -p $a $b $c ("new

使用Python的turtle库实现六角形以及正方形螺旋线的绘制

1.六角形的绘制 思路:一个六角形可以看作是两个等边三角形具有共同的中心且垂线互成60°角.所以只需实现一个等边三角形的绘制以及第二个三角形绘制起点的移动即可. 代码如下: import turtleturtle.setup(650,350,200,200)turtle.penup()turtle.pensize(1)turtle.pencolor("red")turtle.fd(100)turtle.seth(30)turtle.pendown()turtle.fd(80)turtl

动态螺旋线

代码如下: #include <windows.h> //#include <GLUT/glut.h> #include <GL/glut.h> #include <math.h> #include <iostream> using namespace std; #define GL_PI 3.1415f void RenderScene() { //glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)

螺旋线2

代码如下: #include <windows.h> //#include <GLUT/glut.h> #include <GL/glut.h> #include <math.h> #include <iostream> using namespace std; #define GL_PI 3.1415f void RenderScene() { glClear(GL_COLOR_BUFFER_BIT); GLfloat x,y,z,angle;

OpenGL——点的绘制(使用OpenGL来绘制可旋转坐标系的螺旋线)

package com.example.opengl1; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer; import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10; import android.opengl.GLSurfaceView; im

用Turtle画正螺旋线

import turtle as t t.setup(800,600,0,0,) t.pensize(2) t.speed(1) t.color("purple") t.shape("turtle") a=input("请输入任意1-10以内的数值:") a=eval(a)   #红色部分可以改成a=5 for i in range(50): a=a+10 t.left(90) t.fd(a) t.done()