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
22 for(unsigned i=0; i<2; ++i)
24 float z = (i-0.5)*length;
25 builder.normal(0, 0, i*2.0-1.0);
26 builder.texcoord(0.5, 0.5);
28 builder.tangent((i ? 1 : -1), 0, 0);
29 builder.vertex(0, 0, z);
30 for(unsigned j=0; j<segments; ++j)
32 float a = j*M_PI*2/segments;
35 builder.texcoord(0.5+(i ? 0.5 : -0.5)*c, 0.5+0.5*s);
36 builder.vertex(radius*c, radius*s, z);
40 float u_scale = 1.0/segments;
42 adjust_texture_scale(u_scale, v_scale, radius*M_PI*2, length);
44 for(unsigned i=0; i<2; ++i)
46 float z = (i-0.5)*length;
47 for(unsigned j=0; j<=segments; ++j)
49 float a = j*M_PI*2/segments;
52 builder.normal(c, s, 0);
53 builder.texcoord(j*u_scale, i*v_scale);
55 builder.tangent(-s, c, 0);
56 builder.vertex(radius*c, radius*s, z);
61 for(unsigned i=0; i<2; ++i)
63 builder.begin(TRIANGLE_FAN);
64 builder.element(base);
65 for(unsigned j=0; j<=segments; ++j)
66 builder.element(base+1+j%segments);
72 builder.begin(TRIANGLE_STRIP);
73 for(unsigned j=0; j<=segments; ++j)
75 builder.element(base+segments+1+j);
76 builder.element(base+j);