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 8 of 8

Thread: implementation of sweep object

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2011
    Posts
    4

    implementation of sweep object

    Hello,
    Does anyone know where I can find examples about how to use sweep method to draw objects? I have spent a couple of hours to search online, but I did not find any example code for this. (There are some about sweep-selection, but I do not think this is what I want.) Could anyone give me some simple examples like drawing a cube by translating a square along the line and a cylinder by rotating a line along the circle? I really know the idea, but it is difficult for me to figure out all the details. Hopefully, the example also includes how to map texture to this kind of complicate objects. Any advice is appreciated. Thanks!

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Singapore
    Posts
    801
    Regards,
    Mobeen

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2011
    Posts
    4

    Re: implementation of sweep object

    Sorry, it is not helpful so much for me. I am really new for OpenGL Is it possible to find an example or tutorial on it?

  4. #4
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,655

    Re: implementation of sweep object

    Both of these link are quite good, what do you not understand right now ?

    Or you prefer to be given some working code you don't understand ?

  5. #5
    Junior Member Newbie
    Join Date
    Mar 2011
    Posts
    4

    Re: implementation of sweep object

    I am confused about how to connect two shapes. For example, I wrote like this:
    for(...)
    drawSquare(); // simply draw a polygon
    glTranslatef(..);
    drawSquare();

    But how can I connect these two square together. What the code looks like?

  6. #6
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,655

    Re: implementation of sweep object

    This is not provided by OpenGL.
    Take each edge (ex A B) from the original shape, clone it to a translated version (ex C D), and draw a quad using ABDC so that it is CCW when viewed from the outside.
    Then the closing top shape must have its order reversed compared to the original shape.

  7. #7
    Junior Member Newbie
    Join Date
    Mar 2011
    Posts
    4

    Re: implementation of sweep object

    Could you give me some pseudo-code about what I should do step by
    step?

  8. #8
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,655

    Re: implementation of sweep object

    Let's extrude an hexagon along L distance, to make some basic cylinder :
    Code :
    base shape is an regular hexagon ABCDEF in the XY plane, visible when drawn counter clockwise.
    # we will fill in the values for GHIJKL, the second hexagon
    for each vertex M in (A,B,C,D,E,F) do
      O = M
      O.z += L
      add O to second hexagon list of vertices
    done
    # creation of quad sides
    for i = 0 to 5 do
      O = hex1.vertex[i]
      P = hex1.vertex[mod(i+1,6)]
      Q = hex2.vertex[i]
      R = hex2.vertex[mod(i+1,6)]
      add POQR to list of quads for sides
    done
    # drawing
    draw triangle fan ABCDEF
    draw side quads
    draw triangle fan LKJIHG

Posting Permissions

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