Changeset 299

Show
Ignore:
Timestamp:
07/10/08 02:38:14 (3 months ago)
Author:
mattn
Message:

* brush primitive patch by divVerent

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • GtkRadiant/trunk/radiant/brush.cpp

    r289 r299  
    424424} 
    425425 
     426long double HighestImpactSign (long double a, long double b) 
     427{ 
     428        // returns the sign of the value with larger abs 
     429        if (a + b > 0) 
     430                return +1; 
     431        else 
     432                return -1; 
     433} 
     434 
     435void Face_TexdefFromTextureVectors (face_t *f, long double STfromXYZ[2][4], vec3_t pvecs[2], int sv, int tv) 
     436{ 
     437        texdef_t *td; 
     438        qtexture_t *q; 
     439        int j; 
     440        long double ang; 
     441 
     442        td = &f->texdef; 
     443        q = f->d_texture; 
     444 
     445        // undo the texture transform 
     446        for (j=0 ; j<4 ; j++) { 
     447                STfromXYZ[0][j] *= q->width; 
     448                STfromXYZ[1][j] *= q->height; 
     449        } 
     450 
     451        // shift 
     452        td->shift[0] = STfromXYZ[0][3]; 
     453        td->shift[1] = STfromXYZ[1][3]; 
     454 
     455        /** 
     456         * SOLVE: 
     457         *  STfromXYZ[0][sv] = (cosv * pvecs[0][sv] - sinv * pvecs[0][tv]) / td->scale[0]; 
     458         *  STfromXYZ[0][tv] = (sinv * pvecs[0][sv] + cosv * pvecs[0][tv]) / td->scale[0]; 
     459         *  STfromXYZ[1][sv] = (cosv * pvecs[1][sv] - sinv * pvecs[1][tv]) / td->scale[1]; 
     460         *  STfromXYZ[1][tv] = (sinv * pvecs[1][sv] + cosv * pvecs[1][tv]) / td->scale[1]; 
     461         * FOR: 
     462         *  sinv, cosv, td->scale[0], td->scale[1] 
     463         * WE KNOW: 
     464         *  sinv^2 + cosv^2 = 1 
     465         *  pvecs[0][sv] is +/-1 
     466         *  pvecs[0][tv] is 0 
     467         *  pvecs[1][sv] is 0 
     468         *  pvecs[1][tv] is +/-1 
     469         * THUS: 
     470         *  STfromXYZ[0][sv] = +cosv * pvecs[0][sv] / td->scale[0]; 
     471         *  STfromXYZ[0][tv] = +sinv * pvecs[0][sv] / td->scale[0]; 
     472         *  STfromXYZ[1][sv] = -sinv * pvecs[1][tv] / td->scale[1]; 
     473         *  STfromXYZ[1][tv] = +cosv * pvecs[1][tv] / td->scale[1]; 
     474         */ 
     475 
     476        td->scale[0] = sqrt(STfromXYZ[0][sv]*STfromXYZ[0][sv] + STfromXYZ[0][tv]*STfromXYZ[0][tv]); 
     477        td->scale[1] = sqrt(STfromXYZ[1][sv]*STfromXYZ[1][sv] + STfromXYZ[1][tv]*STfromXYZ[1][tv]); 
     478 
     479        if (td->scale[0]) 
     480                td->scale[0] = 1 / td->scale[0]; // avoid NaNs 
     481        if (td->scale[1]) 
     482                td->scale[1] = 1 / td->scale[1]; 
     483 
     484        long double sign0tv = (STfromXYZ[0][tv] > 0) ? +1 : -1; 
     485        ang = atan2( sign0tv * STfromXYZ[0][tv], sign0tv * STfromXYZ[0][sv]); // atan2(y, x) with y positive is in [0, PI[ 
     486 
     487        // STOP 
     488        // We have until now ignored the fact that td->scale[0] or td->scale[1] may 
     489        // have either sign (+ or -). Due to roundoff errors, our choice of 
     490        // sign0tv may even have been wrong in a sense. 
     491        // sign0tv may NOT indicate the appropriate sign for td->scale[0] (namely, 
     492        // if cosv is near zero)! 
     493        // let's look at the signs again 
     494        //   sign0sv =  signcosv * pvecs[0][sv] / td->scale[0]sign 
     495        //   sign0tv =             pvecs[0][sv] / td->scale[0]sign 
     496        //   sign1sv = -1        * pvecs[1][tv] / td->scale[1]sign 
     497        //   sign1tv =  signcosv * pvecs[1][tv] / td->scale[1]sign 
     498        // --> 
     499        //   td->scale[1]sign =  sign1tv * signcosv * pvecs[1][tv] 
     500        //   td->scale[1]sign = -sign1sv * signsinv * pvecs[1][tv] 
     501        //   td->scale[0]sign =  sign0tv * signsinv * pvecs[0][sv] 
     502        //   td->scale[0]sign =  sign0sv * signcosv * pvecs[0][sv] 
     503        // which to choose? 
     504        // the one with the larger impact on the original texcoords, of course 
     505        // to minimize the effect of roundoff errors that may flip the signs! 
     506 
     507        td->scale[0] *= HighestImpactSign(STfromXYZ[0][tv] * +sin(ang), STfromXYZ[0][sv] * cos(ang)) * pvecs[0][sv]; 
     508        td->scale[1] *= HighestImpactSign(STfromXYZ[1][sv] * -sin(ang), STfromXYZ[1][tv] * cos(ang)) * pvecs[1][tv]; 
     509 
     510        td->rotate = ang * 180 / Q_PI; // FIXME possibly snap this to 0/90/180 (270 can't happen)? 
     511} 
     512 
     513 
    426514/* 
    427515================ 
     
    462550        xyzst[4] = DotProduct (xyzst, STfromXYZ[1]) + STfromXYZ[1][3]; 
    463551} 
     552 
     553long double SarrusDetScalar(long double a1, long double b1, long double c1, long double a2, long double b2, long double c2, long double a3, long double b3, long double c3) 
     554{ 
     555        return a1 * b2 * c3 + a2 * b3 * c1 + a3 * b1 * c2 
     556                - a1 * c2 * b3 - a2 * c3 * b1 - a3 * c1 * b2; 
     557} 
     558 
     559void SarrusSolve(long double a1, long double b1, long double c1, long double d1, long double a2, long double b2, long double c2, long double d2, long double a3, long double b3, long double c3, long double d3, long double *a, long double *b, long double *c) 
     560{ 
     561        long double det; 
     562        det = SarrusDetScalar(a1, b1, c1, 
     563                                                a2, b2, c2, 
     564                                                a3, b3, c3); 
     565        *a =  SarrusDetScalar(d1, b1, c1, 
     566                                                d2, b2, c2, 
     567                                                d3, b3, c3) / det; 
     568        *b =  SarrusDetScalar(a1, d1, c1, 
     569                                                a2, d2, c2, 
     570                                                a3, d3, c3) / det; 
     571        *c =  SarrusDetScalar(a1, b1, d1, 
     572                                                a2, b2, d2, 
     573                                                a3, b3, d3) / det; 
     574} 
     575 
     576void Face_TexdefFromTextureCoordinates ( float *xyzst1, float *xyzst2, float *xyzst3, qtexture_t *q, face_t *f) 
     577{ 
     578        vec3_t          pvecs[2]; 
     579        int sv, tv, uv; 
     580 
     581        long double   STfromXYZ[2][4]; 
     582 
     583        // get natural texture axis 
     584        TextureAxisFromPlane(&f->plane, pvecs[0], pvecs[1]); 
     585 
     586        if (pvecs[0][0]) 
     587                sv = 0; 
     588        else if (pvecs[0][1]) 
     589                sv = 1; 
     590        else 
     591                sv = 2; 
     592 
     593        if (pvecs[1][0]) 
     594                tv = 0; 
     595        else if (pvecs[1][1]) 
     596                tv = 1; 
     597        else 
     598                tv = 2; 
     599 
     600        uv = 3 - sv - tv; // the "other one" 
     601 
     602        // find the STfromXYZ 4-vectors 
     603        /* 
     604        SARRUS-SOLVE: 
     605                xyzst1[3] == xyzst1[sv] * STfromXYZ[0][sv] + xyzst1[tv] * STfromXYZ[0][tv] + STfromXYZ[0][3]; 
     606                xyzst2[3] == xyzst2[sv] * STfromXYZ[0][sv] + xyzst2[tv] * STfromXYZ[0][tv] + STfromXYZ[0][3]; 
     607                xyzst3[3] == xyzst3[sv] * STfromXYZ[0][sv] + xyzst3[tv] * STfromXYZ[0][tv] + STfromXYZ[0][3]; 
     608        FOR: STfromXYZ[0] 
     609        GIVEN: one coord of them (uv) is empty (see Face_TextureVectors) 
     610        SARRUS-SOLVE: 
     611                xyzst1[4] == xyzst1[sv] * STfromXYZ[1][sv] + xyzst1[tv] * STfromXYZ[1][tv] + STfromXYZ[1][3]; 
     612                xyzst2[4] == xyzst2[sv] * STfromXYZ[1][sv] + xyzst2[tv] * STfromXYZ[1][tv] + STfromXYZ[1][3]; 
     613                xyzst3[4] == xyzst3[sv] * STfromXYZ[1][sv] + xyzst3[tv] * STfromXYZ[1][tv] + STfromXYZ[1][3]; 
     614        FOR: STfromXYZ[1] 
     615        GIVEN: one coord of them (uv) is empty (see Face_TextureVectors) 
     616        */ 
     617 
     618        STfromXYZ[0][uv] = 0; 
     619        SarrusSolve( 
     620                xyzst1[sv],        xyzst1[tv],        1,               xyzst1[3], 
     621                xyzst2[sv],        xyzst2[tv],        1,               xyzst2[3], 
     622                xyzst3[sv],        xyzst3[tv],        1,               xyzst3[3], 
     623                &STfromXYZ[0][sv], &STfromXYZ[0][tv], &STfromXYZ[0][3] 
     624        ); 
     625 
     626        STfromXYZ[1][uv] = 0; 
     627        SarrusSolve( 
     628                xyzst1[sv],        xyzst1[tv],        1,               xyzst1[4], 
     629                xyzst2[sv],        xyzst2[tv],        1,               xyzst2[4], 
     630                xyzst3[sv],        xyzst3[tv],        1,               xyzst3[4], 
     631                &STfromXYZ[1][sv], &STfromXYZ[1][tv], &STfromXYZ[1][3] 
     632        ); 
     633 
     634        /* 
     635        printf("%s\n", q->name); 
     636 
     637        printf("%f == %Lf\n", xyzst1[3], DotProduct (xyzst1, STfromXYZ[0]) + STfromXYZ[0][3]); 
     638        printf("%f == %Lf\n", xyzst2[3], DotProduct (xyzst2, STfromXYZ[0]) + STfromXYZ[0][3]); 
     639        printf("%f == %Lf\n", xyzst3[3], DotProduct (xyzst3, STfromXYZ[0]) + STfromXYZ[0][3]); 
     640        printf("%f == %Lf\n", xyzst1[4], DotProduct (xyzst1, STfromXYZ[1]) + STfromXYZ[1][3]); 
     641        printf("%f == %Lf\n", xyzst2[4], DotProduct (xyzst2, STfromXYZ[1]) + STfromXYZ[1][3]); 
     642        printf("%f == %Lf\n", xyzst3[4], DotProduct (xyzst3, STfromXYZ[1]) + STfromXYZ[1][3]); 
     643 
     644        float   newSTfromXYZ[2][4]; 
     645 
     646        printf("old: %Lf,%Lf,%Lf,%Lf %Lf,%Lf,%Lf,%Lf\n", 
     647                STfromXYZ[0][0], STfromXYZ[0][1], STfromXYZ[0][2], STfromXYZ[0][3], 
     648                STfromXYZ[1][0], STfromXYZ[1][1], STfromXYZ[1][2], STfromXYZ[1][3]); 
     649        */ 
     650 
     651        Face_TexdefFromTextureVectors (f,  STfromXYZ, pvecs, sv, tv); 
     652 
     653        /* 
     654        Face_TextureVectors(f, newSTfromXYZ); 
     655 
     656        printf("new: %f,%f,%f,%f %f,%f,%f,%f\n", 
     657                newSTfromXYZ[0][0], newSTfromXYZ[0][1], newSTfromXYZ[0][2], newSTfromXYZ[0][3], 
     658                newSTfromXYZ[1][0], newSTfromXYZ[1][1], newSTfromXYZ[1][2], newSTfromXYZ[1][3]); 
     659 
     660        float newxyzst1[5]; 
     661        float newxyzst2[5]; 
     662        float newxyzst3[5]; 
     663        VectorCopy(xyzst1, newxyzst1); 
     664        VectorCopy(xyzst2, newxyzst2); 
     665        VectorCopy(xyzst3, newxyzst3); 
     666        EmitTextureCoordinates (newxyzst1, q, f); 
     667        EmitTextureCoordinates (newxyzst2, q, f); 
     668        EmitTextureCoordinates (newxyzst3, q, f); 
     669        printf("Face_TexdefFromTextureCoordinates: %f,%f %f,%f %f,%f -> %f,%f %f,%f %f,%f\n", 
     670                xyzst1[3], xyzst1[4], 
     671                xyzst2[3], xyzst2[4], 
     672                xyzst3[3], xyzst3[4], 
     673                newxyzst1[3], newxyzst1[4], 
     674                newxyzst2[3], newxyzst2[4], 
     675                newxyzst3[3], newxyzst3[4]); 
     676        // TODO why do these differ, but not the previous ones? this makes no sense whatsoever 
     677        */ 
     678} 
     679 
     680 
    464681 
    465682//========================================================================== 
  • GtkRadiant/trunk/radiant/brush_primit.cpp

    r185 r299  
    6666} 
    6767 
    68 //++timo replace everywhere texX by texS etc. ( ----> and in q3map !)  
     68//++timo replace everywhere texX by texS etc. ( ----> and in q3map !) 
    6969// NOTE : ComputeAxisBase here and in q3map code must always BE THE SAME ! 
    7070// WARNING : special case behaviour of atan2(y,x) <-> atan(y/x) might not be the same everywhere when x == 0 
     
    335335//      vec3_t N[2],Mf[2]; 
    336336        brushprimit_texdef_t N; 
    337   vec3_t Mf[2]; 
     337       vec3_t Mf[2]; 
    338338 
    339339 
     
    344344        ClearBounds( BBoxSTMin, BBoxSTMax ); 
    345345        w = f->face_winding; 
    346   for (i=0 ; i<w->numpoints ; i++) 
    347                
     346       for (i=0 ; i<w->numpoints ; i++) 
     347       
    348348                // AddPointToBounds in 2D on (S,T) coordinates 
    349349                for (j=0 ; j<2 ; j++) 
     
    355355                                BBoxSTMax[j] = val; 
    356356                } 
    357                
     357       
    358358        // we have the three points of the BBox (BBoxSTMin[0].BBoxSTMin[1]) (BBoxSTMax[0],BBoxSTMin[1]) (BBoxSTMin[0],BBoxSTMax[1]) in ST space 
    359   // the BP matrix we are looking for gives (0,0) (nwidth,0) (0,nHeight) coordinates in (Sfit,Tfit) space to these three points 
     359       // the BP matrix we are looking for gives (0,0) (nwidth,0) (0,nHeight) coordinates in (Sfit,Tfit) space to these three points 
    360360        // we have A(Sfit,Tfit) = (0,0) = Mf * A(TexS,TexT) = N * M * A(TexS,TexT) = N * A(S,T) 
    361361        // so we solve the system for N and then Mf = N * M 
     
    364364        D[0][0] = 0.0f; D[0][1] = nWidth; D[0][2] = 0.0f; 
    365365        D[1][0] = 0.0f; D[1][1] = 0.0f; D[1][2] = nHeight; 
    366   MatrixForPoints( M, D, &N ); 
     366       MatrixForPoints( M, D, &N ); 
    367367 
    368368#if 0 
    369   // FIT operation gives coordinates of three points of the bounding box in (S',T'), our target axis base 
     369       // FIT operation gives coordinates of three points of the bounding box in (S',T'), our target axis base 
    370370        // A(S',T')=(0,0) B(S',T')=(nWidth,0) C(S',T')=(0,nHeight) 
    371371        // 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]) 
    372372        // we compute the N transformation so that: A(S',T') = N * A(S,T) 
    373   VectorSet( N[0], (BBoxSTMax[0]-BBoxSTMin[0])/(float)nWidth, 0.0f, BBoxSTMin[0] ); 
     373       VectorSet( N[0], (BBoxSTMax[0]-BBoxSTMin[0])/(float)nWidth, 0.0f, BBoxSTMin[0] ); 
    374374        VectorSet( N[1], 0.0f, (BBoxSTMax[1]-BBoxSTMin[1])/(float)nHeight, BBoxSTMin[1] ); 
    375375#endif 
    376376 
    377377        // the final matrix is the product (Mf stands for Mfit) 
    378   Mf[0][0] = N.coords[0][0] * f->brushprimit_texdef.coords[0][0] + N.coords[0][1] * f->brushprimit_texdef.coords[1][0]; 
     378       Mf[0][0] = N.coords[0][0] * f->brushprimit_texdef.coords[0][0] + N.coords[0][1] * f->brushprimit_texdef.coords[1][0]; 
    379379        Mf[0][1] = N.coords[0][0] * f->brushprimit_texdef.coords[0][1] + N.coords[0][1] * f->brushprimit_texdef.coords[1][1]; 
    380380        Mf[0][2] = N.coords[0][0] * f->brushprimit_texdef.coords[0][2] + N.coords[0][1] * f->brushprimit_texdef.coords[1][2] + N.coords[0][2]; 
    381   Mf[1][0] = N.coords[1][0] * f->brushprimit_texdef.coords[0][0] + N.coords[1][1] * f->brushprimit_texdef.coords[1][0]; 
     381       Mf[1][0] = N.coords[1][0] * f->brushprimit_texdef.coords[0][0] + N.coords[1][1] * f->brushprimit_texdef.coords[1][0]; 
    382382        Mf[1][1] = N.coords[1][0] * f->brushprimit_texdef.coords[0][1] + N.coords[1][1] * f->brushprimit_texdef.coords[1][1]; 
    383383        Mf[1][2] = N.coords[1][0] * f->brushprimit_texdef.coords[0][2] + N.coords[1][1] * f->brushprimit_texdef.coords[1][2] + N.coords[1][2]; 
     
    389389} 
    390390 
    391 void BrushPrimitFaceToFace(face_t *face) 
    392 
    393   // we have parsed brush primitives and need conversion back to standard format 
    394   // NOTE: converting back is a quick hack, there's some information lost and we can't do anything about it 
    395   // FIXME: if we normalize the texture matrix to a standard 2x2 size, we end up with wrong scaling 
    396   // I tried various tweaks, no luck .. seems shifting is lost 
    397   brushprimit_texdef_t aux; 
    398   ConvertTexMatWithQTexture( &face->brushprimit_texdef, face->d_texture, &aux, NULL ); 
    399   TexMatToFakeTexCoords( aux.coords, face->texdef.shift, &face->texdef.rotate, face->texdef.scale ); 
    400   face->texdef.scale[0]/=2.0; 
    401   face->texdef.scale[1]/=2.0; 
     391void BrushPrimitFaceToFace(face_t *f) 
     392
     393#if 0 
     394        // we have parsed brush primitives and need conversion back to standard format 
     395        // NOTE: converting back is a quick hack, there's some information lost and we can't do anything about it 
     396        // FIXME: if we normalize the texture matrix to a standard 2x2 size, we end up with wrong scaling 
     397        // I tried various tweaks, no luck .. seems shifting is lost 
     398        brushprimit_texdef_t aux; 
     399        ConvertTexMatWithQTexture( &face->brushprimit_texdef, face->d_texture, &aux, NULL ); 
     400        TexMatToFakeTexCoords( aux.coords, face->texdef.shift, &face->texdef.rotate, face->texdef.scale ); 
     401        face->texdef.scale[0]/=2.0; 
     402        face->texdef.scale[1]/=2.0; 
     403#else 
     404        // new method by divVerent@alientrap.org: Shift and scale no longer get lost when opening a BP map in texdef mode. 
     405        vec3_t texX,texY; 
     406        vec3_t proj; 
     407        vec_t ST[3][5]; 
     408 
     409        ComputeAxisBase(f->plane.normal,texX,texY); 
     410        VectorCopy(f->plane.normal,proj); 
     411        VectorScale(proj,f->plane.dist,proj); 
     412        VectorCopy(proj,ST[0]); 
     413        VectorCopy(texX,ST[1]); 
     414        VectorAdd(ST[1],proj,ST[1]); 
     415        VectorCopy(texY,ST[2]); 
     416        VectorAdd(ST[2],proj,ST[2]); 
     417 
     418        ST[0][3] = f->brushprimit_texdef.coords[0][2]; 
     419        ST[0][4] = f->brushprimit_texdef.coords[1][2]; 
     420        ST[1][3] = f->brushprimit_texdef.coords[0][0] + ST[0][3]; 
     421        ST[1][4] = f->brushprimit_texdef.coords[1][0] + ST[0][4]; 
     422        ST[2][3] = f->brushprimit_texdef.coords[0][1] + ST[0][3]; 
     423        ST[2][4] = f->brushprimit_texdef.coords[1][1] + ST[0][4]; 
     424 
     425        Face_TexdefFromTextureCoordinates(ST[0], ST[1], ST[2], f->d_texture, f); 
     426#endif 
    402427} 
    403428 
     
    424449void TextureLockTransformation_BrushPrimit(face_t *f) 
    425450{ 
    426   vec3_t Orig,texS,texT;        // axis base of initial plane 
    427   // used by transformation algo 
    428   vec3_t temp; int j; 
     451       vec3_t Orig,texS,texT;        // axis base of initial plane 
     452       // used by transformation algo 
     453       vec3_t temp; int j; 
    429454        vec3_t vRotate;                                 // rotation vector 
    430455 
    431   vec3_t rOrig,rvecS,rvecT;     // geometric transformation of (0,0) (1,0) (0,1) { initial plane axis base } 
    432   vec3_t rNormal,rtexS,rtexT;   // axis base for the transformed plane 
     456       vec3_t rOrig,rvecS,rvecT;     // geometric transformation of (0,0) (1,0) (0,1) { initial plane axis base } 
     457       vec3_t rNormal,rtexS,rtexT;   // axis base for the transformed plane 
    433458        vec3_t lOrig,lvecS,lvecT;       // [2] are not used ( but usefull for debugging ) 
    434459        vec3_t M[3]; 
     
    438463        // compute plane axis base 
    439464        ComputeAxisBase( f->plane.normal, texS, texT ); 
    440   VectorSet(Orig, 0.0f, 0.0f, 0.0f); 
     465       VectorSet(Orig, 0.0f, 0.0f, 0.0f); 
    441466 
    442467        // compute coordinates of (0,0) (1,0) (0,1) ( expressed in initial plane axis base ) after transformation 
    443468        // (0,0) (1,0) (0,1) ( expressed in initial plane axis base ) <-> (0,0,0) texS texT ( expressed world axis base ) 
    444   // input: Orig, texS, texT (and the global locking params) 
    445   // ouput: rOrig, rvecS, rvecT, rNormal 
    446   if (txlock_bRotation) { 
    447     // rotation vector 
    448       VectorSet( vRotate, 0.0f, 0.0f, 0.0f ); 
    449       vRotate[txl_nAxis]=txl_fDeg; 
    450       VectorRotateOrigin ( Orig, vRotate, txl_vOrigin, rOrig ); 
    451       VectorRotateOrigin ( texS, vRotate, txl_vOrigin, rvecS ); 
    452       VectorRotateOrigin ( texT, vRotate, txl_vOrigin, rvecT ); 
    453       // compute normal of plane after rotation 
    454       VectorRotate ( f->plane.normal, vRotate, rNormal ); 
    455  
    456   else 
    457  
    458     VectorSubtract (Orig, txl_origin, temp); 
    459     for (j=0 ; j<3 ; j++) 
    460       rOrig[j] = DotProduct(temp, txl_matrix[j]) + txl_origin[j]; 
    461     VectorSubtract (texS, txl_origin, temp); 
    462     for (j=0 ; j<3 ; j++) 
    463       rvecS[j] = DotProduct(temp, txl_matrix[j]) + txl_origin[j]; 
    464     VectorSubtract (texT, txl_origin, temp); 
    465     for (j=0 ; j<3 ; j++) 
    466       rvecT[j] = DotProduct(temp, txl_matrix[j]) + txl_origin[j]; 
    467     // we also need the axis base of the target plane, apply the transformation matrix to the normal too.. 
    468     for (j=0 ; j<3 ; j++) 
    469       rNormal[j] = DotProduct(f->plane.normal, txl_matrix[j]); 
    470  
     469       // input: Orig, texS, texT (and the global locking params) 
     470       // ouput: rOrig, rvecS, rvecT, rNormal 
     471       if (txlock_bRotation) { 
     472               // rotation vector 
     473              VectorSet( vRotate, 0.0f, 0.0f, 0.0f ); 
     474              vRotate[txl_nAxis]=txl_fDeg; 
     475              VectorRotateOrigin ( Orig, vRotate, txl_vOrigin, rOrig ); 
     476              VectorRotateOrigin ( texS, vRotate, txl_vOrigin, rvecS ); 
     477              VectorRotateOrigin ( texT, vRotate, txl_vOrigin, rvecT ); 
     478              // compute normal of plane after rotation 
     479              VectorRotate ( f->plane.normal, vRotate, rNormal ); 
     480       
     481       else 
     482       
     483               VectorSubtract (Orig, txl_origin, temp); 
     484               for (j=0 ; j<3 ; j++) 
     485               rOrig[j] = DotProduct(temp, txl_matrix[j]) + txl_origin[j]; 
     486               VectorSubtract (texS, txl_origin, temp); 
     487               for (j=0 ; j<3 ; j++) 
     488               rvecS[j] = DotProduct(temp, txl_matrix[j]) + txl_origin[j]; 
     489               VectorSubtract (texT, txl_origin, temp); 
     490               for (j=0 ; j<3 ; j++) 
     491               rvecT[j] = DotProduct(temp, txl_matrix[j]) + txl_origin[j]; 
     492               // we also need the axis base of the target plane, apply the transformation matrix to the normal too.. 
     493               for (j=0 ; j<3 ; j++) 
     494               rNormal[j] = DotProduct(f->plane.normal, txl_matrix[j]); 
     495       
    471496 
    472497        // compute rotated plane axis base 
     
    503528void RotateFaceTexture_BrushPrimit(face_t *f, int nAxis, float fDeg, vec3_t vOrigin ) 
    504529{ 
    505   // this is a placeholder to call the general texture locking algorithm 
    506   txlock_bRotation = true; 
    507   txl_nAxis = nAxis; 
    508   txl_fDeg = fDeg; 
    509   VectorCopy(vOrigin, txl_vOrigin); 
    510   TextureLockTransformation_BrushPrimit(f); 
     530       // this is a placeholder to call the general texture locking algorithm 
     531       txlock_bRotation = true; 
     532       txl_nAxis = nAxis; 
     533       txl_fDeg = fDeg; 
     534       VectorCopy(vOrigin, txl_vOrigin); 
     535       TextureLockTransformation_BrushPrimit(f); 
    511536} 
    512537 
  • GtkRadiant/trunk/radiant/qe3.h

    r289 r299  
    536536// EmitTextureCoordinates, is old code used for brush to brush primitive conversion 
    537537void EmitTextureCoordinates ( float *xyzst, qtexture_t *q, face_t *f); 
     538void Face_TexdefFromTextureCoordinates ( float *xyzst1, float *xyzst2, float *xyzst3, qtexture_t *q, face_t *f); 
    538539//void BrushPrimit_Parse(brush_t *); 
    539540// compute a fake shift scale rot representation from the texture matrix