]> git.tdb.fi Git - libs/gl.git/blobdiff - source/box.cpp
Standard vertex components for tangent and binormal vectors
[libs/gl.git] / source / box.cpp
index 3d6f15fdc6f422e3259088de7a599b8eba6ba762..b20f0d04e98c237d6c96a1f99844f1898149d0e9 100644 (file)
@@ -1,10 +1,3 @@
-/* $Id$
-
-This file is part of libmspgl
-Copyright © 2011  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
 #include <cmath>
 #include "box.h"
 #include "primitivebuilder.h"
@@ -42,22 +35,23 @@ void BoxBuilder::build(PrimitiveBuilder &builder) const
 
 void BoxBuilder::build_face(PrimitiveBuilder &builder, const Vector3 &o, const Vector3 &s1, const Vector3 &s2) const
 {
-       if(tangent_attr>=0)
+       float l1 = 1, l2 = 1;
+       if(generate_tbn || tex_fit!=STRETCH)
        {
-               builder.attrib(tangent_attr, s1.x, s1.y, s1.z);
-               builder.attrib(binormal_attr, s2.x, s2.y, s2.z);
+               l1 = sqrt(s1.x*s1.x+s1.y*s1.y+s1.z*s1.z);
+               l2 = sqrt(s2.x*s2.x+s2.y*s2.y+s2.z*s2.z);
        }
-       float u_size = 1;
-       float v_size = 1;
-       if(tex_fit!=STRETCH)
+
+       if(generate_tbn)
        {
-               float l1 = sqrt(s1.x*s1.x+s1.y*s1.y+s1.z*s1.z);
-               float l2 = sqrt(s2.x*s2.x+s2.y*s2.y+s2.z*s2.z);
-               if((l1<l2)==(tex_fit==CUT))
-                       u_size = l1/l2;
-               else
-                       v_size = l2/l1;
+               builder.tangent(s1.x/l1, s1.y/l1, s1.z/l1);
+               builder.binormal(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);