Open Broadcaster Software
Free, open source software for live streaming and recording
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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,
56  const struct vec3 *v1,
57  const struct vec3 *v2,
58  const struct vec3 *v3);
59 
60 EXPORT void plane_transform(struct plane *dst, const struct plane *p,
61  const struct matrix4 *m);
62 EXPORT void plane_transform3x4(struct plane *dst, const struct plane *p,
63  const struct matrix3 *m);
64 
65 EXPORT bool plane_intersection_ray(const struct plane *p,
66  const struct vec3 *orig, const struct vec3 *dir, float *t);
67 EXPORT bool plane_intersection_line(const struct plane *p,
68  const struct vec3 *v1, const struct vec3 *v2, float *t);
69 
70 EXPORT bool plane_tri_inside(const struct plane *p,
71  const struct vec3 *v1,
72  const struct vec3 *v2,
73  const struct vec3 *v3,
74  float precision);
75 
76 EXPORT bool plane_line_inside(const struct plane *p, const struct vec3 *v1,
77  const struct vec3 *v2, float precision);
78 
79 static inline bool plane_close(const struct plane *p1, const struct plane *p2,
80  float precision)
81 {
82  return vec3_close(&p1->dir, &p2->dir, precision) &&
83  close_float(p1->dist, p2->dist, precision);
84 }
85 
86 static inline bool plane_coplanar(const struct plane *p1,
87  const struct plane *p2, float precision)
88 {
89  float cos_angle = vec3_dot(&p1->dir, &p2->dir);
90 
91  if (close_float(cos_angle, 1.0f, precision))
92  return close_float(p1->dist, p2->dist, precision);
93  else if (close_float(cos_angle, -1.0f, precision))
94  return close_float(-p1->dist, p2->dist, precision);
95 
96  return false;
97 }
98 
99 #ifdef __cplusplus
100 }
101 #endif
EXPORT bool plane_intersection_line(const struct plane *p, const struct vec3 *v1, const struct vec3 *v2, float *t)
Definition: vec3.h:33
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:49
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:39
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