Fixed Constraint projection code in perspective mode. When using a planar constraints...
authorMartin Poirier <theeth@yahoo.com>
Sun, 27 Feb 2005 19:14:21 +0000 (19:14 +0000)
committerMartin Poirier <theeth@yahoo.com>
Sun, 27 Feb 2005 19:14:21 +0000 (19:14 +0000)
In user terms: the motion on screen of the selection follows the motion of the mouse pointer.

Gives some errors when the constraint plane is nearly perpendicular to the view port though.

Added a debug print function for 4D vectors to arithb.c

Optimised the 3D -> view projection functions in view.c (a bit).

source/blender/blenlib/BLI_arithb.h
source/blender/blenlib/intern/arithb.c
source/blender/src/transform.c
source/blender/src/transform_constraints.c
source/blender/src/view.c

index ccada20fbf3fc4894d7b30729effb85cebd4bc68..0bdd6eeca44bd03df6dcd60d27ff749ce826ed33 100644 (file)
@@ -478,6 +478,11 @@ sasqrt(
 printvecf(
        char *str,
        float v[3]
+);
+       void
+printvec4f(
+       char *str,
+       float v[4]
 );
        float 
 Inpf(
index 095f8fb505220478f49d8d2daa4da37348473c4d..95e07dda0c8bd67404fb0ff309768484a998c34a 100644 (file)
@@ -961,6 +961,14 @@ void printvecf( char *str,  float v[3])
 
 }
 
+void printvec4f( char *str,  float v[4])
+{
+       printf("%s\n", str);
+       printf("%f %f %f %f\n",v[0],v[1],v[2], v[3]);
+       printf("\n");
+
+}
+
 void printmatrix4( char *str,  float m[][4])
 {
        printf("%s\n", str);
index 28b4be809d4b429748796b767d28c2de4898feba..b9206587eb2a277b5e13965b52305db4159adf7f 100755 (executable)
@@ -1285,17 +1285,20 @@ void Transform(int mode)
                                        else if (G.qual == LR_CTRLKEY)
                                                setConstraint(&Trans, mati, (APPLYCON|CONAXIS1|CONAXIS2));
                                        break;
+                                       Trans.redraw = 1;
                                case YKEY:
                                        if (G.qual == 0)
                                                setConstraint(&Trans, mati, (APPLYCON|CONAXIS1));
                                        else if (G.qual == LR_CTRLKEY)
                                                setConstraint(&Trans, mati, (APPLYCON|CONAXIS0|CONAXIS2));
                                        break;
+                                       Trans.redraw = 1;
                                case ZKEY:
                                        if (G.qual == 0)
                                                setConstraint(&Trans, mati, (APPLYCON|CONAXIS2));
                                        else if (G.qual == LR_CTRLKEY)
                                                setConstraint(&Trans, mati, (APPLYCON|CONAXIS0|CONAXIS1));
+                                       Trans.redraw = 1;
                                        break;
                                case OKEY:
                                        if (G.qual==LR_SHIFTKEY) {
index 8b717664347fb751ab16e295e28a0d33240a9285..01ff411d0e91175b16f54587e9d64ddab21e42f0 100755 (executable)
@@ -114,8 +114,36 @@ void recalcData();
 /* ************************** CONSTRAINTS ************************* */
 void getConstraintMatrix(TransInfo *t);
 
-void axisProjection(float axis[3], float in[3], float out[3]) {
-       float n[3], vec[3], factor;
+void getViewVector(TransInfo *t, float coord[3], float vec[3]) {
+       if (G.vd->persp)
+       {
+               float p1[4], p2[4];
+
+               VecAddf(p1, coord, t->con.center);
+               p1[3] = 1.0f;
+               VECCOPY(p2, p1);
+               p2[3] = 1.0f;
+               Mat4MulVec4fl(G.vd->viewmat, p2);
+
+               p2[0] = 2.0f * p2[0];
+               p2[1] = 2.0f * p2[1];
+               p2[2] = 2.0f * p2[2];
+
+               Mat4MulVec4fl(G.vd->viewinv, p2);
+
+               VecSubf(vec, p2, p1);
+               Normalise(vec);
+       }
+       else {
+               VECCOPY(vec, G.vd->viewinv[2]);
+       }
+}
+
+void axisProjection(TransInfo *t, float axis[3], float in[3], float out[3]) {
+       float norm[3], n[3], vec[3], factor;
+
+       getViewVector(t, in, norm);
+
        Normalise(axis);
 
        VECCOPY(n, axis);
@@ -123,31 +151,33 @@ void axisProjection(float axis[3], float in[3], float out[3]) {
        n[2] = G.vd->viewmat[3][2];
        Mat4MulVecfl(G.vd->viewinv, n);
 
-       if (Inpf(axis, G.vd->viewinv[2]) != 1.0f) {
+       if (Inpf(axis, norm) != 1.0f) {
                Projf(vec, in, n);
                factor = Normalise(vec);
                factor /= Inpf(axis, vec);
 
                VecMulf(axis, factor);
                VECCOPY(out, axis);
-
        }
        else {
                out[0] = out[1] = out[2] = 0.0f;
        }
 }
 
-void planeProjection(float in[3], float out[3]) {
-       float vec[3], factor, angle;
+void planeProjection(TransInfo *t, float in[3], float out[3]) {
+       float vec[3], factor, angle, norm[3];
+
+       getViewVector(t, in, norm);
 
        VecSubf(vec, out, in);
        factor = Normalise(vec);
-       angle = Inpf(vec, G.vd->viewinv[2]);
+       angle = Inpf(vec, norm);
+
 
        if (angle * angle >= 0.000001f) {
                factor /= angle;
 
-               VECCOPY(vec, G.vd->viewinv[2]);
+               VECCOPY(vec, norm);
                VecMulf(vec, factor);
 
                VecAddf(out, in, vec);
@@ -161,7 +191,7 @@ void applyAxisConstraintVec(TransInfo *t, TransData *td, float in[3], float out[
                Mat3MulVecfl(t->con.imtx, out);
                if (!(out[0] == out[1] == out[2] == 0.0f)) {
                        if (getConstraintSpaceDimension(t) == 2) {
-                               planeProjection(in, out);
+                               planeProjection(t, in, out);
                        }
                        else if (getConstraintSpaceDimension(t) == 1) {
                                float c[3];
@@ -175,7 +205,7 @@ void applyAxisConstraintVec(TransInfo *t, TransData *td, float in[3], float out[
                                else if (t->con.mode & CONAXIS2) {
                                        VECCOPY(c, t->con.mtx[2]);
                                }
-                               axisProjection(c, in, out);
+                               axisProjection(t, c, in, out);
                        }
                }
                
index 41d29c78a08f82d3785b8d8b99524484e42afff4..c3ca9391a4c49b95db5afd35f274c02f77debc20 100644 (file)
@@ -174,11 +174,11 @@ void project_short(float *vec, short *adr)        /* clips */
        Mat4MulVec4fl(G.vd->persmat, vec4);
 
        if( vec4[3]>BL_NEAR_CLIP ) {    /* 0.001 is the NEAR clipping cutoff for picking */
-               fx= (curarea->winx/2)+(curarea->winx/2)*vec4[0]/vec4[3];
+               fx= (curarea->winx/2)*(1 + vec4[0]/vec4[3]);
                
                if( fx>0 && fx<curarea->winx) {
                
-                       fy= (curarea->winy/2)+(curarea->winy/2)*vec4[1]/vec4[3];
+                       fy= (curarea->winy/2)*(1 + vec4[1]/vec4[3]);
                        
                        if(fy>0.0 && fy< (float)curarea->winy) {
                                adr[0]= floor(fx); 
@@ -199,11 +199,11 @@ void project_short_noclip(float *vec, short *adr)
        Mat4MulVec4fl(G.vd->persmat, vec4);
 
        if( vec4[3]>BL_NEAR_CLIP ) {    /* 0.001 is the NEAR clipping cutoff for picking */
-               fx= (curarea->winx/2)+(curarea->winx/2)*vec4[0]/vec4[3];
+               fx= (curarea->winx/2)*(1 + vec4[0]/vec4[3]);
                
                if( fx>-32700 && fx<32700) {
                
-                       fy= (curarea->winy/2)+(curarea->winy/2)*vec4[1]/vec4[3];
+                       fy= (curarea->winy/2)*(1 + vec4[1]/vec4[3]);
                        
                        if(fy>-32700.0 && fy<32700.0) {
                                adr[0]= floor(fx);