Open Broadcaster Software
Free, open source software for live streaming and recording
plane.h
Go to the documentation of this file.
1 /******************************************************************************
2  Copyright (C) 2013 by Hugh Bailey <obs.jim@gmail.com>
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16 ******************************************************************************/
17 
18 #pragma once
19 
20 #include "math-defs.h"
21 #include "vec3.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 struct matrix3;
28 struct matrix4;
29 
30 struct plane {
31  struct vec3 dir;
32  float dist;
33 };
34 
35 static inline void plane_copy(struct plane *dst, const struct plane *p)
36 {
37  vec3_copy(&dst->dir, &p->dir);
38  dst->dist = p->dist;
39 }
40 
41 static inline void plane_set(struct plane *dst, const struct vec3 *dir,
42  float dist)
43 {
44  vec3_copy(&dst->dir, dir);
45  dst->dist = dist;
46 }
47 
48 static inline void plane_setf(struct plane *dst, float a, float b, float c,
49  float d)
50 {
51  vec3_set(&dst->dir, a, b, c);
52  dst->dist = d;
53 }
54 
55 EXPORT void plane_from_tri(struct plane *dst, const struct vec3 *v1,
56  const struct vec3 *v2, const struct vec3 *v3);
57 
58 EXPORT void plane_transform(struct plane *dst, const struct plane *p,
59  const struct matrix4 *m);
60 EXPORT void plane_transform3x4(struct plane *dst, const struct plane *p,
61  const struct matrix3 *m);
62 
63 EXPORT bool plane_intersection_ray(const struct plane *p,
64  const struct vec3 *orig,
65  const struct vec3 *dir, float *t);
66 EXPORT bool plane_intersection_line(const struct plane *p,
67  const struct vec3 *v1,
68  const struct vec3 *v2, float *t);
69 
70 EXPORT bool plane_tri_inside(const struct plane *p, const struct vec3 *v1,
71  const struct vec3 *v2, const struct vec3 *v3,
72  float precision);
73 
74 EXPORT bool plane_line_inside(const struct plane *p, const struct vec3 *v1,
75  const struct vec3 *v2, float precision);
76 
77 static inline bool plane_close(const struct plane *p1, const struct plane *p2,
78  float precision)
79 {
80  return vec3_close(&p1->dir, &p2->dir, precision) &&
81  close_float(p1->dist, p2->dist, precision);
82 }
83 
84 static inline bool plane_coplanar(const struct plane *p1,
85  const struct plane *p2, float precision)
86 {
87  float cos_angle = vec3_dot(&p1->dir, &p2->dir);
88 
89  if (close_float(cos_angle, 1.0f, precision))
90  return close_float(p1->dist, p2->dist, precision);
91  else if (close_float(cos_angle, -1.0f, precision))
92  return close_float(-p1->dist, p2->dist, precision);
93 
94  return false;
95 }
96 
97 #ifdef __cplusplus
98 }
99 #endif
EXPORT bool plane_intersection_line(const struct plane *p, const struct vec3 *v1, const struct vec3 *v2, float *t)
Definition: vec3.h:34
EXPORT bool plane_tri_inside(const struct plane *p, const struct vec3 *v1, const struct vec3 *v2, const struct vec3 *v3, float precision)
Definition: matrix3.h:31
EXPORT void plane_transform(struct plane *dst, const struct plane *p, const struct matrix4 *m)
struct vec3 dir
Definition: plane.h:31
#define EXPORT
Definition: c99defs.h:37
float dist
Definition: plane.h:32
EXPORT void plane_from_tri(struct plane *dst, const struct vec3 *v1, const struct vec3 *v2, const struct vec3 *v3)
__m128 m
Definition: vec3.h:40
Definition: matrix4.h:32
EXPORT bool plane_intersection_ray(const struct plane *p, const struct vec3 *orig, const struct vec3 *dir, float *t)
EXPORT void plane_transform3x4(struct plane *dst, const struct plane *p, const struct matrix3 *m)
EXPORT bool plane_line_inside(const struct plane *p, const struct vec3 *v1, const struct vec3 *v2, float precision)
Definition: plane.h:30