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);
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);
92 m[0][0] = rx.x; m[0][1] = ry.x; m[0][2] = rz.x; m[0][3] = 0.0;
93 m[1][0] = rx.y; m[1][1] = ry.y; m[1][2] = rz.y; m[1][3] = 0.0;
94 m[2][0] = rx.z; m[2][1] = ry.z; m[2][2] = rz.z; m[2][3] = 0.0;
95 m[3][0] = 0.0 ; m[3][1] = 0.0 ; m[3][2] = 0.0 ; m[3][3] = 1.0;
108 void set_parallel (View_parameters *vp, Matrix wc)
110 Matrix m = IDENTITY_MATRIX;
118 SET_COORD3(v,- vp->vrp.x, - vp->vrp.y, - vp->vrp.z);
119 Translate_to_Matrix (&v, wc);
125 set_zy (m, &vp->vpn, &vp->vup);
129 postleft_matrix (m,
'z');
130 postmult_matrix (wc, m);
139 vp->vrp.x - vp->cop.x,
140 vp->vrp.y - vp->cop.y,
141 vp->vrp.z - vp->cop.z);
143 SET_COORD3(cop,dop.x,dop.y,dop.z);
144 point_matrix (&doprim, &cop, m);
146 m[2][0] = - doprim.x / doprim.z;
147 m[2][1] = - doprim.y / doprim.z;
148 postmult_matrix (wc, m);
157 (
float)(-(vp->vwd.umax + vp->vwd.umin) / 2.0),
158 (
float)(-(vp->vwd.vmax + vp->vwd.vmin) / 2.0),
159 (
float)(-vp->depth.front));
160 posttrans_matrix (wc, &v);
162 (
float)(2.0 / (vp->vwd.umax - vp->vwd.umin)),
163 (
float)(2.0 / (vp->vwd.vmax - vp->vwd.vmin)),
164 (
float)(1.0 / (vp->depth.back - vp->depth.front)));
165 postscale_matrix (wc, &v);
178 void set_perspective (View_parameters *vp, Matrix wc)
180 Matrix m = IDENTITY_MATRIX;
188 SET_COORD3(v,- vp->cop.x, - vp->cop.y, - vp->cop.z);
189 Translate_to_Matrix (&v, wc);
195 set_zy (m, &vp->vpn, &vp->vup);
196 postmult_matrix (wc, m);
200 postleft_matrix (wc,
'z');
204 point_matrix (&vrprim, &vp->vrp, wc);
205 cw.x = (float)(vrprim.x + (vp->vwd.umin + vp->vwd.umax) / 2.0);
206 cw.y = (float)(vrprim.y + (vp->vwd.vmin + vp->vwd.vmax) / 2.0);
207 cw.z = (float)(vrprim.z);
209 m[2][0] = - cw.x / cw.z;
210 m[2][1] = - cw.y / cw.z;
211 postmult_matrix (wc, m);
216 (
float)((2.0*vrprim.z)/((vp->vwd.umax-vp->vwd.umin)*(vrprim.z+vp->depth.back))),
217 (
float)((2.0*vrprim.z)/((vp->vwd.vmax-vp->vwd.vmin)*(vrprim.z+vp->depth.back))),
218 (
float)( 1.0/(vrprim.z+vp->depth.back)));
219 postscale_matrix (wc, &v);
223 zmin = (vrprim.z + vp->depth.front) / (vrprim.z + vp->depth.back);
225 m[2][2] = (float)(1.0 / (1.0 - zmin)); m[2][3] = 1.0;
226 m[3][2] = (float)(- zmin / (1.0 - zmin)); m[3][3] = 0.0;
227 postmult_matrix (wc, m);