BLI Math: Add and use new projmat_dimensions utility.
This commit is contained in:
@@ -441,6 +441,11 @@ void window_translate_m4(float winmat[4][4], float perspmat[4][4],
|
||||
void planes_from_projmat(float mat[4][4], float left[4], float right[4], float top[4], float bottom[4],
|
||||
float front[4], float back[4]);
|
||||
|
||||
void projmat_dimensions(const float projmat[4][4],
|
||||
float *r_left, float *r_right,
|
||||
float *r_bottom, float *r_top,
|
||||
float *r_near, float *r_far);
|
||||
|
||||
int box_clip_bounds_m4(float boundbox[2][3],
|
||||
const float bounds[4], float winmat[4][4]);
|
||||
void box_minmax_bounds_m4(float min[3], float max[3],
|
||||
|
||||
@@ -4152,6 +4152,32 @@ void planes_from_projmat(float mat[4][4], float left[4], float right[4], float t
|
||||
}
|
||||
}
|
||||
|
||||
void projmat_dimensions(const float projmat[4][4],
|
||||
float *r_left, float *r_right,
|
||||
float *r_bottom, float *r_top,
|
||||
float *r_near, float *r_far)
|
||||
{
|
||||
bool is_persp = projmat[3][3] == 0.0f;
|
||||
|
||||
if (is_persp) {
|
||||
*r_left = (projmat[2][0] - 1.0f) / projmat[0][0];
|
||||
*r_right = (projmat[2][0] + 1.0f) / projmat[0][0];
|
||||
*r_bottom = (projmat[2][1] - 1.0f) / projmat[1][1];
|
||||
*r_top = (projmat[2][1] + 1.0f) / projmat[1][1];
|
||||
*r_near = projmat[3][2] / (projmat[2][2] - 1.0f);
|
||||
*r_far = projmat[3][2] / (projmat[2][2] + 1.0f);
|
||||
}
|
||||
else {
|
||||
*r_left = (-projmat[3][0] - 1.0f) / projmat[0][0];
|
||||
*r_right = (-projmat[3][0] + 1.0f) / projmat[0][0];
|
||||
*r_bottom = (-projmat[3][1] - 1.0f) / projmat[1][1];
|
||||
*r_top = (-projmat[3][1] + 1.0f) / projmat[1][1];
|
||||
*r_near = ( projmat[3][2] + 1.0f) / projmat[2][2];
|
||||
*r_far = ( projmat[3][2] - 1.0f) / projmat[2][2];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void i_multmatrix(float icand[4][4], float Vm[4][4])
|
||||
{
|
||||
int row, col;
|
||||
|
||||
@@ -464,24 +464,17 @@ void DRW_state_clip_planes_set_from_rv3d(RegionView3D *rv3d)
|
||||
*/
|
||||
static void draw_frustum_boundbox_calc(const float(*projmat)[4], BoundBox *r_bbox)
|
||||
{
|
||||
float near, far, left, right, bottom, top;
|
||||
float left, right, bottom, top, near, far;
|
||||
bool is_persp = projmat[3][3] == 0.0f;
|
||||
|
||||
projmat_dimensions(
|
||||
projmat, &left, &right, &bottom, &top, &near, &far);
|
||||
|
||||
if (is_persp) {
|
||||
near = projmat[3][2] / (projmat[2][2] - 1.0f);
|
||||
far = projmat[3][2] / (projmat[2][2] + 1.0f);
|
||||
left = near * (projmat[2][0] - 1.0f) / projmat[0][0];
|
||||
right = near * (projmat[2][0] + 1.0f) / projmat[0][0];
|
||||
bottom = near * (projmat[2][1] - 1.0f) / projmat[1][1];
|
||||
top = near * (projmat[2][1] + 1.0f) / projmat[1][1];
|
||||
}
|
||||
else {
|
||||
near = ( projmat[3][2] + 1.0f) / projmat[2][2];
|
||||
far = ( projmat[3][2] - 1.0f) / projmat[2][2];
|
||||
left = (-projmat[3][0] - 1.0f) / projmat[0][0];
|
||||
right = (-projmat[3][0] + 1.0f) / projmat[0][0];
|
||||
bottom = (-projmat[3][1] - 1.0f) / projmat[1][1];
|
||||
top = (-projmat[3][1] + 1.0f) / projmat[1][1];
|
||||
left *= near;
|
||||
right *= near;
|
||||
bottom *= near;
|
||||
top *= near;
|
||||
}
|
||||
|
||||
r_bbox->vec[0][2] = r_bbox->vec[3][2] = r_bbox->vec[7][2] = r_bbox->vec[4][2] = -near;
|
||||
@@ -494,8 +487,8 @@ static void draw_frustum_boundbox_calc(const float(*projmat)[4], BoundBox *r_bbo
|
||||
if (is_persp) {
|
||||
float sca_far = far / near;
|
||||
left *= sca_far;
|
||||
bottom *= sca_far;
|
||||
right *= sca_far;
|
||||
bottom *= sca_far;
|
||||
top *= sca_far;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user