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 // Timo 28 // new brush primitive texdef 29 struct brushprimit_texdef_t 30 { brushprimit_texdef_tbrushprimit_texdef_t31 brushprimit_texdef_t() 32 { 33 coords[0][0] = 2.0f; 34 coords[0][1] = 0.f; 35 coords[0][2] = 0.f; 36 coords[1][0] = 0.f; 37 coords[1][1] = 2.0f; 38 coords[1][2] = 0.f; 39 } removeScalebrushprimit_texdef_t40 void removeScale(std::size_t width, std::size_t height) 41 { 42 #if 1 43 coords[0][0] *= width; 44 coords[0][1] *= width; 45 coords[0][2] *= width; 46 coords[1][0] *= height; 47 coords[1][1] *= height; 48 coords[1][2] *= height; 49 #endif 50 } addScalebrushprimit_texdef_t51 void addScale(std::size_t width, std::size_t height) 52 { 53 #if 1 54 coords[0][0] /= width; 55 coords[0][1] /= width; 56 coords[0][2] /= width; 57 coords[1][0] /= height; 58 coords[1][1] /= height; 59 coords[1][2] /= height; 60 #endif 61 } 62 float coords[2][3]; 63 }; 64 65 class TextureProjection 66 { 67 public: 68 texdef_t m_texdef; 69 brushprimit_texdef_t m_brushprimit_texdef; 70 Vector3 m_basis_s; 71 Vector3 m_basis_t; 72 TextureProjection()73 TextureProjection() 74 { 75 } TextureProjection(const texdef_t & texdef,const brushprimit_texdef_t & brushprimit_texdef,const Vector3 & basis_s,const Vector3 & basis_t)76 TextureProjection( 77 const texdef_t& texdef, 78 const brushprimit_texdef_t& brushprimit_texdef, 79 const Vector3& basis_s, 80 const Vector3& basis_t 81 ) : 82 m_texdef(texdef), 83 m_brushprimit_texdef(brushprimit_texdef), 84 m_basis_s(basis_s), 85 m_basis_t(basis_t) 86 { 87 } 88 }; 89 90 float Texdef_getDefaultTextureScale(); 91 92 class texdef_t; 93 struct Winding; 94 template<typename Element> class BasicVector3; 95 typedef BasicVector3<float> Vector3; 96 template<typename Element> class BasicVector4; 97 typedef BasicVector4<float> Vector4; 98 typedef Vector4 Quaternion; 99 class Matrix4; 100 class Plane3; 101 102 void Normal_GetTransform(const Vector3& normal, Matrix4& transform); 103 104 void TexDef_Construct_Default(TextureProjection& projection); 105 106 void Texdef_Assign(TextureProjection& projection, const TextureProjection& other); 107 void Texdef_Shift(TextureProjection& projection, float s, float t); 108 void Texdef_Scale(TextureProjection& projection, float s, float t); 109 void Texdef_Rotate(TextureProjection& projection, float angle); 110 void Texdef_FitTexture(TextureProjection& projection, std::size_t width, std::size_t height, const Vector3& normal, const Winding& w, float s_repeat, float t_repeat); 111 void Texdef_EmitTextureCoordinates(const TextureProjection& projection, std::size_t width, std::size_t height, Winding& w, const Vector3& normal, const Matrix4& localToWorld); 112 113 void ShiftScaleRotate_fromFace(texdef_t& shiftScaleRotate, const TextureProjection& projection); 114 void ShiftScaleRotate_toFace(const texdef_t& shiftScaleRotate, TextureProjection& projection); 115 116 void Texdef_transformLocked(TextureProjection& projection, std::size_t width, std::size_t height, const Plane3& plane, const Matrix4& transform); 117 void Texdef_normalise(TextureProjection& projection, float width, float height); 118 119 enum TexdefTypeId 120 { 121 TEXDEFTYPEID_QUAKE, 122 TEXDEFTYPEID_BRUSHPRIMITIVES, 123 TEXDEFTYPEID_HALFLIFE, 124 }; 125 126 struct bp_globals_t 127 { 128 // tells if we are internally using brush primitive (texture coordinates and map format) 129 // this is a shortcut for IntForKey( g_qeglobals.d_project_entity, "brush_primit" ) 130 // NOTE: must keep the two ones in sync 131 TexdefTypeId m_texdefTypeId; 132 }; 133 134 extern bp_globals_t g_bp_globals; 135 extern float g_texdef_default_scale; 136 137 #endif 138