# include <config.h>
#endif
-#include <Aircraft/aircraft.h>
+#include <Aircraft/aircraft.hxx>
#include <Debug/fg_debug.h>
#include <Include/fg_constants.h>
#include <Math/mat3.h>
+#include <Math/point3d.hxx>
#include <Math/polar3d.hxx>
#include <Math/vector.hxx>
#include <Scenery/scenery.hxx>
winWidth = 640; // FG_DEFAULT_WIN_WIDTH
winHeight = 480; // FG_DEFAULT_WIN_HEIGHT
win_ratio = (double) winWidth / (double) winHeight;
- update_fov = TRUE;
+ update_fov = true;
}
// printf("theta_x = %.2f\n", theta_x);
sin_fov_x = sin(theta_x);
cos_fov_x = cos(theta_x);
- slope_x = - cos_fov_x / sin_fov_x;
- // (HUH?) sin_fov_x /= slope_x;
+ slope_x = -cos_fov_x / sin_fov_x;
// printf("slope_x = %.2f\n", slope_x);
+#if defined( USE_FAST_FOV_CLIP )
+ fov_x_clip = slope_x*cos_fov_x - sin_fov_x;
+#endif // defined( USE_FAST_FOV_CLIP )
+
// calculate sin() and cos() of fov / 2 in Y direction;
theta_y = (fov * DEG_TO_RAD) / 2.0;
// printf("theta_y = %.2f\n", theta_y);
sin_fov_y = sin(theta_y);
cos_fov_y = cos(theta_y);
slope_y = cos_fov_y / sin_fov_y;
- // (HUH?) sin_fov_y /= slope_y;
// printf("slope_y = %.2f\n", slope_y);
+
+#if defined( USE_FAST_FOV_CLIP )
+ fov_y_clip = -(slope_y*cos_fov_y + sin_fov_y);
+#endif // defined( USE_FAST_FOV_CLIP )
}
xglLoadIdentity();
// set up our view volume (default)
- LookAt(view_pos.x, view_pos.y, view_pos.z,
- view_pos.x + view_forward[0],
- view_pos.y + view_forward[1],
- view_pos.z + view_forward[2],
+ LookAt(view_pos.x(), view_pos.y(), view_pos.z(),
+ view_pos.x() + view_forward[0],
+ view_pos.y() + view_forward[1],
+ view_pos.z() + view_forward[2],
view_up[0], view_up[1], view_up[2]);
// look almost straight up (testing and eclipse watching)
- /* LookAt(view_pos.x, view_pos.y, view_pos.z,
- view_pos.x + view_up[0] + .001,
- view_pos.y + view_up[1] + .001,
- view_pos.z + view_up[2] + .001,
+ /* LookAt(view_pos.x(), view_pos.y(), view_pos.z(),
+ view_pos.x() + view_up[0] + .001,
+ view_pos.y() + view_up[1] + .001,
+ view_pos.z() + view_up[2] + .001,
view_up[0], view_up[1], view_up[2]); */
// lock view horizontally towards sun (testing)
- /* LookAt(view_pos.x, view_pos.y, view_pos.z,
- view_pos.x + surface_to_sun[0],
- view_pos.y + surface_to_sun[1],
- view_pos.z + surface_to_sun[2],
+ /* LookAt(view_pos.x(), view_pos.y(), view_pos.z(),
+ view_pos.x() + surface_to_sun[0],
+ view_pos.y() + surface_to_sun[1],
+ view_pos.z() + surface_to_sun[2],
view_up[0], view_up[1], view_up[2]); */
// lock view horizontally towards south (testing)
- /* LookAt(view_pos.x, view_pos.y, view_pos.z,
- view_pos.x + surface_south[0],
- view_pos.y + surface_south[1],
- view_pos.z + surface_south[2],
+ /* LookAt(view_pos.x(), view_pos.y(), view_pos.z(),
+ view_pos.x() + surface_south[0],
+ view_pos.y() + surface_south[1],
+ view_pos.z() + surface_south[2],
view_up[0], view_up[1], view_up[2]); */
// set the sun position
// Update the view parameters
void fgVIEW::UpdateViewMath( fgFLIGHT *f ) {
- fgPoint3d p;
+ Point3D p;
MAT3vec vec, forward, v0, minus_z;
MAT3mat R, TMP, UP, LOCAL, VIEW;
double ntmp;
- if(update_fov == TRUE) {
+ if(update_fov == true) {
// printf("Updating fov\n");
UpdateFOV(¤t_options);
- update_fov = FALSE;
+ update_fov = false;
}
- scenery.center.x = scenery.next_center.x;
- scenery.center.y = scenery.next_center.y;
- scenery.center.z = scenery.next_center.z;
+ scenery.center = scenery.next_center;
// printf("scenery center = %.2f %.2f %.2f\n", scenery.center.x,
// scenery.center.y, scenery.center.z);
// calculate the cartesion coords of the current lat/lon/0 elev
- p.lon = FG_Longitude;
- p.lat = FG_Lat_geocentric;
- p.radius = FG_Sea_level_radius * FEET_TO_METER;
-
- cur_zero_elev = fgPolarToCart3d(p);
+ p.setvals(
+ FG_Longitude,
+ FG_Lat_geocentric,
+ FG_Sea_level_radius * FEET_TO_METER );
- cur_zero_elev.x -= scenery.center.x;
- cur_zero_elev.y -= scenery.center.y;
- cur_zero_elev.z -= scenery.center.z;
+ cur_zero_elev = fgPolarToCart3d(p) - scenery.center;
// calculate view position in current FG view coordinate system
// p.lon & p.lat are already defined earlier, p.radius was set to
// the sea level radius, so now we add in our altitude.
if ( FG_Altitude * FEET_TO_METER >
(scenery.cur_elev + 0.5 * METER_TO_FEET) ) {
- p.radius += FG_Altitude * FEET_TO_METER;
+ p.setz( p.radius() + FG_Altitude * FEET_TO_METER );
} else {
- p.radius += scenery.cur_elev + 0.5 * METER_TO_FEET;
+ p.setz( p.radius() + scenery.cur_elev + 0.5 * METER_TO_FEET );
}
abs_view_pos = fgPolarToCart3d(p);
-
- view_pos.x = abs_view_pos.x - scenery.center.x;
- view_pos.y = abs_view_pos.y - scenery.center.y;
- view_pos.z = abs_view_pos.z - scenery.center.z;
+ view_pos = abs_view_pos - scenery.center;
fgPrintf( FG_VIEW, FG_DEBUG, "Absolute view pos = %.4f, %.4f, %.4f\n",
- abs_view_pos.x, abs_view_pos.y, abs_view_pos.z);
+ abs_view_pos.x(), abs_view_pos.y(), abs_view_pos.z());
fgPrintf( FG_VIEW, FG_DEBUG, "Relative view pos = %.4f, %.4f, %.4f\n",
- view_pos.x, view_pos.y, view_pos.z);
+ view_pos.x(), view_pos.y(), view_pos.z());
// Derive the LOCAL aircraft rotation matrix (roll, pitch, yaw)
// from FG_T_local_to_body[3][3]
MAT3mult_vec(view_forward, forward, TMP);
// make a vector to the current view position
- MAT3_SET_VEC(v0, view_pos.x, view_pos.y, view_pos.z);
+ MAT3_SET_VEC(v0, view_pos.x(), view_pos.y(), view_pos.z());
// Given a vector pointing straight down (-Z), map into onto the
// local plane representing "horizontal". This should give us the
// MAT3print(AIRCRAFT, stdout);
// View position in scenery centered coordinates
- MAT3_SET_HVEC(vec, view_pos.x, view_pos.y, view_pos.z, 1.0);
+ MAT3_SET_HVEC(vec, view_pos.x(), view_pos.y(), view_pos.z(), 1.0);
MAT3translate(T_view, vec);
// printf("\nTranslation matrix\n");
// MAT3print(T_view, stdout);
}
+#if 0
+// Reject non viewable spheres from current View Frustrum by Curt
+// Olson curt@me.umn.edu and Norman Vine nhv@yahoo.com with 'gentle
+// guidance' from Steve Baker sbaker@link.com
+int
+fgVIEW::SphereClip( const Point3D& cp, const double radius )
+{
+ double x1, y1;
+
+ MAT3vec eye;
+ double *mat;
+ double x, y, z;
+
+ x = cp->x;
+ y = cp->y;
+ z = cp->z;
+
+ mat = (double *)(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.visibility < 0) )
+ // ( eye[2] + radius + far_plane < 0) )
+ {
+ return 1;
+ }
+
+ // check right and left clip plane (from eye perspective)
+ x1 = radius * fov_x_clip;
+ eye[0] = (x*mat[0] + y*mat[4] + z*mat[8] + mat[12]) * slope_x;
+ if( (eye[2] > -(eye[0]+x1)) || (eye[2] > (eye[0]-x1)) ) {
+ return(1);
+ }
+
+ // check bottom and top clip plane (from eye perspective)
+ y1 = radius * fov_y_clip;
+ eye[1] = (x*mat[1] + y*mat[5] + z*mat[9] + mat[13]) * slope_y;
+ if( (eye[2] > -(eye[1]+y1)) || (eye[2] > (eye[1]-y1)) ) {
+ return 1;
+ }
+
+ return 0;
+}
+#endif
+
+
// Destructor
fgVIEW::~fgVIEW( void ) {
}
// $Log$
+// Revision 1.23 1998/10/17 01:34:26 curt
+// C++ ifying ...
+//
+// Revision 1.22 1998/10/16 00:54:03 curt
+// Converted to Point3D class.
+//
+// Revision 1.21 1998/09/17 18:35:33 curt
+// Added F8 to toggle fog and F9 to toggle texturing.
+//
+// Revision 1.20 1998/09/08 15:04:35 curt
+// Optimizations by Norman Vine.
+//
// Revision 1.19 1998/08/20 20:32:34 curt
// Reshuffled some of the code in and around views.[ch]xx
//