]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - radiant/brush_primit.h
q3map2: fix prt loading for vis computation when using -prtfile
[xonotic/netradiant.git] / radiant / brush_primit.h
1 /*
2    Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3    For a list of contributors, see the accompanying CONTRIBUTORS file.
4
5    This file is part of GtkRadiant.
6
7    GtkRadiant is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    GtkRadiant is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with GtkRadiant; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21
22 #if !defined( INCLUDED_BRUSH_PRIMIT_H )
23 #define INCLUDED_BRUSH_PRIMIT_H
24
25 #include "math/vector.h"
26 #include "itexdef.h"
27 #include "debugging/debugging.h"
28
29 // Timo
30 // new brush primitive texdef
31 struct brushprimit_texdef_t {
32     brushprimit_texdef_t()
33     {
34         coords[0][0] = 2.0f;
35         coords[0][1] = 0.f;
36         coords[0][2] = 0.f;
37         coords[1][0] = 0.f;
38         coords[1][1] = 2.0f;
39         coords[1][2] = 0.f;
40     }
41
42     void removeScale(std::size_t width, std::size_t height)
43     {
44 #if 1
45         coords[0][0] *= width;
46         coords[0][1] *= width;
47         coords[0][2] *= width;
48         coords[1][0] *= height;
49         coords[1][1] *= height;
50         coords[1][2] *= height;
51 #endif
52     }
53
54     void addScale(std::size_t width, std::size_t height)
55     {
56 #if 1
57         ASSERT_MESSAGE(width > 0, "shader-width is 0");
58         ASSERT_MESSAGE(height > 0, "shader-height is 0");
59         coords[0][0] /= width;
60         coords[0][1] /= width;
61         coords[0][2] /= width;
62         coords[1][0] /= height;
63         coords[1][1] /= height;
64         coords[1][2] /= height;
65 #endif
66     }
67
68     float coords[2][3];
69 };
70
71 class TextureProjection {
72 public:
73     texdef_t m_texdef;
74     brushprimit_texdef_t m_brushprimit_texdef;
75     Vector3 m_basis_s;
76     Vector3 m_basis_t;
77
78     TextureProjection()
79     {
80     }
81
82     TextureProjection(
83             const texdef_t &texdef,
84             const brushprimit_texdef_t &brushprimit_texdef,
85             const Vector3 &basis_s,
86             const Vector3 &basis_t
87     ) :
88             m_texdef(texdef),
89             m_brushprimit_texdef(brushprimit_texdef),
90             m_basis_s(basis_s),
91             m_basis_t(basis_t)
92     {
93     }
94 };
95
96 float Texdef_getDefaultTextureScale();
97
98 class texdef_t;
99
100 struct Winding;
101
102 template<typename Element>
103 class BasicVector3;
104
105 typedef BasicVector3<float> Vector3;
106
107 template<typename Element>
108 class BasicVector4;
109
110 typedef BasicVector4<float> Vector4;
111 typedef Vector4 Quaternion;
112
113 class Matrix4;
114
115 class Plane3;
116
117 void Normal_GetTransform(const Vector3 &normal, Matrix4 &transform);
118
119 void TexDef_Construct_Default(TextureProjection &projection);
120
121 void Texdef_Assign(TextureProjection &projection, const TextureProjection &other);
122
123 void Texdef_Shift(TextureProjection &projection, float s, float t);
124
125 void Texdef_Scale(TextureProjection &projection, float s, float t);
126
127 void Texdef_Rotate(TextureProjection &projection, float angle);
128
129 void Texdef_FitTexture(TextureProjection &projection, std::size_t width, std::size_t height, const Vector3 &normal,
130                        const Winding &w, float s_repeat, float t_repeat);
131
132 void
133 Texdef_EmitTextureCoordinates(const TextureProjection &projection, std::size_t width, std::size_t height, Winding &w,
134                               const Vector3 &normal, const Matrix4 &localToWorld);
135
136 void ShiftScaleRotate_fromFace(texdef_t &shiftScaleRotate, const TextureProjection &projection);
137
138 void ShiftScaleRotate_toFace(const texdef_t &shiftScaleRotate, TextureProjection &projection);
139
140 void Texdef_transformLocked(TextureProjection &projection, std::size_t width, std::size_t height, const Plane3 &plane,
141                             const Matrix4 &transform);
142
143 void Texdef_normalise(TextureProjection &projection, float width, float height);
144
145 enum TexdefTypeId {
146     TEXDEFTYPEID_QUAKE,
147     TEXDEFTYPEID_BRUSHPRIMITIVES,
148     TEXDEFTYPEID_HALFLIFE,
149 };
150
151 struct bp_globals_t {
152     // tells if we are internally using brush primitive (texture coordinates and map format)
153     // this is a shortcut for IntForKey( g_qeglobals.d_project_entity, "brush_primit" )
154     // NOTE: must keep the two ones in sync
155     TexdefTypeId m_texdefTypeId;
156 };
157
158 extern bp_globals_t g_bp_globals;
159 extern float g_texdef_default_scale;
160
161 void ComputeAxisBase(const Vector3 &normal, Vector3 &texS, Vector3 &texT);
162
163 #endif