-//++timo FIXME quick'n dirty hack, doesn't care about current texture settings (angle)
-// can be improved .. bug #107311
-void BPTexdef_FitTexture(brushprimit_texdef_t& bp_td, std::size_t width, std::size_t height, const Vector3& normal, const Winding& w, float s_repeat, float t_repeat)
-{
- Vector3 BBoxSTMin, BBoxSTMax;
- Vector3 M[3],D[2];
-// Vector3 N[2],Mf[2];
- brushprimit_texdef_t N;
- Vector3 Mf[2];
-
- //qtexture_t texture;
- //texture.width = width;
- //texture.height = height;
-
-
- // we'll be working on a standardized texture size
-// ConvertTexMatWithQTexture( &bp_td, &texture, &bp_td, 0 );
- // compute the BBox in ST coords
- {
- Winding tmp(w);
- Texdef_EmitTextureCoordinates(TextureProjection(texdef_t(), bp_td, Vector3(0, 0, 0), Vector3(0, 0, 0)), width, height, tmp, normal, g_matrix4_identity);
-
- ClearBounds( BBoxSTMin, BBoxSTMax );
- for(Winding::const_iterator i = tmp.begin(); i != tmp.end(); ++i)
- {
- // AddPointToBounds in 2D on (S,T) coordinates
- for(int j=0 ; j<2 ; j++)
- {
- float val = (*i).texcoord[j];
- if (val < BBoxSTMin[j])
- BBoxSTMin[j] = val;
- if (val > BBoxSTMax[j])
- BBoxSTMax[j] = val;
- }
- }
- }
- // we have the three points of the BBox (BBoxSTMin[0].BBoxSTMin[1]) (BBoxSTMax[0],BBoxSTMin[1]) (BBoxSTMin[0],BBoxSTMax[1]) in ST space
- // the BP matrix we are looking for gives (0,0) (nwidth,0) (0,t_repeat) coordinates in (Sfit,Tfit) space to these three points
- // we have A(Sfit,Tfit) = (0,0) = Mf * A(TexS,TexT) = N * M * A(TexS,TexT) = N * A(S,T)
- // so we solve the system for N and then Mf = N * M
- M[0][0] = BBoxSTMin[0]; M[0][1] = BBoxSTMax[0]; M[0][2] = BBoxSTMin[0];
- M[1][0] = BBoxSTMin[1]; M[1][1] = BBoxSTMin[1]; M[1][2] = BBoxSTMax[1];
- D[0][0] = 0.0f; D[0][1] = s_repeat; D[0][2] = 0.0f;
- D[1][0] = 0.0f; D[1][1] = 0.0f; D[1][2] = t_repeat;
- MatrixForPoints( M, D, &N );
-
-#if 0
- // FIT operation gives coordinates of three points of the bounding box in (S',T'), our target axis base
- // A(S',T')=(0,0) B(S',T')=(s_repeat,0) C(S',T')=(0,t_repeat)
- // and we have them in (S,T) axis base: A(S,T)=(BBoxSTMin[0],BBoxSTMin[1]) B(S,T)=(BBoxSTMax[0],BBoxSTMin[1]) C(S,T)=(BBoxSTMin[0],BBoxSTMax[1])
- // we compute the N transformation so that: A(S',T') = N * A(S,T)
- VectorSet( N[0], (BBoxSTMax[0]-BBoxSTMin[0])/s_repeat, 0.0f, BBoxSTMin[0] );
- VectorSet( N[1], 0.0f, (BBoxSTMax[1]-BBoxSTMin[1])/t_repeat, BBoxSTMin[1] );
-#endif
-
- // the final matrix is the product (Mf stands for Mfit)
- Mf[0][0] = N.coords[0][0] * bp_td.coords[0][0] + N.coords[0][1] * bp_td.coords[1][0];
- Mf[0][1] = N.coords[0][0] * bp_td.coords[0][1] + N.coords[0][1] * bp_td.coords[1][1];
- Mf[0][2] = N.coords[0][0] * bp_td.coords[0][2] + N.coords[0][1] * bp_td.coords[1][2] + N.coords[0][2];
- Mf[1][0] = N.coords[1][0] * bp_td.coords[0][0] + N.coords[1][1] * bp_td.coords[1][0];
- Mf[1][1] = N.coords[1][0] * bp_td.coords[0][1] + N.coords[1][1] * bp_td.coords[1][1];
- Mf[1][2] = N.coords[1][0] * bp_td.coords[0][2] + N.coords[1][1] * bp_td.coords[1][2] + N.coords[1][2];
- // copy back
- bp_td.coords[0][0] = Mf[0][0];
- bp_td.coords[0][1] = Mf[0][1];
- bp_td.coords[0][2] = Mf[0][2];
- bp_td.coords[1][0] = Mf[1][0];
- bp_td.coords[1][1] = Mf[1][1];
- bp_td.coords[1][2] = Mf[1][2];
- // handle the texture size
-// ConvertTexMatWithQTexture( &bp_td, 0, &bp_td, &texture );
-}
-
-
-