# Question on how to draw 3d pipes in Direct3d

This topic is 3318 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello to everyone, My name is Falco and I wish you accept compliments for this super forum! My question is this: I have to draw 3d pipes in directx. The bends are not always 90 degrees as in the famous screensaver. Then - given the lengths of the straight parts and the bends's angles - I am looking for a simple way to draw these pipes. For the stright parts there is the Cylinder method and this is very easy to use. But for the bends I really do not know how to do that in a simple way. Can someone help me? Thank you! :-)

##### Share on other sites
Is it possible to draw the bend using the Thorus method and then erasing a part of the thorus mesh in order to obtain a bend?

I other words, does someone know how to draw a sector of thorus?

##### Share on other sites
Well... That'll require some math. I suggest you start by rendering a cylinder based on a length, a radius, ammount of length-segments (cylinder slices) and ammount of circumvential segments (ammount of pie-shapes per slice).

You have to visualize a cylinder as a series of circles defined by a certain number of vertices. The ammount of vertices per circle equals the ammount of circumvential segments. The ammount of circles minus one equals the ammount of length segments. You have to generate all the vertices using a loop:

  for (I=0; I<Circumvential_Segs; I++)   {    Angle = (I/Circumvential_Segs) * (2*pi);    Vertex.x = sin(Angle) * Radius;    Vertex.y = cos(Angle) * Radius;    Vertex.z = (Cylinder_Length / Length_Segs) * I;  }

If you have generated all the vertices that make up the circles, you can connect by filling the indexbuffer.

It's a little hard to explain, but i hope this helps you a bit.