3 #include "primitivebuilder.h"
10 BoxBuilder::BoxBuilder(float w, float h, float d):
11 origin(-w/2, -h/2, -d/2),
15 BoxBuilder::BoxBuilder(const Vector3 &o, const Vector3 &s):
20 void BoxBuilder::build(PrimitiveBuilder &builder) const
22 builder.normal(1, 0, 0);
23 build_face(builder, Vector3(origin.x+span.x, origin.y, origin.z), Vector3(0, span.y, 0), Vector3(0, 0, span.z));
24 builder.normal(0, 1, 0);
25 build_face(builder, Vector3(origin.x+span.x, origin.y+span.y, origin.z), Vector3(-span.x, 0, 0), Vector3(0, 0, span.z));
26 builder.normal(-1, 0, 0);
27 build_face(builder, Vector3(origin.x, origin.y+span.y, origin.z), Vector3(0, -span.y, 0), Vector3(0, 0, span.z));
28 builder.normal(0, -1, 0);
29 build_face(builder, origin, Vector3(span.x, 0, 0), Vector3(0, 0, span.z));
30 builder.normal(0, 0, 1);
31 build_face(builder, Vector3(origin.x, origin.y, origin.z+span.z), Vector3(span.x, 0, 0), Vector3(0, span.y, 0));
32 builder.normal(0, 0, -1);
33 build_face(builder, Vector3(origin.x+span.x, origin.y, origin.z), Vector3(-span.x, 0, 0), Vector3(0, span.y, 0));
36 void BoxBuilder::build_face(PrimitiveBuilder &builder, const Vector3 &o, const Vector3 &s1, const Vector3 &s2) const
39 if(generate_tbn || tex_fit!=STRETCH)
47 builder.tangent(s1/l1);
48 builder.binormal(s2/l2);
53 adjust_texture_scale(u_size, v_size, l1, l2);
55 builder.begin(TRIANGLE_STRIP);
56 builder.texcoord(0, v_size);
58 builder.texcoord(0, 0);
60 builder.texcoord(u_size, v_size);
61 builder.vertex(o+s1+s2);
62 builder.texcoord(u_size, 0);