Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Poirier <theeth@yahoo.com>2005-02-27 22:14:21 +0300
committerMartin Poirier <theeth@yahoo.com>2005-02-27 22:14:21 +0300
commitcfd5439bc698f5dc2693e0ae86cdf3c0c72d03ec (patch)
tree1f333ebd32887478751198ea67b887fc95453b90
parentdb892de35fb7f20f93cccf5287d69a9090ec4555 (diff)
Fixed Constraint projection code in perspective mode. When using a planar constraints, it follows the movement of the mouse exactly instead of just casting on the plane.
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).
-rw-r--r--source/blender/blenlib/BLI_arithb.h5
-rw-r--r--source/blender/blenlib/intern/arithb.c8
-rwxr-xr-xsource/blender/src/transform.c3
-rwxr-xr-xsource/blender/src/transform_constraints.c50
-rw-r--r--source/blender/src/view.c8
5 files changed, 60 insertions, 14 deletions
diff --git a/source/blender/blenlib/BLI_arithb.h b/source/blender/blenlib/BLI_arithb.h
index ccada20fbf3..0bdd6eeca44 100644
--- a/source/blender/blenlib/BLI_arithb.h
+++ b/source/blender/blenlib/BLI_arithb.h
@@ -479,6 +479,11 @@ printvecf(
char *str,
float v[3]
);
+ void
+printvec4f(
+ char *str,
+ float v[4]
+);
float
Inpf(
float *v1,
diff --git a/source/blender/blenlib/intern/arithb.c b/source/blender/blenlib/intern/arithb.c
index 095f8fb5052..95e07dda0c8 100644
--- a/source/blender/blenlib/intern/arithb.c
+++ b/source/blender/blenlib/intern/arithb.c
@@ -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);
diff --git a/source/blender/src/transform.c b/source/blender/src/transform.c
index 28b4be809d4..b9206587eb2 100755
--- a/source/blender/src/transform.c
+++ b/source/blender/src/transform.c
@@ -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) {
diff --git a/source/blender/src/transform_constraints.c b/source/blender/src/transform_constraints.c
index 8b717664347..01ff411d0e9 100755
--- a/source/blender/src/transform_constraints.c
+++ b/source/blender/src/transform_constraints.c
@@ -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);
}
}
diff --git a/source/blender/src/view.c b/source/blender/src/view.c
index 41d29c78a08..c3ca9391a4c 100644
--- a/source/blender/src/view.c
+++ b/source/blender/src/view.c
@@ -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);