3 This file is part of libmspgl
4 Copyright © 2011 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
10 #include "primitivebuilder.h"
17 CylinderBuilder::CylinderBuilder(float r, float l, unsigned s):
26 void CylinderBuilder::build(PrimitiveBuilder &builder) const
29 builder.attrib(binormal_attr, 0, 1, 0);
30 for(unsigned i=0; i<2; ++i)
32 float z = (i-0.5)*length;
33 builder.normal(0, 0, i*2.0-1.0);
34 builder.texcoord(0.5, 0.5);
36 builder.attrib(tangent_attr, (i ? 1 : -1), 0, 0);
37 builder.vertex(0, 0, z);
38 for(unsigned j=0; j<segments; ++j)
40 float a = j*M_PI*2/segments;
43 builder.texcoord(0.5+(i ? 0.5 : -0.5)*c, 0.5+0.5*s);
44 builder.vertex(radius*c, radius*s, z);
48 float u_scale = 1.0/segments;
50 adjust_texture_scale(u_scale, v_scale, radius*M_PI*2, length);
53 builder.attrib(binormal_attr, 0, 0, 1);
54 for(unsigned i=0; i<2; ++i)
56 float z = (i-0.5)*length;
57 for(unsigned j=0; j<=segments; ++j)
59 float a = j*M_PI*2/segments;
62 builder.normal(c, s, 0);
63 builder.texcoord(j*u_scale, i*v_scale);
65 builder.attrib(tangent_attr, -s, c, 0);
66 builder.vertex(radius*c, radius*s, z);
71 for(unsigned i=0; i<2; ++i)
73 builder.begin(TRIANGLE_FAN);
74 builder.element(base);
75 for(unsigned j=0; j<=segments; ++j)
76 builder.element(base+1+j%segments);
82 builder.begin(TRIANGLE_STRIP);
83 for(unsigned j=0; j<=segments; ++j)
85 builder.element(base+segments+1+j);
86 builder.element(base+j);