40 #include <visp3/core/vpConfig.h>
42 #ifndef DOXYGEN_SHOULD_SKIP_THIS
43 #include "vpProjection.h"
55 void View_to_Matrix(View_parameters *vp, Matrix m)
57 static char proc_name[] =
"View_to_Matrix";
64 set_perspective(vp, m);
67 fprintf(stderr,
"%s: bad view type\n", proc_name);
68 set_perspective(vp, m);
82 static void set_zy(Matrix m, Vector *v0, Vector *v1)
86 SET_COORD3(rz, -v0->x, -v0->y, -v0->z);
87 CROSS_PRODUCT(rx, *v0, *v1);
90 CROSS_PRODUCT(ry, rz, rx);
120 void set_parallel(View_parameters *vp, Matrix wc)
122 Matrix m = IDENTITY_MATRIX;
130 SET_COORD3(v, -vp->vrp.x, -vp->vrp.y, -vp->vrp.z);
131 Translate_to_Matrix(&v, wc);
137 set_zy(m, &vp->vpn, &vp->vup);
141 postleft_matrix(m,
'z');
142 postmult_matrix(wc, m);
150 SET_COORD3(dop, vp->vrp.x - vp->cop.x, vp->vrp.y - vp->cop.y, vp->vrp.z - vp->cop.z);
152 SET_COORD3(cop, dop.x, dop.y, dop.z);
153 point_matrix(&doprim, &cop, m);
155 m[2][0] = -doprim.x / doprim.z;
156 m[2][1] = -doprim.y / doprim.z;
157 postmult_matrix(wc, m);
165 SET_COORD3(v, (
float)(-(vp->vwd.umax + vp->vwd.umin) / 2.0), (
float)(-(vp->vwd.vmax + vp->vwd.vmin) / 2.0),
166 (
float)(-vp->depth.front));
167 posttrans_matrix(wc, &v);
168 SET_COORD3(v, (
float)(2.0 / (vp->vwd.umax - vp->vwd.umin)), (
float)(2.0 / (vp->vwd.vmax - vp->vwd.vmin)),
169 (
float)(1.0 / (vp->depth.back - vp->depth.front)));
170 postscale_matrix(wc, &v);
183 void set_perspective(View_parameters *vp, Matrix wc)
185 Matrix m = IDENTITY_MATRIX;
193 SET_COORD3(v, -vp->cop.x, -vp->cop.y, -vp->cop.z);
194 Translate_to_Matrix(&v, wc);
200 set_zy(m, &vp->vpn, &vp->vup);
201 postmult_matrix(wc, m);
205 postleft_matrix(wc,
'z');
209 point_matrix(&vrprim, &vp->vrp, wc);
210 cw.x = (float)(vrprim.x + (vp->vwd.umin + vp->vwd.umax) / 2.0);
211 cw.y = (float)(vrprim.y + (vp->vwd.vmin + vp->vwd.vmax) / 2.0);
212 cw.z = (float)(vrprim.z);
214 m[2][0] = -cw.x / cw.z;
215 m[2][1] = -cw.y / cw.z;
216 postmult_matrix(wc, m);
220 SET_COORD3(v, (
float)((2.0 * vrprim.z) / ((vp->vwd.umax - vp->vwd.umin) * (vrprim.z + vp->depth.back))),
221 (
float)((2.0 * vrprim.z) / ((vp->vwd.vmax - vp->vwd.vmin) * (vrprim.z + vp->depth.back))),
222 (
float)(1.0 / (vrprim.z + vp->depth.back)));
223 postscale_matrix(wc, &v);
227 zmin = (vrprim.z + vp->depth.front) / (vrprim.z + vp->depth.back);
229 m[2][2] = (float)(1.0 / (1.0 - zmin));
231 m[3][2] = (float)(-zmin / (1.0 - zmin));
233 postmult_matrix(wc, m);