40 #include <visp3/core/vpConfig.h> 42 #ifndef DOXYGEN_SHOULD_SKIP_THIS 43 #include "vpProjection.h" 54 void View_to_Matrix(View_parameters *
vp, Matrix m)
56 static char proc_name[] =
"View_to_Matrix";
63 set_perspective(vp, m);
66 fprintf(stderr,
"%s: bad view type\n", proc_name);
67 set_perspective(vp, m);
81 static void set_zy(Matrix m, Vector *v0, Vector *v1)
85 SET_COORD3(rz, -v0->x, -v0->y, -v0->z);
86 CROSS_PRODUCT(rx, *v0, *v1);
89 CROSS_PRODUCT(ry, rz, rx);
119 void set_parallel(View_parameters *vp, Matrix wc)
121 Matrix m = IDENTITY_MATRIX;
129 SET_COORD3(v, -vp->vrp.x, -vp->vrp.y, -vp->vrp.z);
130 Translate_to_Matrix(&v, wc);
136 set_zy(m, &vp->vpn, &vp->vup);
140 postleft_matrix(m,
'z');
141 postmult_matrix(wc, m);
149 SET_COORD3(dop, vp->vrp.x - vp->cop.x, vp->vrp.y - vp->cop.y, vp->vrp.z - vp->cop.z);
151 SET_COORD3(cop, dop.x, dop.y, dop.z);
152 point_matrix(&doprim, &cop, m);
154 m[2][0] = -doprim.x / doprim.z;
155 m[2][1] = -doprim.y / doprim.z;
156 postmult_matrix(wc, m);
164 SET_COORD3(v, (
float)(-(vp->vwd.umax + vp->vwd.umin) / 2.0), (
float)(-(vp->vwd.vmax + vp->vwd.vmin) / 2.0),
165 (
float)(-vp->depth.front));
166 posttrans_matrix(wc, &v);
167 SET_COORD3(v, (
float)(2.0 / (vp->vwd.umax - vp->vwd.umin)), (
float)(2.0 / (vp->vwd.vmax - vp->vwd.vmin)),
168 (
float)(1.0 / (vp->depth.back - vp->depth.front)));
169 postscale_matrix(wc, &v);
182 void set_perspective(View_parameters *vp, Matrix wc)
184 Matrix m = IDENTITY_MATRIX;
192 SET_COORD3(v, -vp->cop.x, -vp->cop.y, -vp->cop.z);
193 Translate_to_Matrix(&v, wc);
199 set_zy(m, &vp->vpn, &vp->vup);
200 postmult_matrix(wc, m);
204 postleft_matrix(wc,
'z');
208 point_matrix(&vrprim, &vp->vrp, wc);
209 cw.x = (float)(vrprim.x + (vp->vwd.umin + vp->vwd.umax) / 2.0);
210 cw.y = (float)(vrprim.y + (vp->vwd.vmin + vp->vwd.vmax) / 2.0);
211 cw.z = (float)(vrprim.z);
213 m[2][0] = -cw.x / cw.z;
214 m[2][1] = -cw.y / cw.z;
215 postmult_matrix(wc, m);
219 SET_COORD3(v, (
float)((2.0 * vrprim.z) / ((vp->vwd.umax - vp->vwd.umin) * (vrprim.z + vp->depth.back))),
220 (
float)((2.0 * vrprim.z) / ((vp->vwd.vmax - vp->vwd.vmin) * (vrprim.z + vp->depth.back))),
221 (
float)(1.0 / (vrprim.z + vp->depth.back)));
222 postscale_matrix(wc, &v);
226 zmin = (vrprim.z + vp->depth.front) / (vrprim.z + vp->depth.back);
228 m[2][2] = (float)(1.0 / (1.0 - zmin));
230 m[3][2] = (float)(-zmin / (1.0 - zmin));
232 postmult_matrix(wc, m);