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(tangent_attr>=0 || tex_fit!=STRETCH)
40 l1 = sqrt(s1.x*s1.x+s1.y*s1.y+s1.z*s1.z);
41 if(binormal_attr>=0 || tex_fit!=STRETCH)
42 l2 = sqrt(s2.x*s2.x+s2.y*s2.y+s2.z*s2.z);
45 builder.attrib(tangent_attr, s1.x/l1, s1.y/l1, s1.z/l1);
47 builder.attrib(binormal_attr, s2.x/l2, s2.y/l2, s2.z/l2);
51 adjust_texture_scale(u_size, v_size, l1, l2);
53 builder.begin(TRIANGLE_STRIP);
54 builder.texcoord(0, v_size);
55 builder.vertex(o.x+s2.x, o.y+s2.y, o.z+s2.z);
56 builder.texcoord(0, 0);
57 builder.vertex(o.x, o.y, o.z);
58 builder.texcoord(u_size, v_size);
59 builder.vertex(o.x+s1.x+s2.x, o.y+s1.y+s2.y, o.z+s1.z+s2.z);
60 builder.texcoord(u_size, 0);
61 builder.vertex(o.x+s1.x, o.y+s1.y, o.z+s1.z);