| 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 |
namespace { |
| 19 |
|
| 20 |
static void scale_matrix(fix); |
| 21 |
|
| 22 |
} |
| 23 |
|
| 24 |
//set view from x,y,z, viewer matrix, and zoom. Must call one of g3_set_view_*() |
| 25 |
void g3_set_view_matrix(const vms_vector &view_pos,const vms_matrix &view_matrix,fix zoom) |
| 26 |
{ |
| 27 |
View_position = view_pos; |
| 28 |
View_matrix = view_matrix; |
| 29 |
scale_matrix(zoom); |
| 30 |
} |
| 31 |
|
| 32 |
namespace { |
| 33 |
|
| 34 |
//performs aspect scaling on global view matrix |
| 35 |
static void scale_matrix(const fix View_zoom) |
| 36 |
{ |
| 37 |
Unscaled_matrix = View_matrix; //so we can use unscaled if we want |
| 38 |
|
| 39 |
Matrix_scale = Window_scale; |
| 40 |
|
| 41 |
if (View_zoom <= f1_0) //zoom in by scaling z |
| 42 |
|
| 43 |
Matrix_scale.z = fixmul(Matrix_scale.z,View_zoom); |
| 44 |
|
| 45 |
else { //zoom out by scaling x&y |
| 46 |
|
| 47 |
fix s = fixdiv(f1_0,View_zoom); |
| 48 |
|
| 49 |
Matrix_scale.x = fixmul(Matrix_scale.x,s); |
| 50 |
Matrix_scale.y = fixmul(Matrix_scale.y,s); |
| 51 |
} |
| 52 |
|
| 53 |
//now scale matrix elements |
| 54 |
|
| 55 |
vm_vec_scale(View_matrix.rvec,Matrix_scale.x); |
| 56 |
vm_vec_scale(View_matrix.uvec,Matrix_scale.y); |
| 57 |
vm_vec_scale(View_matrix.fvec,Matrix_scale.z); |
| 58 |
|
| 59 |
} |
| 60 |
|
| 61 |
} |
| 62 |
|
| 63 |
} |