1 #define _USE_MATH_DEFINES
4 #include "primitivebuilder.h"
11 CylinderBuilder::CylinderBuilder(float r, float l, unsigned s):
20 void CylinderBuilder::build(PrimitiveBuilder &builder) const
23 builder.binormal(0, 1, 0);
24 for(unsigned i=0; i<2; ++i)
26 float z = (i-0.5)*length;
27 builder.normal(0, 0, i*2.0-1.0);
28 builder.texcoord(0.5, 0.5);
30 builder.tangent((i ? 1 : -1), 0, 0);
31 builder.vertex(0, 0, z);
32 for(unsigned j=0; j<segments; ++j)
34 float a = j*M_PI*2/segments;
37 builder.texcoord(0.5+(i ? 0.5 : -0.5)*c, 0.5+0.5*s);
38 builder.vertex(radius*c, radius*s, z);
42 float u_scale = 1.0/segments;
44 adjust_texture_scale(u_scale, v_scale, radius*M_PI*2, length);
47 builder.binormal(0, 0, 1);
48 for(unsigned i=0; i<2; ++i)
50 float z = (i-0.5)*length;
51 for(unsigned j=0; j<=segments; ++j)
53 float a = j*M_PI*2/segments;
56 builder.normal(c, s, 0);
57 builder.texcoord(j*u_scale, i*v_scale);
59 builder.tangent(-s, c, 0);
60 builder.vertex(radius*c, radius*s, z);
65 for(unsigned i=0; i<2; ++i)
67 builder.begin(TRIANGLE_FAN);
68 builder.element(base);
69 for(unsigned j=0; j<=segments; ++j)
70 builder.element(base+1+j%segments);
76 builder.begin(TRIANGLE_STRIP);
77 for(unsigned j=0; j<=segments; ++j)
79 builder.element(base+segments+1+j);
80 builder.element(base+j);