3 #include "primitivebuilder.h"
10 CylinderBuilder::CylinderBuilder(float r, float l, unsigned s):
19 void CylinderBuilder::build(PrimitiveBuilder &builder) const
22 builder.binormal(0, 1, 0);
23 for(unsigned i=0; i<2; ++i)
25 float z = (i-0.5)*length;
26 builder.normal(0, 0, i*2.0-1.0);
27 builder.texcoord(0.5, 0.5);
29 builder.tangent((i ? 1 : -1), 0, 0);
30 builder.vertex(0, 0, z);
31 for(unsigned j=0; j<segments; ++j)
33 float a = j*M_PI*2/segments;
36 builder.texcoord(0.5+(i ? 0.5 : -0.5)*c, 0.5+0.5*s);
37 builder.vertex(radius*c, radius*s, z);
41 float u_scale = 1.0/segments;
43 adjust_texture_scale(u_scale, v_scale, radius*M_PI*2, length);
46 builder.binormal(0, 0, 1);
47 for(unsigned i=0; i<2; ++i)
49 float z = (i-0.5)*length;
50 for(unsigned j=0; j<=segments; ++j)
52 float a = j*M_PI*2/segments;
55 builder.normal(c, s, 0);
56 builder.texcoord(j*u_scale, i*v_scale);
58 builder.tangent(-s, c, 0);
59 builder.vertex(radius*c, radius*s, z);
64 for(unsigned i=0; i<2; ++i)
66 builder.begin(TRIANGLE_FAN);
67 builder.element(base);
68 for(unsigned j=0; j<=segments; ++j)
69 builder.element(base+1+j%segments);
75 builder.begin(TRIANGLE_STRIP);
76 for(unsigned j=0; j<=segments; ++j)
78 builder.element(base+segments+1+j);
79 builder.element(base+j);