1 /*
2  Copyright (C) 2010-2014 Kristian Duske
3 
4  This file is part of TrenchBroom.
5 
6  TrenchBroom is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  TrenchBroom is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with TrenchBroom. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef TrenchBroom_ParallelTexCoordSystem
21 #define TrenchBroom_ParallelTexCoordSystem
22 
23 #include "TrenchBroom.h"
24 #include "VecMath.h"
25 #include "Model/TexCoordSystem.h"
26 
27 namespace TrenchBroom {
28     namespace Model {
29         class BrushFaceAttributes;
30         class ParallelTexCoordSystem;
31 
32         class ParallelTexCoordSystemSnapshot : public TexCoordSystemSnapshot {
33         private:
34             ParallelTexCoordSystem* m_coordSystem;
35             Vec3 m_xAxis;
36             Vec3 m_yAxis;
37         public:
38             ParallelTexCoordSystemSnapshot(ParallelTexCoordSystem* coordSystem);
39         private:
40             void doRestore();
41         };
42 
43         class ParallelTexCoordSystem : public TexCoordSystem {
44         private:
45             Vec3 m_xAxis;
46             Vec3 m_yAxis;
47 
48             friend class ParallelTexCoordSystemSnapshot;
49         public:
50             ParallelTexCoordSystem(const Vec3& point0, const Vec3& point1, const Vec3& point2, const BrushFaceAttributes& attribs);
51             ParallelTexCoordSystem(const Vec3& xAxis, const Vec3& yAxis, const BrushFaceAttributes& attribs);
52         private:
53             TexCoordSystem* doClone() const;
54             TexCoordSystemSnapshot* doTakeSnapshot();
55 
56             Vec3 getXAxis() const;
57             Vec3 getYAxis() const;
58             Vec3 getZAxis() const;
59 
60             void doResetTextureAxes(const Vec3& normal);
61             void doResetTextureAxesToParaxial(const Vec3& normal, float angle);
62             void doResetTextureAxesToParallel(const Vec3& normal, float angle);
63 
64             bool isRotationInverted(const Vec3& normal) const;
65             Vec2f doGetTexCoords(const Vec3& point, const BrushFaceAttributes& attribs) const;
66 
67             void doSetRotation(const Vec3& normal, float oldAngle, float newAngle);
68             void applyRotation(const Vec3& normal, FloatType angle);
69 
70             void doTransform(const Plane3& oldBoundary, const Mat4x4& transformation, BrushFaceAttributes& attribs, bool lockTexture, const Vec3& invariant);
71             float computeTextureAngle(const Plane3& oldBoundary, const Mat4x4& transformation) const;
72             Mat4x4 computeNonTextureRotation(const Vec3& oldNormal, const Vec3& newNormal, const Mat4x4& rotation) const;
73 
74             void doUpdateNormal(const Vec3& oldNormal, const Vec3& newNormal, const BrushFaceAttributes& attribs);
75 
76             void doShearTexture(const Vec3& normal, const Vec2f& factors);
77 
78             float doMeasureAngle(float currentAngle, const Vec2f& center, const Vec2f& point) const;
79             void computeInitialAxes(const Vec3& normal, Vec3& xAxis, Vec3& yAxis) const;
80         };
81     }
82 }
83 
84 #endif /* defined(TrenchBroom_ParallelTexCoordSystem) */
85