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).
This commit is contained in:
Martin Poirier 2005-02-27 19:14:21 +00:00
parent db892de35f
commit cfd5439bc6
5 changed files with 60 additions and 14 deletions

@ -478,6 +478,11 @@ sasqrt(
printvecf(
char *str,
float v[3]
);
void
printvec4f(
char *str,
float v[4]
);
float
Inpf(

@ -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);

@ -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) {

@ -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);
}
}

@ -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);