Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Drawing a cone

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2009
    Location
    UK
    Posts
    24

    Drawing a cone

    My following challege it to draw a cone inside a quad thanks to Shaders. I have developed a code that is near to be successful but it you pay attencion you will see it fails...



    Any idea? a book or reference to draw figures in a plain?

    Parametric equations (I dont know very well how to apply them)

    x=(h-u)/h * r * cost heta
    y=(h-u)/h * r * sint heta
    z=u

    VS

    varying float myx;
    varying float myy;
    varying float myz;

    void main()
    {
    gl_Position = ftransform();

    myx = gl_Vertex.x;
    myy = gl_Vertex.y;
    myz = gl_Vertex.z;

    }

    FS

    uniform float angle;// It serves to rotate the cone 0-360
    varying float myx;
    varying float myy;
    varying float myz;

    void main()
    {
    float degree = abs(cos(radians(angle)));
    float x2 = myx;
    x2 *= x2;
    float y2 = myy / (1.0 - degree);
    y2 *= y2;
    float h = 1.0 * degree;
    float r = 1.0;

    if(myy >= 0.0 //Triangle in the positive y axis
    && myy <= h //Triangle cannot be higher than height
    && pow(myx,2.0) < pow( r - (myy/h),2.0) // It draws a triangle
    || x2 + y2 < pow(r,2.0) //It draws a a elipsoide
    ) {

    gl_FragColor = vec4( 1.0, 0.0, 1.0, 1.0);

    } else {

    gl_FragColor = vec4( 0.0, 0.0, 1.0, 1.0);

    }

    }

    Any tip is welcome

  2. #2
    Junior Member Newbie
    Join Date
    Apr 2009
    Posts
    18

    Re: Drawing a cone

    Here is what the parameter of the parametric ecuations are:
    http://mathworld.wolfram.com/Cone.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •