PDA

View Full Version : implementation of sweep object



yyyy988
03-05-2011, 11:01 PM
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!

mobeen
03-06-2011, 03:02 AM
http://graphicsbb.itgo.com/solutions/extrude.html
http://stackoverflow.com/questions/4117084/opengl-how-to-lathe-a-2d-shape-into-3d

yyyy988
03-06-2011, 03:35 AM
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?

ZbuffeR
03-06-2011, 03:19 PM
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 ?

yyyy988
03-06-2011, 03:57 PM
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?

ZbuffeR
03-06-2011, 04:48 PM
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.

yyyy988
03-06-2011, 05:44 PM
Could you give me some pseudo-code about what I should do step by
step?

ZbuffeR
03-06-2011, 07:15 PM
Let's extrude an hexagon along L distance, to make some basic cylinder :


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