X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fbox.cpp;h=46f1b48ed7bfc315a23a221134544adcccf5c19e;hp=5347ccc7da411c847d0c5df13ce4cd27984fbde3;hb=4e4a3514961d130045619ea74d0bbab71580838c;hpb=fc503f2996e663e6bea88d95e4b251dd87428161 diff --git a/source/box.cpp b/source/box.cpp index 5347ccc7..46f1b48e 100644 --- a/source/box.cpp +++ b/source/box.cpp @@ -1,10 +1,3 @@ -/* $Id$ - -This file is part of libmspgl -Copyright © 2011 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - #include #include "box.h" #include "primitivebuilder.h" @@ -43,15 +36,17 @@ void BoxBuilder::build(PrimitiveBuilder &builder) const 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(generate_tbn || tex_fit!=STRETCH) + { + l1 = s1.norm(); + l2 = s2.norm(); + } - 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); + if(generate_tbn) + { + builder.tangent(s1/l1); + builder.binormal(s2/l2); + } float u_size = 1; float v_size = 1; @@ -59,13 +54,13 @@ void BoxBuilder::build_face(PrimitiveBuilder &builder, const Vector3 &o, const V builder.begin(TRIANGLE_STRIP); builder.texcoord(0, v_size); - builder.vertex(o.x+s2.x, o.y+s2.y, o.z+s2.z); + builder.vertex(o+s2); builder.texcoord(0, 0); - builder.vertex(o.x, o.y, o.z); + builder.vertex(o); 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.vertex(o+s1+s2); builder.texcoord(u_size, 0); - builder.vertex(o.x+s1.x, o.y+s1.y, o.z+s1.z); + builder.vertex(o+s1); builder.end(); }