FreeWRL / FreeX3D 4.3.0
Frustum.h
1/*
2
3
4Global includes.
5
6*/
7
8/****************************************************************************
9 This file is part of the FreeWRL/FreeX3D Distribution.
10
11 Copyright 2009 CRC Canada. (http://www.crc.gc.ca)
12
13 FreeWRL/FreeX3D is free software: you can redistribute it and/or modify
14 it under the terms of the GNU Lesser Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 FreeWRL/FreeX3D is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with FreeWRL/FreeX3D. If not, see <http://www.gnu.org/licenses/>.
25****************************************************************************/
26
27
28#ifndef __FREEWRL_FRUSTUM_H__
29#define __FREEWRL_FRUSTUM_H__
30
31/* for Extents and BoundingBoxen */
32#define EXTENT_MAX_X _extent[0]
33#define EXTENT_MIN_X _extent[1]
34#define EXTENT_MAX_Y _extent[2]
35#define EXTENT_MIN_Y _extent[3]
36#define EXTENT_MAX_Z _extent[4]
37#define EXTENT_MIN_Z _extent[5]
38
39/* no occlusion queries right now - need to work on the shader implementation
40 of occlusion culling */
41
42// OLD_IPHONE_AQUA #if defined (AQUA)
43// OLD_IPHONE_AQUA #define OCCLUSION
44// OLD_IPHONE_AQUA #define VISIBILITYOCCLUSION
45// OLD_IPHONE_AQUA #define SHAPEOCCLUSION
46// OLD_IPHONE_AQUA #else
47
48 #undef OCCLUSION
49 #undef VISIBILITYOCCLUSION
50 #undef SHAPEOCCLUSION
51
52// OLD_IPHONE_AQUA #endif
53
54
55
56
57int newOcclude(void);
58
59
60#ifdef OCCLUSION
61#define OCCLUSIONTEST \
62 /* a value of ZERO means that it HAS visible children - helps with initialization */ \
63 if ((renderstate()->render_geom!=0) | (renderstate()->render_sensitive!=0)) { \
64 /* printf ("OCCLUSIONTEST node %d fl %x\n",node, node->_renderFlags & VF_hasVisibleChildren); */ \
65 if ((node->_renderFlags & VF_hasVisibleChildren) == 0) { \
66 /* printf ("WOW - we do NOT need to do this transform but doing it %x!\n",(node->_renderFlags)); \
67 printf (" vp %d geom %d light %d sens %d blend %d prox %d col %d\n", \
68 render_vp,render_geom,render_light,render_sensitive,render_blend,render_proximity,render_collision); */ \
69 return; \
70 } \
71 }
72#else
73#define OCCLUSIONTEST
74#endif
75
76
77void beginOcclusionQuery(struct X3D_VisibilitySensor* node, int render_geometry);
78void endOcclusionQuery(struct X3D_VisibilitySensor* node, int render_geometry);
79
80/*
81#define BEGINOCCLUSIONQUERY \
82 if (render_geom) { \
83 if (potentialOccluderCount < OccQuerySize) { \
84 printf ("beginOcclusionQuery, potoc %d occQ %d\n",potentialOccluderCount, OccQuerySize, node->__occludeCheckCount); \
85 if (node->__occludeCheckCount < 0) { \
86 printf ("beginOcclusionQuery, query %u, node %s\n",potentialOccluderCount, stringNodeType(node->_nodeType)); \
87 FW_GL_BEGIN_QUERY(GL_SAMPLES_PASSED, OccQueries[potentialOccluderCount]); \
88 occluderNodePointer[potentialOccluderCount] = (void *)node; \
89 } \
90 } \
91 }
92
93#define ENDOCCLUSIONQUERY \
94 if (render_geom) { \
95 if (potentialOccluderCount < OccQuerySize) { \
96 if (node->__occludeCheckCount < 0) { \
97 printf ("glEndQuery node %u\n",node); \
98 FW_GL_END_QUERY(GL_SAMPLES_PASSED); \
99 potentialOccluderCount++; \
100 } \
101 } \
102 }
103*/
104
105void moveAndRotateThisPoint(struct point_XYZ *mypt, double x, double y, double z, double *MM);
106void setExtent(float maxx, float minx, float maxy, float miny, float maxz, float minz, struct X3D_Node *me);
107void printmatrix(GLDOUBLE* mat);
108
109void record_ZBufferDistance(struct X3D_Node *, void *);
110void OcclusionStartofRenderSceneUpdateScene(void);
111void OcclusionCulling (void);
112void zeroOcclusion(void);
113
114int is_Switchchild_inrange(struct X3D_Switch *node, struct X3D_Node *me);
115int is_GeoLODchild_inrange (struct X3D_GeoLOD* gpnode, struct X3D_Node *me);
116int is_CADLayerchild_inrange(struct X3D_CADLayer *node, struct X3D_Node *me);
117
118
119//extent6f {xmax,xmin,ymax,ymin,zmax,zmin}
120float *extent6f_constructor(float *extent6, float xmin,float xmax, float ymin,float ymax, float zmin,float zmax);
121float *extent6f_clear(float *extent6);
122int extent6f_isSet(float *extent6);
123float *extent6f_copy(float *eout6, float *ein6);
124void extent6f_to_vec3f(float *extent6, float *pmin, float *pmax);
125void extent6f_from_vec3f2(float *extent6, float *pmin, float *pmax);
126void extent6f_to_box3f8(float *extent6, float *p3f8);
127float *extent6f_from_box3fn(float *extent6,float *p, int n);
128float *extent6f_union_extent6f(float *extent6, float *ein6);
129float *extent6f_intersect_extent6f(float *extent6, float *eina, float *einb);
130float *extent6f_union_vec3f(float *extent6, float *p3);
131float *extent6f_scale3f(float *eout6, float *ein6, float *s3);
132float *extent6f_translate3f(float *eout6, float *ein6, float *p3);
133float *extent6f_translate3d(float *eout6, float *ein6, double *p3);
134float *extent6f_get_center3f(float *extent6, float *center3);
135float extent6f_get_maxsize(float *extent6);
136float extent6f_get_maxradius(float *extent6);
137float *extent6f_rotate4f(float *eout6, float *ein6, float *vrot4);
138float *extent6f_rotate4d(float *eout6, float *ein6, double *vrot4);
139float *extent6f_mattransform4d(float *eout6,float *ein6, double *mat4);
140void extent6f_printf(float *extent6);
141void extent6f_draw(float *extent); //in CursorDraw.c
142void bbox2extent6f(float* center, float *size, float *extent6);
143void extent6f2bbox(float *extent6, float* center, float *size);
144void draw_bbox(float *center, float *size);
145
146float *orientedBBox_mattransformAFFINE4d(float *p3fn24, float *obb12, double *mat4);
147float *orientedBBox2vec3fn(float *p3fn24, float *obb12);
148int extent6f_point_inside(float *extent6, float *pd);
149
150
151struct Planed {
152 double normal[3];
153 double p[3]; //redundant but convenient
154 double d;
155};
156enum {
157 NEARP =0,
158 FARP,
159 BOTTOM,
160 TOP,
161 LEFT,
162 RIGHT,
163};
164void setFrustumPlanes(double *mvpMatrix, struct Planed *pl);
165int frustum_point_inside(struct Planed *frustum_planes, double *p);
166int frustum_generate_corner_points(struct Planed *frustum_planes, float *pf24n);
167int plane_intersect_plane_intersect_plane(struct Planed *p1, struct Planed *p2, struct Planed *p3, double *point);
168int frustum_box_inside(struct Planed *frustum_planes, float *corners3f, int np);
169#endif /* __FREEWRL_FRUSTUM_H__ */