-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathvfc.c
74 lines (56 loc) · 2.05 KB
/
vfc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "vfc.h"
int
vf_point_inside(const view_params *vp, const vec3 v)
{
vec3 v_eye;
/* transform vertex to eye space */
VecSub(v_eye, v, vp->eye);
/* check if it's inside near and far z planes */
real d = VecDot(vp->gaze, v_eye);
if (d < vp->znear || d > vp->zfar)
return 0;
/* now if it's outside with respect to any of top, bottom, left or right
* view planes, it's outside the vf, otherwise it's inside */
if (VecDot(v_eye, vp->nr) > 0) return 0;
if (VecDot(v_eye, vp->nl) > 0) return 0;
if (VecDot(v_eye, vp->nt) > 0) return 0;
if (VecDot(v_eye, vp->nb) > 0) return 0;
return 1;
}
int
vf_aabb_inside(const view_params *vp, const vec3 min, const vec3 max)
{
vec3 tmp;
if (vf_point_inside(vp, min)) return 1;
if (vf_point_inside(vp, max)) return 1;
tmp[0]=min[0]; tmp[1]=max[1]; tmp[2]=max[2];
if (vf_point_inside(vp, tmp)) return 1;
tmp[0]=min[0]; tmp[1]=min[1]; tmp[2]=max[2];
if (vf_point_inside(vp, tmp)) return 1;
tmp[0]=min[0]; tmp[1]=max[1]; tmp[2]=min[2];
if (vf_point_inside(vp, tmp)) return 1;
tmp[0]=max[0]; tmp[1]=min[1]; tmp[2]=max[2];
if (vf_point_inside(vp, tmp)) return 1;
tmp[0]=max[0]; tmp[1]=max[1]; tmp[2]=min[2];
if (vf_point_inside(vp, tmp)) return 1;
tmp[0]=max[0]; tmp[1]=min[1]; tmp[2]=min[2];
if (vf_point_inside(vp, tmp)) return 1;
return 0;
}
int
vf_sphere_inside(const view_params *vp, const vec3 center, real radius)
{
vec3 c_eye;
/* transform center to eye space */
VecSub(c_eye, center, vp->eye);
/* check if it's inside near and far z planes */
real d = VecDot(vp->gaze, c_eye);
if (d+radius < vp->znear || d-radius > vp->zfar) return 0;
/* now if it's outside with respect to any of top, bottom, left or right
* view planes, it's outside the vf, otherwise it's inside */
if (VecDot(c_eye, vp->nr) > radius) return 0;
if (VecDot(c_eye, vp->nl) > radius) return 0;
if (VecDot(c_eye, vp->nt) > radius) return 0;
if (VecDot(c_eye, vp->nb) > radius) return 0;
return 1;
}