| 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 |
* Instancing routines |
| 10 |
* |
| 11 |
*/ |
| 12 |
|
| 13 |
#include <stdlib.h> |
| 14 |
#include "dxxerror.h" |
| 15 |
|
| 16 |
#include "3d.h" |
| 17 |
#include "globvars.h" |
| 18 |
|
| 19 |
namespace dcx { |
| 20 |
|
| 21 |
//instance at specified point with specified orientation |
| 22 |
//if matrix==NULL, don't modify matrix. This will be like doing an offset |
| 23 |
g3_instance_context g3_start_instance_matrix() |
| 24 |
{ |
| 25 |
return {View_matrix, View_position}; |
| 26 |
} |
| 27 |
|
| 28 |
g3_instance_context g3_start_instance_matrix(const vms_vector &pos, const vms_matrix &orient) |
| 29 |
{ |
| 30 |
auto r{g3_start_instance_matrix()}; |
| 31 |
//step 1: vm_vec_sub: subtract object position from view position |
| 32 |
//step 2: vm_vec_rotate: rotate view vector through object matrix |
| 33 |
vm_vec_rotate(View_position, vm_vec_build_sub(View_position, pos), orient); |
| 34 |
|
| 35 |
//step 3: rotate object matrix through view_matrix (vm = ob * vm) |
| 36 |
View_matrix = vm_matrix_x_matrix(vm_transposed_matrix(orient), View_matrix); |
| 37 |
return r; |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
//instance at specified point with specified orientation |
| 42 |
//if angles==NULL, don't modify matrix. This will be like doing an offset |
| 43 |
g3_instance_context g3_start_instance_angles(const vms_vector &pos, const vms_angvec &angles) |
| 44 |
{ |
| 45 |
const auto &&tm{vm_angles_2_matrix(angles)}; |
| 46 |
return g3_start_instance_matrix(pos, tm); |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
//pops the old context |
| 51 |
void g3_done_instance(const g3_instance_context &ctx) |
| 52 |
{ |
| 53 |
View_position = ctx.position; |
| 54 |
View_matrix = ctx.matrix; |
| 55 |
} |
| 56 |
|
| 57 |
} |