]> git.tdb.fi Git - libs/gl.git/blob - source/geometrybuilder.cpp
327e8fcf8a3b56b4daa35b8bf20727bc6f7c6ad6
[libs/gl.git] / source / geometrybuilder.cpp
1 /* $Id$
2
3 This file is part of libmspgl
4 Copyright © 2011  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include "geometrybuilder.h"
9 #include "meshbuilder.h"
10
11 namespace Msp {
12 namespace GL {
13
14 GeometryBuilder::GeometryBuilder():
15         tangent_attr(-1),
16         binormal_attr(-1),
17         tex_fit(STRETCH)
18 { }
19
20 GeometryBuilder &GeometryBuilder::tangent(unsigned t)
21 {
22         tangent_attr = t;
23         return *this;
24 }
25
26 GeometryBuilder &GeometryBuilder::binormal(unsigned b)
27 {
28         binormal_attr = b;
29         return *this;
30 }
31
32 GeometryBuilder &GeometryBuilder::texture_fit(TextureFit tf)
33 {
34         tex_fit = tf;
35         return *this;
36 }
37
38 void GeometryBuilder::adjust_texture_scale(float &u_scale, float &v_scale, float width, float height) const
39 {
40         if(tex_fit!=STRETCH)
41         {
42                 if((width<height)==(tex_fit==CROP))
43                         u_scale *= width/height;
44                 else
45                         v_scale *= height/width;
46         }
47 }
48
49 void GeometryBuilder::build(Mesh &mesh) const
50 {
51         MeshBuilder builder(mesh);
52         builder.auto_offset();
53         build(builder);
54 }
55
56 } // namespace GL
57 } // namespace Msp