-void BPTexdef_Assign(brushprimit_texdef_t &bp_td, const brushprimit_texdef_t &bp_other)
-{
- bp_td = bp_other;
-}
-
-void BPTexdef_Shift(brushprimit_texdef_t &bp_td, float s, float t)
-{
- // shift a texture (texture adjustments) along it's current texture axes
- // x and y are geometric values, which we must compute as ST increments
- // this depends on the texture size and the pixel/texel ratio
- // as a ratio against texture size
- // the scale of the texture is not relevant here (we work directly on a transformation from the base vectors)
- bp_td.coords[0][2] -= s;
- bp_td.coords[1][2] += t;
-}
-
-void BPTexdef_Scale(brushprimit_texdef_t &bp_td, float s, float t)
-{
- // apply same scale as the spinner button of the surface inspector
- texdef_t texdef;
- // compute fake shift scale rot
- TexMatToFakeTexCoords(bp_td, texdef);
- // update
- texdef.scale[0] += s;
- texdef.scale[1] += t;
- // compute new normalized texture matrix
- FakeTexCoordsToTexMat(texdef, bp_td);
-}
-
-void BPTexdef_Rotate(brushprimit_texdef_t &bp_td, float angle)
-{
- // apply same scale as the spinner button of the surface inspector
- texdef_t texdef;
- // compute fake shift scale rot
- TexMatToFakeTexCoords(bp_td, texdef);
- // update
- texdef.rotate += angle;
- // compute new normalized texture matrix
- FakeTexCoordsToTexMat(texdef, bp_td);
-}
-
-void BPTexdef_Construct(brushprimit_texdef_t &bp_td, std::size_t width, std::size_t height)
-{
- bp_td.coords[0][0] = 1.0f;
- bp_td.coords[1][1] = 1.0f;
- ConvertTexMatWithDimensions(bp_td.coords, 2, 2, bp_td.coords, width, height);
-}
-
-void Texdef_Assign(TextureProjection &projection, const TextureProjection &other)
-{
- if (g_bp_globals.m_texdefTypeId == TEXDEFTYPEID_BRUSHPRIMITIVES) {
- BPTexdef_Assign(projection.m_brushprimit_texdef, other.m_brushprimit_texdef);
- } else {
- Texdef_Assign(projection.m_texdef, other.m_texdef);
- if (g_bp_globals.m_texdefTypeId == TEXDEFTYPEID_HALFLIFE) {
- projection.m_basis_s = other.m_basis_s;
- projection.m_basis_t = other.m_basis_t;
- }
- }
-}
-
-void Texdef_Shift(TextureProjection &projection, float s, float t)
-{
- if (g_bp_globals.m_texdefTypeId == TEXDEFTYPEID_BRUSHPRIMITIVES) {
- BPTexdef_Shift(projection.m_brushprimit_texdef, s, t);
- } else {
- Texdef_Shift(projection.m_texdef, s, t);
- }
-}
-
-void Texdef_Scale(TextureProjection &projection, float s, float t)
-{
- if (g_bp_globals.m_texdefTypeId == TEXDEFTYPEID_BRUSHPRIMITIVES) {
- BPTexdef_Scale(projection.m_brushprimit_texdef, s, t);
- } else {
- Texdef_Scale(projection.m_texdef, s, t);
- }
-}
-
-void Texdef_Rotate(TextureProjection &projection, float angle)
-{
- if (g_bp_globals.m_texdefTypeId == TEXDEFTYPEID_BRUSHPRIMITIVES) {
- BPTexdef_Rotate(projection.m_brushprimit_texdef, angle);
- } else {
- Texdef_Rotate(projection.m_texdef, angle);
- }
-}
-
-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)
-{
- if (w.numpoints < 3) {
- return;
- }
-
- Matrix4 st2tex;
- Texdef_toTransform(projection, (float) width, (float) height, st2tex);
-
- // the current texture transform
- Matrix4 local2tex = st2tex;
- {
- Matrix4 xyz2st;
- Texdef_basisForNormal(projection, normal, xyz2st);
- matrix4_multiply_by_matrix4(local2tex, xyz2st);
- }
-
- // the bounds of the current texture transform
- AABB bounds;
- for (Winding::const_iterator i = w.begin(); i != w.end(); ++i) {
- Vector3 texcoord = matrix4_transformed_point(local2tex, (*i).vertex);
- aabb_extend_by_point_safe(bounds, texcoord);
- }
- bounds.origin.z() = 0;
- bounds.extents.z() = 1;
-
- // the bounds of a perfectly fitted texture transform
- AABB perfect(Vector3(s_repeat * 0.5, t_repeat * 0.5, 0), Vector3(s_repeat * 0.5, t_repeat * 0.5, 1));
-
- // the difference between the current texture transform and the perfectly fitted transform
- Matrix4 matrix(matrix4_translation_for_vec3(bounds.origin - perfect.origin));
- matrix4_pivoted_scale_by_vec3(matrix, bounds.extents / perfect.extents, perfect.origin);
- matrix4_affine_invert(matrix);
+void BPTexdef_Assign( brushprimit_texdef_t& bp_td, const brushprimit_texdef_t& bp_other ){
+ bp_td = bp_other;
+}
+
+void BPTexdef_Shift( brushprimit_texdef_t& bp_td, float s, float t ){
+ // shift a texture (texture adjustments) along it's current texture axes
+ // x and y are geometric values, which we must compute as ST increments
+ // this depends on the texture size and the pixel/texel ratio
+ // as a ratio against texture size
+ // the scale of the texture is not relevant here (we work directly on a transformation from the base vectors)
+ bp_td.coords[0][2] -= s;
+ bp_td.coords[1][2] += t;
+}
+
+void BPTexdef_Scale( brushprimit_texdef_t& bp_td, float s, float t ){
+ // apply same scale as the spinner button of the surface inspector
+ texdef_t texdef;
+ // compute fake shift scale rot
+ TexMatToFakeTexCoords( bp_td, texdef );
+ // update
+ texdef.scale[0] += s;
+ texdef.scale[1] += t;
+ // compute new normalized texture matrix
+ FakeTexCoordsToTexMat( texdef, bp_td );
+}
+
+void BPTexdef_Rotate( brushprimit_texdef_t& bp_td, float angle ){
+ // apply same scale as the spinner button of the surface inspector
+ texdef_t texdef;
+ // compute fake shift scale rot
+ TexMatToFakeTexCoords( bp_td, texdef );
+ // update
+ texdef.rotate += angle;
+ // compute new normalized texture matrix
+ FakeTexCoordsToTexMat( texdef, bp_td );
+}
+
+void BPTexdef_Construct( brushprimit_texdef_t& bp_td, std::size_t width, std::size_t height ){
+ bp_td.coords[0][0] = 1.0f;
+ bp_td.coords[1][1] = 1.0f;
+ ConvertTexMatWithDimensions( bp_td.coords, 2, 2, bp_td.coords, width, height );
+}
+
+void Texdef_Assign( TextureProjection& projection, const TextureProjection& other ){
+ if ( g_bp_globals.m_texdefTypeId == TEXDEFTYPEID_BRUSHPRIMITIVES ) {
+ BPTexdef_Assign( projection.m_brushprimit_texdef, other.m_brushprimit_texdef );
+ }
+ else
+ {
+ Texdef_Assign( projection.m_texdef, other.m_texdef );
+ if ( g_bp_globals.m_texdefTypeId == TEXDEFTYPEID_HALFLIFE ) {
+ projection.m_basis_s = other.m_basis_s;
+ projection.m_basis_t = other.m_basis_t;
+ }
+ }
+}
+
+void Texdef_Shift( TextureProjection& projection, float s, float t ){
+ if ( g_bp_globals.m_texdefTypeId == TEXDEFTYPEID_BRUSHPRIMITIVES ) {
+ BPTexdef_Shift( projection.m_brushprimit_texdef, s, t );
+ }
+ else
+ {
+ Texdef_Shift( projection.m_texdef, s, t );
+ }
+}
+
+void Texdef_Scale( TextureProjection& projection, float s, float t ){
+ if ( g_bp_globals.m_texdefTypeId == TEXDEFTYPEID_BRUSHPRIMITIVES ) {
+ BPTexdef_Scale( projection.m_brushprimit_texdef, s, t );
+ }
+ else
+ {
+ Texdef_Scale( projection.m_texdef, s, t );
+ }
+}
+
+void Texdef_Rotate( TextureProjection& projection, float angle ){
+ if ( g_bp_globals.m_texdefTypeId == TEXDEFTYPEID_BRUSHPRIMITIVES ) {
+ BPTexdef_Rotate( projection.m_brushprimit_texdef, angle );
+ }
+ else
+ {
+ Texdef_Rotate( projection.m_texdef, angle );
+ }
+}
+
+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 ){
+ if ( w.numpoints < 3 ) {
+ return;
+ }
+
+ Matrix4 st2tex;
+ Texdef_toTransform( projection, (float)width, (float)height, st2tex );
+
+ // the current texture transform
+ Matrix4 local2tex = st2tex;
+ {
+ Matrix4 xyz2st;
+ Texdef_basisForNormal( projection, normal, xyz2st );
+ matrix4_multiply_by_matrix4( local2tex, xyz2st );
+ }
+
+ // the bounds of the current texture transform
+ AABB bounds;
+ for ( Winding::const_iterator i = w.begin(); i != w.end(); ++i )
+ {
+ Vector3 texcoord = matrix4_transformed_point( local2tex, ( *i ).vertex );
+ aabb_extend_by_point_safe( bounds, texcoord );
+ }
+ bounds.origin.z() = 0;
+ bounds.extents.z() = 1;
+
+ // the bounds of a perfectly fitted texture transform
+ AABB perfect( Vector3( s_repeat * 0.5, t_repeat * 0.5, 0 ), Vector3( s_repeat * 0.5, t_repeat * 0.5, 1 ) );
+
+ // the difference between the current texture transform and the perfectly fitted transform
+ Matrix4 matrix( matrix4_translation_for_vec3( bounds.origin - perfect.origin ) );
+ matrix4_pivoted_scale_by_vec3( matrix, bounds.extents / perfect.extents, perfect.origin );
+ matrix4_affine_invert( matrix );
+
+ // apply the difference to the current texture transform
+ matrix4_premultiply_by_matrix4( st2tex, matrix );
+
+ Texdef_fromTransform( projection, (float)width, (float)height, st2tex );
+ Texdef_normalise( projection, (float)width, (float)height );
+}
+
+void Texdef_FitTextureW( TextureProjection& projection, std::size_t width, std::size_t height, const Vector3& normal, const Winding& w, float s_repeat, float t_repeat ){
+ if ( w.numpoints < 3 ) {
+ return;
+ }
+
+ Matrix4 st2tex;
+ Texdef_toTransform( projection, (float)width, (float)height, st2tex );
+
+ // the current texture transform
+ Matrix4 local2tex = st2tex;
+ {
+ Matrix4 xyz2st;
+ Texdef_basisForNormal( projection, normal, xyz2st );
+ matrix4_multiply_by_matrix4( local2tex, xyz2st );
+ }
+
+ // the bounds of the current texture transform
+ AABB bounds;
+ for ( Winding::const_iterator i = w.begin(); i != w.end(); ++i )
+ {
+ Vector3 texcoord = matrix4_transformed_point( local2tex, ( *i ).vertex );
+ aabb_extend_by_point_safe( bounds, texcoord );
+ }
+ bounds.origin.z() = 0;
+ bounds.extents.z() = 1;
+
+ // the bounds of a perfectly fitted texture transform
+ AABB perfect( Vector3( s_repeat * 0.5, s_repeat * 0.5 * bounds.extents.y() / bounds.extents.x(), 0 ), Vector3( s_repeat * 0.5, s_repeat * 0.5 * bounds.extents.y() / bounds.extents.x(), 1 ) );
+
+ // the difference between the current texture transform and the perfectly fitted transform
+ Matrix4 matrix( matrix4_translation_for_vec3( bounds.origin - perfect.origin ) );
+ matrix4_pivoted_scale_by_vec3( matrix, bounds.extents / perfect.extents, perfect.origin );
+ matrix4_affine_invert( matrix );
+
+ // apply the difference to the current texture transform
+ matrix4_premultiply_by_matrix4( st2tex, matrix );
+
+ Texdef_fromTransform( projection, (float)width, (float)height, st2tex );
+ Texdef_normalise( projection, (float)width, (float)height );
+}
+
+void Texdef_FitTextureH( TextureProjection& projection, std::size_t width, std::size_t height, const Vector3& normal, const Winding& w, float s_repeat, float t_repeat ){
+ if ( w.numpoints < 3 ) {
+ return;
+ }
+
+ Matrix4 st2tex;
+ Texdef_toTransform( projection, (float)width, (float)height, st2tex );
+
+ // the current texture transform
+ Matrix4 local2tex = st2tex;
+ {
+ Matrix4 xyz2st;
+ Texdef_basisForNormal( projection, normal, xyz2st );
+ matrix4_multiply_by_matrix4( local2tex, xyz2st );
+ }
+
+ // the bounds of the current texture transform
+ AABB bounds;
+ for ( Winding::const_iterator i = w.begin(); i != w.end(); ++i )
+ {
+ Vector3 texcoord = matrix4_transformed_point( local2tex, ( *i ).vertex );
+ aabb_extend_by_point_safe( bounds, texcoord );
+ }
+ bounds.origin.z() = 0;
+ bounds.extents.z() = 1;