I have a path, lets say a bezier, or a circle.
I d like to make a continously 3d cylinder (tunnel) on it (R=0.5f)
How can I calculate tha TRIangles (TRIANGLE_STRIP) coordinate, and the texture coords right?
|
|
|
You need normal and binormal for each point in your curve, as illustrated in this picture as n and b:
You can calculate the tangent t from the curve, it's the first derivative. If the derivative is not available, you can approximate it with a direction vector from previous sample point to the next one. Binormal is simply a cross product from tangent and normal. The only problem is how to define the normal. Normals can be arbitrary, but it should always be on the "same side of the curve" so that adjacent vertices in the tube are close to each other and not jumping around. Four ways to calculate the normal comes to my mind.
When you have the normals and binormals, you can generate the tunnel vertices simply with a linear combination of those vectors.
Texture coordinates are simple to calculate if your points are evenly distributed or the stretching is not a problem. If those are a problem, you need to numerically first calculate the length of the curve and then also numerically find the correct texture coordinate for any given point in the curve. This gives the u part. v part is simply |
||||
|
|