2006-03-20 16:43:15 +00:00
|
|
|
/*
|
2018-09-02 00:57:29 +00:00
|
|
|
* This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>.
|
2014-06-12 08:41:03 +00:00
|
|
|
* It is copyright by its individual contributors, as recorded in the
|
|
|
|
* project's Git history. See COPYING.txt at the top level for license
|
|
|
|
* terms and a link to the Git history.
|
|
|
|
*/
|
2006-03-20 16:43:15 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Instancing routines
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2012-07-07 18:35:06 +00:00
|
|
|
#include "dxxerror.h"
|
2006-03-20 16:43:15 +00:00
|
|
|
|
|
|
|
#include "3d.h"
|
|
|
|
#include "globvars.h"
|
|
|
|
|
2015-12-13 18:00:49 +00:00
|
|
|
namespace dcx {
|
2015-12-05 22:57:24 +00:00
|
|
|
|
2015-08-12 03:11:46 +00:00
|
|
|
namespace {
|
|
|
|
|
2006-03-20 16:43:15 +00:00
|
|
|
struct instance_context {
|
|
|
|
vms_matrix m;
|
|
|
|
vms_vector p;
|
2015-08-12 03:11:46 +00:00
|
|
|
};
|
|
|
|
|
2015-08-12 03:11:46 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 21:18:42 +00:00
|
|
|
static std::array<instance_context, 5> instance_stack;
|
2006-03-20 16:43:15 +00:00
|
|
|
|
|
|
|
int instance_depth = 0;
|
|
|
|
|
|
|
|
//instance at specified point with specified orientation
|
|
|
|
//if matrix==NULL, don't modify matrix. This will be like doing an offset
|
2017-08-26 19:47:51 +00:00
|
|
|
void g3_start_instance_matrix()
|
2006-03-20 16:43:15 +00:00
|
|
|
{
|
2020-05-02 21:18:43 +00:00
|
|
|
auto &s = instance_stack.at(instance_depth++);
|
|
|
|
s.m = View_matrix;
|
|
|
|
s.p = View_position;
|
2017-08-26 19:47:51 +00:00
|
|
|
}
|
2006-03-20 16:43:15 +00:00
|
|
|
|
2017-08-26 19:47:51 +00:00
|
|
|
void g3_start_instance_matrix(const vms_vector &pos, const vms_matrix &orient)
|
|
|
|
{
|
|
|
|
g3_start_instance_matrix();
|
2006-03-20 16:43:15 +00:00
|
|
|
//step 1: subtract object position from view position
|
|
|
|
|
2014-10-29 03:24:31 +00:00
|
|
|
const auto tempv = vm_vec_sub(View_position, pos);
|
2006-03-20 16:43:15 +00:00
|
|
|
//step 2: rotate view vector through object matrix
|
|
|
|
|
2017-08-26 19:47:51 +00:00
|
|
|
vm_vec_rotate(View_position, tempv, orient);
|
2006-03-20 16:43:15 +00:00
|
|
|
|
|
|
|
//step 3: rotate object matrix through view_matrix (vm = ob * vm)
|
2017-08-26 19:47:51 +00:00
|
|
|
View_matrix = vm_matrix_x_matrix(vm_transposed_matrix(orient), View_matrix);
|
2006-03-20 16:43:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//instance at specified point with specified orientation
|
|
|
|
//if angles==NULL, don't modify matrix. This will be like doing an offset
|
2017-08-26 19:47:51 +00:00
|
|
|
void g3_start_instance_angles(const vms_vector &pos, const vms_angvec &angles)
|
2006-03-20 16:43:15 +00:00
|
|
|
{
|
2017-08-26 19:47:51 +00:00
|
|
|
const auto &&tm = vm_angles_2_matrix(angles);
|
2017-08-26 19:47:51 +00:00
|
|
|
g3_start_instance_matrix(pos, tm);
|
2006-03-20 16:43:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//pops the old context
|
|
|
|
void g3_done_instance()
|
|
|
|
{
|
|
|
|
instance_depth--;
|
|
|
|
|
|
|
|
Assert(instance_depth >= 0);
|
|
|
|
|
|
|
|
View_position = instance_stack[instance_depth].p;
|
|
|
|
View_matrix = instance_stack[instance_depth].m;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-05 22:57:24 +00:00
|
|
|
}
|