X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fbox.cpp;h=46f1b48ed7bfc315a23a221134544adcccf5c19e;hb=refs%2Fheads%2Fmaster;hp=5347ccc7da411c847d0c5df13ce4cd27984fbde3;hpb=fc503f2996e663e6bea88d95e4b251dd87428161;p=libs%2Fgl.git diff --git a/source/box.cpp b/source/box.cpp deleted file mode 100644 index 5347ccc7..00000000 --- a/source/box.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* $Id$ - -This file is part of libmspgl -Copyright © 2011 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - -#include -#include "box.h" -#include "primitivebuilder.h" - -using namespace std; - -namespace Msp { -namespace GL { - -BoxBuilder::BoxBuilder(float w, float h, float d): - origin(-w/2, -h/2, -d/2), - span(w, h, d) -{ } - -BoxBuilder::BoxBuilder(const Vector3 &o, const Vector3 &s): - origin(o), - span(s) -{ } - -void BoxBuilder::build(PrimitiveBuilder &builder) const -{ - builder.normal(1, 0, 0); - build_face(builder, Vector3(origin.x+span.x, origin.y, origin.z), Vector3(0, span.y, 0), Vector3(0, 0, span.z)); - builder.normal(0, 1, 0); - build_face(builder, Vector3(origin.x+span.x, origin.y+span.y, origin.z), Vector3(-span.x, 0, 0), Vector3(0, 0, span.z)); - builder.normal(-1, 0, 0); - build_face(builder, Vector3(origin.x, origin.y+span.y, origin.z), Vector3(0, -span.y, 0), Vector3(0, 0, span.z)); - builder.normal(0, -1, 0); - build_face(builder, origin, Vector3(span.x, 0, 0), Vector3(0, 0, span.z)); - builder.normal(0, 0, 1); - build_face(builder, Vector3(origin.x, origin.y, origin.z+span.z), Vector3(span.x, 0, 0), Vector3(0, span.y, 0)); - builder.normal(0, 0, -1); - build_face(builder, Vector3(origin.x+span.x, origin.y, origin.z), Vector3(-span.x, 0, 0), Vector3(0, span.y, 0)); -} - -void BoxBuilder::build_face(PrimitiveBuilder &builder, const Vector3 &o, const Vector3 &s1, const Vector3 &s2) const -{ - float l1 = 1, l2 = 1; - if(tangent_attr>=0 || tex_fit!=STRETCH) - l1 = sqrt(s1.x*s1.x+s1.y*s1.y+s1.z*s1.z); - if(binormal_attr>=0 || tex_fit!=STRETCH) - l2 = sqrt(s2.x*s2.x+s2.y*s2.y+s2.z*s2.z); - - if(tangent_attr>=0) - builder.attrib(tangent_attr, s1.x/l1, s1.y/l1, s1.z/l1); - if(binormal_attr>=0) - builder.attrib(binormal_attr, s2.x/l2, s2.y/l2, s2.z/l2); - - float u_size = 1; - float v_size = 1; - adjust_texture_scale(u_size, v_size, l1, l2); - - builder.begin(TRIANGLE_STRIP); - builder.texcoord(0, v_size); - builder.vertex(o.x+s2.x, o.y+s2.y, o.z+s2.z); - builder.texcoord(0, 0); - builder.vertex(o.x, o.y, o.z); - builder.texcoord(u_size, v_size); - builder.vertex(o.x+s1.x+s2.x, o.y+s1.y+s2.y, o.z+s1.z+s2.z); - builder.texcoord(u_size, 0); - builder.vertex(o.x+s1.x, o.y+s1.y, o.z+s1.z); - builder.end(); -} - -} // namespace GL -} // namespace Msp