3 #include "primitivebuilder.h"
10 CapsuleBuilder::CapsuleBuilder(float r, float l, unsigned s, unsigned n):
23 void CapsuleBuilder::build(PrimitiveBuilder &builder) const
25 float u_scale = 1.0/segments;
26 float v_scale = 1/(length+radius*M_PI);
27 adjust_texture_scale(u_scale, v_scale, radius*M_PI*2, length+radius*M_PI);
29 builder.normal(0, 0, -1);
30 builder.texcoord(0.5, 0);
31 builder.vertex(0, 0, -length/2-radius);
32 for(unsigned i=1; i<rings; ++i)
34 float cz = length*(i>rings/2 ? 0.5 : -0.5);
35 float v = ((i>rings/2 ? i-1 : i)*radius*M_PI/(rings-1)+(i>rings/2 ? length : 0))*v_scale;
36 float ra = (i>rings/2 ? i-1 : i)*M_PI/(rings-1);
39 for(unsigned j=0; j<=segments; ++j)
41 float sa = j*M_PI*2/segments;
44 builder.normal(rs*sc, rs*ss, -rc);
47 builder.tangent(-ss, sc, 0);
48 builder.binormal(rc*sc, rc*ss, rs);
50 builder.texcoord(j*u_scale, v);
51 builder.vertex(rs*sc*radius, rs*ss*radius, cz-rc*radius);
54 builder.normal(0, 0, 1);
55 builder.texcoord(0.5, (length+radius*M_PI)*v_scale);
56 builder.vertex(0, 0, length/2+radius);
58 for(unsigned i=0; i<segments; ++i)
60 builder.begin(GL::TRIANGLE_STRIP);
62 for(unsigned j=0; j+1<rings; ++j)
64 builder.element(1+j*(segments+1)+i+1);
65 builder.element(1+j*(segments+1)+i);
67 builder.element((segments+1)*(rings-1)+1);