]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/brush_primit.cpp
Merge commit '173f350be76237a7dee9c00c389dff4e56b3da4c' into garux-merge
[xonotic/netradiant.git] / radiant / brush_primit.cpp
index 85ee1e46ebbb95de2502733ad8aad23efba94ae8..c2042d1e6e2dcdb8174aaa5b237141165af0ca5e 100644 (file)
@@ -20,6 +20,7 @@
  */
 
 #include "brush_primit.h"
+#include "globaldefs.h"
 
 #include "debugging/debugging.h"
 
@@ -397,11 +398,11 @@ inline BasicVector3<Element> vector3_inverse( const BasicVector3<Element>& self
 void BPMatMul( float A[2][3], float B[2][3], float C[2][3] );
 // apply a rotation (degrees)
 void BPMatRotate( float A[2][3], float theta );
-#ifdef _DEBUG
+#if GDEF_DEBUG
 void BPMatDump( float A[2][3] );
 #endif
 
-#ifdef _DEBUG
+#if GDEF_DEBUG
 //#define DBG_BP
 #endif
 
@@ -1108,90 +1109,28 @@ void Texdef_FitTexture( TextureProjection& projection, std::size_t width, std::s
        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;
+       AABB perfect;
+       if( t_repeat == 0 && s_repeat == 0 ){
+               //bad user's input
+               t_repeat = s_repeat = 1;
+               perfect.origin = Vector3( s_repeat * 0.5, t_repeat * 0.5, 0 );
+               perfect.extents = Vector3( s_repeat * 0.5, t_repeat * 0.5, 1 );
        }
-
-       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 );
+       if( t_repeat == 0 ){
+               //fit width
+               perfect.origin = Vector3( s_repeat * 0.5, s_repeat * 0.5 * bounds.extents.y() / bounds.extents.x(), 0 );
+               perfect.extents = Vector3( s_repeat * 0.5, s_repeat * 0.5 * bounds.extents.y() / bounds.extents.x(), 1 );
        }
-
-       // 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 );
+       else if( s_repeat == 0 ){
+               //fit height
+               perfect.origin = Vector3( t_repeat * 0.5 * bounds.extents.x() / bounds.extents.y(), t_repeat * 0.5, 0 );
+               perfect.extents = Vector3( t_repeat * 0.5 * bounds.extents.x() / bounds.extents.y(), t_repeat * 0.5, 1 );
        }
-       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;
+       else{
+               perfect.origin = Vector3( s_repeat * 0.5, t_repeat * 0.5, 0 );
+               perfect.extents = Vector3( s_repeat * 0.5, t_repeat * 0.5, 1 );
        }
 
-       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( t_repeat * 0.5 * bounds.extents.x() / bounds.extents.y(), t_repeat * 0.5, 0 ), Vector3( t_repeat * 0.5 * bounds.extents.x() / bounds.extents.y(), 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 );
@@ -1317,7 +1256,7 @@ inline Matrix4 matrix4_reflection_for_plane45( const Plane3& plane, const Vector
        Vector3 first = from;
        Vector3 second = to;
 
-       if ( vector3_dot( from, plane.normal() ) > 0 == vector3_dot( to, plane.normal() ) > 0 ) {
+       if ( (vector3_dot( from, plane.normal() ) > 0) == (vector3_dot( to, plane.normal() ) > 0) ) {
                first = vector3_negated( first );
                second = vector3_negated( second );
        }
@@ -1335,8 +1274,6 @@ inline Matrix4 matrix4_reflection_for_plane45( const Plane3& plane, const Vector
 
        Matrix4 swap = matrix4_swap_axes( first, second );
 
-       Matrix4 tmp = matrix4_reflection_for_plane( plane );
-
        swap.tx() = -static_cast<float>( -2 * plane.a * plane.d );
        swap.ty() = -static_cast<float>( -2 * plane.b * plane.d );
        swap.tz() = -static_cast<float>( -2 * plane.c * plane.d );