-// Calculate if point/radius is inside view frustum
-static int viewable( const Point3D& cp, double radius ) {
- int viewable = 1; // start by assuming it's viewable
- double x1, y1;
-
- /********************************/
-#if defined( USE_FAST_FOV_CLIP ) // views.hxx
- /********************************/
-
- MAT3vec eye;
- double *mat;
- double x, y, z;
-
- x = cp.x();
- y = cp.y();
- z = cp.z();
-
- mat = (double *)(current_view.get_WORLD_TO_EYE());
-
- eye[2] = x*mat[2] + y*mat[6] + z*mat[10] + mat[14];
-
- // Check near and far clip plane
- if( ( eye[2] > radius ) ||
- ( eye[2] + radius + current_weather.get_visibility() < 0) )
- {
- return(0);
- }
-
- eye[0] = (x*mat[0] + y*mat[4] + z*mat[8] + mat[12])
- * current_view.get_slope_x();
-
- // check right and left clip plane (from eye perspective)
- x1 = radius * current_view.get_fov_x_clip();
- if( (eye[2] > -(eye[0]+x1)) || (eye[2] > (eye[0]-x1)) )
- {
- return(0);
- }
-
- eye[1] = (x*mat[1] + y*mat[5] + z*mat[9] + mat[13])
- * current_view.get_slope_y();
-
- // check bottom and top clip plane (from eye perspective)
- y1 = radius * current_view.get_fov_y_clip();
- if( (eye[2] > -(eye[1]+y1)) || (eye[2] > (eye[1]-y1)) )
- {
- return(0);
- }
-
- /********************************/
-#else // DO NOT USE_FAST_FOV_CLIP
- /********************************/
-
- fgVIEW *v;
- MAT3hvec world, eye;
- double x0, slope;
-
- v = ¤t_view;
-
- MAT3_SET_HVEC(world, cp->x, cp->y, cp->z, 1.0);
- // MAT3mult_vec(eye, world, v->WORLD_TO_EYE);
- // printf( "\nworld -> eye = %.2f %.2f %.2f radius = %.2f\n",
- // eye[0], eye[1], eye[2], radius);
-
- // Use lazy evaluation for calculating eye hvec.
-#define vec world
-#define mat v->WORLD_TO_EYE
- eye[2] = vec[0]*mat[0][2]+vec[1]*mat[1][2]+vec[2]*mat[2][2]+mat[3][2];
-
- // Check near clip plane
- if ( eye[2] > radius ) {
- return(0);
- }
-
- // Check far clip plane
- if ( eye[2] + radius < -current_weather.get_visibility() ) {
- return(0);
- }
-
- // check right clip plane (from eye perspective)
- // y = m * (x - x0) = equation of a line intercepting X axis at x0
- x1 = v->cos_fov_x * radius;
- y1 = v->sin_fov_x * radius;
- slope = v->slope_x;
- eye[0] = vec[0]*mat[0][0]+vec[1]*mat[1][0]+vec[2]*mat[2][0]+mat[3][0];
-
- if ( eye[2] > ((slope * (eye[0] - x1)) + y1) ) {
- return( false );
- }
-
- // check left clip plane (from eye perspective)
- if ( eye[2] > -((slope * (eye[0] + x1)) - y1) ) {
- return( false );
- }
-
- // check bottom clip plane (from eye perspective)
- x1 = -(v->cos_fov_y) * radius;
- y1 = v->sin_fov_y * radius;
- slope = v->slope_y;
- eye[1] = vec[0]*mat[0][1]+vec[1]*mat[1][1]+vec[2]*mat[2][1]+mat[3][1];
-#undef vec
-#undef mat
-
- if ( eye[2] > ((slope * (eye[1] - x1)) + y1) ) {
- return( false );
- }
-
- // check top clip plane (from eye perspective)
- if ( eye[2] > -((slope * (eye[1] + x1)) - y1) ) {
- return( false );
- }
-
-#endif // defined( USE_FAST_FOV_CLIP )
-
- return(viewable);
-}
-
-