yolobs-studio/libobs/graphics/bounds.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

135 lines
4.2 KiB
C
Raw Permalink Normal View History

2016-02-23 23:16:51 +00:00
/******************************************************************************
Copyright (C) 2013 by Hugh Bailey <obs.jim@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
#pragma once
#include "math-defs.h"
#include "vec3.h"
/*
* Axis Aligned Bounding Box
*/
#ifdef __cplusplus
extern "C" {
#endif
#define BOUNDS_MAX_X 1
#define BOUNDS_MAX_Y 2
#define BOUNDS_MAX_Z 4
#define BOUNDS_OUTSIDE 1
2019-09-22 21:19:10 +00:00
#define BOUNDS_INSIDE 2
2016-02-23 23:16:51 +00:00
#define BOUNDS_PARTIAL 3
struct bounds {
struct vec3 min, max;
};
static inline void bounds_zero(struct bounds *dst)
{
vec3_zero(&dst->min);
vec3_zero(&dst->max);
}
static inline void bounds_copy(struct bounds *dst, const struct bounds *b)
{
vec3_copy(&dst->min, &b->min);
vec3_copy(&dst->max, &b->max);
}
EXPORT void bounds_move(struct bounds *dst, const struct bounds *b,
2019-09-22 21:19:10 +00:00
const struct vec3 *v);
2016-02-23 23:16:51 +00:00
EXPORT void bounds_scale(struct bounds *dst, const struct bounds *b,
2019-09-22 21:19:10 +00:00
const struct vec3 *v);
2016-02-23 23:16:51 +00:00
EXPORT void bounds_merge(struct bounds *dst, const struct bounds *b1,
2019-09-22 21:19:10 +00:00
const struct bounds *b2);
2016-02-23 23:16:51 +00:00
EXPORT void bounds_merge_point(struct bounds *dst, const struct bounds *b,
2019-09-22 21:19:10 +00:00
const struct vec3 *v);
2016-02-23 23:16:51 +00:00
EXPORT void bounds_get_point(struct vec3 *dst, const struct bounds *b,
2019-09-22 21:19:10 +00:00
unsigned int i);
2016-02-23 23:16:51 +00:00
EXPORT void bounds_get_center(struct vec3 *dst, const struct bounds *b);
/**
* Note: transforms as OBB, then converts back to AABB, which can result in
* the actual size becoming larger than it originally was.
*/
EXPORT void bounds_transform(struct bounds *dst, const struct bounds *b,
2019-09-22 21:19:10 +00:00
const struct matrix4 *m);
2016-02-23 23:16:51 +00:00
EXPORT void bounds_transform3x4(struct bounds *dst, const struct bounds *b,
2019-09-22 21:19:10 +00:00
const struct matrix3 *m);
2016-02-23 23:16:51 +00:00
EXPORT bool bounds_intersection_ray(const struct bounds *b,
2019-09-22 21:19:10 +00:00
const struct vec3 *orig,
const struct vec3 *dir, float *t);
2016-02-23 23:16:51 +00:00
EXPORT bool bounds_intersection_line(const struct bounds *b,
2019-09-22 21:19:10 +00:00
const struct vec3 *p1,
const struct vec3 *p2, float *t);
2016-02-23 23:16:51 +00:00
EXPORT bool bounds_plane_test(const struct bounds *b, const struct plane *p);
2019-09-22 21:19:10 +00:00
EXPORT bool bounds_under_plane(const struct bounds *b, const struct plane *p);
2016-02-23 23:16:51 +00:00
static inline bool bounds_inside(const struct bounds *b,
2019-09-22 21:19:10 +00:00
const struct bounds *test)
2016-02-23 23:16:51 +00:00
{
2019-09-22 21:19:10 +00:00
return test->min.x >= b->min.x && test->min.y >= b->min.y &&
test->min.z >= b->min.z && test->max.x <= b->max.x &&
test->max.y <= b->max.y && test->max.z <= b->max.z;
2016-02-23 23:16:51 +00:00
}
static inline bool bounds_vec3_inside(const struct bounds *b,
2019-09-22 21:19:10 +00:00
const struct vec3 *v)
2016-02-23 23:16:51 +00:00
{
2019-09-22 21:19:10 +00:00
return v->x >= (b->min.x - EPSILON) && v->x <= (b->max.x + EPSILON) &&
v->y >= (b->min.y - EPSILON) && v->y <= (b->max.y + EPSILON) &&
v->z >= (b->min.z - EPSILON) && v->z <= (b->max.z + EPSILON);
2016-02-23 23:16:51 +00:00
}
2019-09-22 21:19:10 +00:00
EXPORT bool bounds_intersects(const struct bounds *b, const struct bounds *test,
float epsilon);
2016-02-23 23:16:51 +00:00
EXPORT bool bounds_intersects_obb(const struct bounds *b,
2019-09-22 21:19:10 +00:00
const struct bounds *test,
const struct matrix4 *m, float epsilon);
2016-02-23 23:16:51 +00:00
EXPORT bool bounds_intersects_obb3x4(const struct bounds *b,
2019-09-22 21:19:10 +00:00
const struct bounds *test,
const struct matrix3 *m, float epsilon);
2016-02-23 23:16:51 +00:00
static inline bool bounds_intersects_ray(const struct bounds *b,
2019-09-22 21:19:10 +00:00
const struct vec3 *orig,
const struct vec3 *dir)
2016-02-23 23:16:51 +00:00
{
float t;
return bounds_intersection_ray(b, orig, dir, &t);
}
static inline bool bounds_intersects_line(const struct bounds *b,
2019-09-22 21:19:10 +00:00
const struct vec3 *p1,
const struct vec3 *p2)
2016-02-23 23:16:51 +00:00
{
float t;
return bounds_intersection_line(b, p1, p2, &t);
}
EXPORT float bounds_min_dist(const struct bounds *b, const struct plane *p);
#ifdef __cplusplus
}
#endif