1 /*
2 * This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>.
3 * It is copyright by its individual contributors, as recorded in the
4 * project's Git history. See COPYING.txt at the top level for license
5 * terms and a link to the Git history.
6 */
7 /*
8 *
9 * Matrix setup & manipulation routines
10 *
11 */
12
13
14 #include "3d.h"
15 #include "globvars.h"
16
17 namespace dcx {
18
19 static void scale_matrix(fix);
20
21 //set view from x,y,z, viewer matrix, and zoom. Must call one of g3_set_view_*()
g3_set_view_matrix(const vms_vector & view_pos,const vms_matrix & view_matrix,fix zoom)22 void g3_set_view_matrix(const vms_vector &view_pos,const vms_matrix &view_matrix,fix zoom)
23 {
24 View_position = view_pos;
25 View_matrix = view_matrix;
26 scale_matrix(zoom);
27 }
28
29 //performs aspect scaling on global view matrix
scale_matrix(const fix View_zoom)30 static void scale_matrix(const fix View_zoom)
31 {
32 Unscaled_matrix = View_matrix; //so we can use unscaled if we want
33
34 Matrix_scale = Window_scale;
35
36 if (View_zoom <= f1_0) //zoom in by scaling z
37
38 Matrix_scale.z = fixmul(Matrix_scale.z,View_zoom);
39
40 else { //zoom out by scaling x&y
41
42 fix s = fixdiv(f1_0,View_zoom);
43
44 Matrix_scale.x = fixmul(Matrix_scale.x,s);
45 Matrix_scale.y = fixmul(Matrix_scale.y,s);
46 }
47
48 //now scale matrix elements
49
50 vm_vec_scale(View_matrix.rvec,Matrix_scale.x);
51 vm_vec_scale(View_matrix.uvec,Matrix_scale.y);
52 vm_vec_scale(View_matrix.fvec,Matrix_scale.z);
53
54 }
55
56 }
57