# CS代考计算机代写 fprintf( ‘————————————- ’ );

fprintf( ‘————————————-
’ );
fprintf( ‘Q 1
’ );
fprintf( ‘————————————-
’ );
nx = 640;
ny = 480;
T_cann_from_screen = [ 2/nx 0 -(1-1/nx);
0 -2/ny (1-1/ny);
0 0 1 ]
ptA = [ 10 35 1 ]’;
ptB = [ 50 340 1 ]’;

ptA_cann = T_cann_from_screen * ptA;
ptB_cann = T_cann_from_screen * ptB;

fprintf( ‘Click A =
’)
fprintf( ‘[ %5.2f %5.2f ]^T
’, ptA_cann(1:2) );
fprintf( ‘Click B =
’)
fprintf( ‘[ %5.2f %5.2f ]^T
’, ptB_cann(1:2) );

% Try this to convince yourself that its is correct:
% inv(T_cann_from_screen)

clear all;

fprintf( ‘————————————-
’ );
fprintf( ‘Q 2
’ );
fprintf( ‘————————————-
’ );
eyeVec = [ 5 1 3 ]’;
atVec = [ -1 -1 -6 ]’;
upVec = [ 0 0 1]’;

gazeVec = atVec-eyeVec;
w = -gazeVec/norm(gazeVec,2);
u = cross( upVec, w )/norm(upVec,2);
v = cross( w, u );

fprintf( ‘u =
’)
fprintf( ‘[ %5.2f %5.2f %5.2f ]^T
’, u );
fprintf( ‘v =
’)
fprintf( ‘[ %5.2f %5.2f %5.2f ]^T
’, v );
fprintf( ‘w =
’)
fprintf( ‘[ %5.2f %5.2f %5.2f ]^T
’, w );
fprintf( ‘
’)

M_v = [ u’ -dot(u,eyeVec);
v’ -dot(v,eyeVec);
w’ -dot(w,eyeVec);
0 0 0 1 ];

fprintf( ‘Therefore M_v =
’)
fprintf( ‘%5.2f %5.2f %5.2f %5.2f
’, (M_v)’ );
fprintf( ‘

’)
clear all;

fprintf( ‘————————————-
’ );
fprintf( ‘Q 3
’ );
fprintf( ‘————————————-
’ );

% Viewing frustum from question
n_p = -5;
l_p = -3;
b_p = -1;
r_p = l_p + 5;
t_p = b_p + 5;
f_p = n_p – 10;

% Open GL projection matrix set with glFrustum
MOpenGLProj = [ 2*abs(n_p)/(r_p-l_p) 0 (r_p+l_p)/(r_p-l_p) 0;
0 2*abs(n_p)/(r_p-l_p) (t_p+b_p)/(t_p-b_p) 0;
0 0 (abs(n_p)+abs(f_p))/(abs(n_p)-abs(f_p)) 2*abs(n_p)*abs(f_p)/(abs(n_p)-abs(f_p));
0 0 -1 0 ];

% Scene points to be projected
a1 = transpose([ 2 -1 -5 1 ]);
a2 = transpose([ -9 12 -15 1 ]);

% Points in homogenous canonical volume coordinates
a1Proj_homogeneous = MOpenGLProj * a1;
a2Proj_homogeneous = MOpenGLProj * a2;

% Points in cartesian canonical volume coordinates
a1Proj = a1Proj_homogeneous(1:3)/a1Proj_homogeneous(4);
a2Proj = a2Proj_homogeneous(1:3)/a2Proj_homogeneous(4);

fprintf( ‘Points in cartesian canonical viewing volume:
’)
fprintf( ‘[ %5.2f %5.2f %5.2f ]^T
’, a1Proj );
fprintf( ‘[ %5.2f %5.2f %5.2f ]^T
’, a2Proj );
fprintf( ‘

’)
clear all;