-#endif
-
- // computing new local axis base
- TextureAxisFromPlane( &normal2, ex, ey );
- CrossProduct( ex, ey, ez );
-
- // projecting back on (ex,ey)
- Back( ez,p1 );
- Back( ez,p2 );
- Back( ez,p3 );
-
- vec3_t aux;
- // rotation
- VectorCopy( p2, aux );
- VectorSubtract( aux, p1,aux );
-
- float x = DotProduct( aux,ex );
- float y = DotProduct( aux,ey );
- f->texdef.rotate = 180 * atan2( y,x ) / Q_PI;
-
- vec3_t rex,rey;
- // computing rotated local axis base
- VectorCopy( ez, aux );
- VectorScale( aux, f->texdef.rotate, aux );
- VectorCopy( ex, rex );
- VectorRotate( rex, aux, rex );
- VectorCopy( ey, rey );
- VectorRotate( rey, aux, rey );
-
- // scale
- VectorCopy( p2, aux );
- VectorSubtract( aux, p1, aux );
- f->texdef.scale[0] = DotProduct( aux, rex );
- VectorCopy( p3, aux );
- VectorSubtract( aux, p1, aux );
- f->texdef.scale[1] = DotProduct( aux, rey );
-
- // shift
- // only using p1
- x = DotProduct( rex,p1 );
- y = DotProduct( rey,p1 );
- x /= f->texdef.scale[0];
- y /= f->texdef.scale[1];
-
- VectorCopy( rex, p1 );
- VectorScale( p1, x, p1 );
- VectorCopy( rey, aux );
- VectorScale( aux, y, aux );
- VectorAdd( p1, aux, p1 );
- VectorCopy( ez, aux );
- VectorScale( aux, -f->texdef.rotate, aux );
- VectorRotate( p1, aux, p1 );
- f->texdef.shift[0] = -DotProduct( p1, ex );
- f->texdef.shift[1] = -DotProduct( p1, ey );
-
- // stored rot is good considering local axis base
- // change it if necessary
- f->texdef.rotate = -f->texdef.rotate;
-
- Clamp( f->texdef.shift[0], f->d_texture->width );
- Clamp( f->texdef.shift[1], f->d_texture->height );
- Clamp( f->texdef.rotate, 360 );
-
-}
-
-void RotateFaceTexture( face_t* f, int nAxis, float fDeg ){
- vec3_t p1,p2,p3, rota;
- p1[0] = p1[1] = p1[2] = 0;
- VectorCopy( p1, p2 );
- VectorCopy( p1, p3 );
- VectorCopy( p1, rota );
- ComputeAbsolute( f, p1, p2, p3 );
-
- rota[nAxis] = fDeg;
- VectorRotateOrigin( p1, rota, select_origin, p1 );
- VectorRotateOrigin( p2, rota, select_origin, p2 );
- VectorRotateOrigin( p3, rota, select_origin, p3 );
-
- plane_t normal2;
- vec3_t vNormal;
- vNormal[0] = f->plane.normal[0];
- vNormal[1] = f->plane.normal[1];
- vNormal[2] = f->plane.normal[2];
- VectorRotate( vNormal, rota, vNormal );
- normal2.normal[0] = vNormal[0];
- normal2.normal[1] = vNormal[1];
- normal2.normal[2] = vNormal[2];
- AbsoluteToLocal( normal2, f, p1, p2,p3 );
-
-}
-
-void RotateTextures( int nAxis, float fDeg, vec3_t vOrigin ){
- for ( brush_t* b = selected_brushes.next ; b != &selected_brushes ; b = b->next )