From 7e240adff128dc047f39cd91ff7146583d765422 Mon Sep 17 00:00:00 2001 From: curt <curt> Date: Fri, 16 Oct 1998 00:51:46 +0000 Subject: [PATCH] Converted to Point3D class. --- Airports/genapt.cxx | 164 ++++++++++++++++++++---------------------- Astro/sky.cxx | 11 ++- Astro/stars.cxx | 19 +++-- Main/GLUTmain.cxx | 5 +- Main/fg_init.cxx | 18 ++--- Main/views.cxx | 75 +++++++++---------- Main/views.hxx | 12 ++-- Objects/fragment.cxx | 36 +++++----- Objects/fragment.hxx | 18 ++--- Objects/obj.cxx | 68 +++++++++--------- Objects/obj.hxx | 5 +- Scenery/scenery.hxx | 24 ++++--- Scenery/tile.cxx | 14 ++-- Scenery/tile.hxx | 28 ++++---- Scenery/tilecache.cxx | 19 ++--- Scenery/tilecache.hxx | 6 +- Scenery/tilemgr.cxx | 82 ++++++++++----------- Scenery/tilemgr.hxx | 5 +- Time/event.hxx | 5 +- Time/fg_time.hxx | 4 +- Time/light.hxx | 8 ++- Time/sunpos.cxx | 31 ++++---- Time/sunpos.hxx | 2 - 23 files changed, 346 insertions(+), 313 deletions(-) diff --git a/Airports/genapt.cxx b/Airports/genapt.cxx index dac8ee469..e9789faa0 100644 --- a/Airports/genapt.cxx +++ b/Airports/genapt.cxx @@ -32,9 +32,10 @@ using namespace std; #endif #include <Debug/fg_debug.h> -#include <Include/fg_types.h> +// #include <Include/fg_types.h> #include <Math/fg_geodesy.h> #include <Math/mat3.h> +#include <Math/point3d.hxx> #include <Math/polar3d.hxx> #include <Misc/fgstream.hxx> #include <Objects/material.hxx> @@ -44,46 +45,47 @@ using namespace std; #include "genapt.hxx" -typedef vector < fgPoint3d > container; +typedef vector < Point3D > container; typedef container::iterator iterator; typedef container::const_iterator const_iterator; -// Calculate distance between to fgPoint3d's -static double calc_dist(const fgPoint3d& p1, const fgPoint3d& p2) { +/* +// Calculate distance between to Point3D's +static double calc_dist(const Point3D& p1, const Point3D& p2) { double x, y, z; - x = p1.x - p2.x; - y = p1.y - p2.y; - z = p1.z - p2.z; + x = p1.x() - p2.x(); + y = p1.y() - p2.y(); + z = p1.z() - p2.z(); return sqrt(x*x + y*y + z*z); } +*/ -// convert a geodetic point lon(degrees), lat(degrees), elev(meter) to a -// cartesian point -static fgPoint3d geod_to_cart(fgPoint3d geod) { - fgPoint3d cart; - fgPoint3d geoc; - double sl_radius; +// convert a geodetic point lon(radians), lat(radians), elev(meter) to +// a cartesian point +static Point3D geod_to_cart(const Point3D& geod) { + Point3D cp; + Point3D pp; + double gc_lon, gc_lat, sl_radius; - // printf("A geodetic point is (%.2f, %.2f, %.2f)\n", geod[0], - // geod[1], geod[2]); + // printf("A geodetic point is (%.2f, %.2f, %.2f)\n", + // geod[0], geod[1], geod[2]); - geoc.lon = geod.lon*DEG_TO_RAD; - fgGeodToGeoc(geod.lat*DEG_TO_RAD, geod.radius, &sl_radius, &geoc.lat); + gc_lon = geod.lon(); + fgGeodToGeoc(geod.lat(), geod.radius(), &sl_radius, &gc_lat); // printf("A geocentric point is (%.2f, %.2f, %.2f)\n", gc_lon, - // gc_lat, sl_radius+geod[2]); */ + // gc_lat, sl_radius+geod[2]); - geoc.radius = sl_radius + geod.radius; - cart = fgPolarToCart3d(geoc); + pp.setvals(gc_lon, gc_lat, sl_radius + geod.radius()); + cp = fgPolarToCart3d(pp); // printf("A cart point is (%.8f, %.8f, %.8f)\n", cp.x, cp.y, cp.z); - return cart; + return(cp); } - #define FG_APT_BASE_TEX_CONSTANT 2000.0 #ifdef OLD_TEX_COORDS @@ -115,25 +117,23 @@ calc_tex_coords(const fgPoint3d& p) { // Calculate texture coordinates for a given point. -static fgPoint3d calc_tex_coords(double *node, fgPoint3d *ref) { - fgPoint3d cp; - fgPoint3d pp; +static Point3D calc_tex_coords(double *node, const Point3D& ref) { + Point3D cp; + Point3D pp; - cp.x = node[0] + ref->x; - cp.y = node[1] + ref->y; - cp.z = node[2] + ref->z; + cp.setvals( node[0] + ref.x(), node[1] + ref.y(), node[2] + ref.z() ); pp = fgCartToPolar3d(cp); - pp.lon = fmod(FG_APT_BASE_TEX_CONSTANT * pp.lon, 10.0); - pp.lat = fmod(FG_APT_BASE_TEX_CONSTANT * pp.lat, 10.0); + pp.setx( fmod(FG_APT_BASE_TEX_CONSTANT * pp.x(), 10.0) ); + pp.sety( fmod(FG_APT_BASE_TEX_CONSTANT * pp.y(), 10.0) ); - if ( pp.lon < 0.0 ) { - pp.lon += 10.0; + if ( pp.x() < 0.0 ) { + pp.setx( pp.x() + 10.0 ); } - if ( pp.lat < 0.0 ) { - pp.lat += 10.0; + if ( pp.y() < 0.0 ) { + pp.sety( pp.y() + 10.0 ); } return(pp); @@ -142,10 +142,10 @@ static fgPoint3d calc_tex_coords(double *node, fgPoint3d *ref) { // generate the actual base area for the airport static void -gen_base( const fgPoint3d& average, const container& perimeter, fgTILE *t) +gen_base( const Point3D& average, const container& perimeter, fgTILE *t) { GLint display_list; - fgPoint3d cart, cart_trans, tex; + Point3D cart, cart_trans, tex; MAT3vec normal; double dist, max_dist, temp; int center_num, i; @@ -167,16 +167,14 @@ gen_base( const fgPoint3d& average, const container& perimeter, fgTILE *t) } printf(" tile center = %.2f %.2f %.2f\n", - t->center.x, t->center.y, t->center.z); + t->center.x(), t->center.y(), t->center.z() ); printf(" airport center = %.2f %.2f %.2f\n", - average.x, average.y, average.z); - fragment.center.x = average.x; - fragment.center.y = average.y; - fragment.center.z = average.z; + average.x(), average.y(), average.z()); + fragment.center = average; - normal[0] = average.x; - normal[1] = average.y; - normal[2] = average.z; + normal[0] = average.x(); + normal[1] = average.y(); + normal[2] = average.z(); MAT3_NORMALIZE_VEC(normal, temp); display_list = xglGenLists(1); @@ -184,38 +182,34 @@ gen_base( const fgPoint3d& average, const container& perimeter, fgTILE *t) xglBegin(GL_TRIANGLE_FAN); // first point center of fan - cart_trans.x = average.x - t->center.x; - cart_trans.y = average.y - t->center.y; - cart_trans.z = average.z - t->center.z; - t->nodes[t->ncount][0] = cart_trans.x; - t->nodes[t->ncount][1] = cart_trans.y; - t->nodes[t->ncount][2] = cart_trans.z; + cart_trans = average - t->center; + t->nodes[t->ncount][0] = cart_trans.x(); + t->nodes[t->ncount][1] = cart_trans.y(); + t->nodes[t->ncount][2] = cart_trans.z(); center_num = t->ncount; t->ncount++; - tex = calc_tex_coords( t->nodes[t->ncount-1], &(t->center) ); - xglTexCoord2f(tex.x, tex.y); + tex = calc_tex_coords( t->nodes[t->ncount-1], t->center ); + xglTexCoord2f(tex.x(), tex.y()); xglNormal3dv(normal); xglVertex3dv(t->nodes[t->ncount-1]); // first point on perimeter - iterator current = perimeter.begin(); + const_iterator current = perimeter.begin(); cart = geod_to_cart( *current ); - cart_trans.x = cart.x - t->center.x; - cart_trans.y = cart.y - t->center.y; - cart_trans.z = cart.z - t->center.z; - t->nodes[t->ncount][0] = cart_trans.x; - t->nodes[t->ncount][1] = cart_trans.y; - t->nodes[t->ncount][2] = cart_trans.z; + cart_trans = cart - t->center; + t->nodes[t->ncount][0] = cart_trans.x(); + t->nodes[t->ncount][1] = cart_trans.y(); + t->nodes[t->ncount][2] = cart_trans.z(); t->ncount++; i = 1; - tex = calc_tex_coords( t->nodes[i], &(t->center) ); - dist = calc_dist(average, cart); + tex = calc_tex_coords( t->nodes[i], t->center ); + dist = distance3D(average, cart); if ( dist > max_dist ) { max_dist = dist; } - xglTexCoord2f(tex.x, tex.y); + xglTexCoord2f(tex.x(), tex.y()); xglVertex3dv(t->nodes[i]); ++current; ++i; @@ -223,21 +217,19 @@ gen_base( const fgPoint3d& average, const container& perimeter, fgTILE *t) const_iterator last = perimeter.end(); for ( ; current != last; ++current ) { cart = geod_to_cart( *current ); - cart_trans.x = cart.x - t->center.x; - cart_trans.y = cart.y - t->center.y; - cart_trans.z = cart.z - t->center.z; - t->nodes[t->ncount][0] = cart_trans.x; - t->nodes[t->ncount][1] = cart_trans.y; - t->nodes[t->ncount][2] = cart_trans.z; + cart_trans = cart - t->center; + t->nodes[t->ncount][0] = cart_trans.x(); + t->nodes[t->ncount][1] = cart_trans.y(); + t->nodes[t->ncount][2] = cart_trans.z(); t->ncount++; fragment.add_face(center_num, i - 1, i); - tex = calc_tex_coords( t->nodes[i], &(t->center) ); - dist = calc_dist(average, cart); + tex = calc_tex_coords( t->nodes[i], t->center ); + dist = distance3D(average, cart); if ( dist > max_dist ) { max_dist = dist; } - xglTexCoord2f(tex.x, tex.y); + xglTexCoord2f(tex.x(), tex.y()); xglVertex3dv(t->nodes[i]); i++; } @@ -245,13 +237,11 @@ gen_base( const fgPoint3d& average, const container& perimeter, fgTILE *t) // last point (first point in perimeter list) current = perimeter.begin(); cart = geod_to_cart( *current ); - cart_trans.x = cart.x - t->center.x; - cart_trans.y = cart.y - t->center.y; - cart_trans.z = cart.z - t->center.z; + cart_trans = cart - t->center; fragment.add_face(center_num, i - 1, 1); - tex = calc_tex_coords( t->nodes[1], &(t->center) ); - xglTexCoord2f(tex.x, tex.y); + tex = calc_tex_coords( t->nodes[1], t->center ); + xglTexCoord2f(tex.x(), tex.y()); xglVertex3dv(t->nodes[1]); xglEnd(); @@ -276,7 +266,8 @@ fgAptGenerate(const string& path, fgTILE *tile) // face list (this indexes into the master tile vertex list) container perimeter; - fgPoint3d p, average; + Point3D p, average; + double avex = 0.0, avey = 0.0, avez = 0.0; int size; // gpc_vertex p_2d, list_2d[MAX_PERIMETER]; @@ -310,7 +301,7 @@ fgAptGenerate(const string& path, fgTILE *tile) in.stream() >> apt_id; apt_name = ""; i = 1; - average.lon = average.lat = average.radius = 0.0; + avex = avey = avez = 0.0; perimeter.erase( perimeter.begin(), perimeter.end() ); // skip to end of line. while ( in.get(c) && c != '\n' ) { @@ -323,10 +314,10 @@ fgAptGenerate(const string& path, fgTILE *tile) // out of the base terrain. The points are given in // counter clockwise order and are specified in lon/lat // degrees. - in.stream() >> p.lon >> p.lat >> p.radius; - average.x += tile->nodes[i][0]; - average.y += tile->nodes[i][1]; - average.z += tile->nodes[i][2]; + in.stream() >> p; + avex += tile->nodes[i][0]; + avey += tile->nodes[i][1]; + avez += tile->nodes[i][2]; perimeter.push_back(p); ++i; } else if ( token == "r" ) { @@ -343,9 +334,9 @@ fgAptGenerate(const string& path, fgTILE *tile) // we have just finished reading and airport record. // process the info size = perimeter.size(); - average.x = average.x / (double)size + tile->center.x; - average.y = average.y / (double)size + tile->center.y; - average.z = average.z / (double)size + tile->center.z; + average.setvals( avex / (double)size + tile->center.x(), + avey / (double)size + tile->center.y(), + avez / (double)size + tile->center.z() ); gen_base(average, perimeter, tile); } @@ -355,6 +346,9 @@ fgAptGenerate(const string& path, fgTILE *tile) // $Log$ +// Revision 1.4 1998/10/16 00:51:46 curt +// Converted to Point3D class. +// // Revision 1.3 1998/09/21 20:55:00 curt // Used the cartesian form of the airport area coordinates to determine the // center. diff --git a/Astro/sky.cxx b/Astro/sky.cxx index 019447d26..414d9bad3 100644 --- a/Astro/sky.cxx +++ b/Astro/sky.cxx @@ -291,7 +291,9 @@ void fgSkyRender( void ) { xglPushMatrix(); /* Translate to view position */ - xglTranslatef( v->cur_zero_elev.x, v->cur_zero_elev.y, v->cur_zero_elev.z ); + xglTranslatef( v->cur_zero_elev.x(), + v->cur_zero_elev.y(), + v->cur_zero_elev.z() ); /* printf(" Translated to %.2f %.2f %.2f\n", v->cur_zero_elev.x, v->cur_zero_elev.y, v->cur_zero_elev.z ); */ @@ -368,9 +370,12 @@ void fgSkyRender( void ) { /* $Log$ -/* Revision 1.10 1998/08/29 13:07:16 curt -/* Rewrite of event manager thanks to Bernie Bright. +/* Revision 1.11 1998/10/16 00:52:19 curt +/* Converted to Point3D class. /* + * Revision 1.10 1998/08/29 13:07:16 curt + * Rewrite of event manager thanks to Bernie Bright. + * * Revision 1.9 1998/08/22 01:18:59 curt * Minor tweaks to avoid using unitialized memory. * diff --git a/Astro/stars.cxx b/Astro/stars.cxx index 31617488b..87bf8c517 100644 --- a/Astro/stars.cxx +++ b/Astro/stars.cxx @@ -43,7 +43,6 @@ #include <Aircraft/aircraft.h> #include <Debug/fg_debug.h> #include <Include/fg_constants.h> -#include <Include/fg_types.h> #include <Misc/fgstream.hxx> #include <Main/options.hxx> #include <Main/views.hxx> @@ -63,7 +62,7 @@ static GLint stars[FG_STAR_LEVELS]; // Initialize the Star Management Subsystem int fgStarsInit( void ) { - fgPoint3d starlist[FG_MAX_STARS]; + Point3D starlist[FG_MAX_STARS]; // struct CelestialCoord pltPos; double right_ascension, declination, magnitude; double min_magnitude[FG_STAR_LEVELS]; @@ -97,13 +96,8 @@ int fgStarsInit( void ) { { in.eat_comments(); string name; - char c = 0; getline( in.stream(), name, ',' ); - in.stream() >> starlist[starcount].x >> c; - in.stream() >> starlist[starcount].y >> c; - // in.stream() >> starlist[starcount].x; in.get(c); - // in.stream() >> starlist[starcount].y; in.get(c); - in.stream() >> starlist[starcount].z; + in.stream() >> starlist[starcount]; ++starcount; } @@ -130,12 +124,12 @@ int fgStarsInit( void ) { count = 0; for ( j = 0; j < starcount; j++ ) { - magnitude = starlist[j].z; + magnitude = starlist[j].z(); // printf("magnitude = %.2f\n", magnitude); if ( magnitude < min_magnitude[i] ) { - right_ascension = starlist[j].x; - declination = starlist[j].y; + right_ascension = starlist[j].x(); + declination = starlist[j].y(); count++; @@ -258,6 +252,9 @@ void fgStarsRender( void ) { // $Log$ +// Revision 1.18 1998/10/16 00:52:20 curt +// Converted to Point3D class. +// // Revision 1.17 1998/09/24 15:36:19 curt // Converted to c++ style comments. // diff --git a/Main/GLUTmain.cxx b/Main/GLUTmain.cxx index ac622dda1..c610a8f5b 100644 --- a/Main/GLUTmain.cxx +++ b/Main/GLUTmain.cxx @@ -300,7 +300,7 @@ static void fgRenderFrame( void ) { // setup transformation for drawing astronomical objects xglPushMatrix(); // Translate to view position - xglTranslatef( v->view_pos.x, v->view_pos.y, v->view_pos.z ); + xglTranslatef( v->view_pos.x(), v->view_pos.y(), v->view_pos.z() ); // Rotate based on gst (sidereal time) // note: constant should be 15.041085, Curt thought it was 15 angle = t->gst * 15.041085; @@ -894,6 +894,9 @@ int main( int argc, char **argv ) { // $Log$ +// Revision 1.57 1998/10/16 00:54:00 curt +// Converted to Point3D class. +// // Revision 1.56 1998/10/02 12:46:47 curt // Added an "auto throttle" // diff --git a/Main/fg_init.cxx b/Main/fg_init.cxx index c908e8c49..8089d8225 100644 --- a/Main/fg_init.cxx +++ b/Main/fg_init.cxx @@ -56,6 +56,7 @@ #include <Joystick/joystick.h> #include <Math/fg_geodesy.h> #include <Math/fg_random.h> +#include <Math/point3d.hxx> #include <Math/polar3d.hxx> #include <Scenery/scenery.hxx> #include <Scenery/tilemgr.hxx> @@ -154,9 +155,9 @@ int fgInitGeneral( void ) { // convert a geodetic point lon(radians), lat(radians), elev(meter) to // a cartesian point -fgPoint3d geod_to_cart(double geod[3]) { - fgPoint3d cp; - fgPoint3d pp; +static Point3D geod_to_cart(double geod[3]) { + Point3D cp; + Point3D pp; double gc_lon, gc_lat, sl_radius; // printf("A geodetic point is (%.2f, %.2f, %.2f)\n", @@ -168,9 +169,7 @@ fgPoint3d geod_to_cart(double geod[3]) { // printf("A geocentric point is (%.2f, %.2f, %.2f)\n", gc_lon, // gc_lat, sl_radius+geod[2]); - pp.lon = gc_lon; - pp.lat = gc_lat; - pp.radius = sl_radius + geod[2]; + pp.setvals( gc_lon, gc_lat, sl_radius + geod[2] ); cp = fgPolarToCart3d(pp); // printf("A cart point is (%.8f, %.8f, %.8f)\n", cp.x, cp.y, cp.z); @@ -190,7 +189,7 @@ int fgInitSubsystems( void ) fgTIME *t; fgVIEW *v; double geod_pos[3]; - fgPoint3d abs_view_pos; + Point3D abs_view_pos; l = &cur_light_params; t = &cur_time_params; @@ -236,7 +235,7 @@ int fgInitSubsystems( void ) // Calculate ground elevation at starting point scenery.cur_elev = - fgTileMgrCurElev( FG_Longitude, FG_Latitude, &abs_view_pos ); + fgTileMgrCurElev( FG_Longitude, FG_Latitude, abs_view_pos ); FG_Runway_altitude = scenery.cur_elev * METER_TO_FEET; // Reset our altitude if we are below ground @@ -394,6 +393,9 @@ int fgInitSubsystems( void ) // $Log$ +// Revision 1.41 1998/10/16 00:54:01 curt +// Converted to Point3D class. +// // Revision 1.40 1998/10/02 12:46:49 curt // Added an "auto throttle" // diff --git a/Main/views.cxx b/Main/views.cxx index 8ec456d4f..4ea58af4c 100644 --- a/Main/views.cxx +++ b/Main/views.cxx @@ -31,6 +31,7 @@ #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> @@ -216,31 +217,31 @@ void fgVIEW::UpdateViewParams( void ) { 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 @@ -250,7 +251,7 @@ void fgVIEW::UpdateViewParams( void ) { // 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; @@ -261,44 +262,36 @@ void fgVIEW::UpdateViewMath( fgFLIGHT *f ) { 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; + p.setvals( + FG_Longitude, + FG_Lat_geocentric, + FG_Sea_level_radius * FEET_TO_METER ); - cur_zero_elev = fgPolarToCart3d(p); - - 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] @@ -396,7 +389,7 @@ void fgVIEW::UpdateViewMath( fgFLIGHT *f ) { 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 @@ -477,7 +470,7 @@ void fgVIEW::UpdateWorldToEye( fgFLIGHT *f ) { // 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); @@ -543,8 +536,7 @@ void fgVIEW::UpdateWorldToEye( fgFLIGHT *f ) { // Olson curt@me.umn.edu and Norman Vine nhv@yahoo.com with 'gentle // guidance' from Steve Baker sbaker@link.com int -fgVIEW::SphereClip( const fgPoint3d *cp, - const double radius ) +fgVIEW::SphereClip( const Point3D& cp, const double radius ) { double x1, y1; @@ -593,6 +585,9 @@ fgVIEW::~fgVIEW( void ) { // $Log$ +// 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. // diff --git a/Main/views.hxx b/Main/views.hxx index dfd1d5d74..e63ce32d1 100644 --- a/Main/views.hxx +++ b/Main/views.hxx @@ -32,9 +32,10 @@ #endif -#include <Include/fg_types.h> +// #include <Include/fg_types.h> #include <Flight/flight.h> #include <Math/mat3.h> +#include <Math/point3d.hxx> #include <Time/fg_time.hxx> #include <Time/light.hxx> @@ -91,14 +92,14 @@ public: int tris_rendered; // absolute view position - fgPoint3d abs_view_pos; + Point3D abs_view_pos; // view position translated to scenery.center - fgPoint3d view_pos; + Point3D view_pos; // cartesion coordinates of current lon/lat if at sea level // translated to scenery.center*/ - fgPoint3d cur_zero_elev; + Point3D cur_zero_elev; // vector in cartesian coordinates from current position to the // postion on the earth's surface the sun is directly over @@ -181,6 +182,9 @@ extern fgVIEW current_view; // $Log$ +// Revision 1.14 1998/10/16 00:54:04 curt +// Converted to Point3D class. +// // Revision 1.13 1998/09/08 15:04:36 curt // Optimizations by Norman Vine. // diff --git a/Objects/fragment.cxx b/Objects/fragment.cxx index 60f171a26..aff61494b 100644 --- a/Objects/fragment.cxx +++ b/Objects/fragment.cxx @@ -23,8 +23,9 @@ #include <Include/fg_constants.h> -#include <Include/fg_types.h> +// #include <Include/fg_types.h> #include <Math/mat3.h> +#include <Math/point3d.hxx> #include <Scenery/tile.hxx> #include "fragment.hxx" @@ -92,10 +93,10 @@ fgFRAGMENT & fgFRAGMENT::operator = ( const fgFRAGMENT & rhs ) // intersection found, 0 otherwise. If it intesects, result is the // point of intersection -int fgFRAGMENT::intersect( const fgPoint3d *end0, - const fgPoint3d *end1, +int fgFRAGMENT::intersect( const Point3D& end0, + const Point3D& end1, int side_flag, - fgPoint3d *result) const + Point3D& result) const { fgTILE *t; MAT3vec v1, v2, n, center; @@ -120,9 +121,9 @@ int fgFRAGMENT::intersect( const fgPoint3d *end0, // printf("."); // get face vertex coordinates - center[0] = t->center.x; - center[1] = t->center.y; - center[2] = t->center.z; + center[0] = t->center.x(); + center[1] = t->center.y(); + center[2] = t->center.z(); MAT3_ADD_VEC(p1, t->nodes[(*current).n1], center); MAT3_ADD_VEC(p2, t->nodes[(*current).n2], center); @@ -152,9 +153,9 @@ int fgFRAGMENT::intersect( const fgPoint3d *end0, // printf("p3(d) = %.2f\n", a * p3[0] + b * p3[1] + c * p3[2]); // calculate the line coefficients for the specified line - x0 = end0->x; x1 = end1->x; - y0 = end0->y; y1 = end1->y; - z0 = end0->z; z1 = end1->z; + x0 = end0.x(); x1 = end1.x(); + y0 = end0.y(); y1 = end1.y(); + z0 = end0.z(); z1 = end1.z(); if ( fabs(x1 - x0) > FG_EPSILON ) { a1 = 1.0 / (x1 - x0); @@ -201,9 +202,7 @@ int fgFRAGMENT::intersect( const fgPoint3d *end0, // everything is too close together to tell the difference // so the current intersection point should work as good // as any - result->x = x; - result->y = y; - result->z = z; + result.setvals(x, y, z); return(1); } side1 = FG_SIGN (t1 - t2); @@ -283,9 +282,7 @@ int fgFRAGMENT::intersect( const fgPoint3d *end0, } else { // all dimensions are really small so lets call it close // enough and return a successful match - result->x = x; - result->y = y; - result->z = z; + result.setvals(x, y, z); return(1); } @@ -317,9 +314,7 @@ int fgFRAGMENT::intersect( const fgPoint3d *end0, } // printf( "intersection point = %.2f %.2f %.2f\n", x, y, z); - result->x = x; - result->y = y; - result->z = z; + result.setvals(x, y, z); return(1); } @@ -329,6 +324,9 @@ int fgFRAGMENT::intersect( const fgPoint3d *end0, } // $Log$ +// Revision 1.5 1998/10/16 00:54:37 curt +// Converted to Point3D class. +// // Revision 1.4 1998/09/15 01:35:03 curt // cleaned up my fragment.num_faces hack :-) to use the STL (no need in // duplicating work.) diff --git a/Objects/fragment.hxx b/Objects/fragment.hxx index afac9b569..be8e05b05 100644 --- a/Objects/fragment.hxx +++ b/Objects/fragment.hxx @@ -49,9 +49,10 @@ extern "C" void *memset(void *, int, size_t); #include <vector> #include <Bucket/bucketutils.h> -#include <Include/fg_types.h> +// #include <Include/fg_types.h> #include "Include/fg_constants.h" #include <Math/mat3.h> +#include <Math/point3d.hxx> #ifdef NEEDNAMESPACESTD using namespace std; @@ -84,7 +85,7 @@ private: public: // culling data for this object fragment (fine grain culling) - fgPoint3d center; + Point3D center; double bounding_radius; // variable offset data for this object fragment for this frame @@ -128,10 +129,10 @@ public: // to see that end points are on opposite sides of face. Returns // 1 if it intersection found, 0 otherwise. If it intesects, // result is the point of intersection - int intersect( const fgPoint3d *end0, - const fgPoint3d *end1, + int intersect( const Point3D& end0, + const Point3D& end1, int side_flag, - fgPoint3d *result) const; + Point3D& result) const; // Constructors fgFRAGMENT () { /*faces.reserve(512);*/} @@ -166,9 +167,7 @@ operator == ( const fgFRAGMENT::fgFACE& lhs, inline bool operator == ( const fgFRAGMENT & lhs, const fgFRAGMENT & rhs ) { - return (( lhs.center.x - rhs.center.x ) < FG_EPSILON && - ( lhs.center.y - rhs.center.y ) < FG_EPSILON && - ( lhs.center.z - rhs.center.z ) < FG_EPSILON ); + return lhs.center == rhs.center; } @@ -176,6 +175,9 @@ operator == ( const fgFRAGMENT & lhs, const fgFRAGMENT & rhs ) { // $Log$ +// Revision 1.6 1998/10/16 00:54:38 curt +// Converted to Point3D class. +// // Revision 1.5 1998/09/15 01:35:04 curt // cleaned up my fragment.num_faces hack :-) to use the STL (no need in // duplicating work.) diff --git a/Objects/obj.cxx b/Objects/obj.cxx index 78f8066fb..2f997f9ce 100644 --- a/Objects/obj.cxx +++ b/Objects/obj.cxx @@ -54,6 +54,7 @@ using namespace std; #include <Main/options.hxx> #include <Math/mat3.h> #include <Math/fg_random.h> +#include <Math/point3d.hxx> #include <Math/polar3d.hxx> #include <Misc/stopwatch.hxx> #include <Misc/fgstream.hxx> @@ -88,25 +89,25 @@ static void calc_normal(double p1[3], double p2[3], // Calculate texture coordinates for a given point. -fgPoint3d calc_tex_coords(double *node, fgPoint3d *ref) { - fgPoint3d cp; - fgPoint3d pp; +Point3D calc_tex_coords(double *node, const Point3D& ref) { + Point3D cp; + Point3D pp; - cp.x = node[0] + ref->x; - cp.y = node[1] + ref->y; - cp.z = node[2] + ref->z; + cp.setvals( node[0] + ref.x(), + node[1] + ref.y(), + node[2] + ref.z() ); pp = fgCartToPolar3d(cp); - pp.lon = fmod(RAD_TO_DEG * FG_TEX_CONSTANT * pp.lon, 25.0); - pp.lat = fmod(RAD_TO_DEG * FG_TEX_CONSTANT * pp.lat, 25.0); + pp.setx( fmod(RAD_TO_DEG * FG_TEX_CONSTANT * pp.x(), 25.0) ); + pp.sety( fmod(RAD_TO_DEG * FG_TEX_CONSTANT * pp.y(), 25.0) ); - if ( pp.lon < 0.0 ) { - pp.lon += 25.0; + if ( pp.x() < 0.0 ) { + pp.setx( pp.x() + 25.0 ); } - if ( pp.lat < 0.0 ) { - pp.lat += 25.0; + if ( pp.y() < 0.0 ) { + pp.sety( pp.y() + 25.0 ); } return(pp); @@ -116,7 +117,7 @@ fgPoint3d calc_tex_coords(double *node, fgPoint3d *ref) { // Load a .obj file and build the GL fragment list int fgObjLoad( const string& path, fgTILE *t) { fgFRAGMENT fragment; - fgPoint3d pp; + Point3D pp; double approx_normal[3], normal[3], scale; // double x, y, z, xmax, xmin, ymax, ymin, zmax, zmin; // GLfloat sgenparams[] = { 1.0, 0.0, 0.0, 0.0 }; @@ -125,7 +126,7 @@ int fgObjLoad( const string& path, fgTILE *t) { int in_fragment, in_faces, vncount, n1, n2, n3, n4; int last1, last2, odd; double (*nodes)[3]; - fgPoint3d *center; + Point3D center; // printf("loading %s\n", path.c_str() ); @@ -150,7 +151,7 @@ int fgObjLoad( const string& path, fgTILE *t) { vncount = 1; t->bounding_radius = 0.0; nodes = t->nodes; - center = &t->center; + center = t->center; StopWatch stopwatch; stopwatch.start(); @@ -169,18 +170,18 @@ int fgObjLoad( const string& path, fgTILE *t) { if ( token == "gbs" ) { // reference point (center offset) - in.stream() >> t->center.x - >> t->center.y - >> t->center.z - >> t->bounding_radius; + in.stream() >> t->center >> t->bounding_radius; } else if ( token == "bs" ) { // reference point (center offset) + /* in.stream() >> fragment.center.x >> fragment.center.y >> fragment.center.z - >> fragment.bounding_radius; + */ + in.stream() >> fragment.center; + in.stream() >> fragment.bounding_radius; } else if ( token == "vn" ) { @@ -283,21 +284,21 @@ int fgObjLoad( const string& path, fgTILE *t) { MAT3_SCALE_VEC(normal, normals[n1], scale); xglNormal3dv(normal); pp = calc_tex_coords(nodes[n1], center); - xglTexCoord2f(pp.lon, pp.lat); + xglTexCoord2f(pp.lon(), pp.lat()); // xglVertex3d(t->nodes[n1][0],t->nodes[n1][1],t->nodes[n1][2]); xglVertex3dv(nodes[n1]); MAT3_SCALE_VEC(normal, normals[n2], scale); xglNormal3dv(normal); pp = calc_tex_coords(nodes[n2], center); - xglTexCoord2f(pp.lon, pp.lat); + xglTexCoord2f(pp.lon(), pp.lat()); //xglVertex3d(t->nodes[n2][0],t->nodes[n2][1],t->nodes[n2][2]); xglVertex3dv(nodes[n2]); MAT3_SCALE_VEC(normal, normals[n3], scale); xglNormal3dv(normal); pp = calc_tex_coords(nodes[n3], center); - xglTexCoord2f(pp.lon, pp.lat); + xglTexCoord2f(pp.lon(), pp.lat()); // xglVertex3d(t->nodes[n3][0],t->nodes[n3][1],t->nodes[n3][2]); xglVertex3dv(nodes[n3]); } else { @@ -314,17 +315,17 @@ int fgObjLoad( const string& path, fgTILE *t) { xglNormal3dv(normal); pp = calc_tex_coords(nodes[n1], center); - xglTexCoord2f(pp.lon, pp.lat); + xglTexCoord2f(pp.lon(), pp.lat()); // xglVertex3d(t->nodes[n1][0],t->nodes[n1][1],t->nodes[n1][2]); xglVertex3dv(nodes[n1]); pp = calc_tex_coords(nodes[n2], center); - xglTexCoord2f(pp.lon, pp.lat); + xglTexCoord2f(pp.lon(), pp.lat()); // xglVertex3d(t->nodes[n2][0],t->nodes[n2][1],t->nodes[n2][2]); xglVertex3dv(nodes[n2]); pp = calc_tex_coords(nodes[n3], center); - xglTexCoord2f(pp.lon, pp.lat); + xglTexCoord2f(pp.lon(), pp.lat()); // xglVertex3d(t->nodes[n3][0],t->nodes[n3][1],t->nodes[n3][2]); xglVertex3dv(nodes[n3]); } @@ -363,7 +364,7 @@ int fgObjLoad( const string& path, fgTILE *t) { } xglNormal3dv(normal); pp = calc_tex_coords(nodes[n4], center); - xglTexCoord2f(pp.lon, pp.lat); + xglTexCoord2f(pp.lon(), pp.lat()); // xglVertex3d(t->nodes[n4][0],t->nodes[n4][1],t->nodes[n4][2]); xglVertex3dv(nodes[n4]); @@ -388,21 +389,21 @@ int fgObjLoad( const string& path, fgTILE *t) { // xglNormal3d(normals[n1][0], normals[n1][1], normals[n1][2]); xglNormal3dv(normals[n1]); pp = calc_tex_coords(nodes[n1], center); - xglTexCoord2f(pp.lon, pp.lat); + xglTexCoord2f(pp.lon(), pp.lat()); // xglVertex3d(t->nodes[n1][0], t->nodes[n1][1], t->nodes[n1][2]); xglVertex3dv(nodes[n1]); // xglNormal3d(normals[n2][0], normals[n2][1], normals[n2][2]); xglNormal3dv(normals[n2]); pp = calc_tex_coords(nodes[n2], center); - xglTexCoord2f(pp.lon, pp.lat); + xglTexCoord2f(pp.lon(), pp.lat()); // xglVertex3d(t->nodes[n2][0], t->nodes[n2][1], t->nodes[n2][2]); xglVertex3dv(nodes[n2]); // xglNormal3d(normals[n3][0], normals[n3][1], normals[n3][2]); xglNormal3dv(normals[n3]); pp = calc_tex_coords(nodes[n3], center); - xglTexCoord2f(pp.lon, pp.lat); + xglTexCoord2f(pp.lon(), pp.lat()); // xglVertex3d(t->nodes[n3][0], t->nodes[n3][1], t->nodes[n3][2]); xglVertex3dv(nodes[n3]); // printf("some normals, texcoords, and vertices (tris)\n"); @@ -453,7 +454,7 @@ int fgObjLoad( const string& path, fgTILE *t) { xglNormal3dv(normal); pp = calc_tex_coords(nodes[n1], center); - xglTexCoord2f(pp.lon, pp.lat); + xglTexCoord2f(pp.lon(), pp.lat()); // xglVertex3d(t->nodes[n1][0], t->nodes[n1][1], t->nodes[n1][2]); xglVertex3dv(nodes[n1]); // printf("a normal, texcoord, and vertex (4th)\n"); @@ -488,7 +489,7 @@ int fgObjLoad( const string& path, fgTILE *t) { xglNormal3dv(normal); pp = calc_tex_coords(nodes[n2], center); - xglTexCoord2f(pp.lon, pp.lat); + xglTexCoord2f(pp.lon(), pp.lat()); // xglVertex3d(t->nodes[n2][0],t->nodes[n2][1],t->nodes[n2][2]); xglVertex3dv(nodes[n2]); // printf("a normal, texcoord, and vertex (4th)\n"); @@ -546,6 +547,9 @@ int fgObjLoad( const string& path, fgTILE *t) { // $Log$ +// Revision 1.5 1998/10/16 00:54:39 curt +// Converted to Point3D class. +// // Revision 1.4 1998/09/15 01:35:07 curt // cleaned up my fragment.num_faces hack :-) to use the STL (no need in // duplicating work.) diff --git a/Objects/obj.hxx b/Objects/obj.hxx index c999a22ea..c07dd1c26 100644 --- a/Objects/obj.hxx +++ b/Objects/obj.hxx @@ -43,8 +43,6 @@ #include <string> -#include <Include/fg_types.h> - #include <Scenery/tile.hxx> @@ -56,6 +54,9 @@ int fgObjLoad(const string& path, fgTILE *tile); // $Log$ +// Revision 1.3 1998/10/16 00:54:41 curt +// Converted to Point3D class. +// // Revision 1.2 1998/09/01 19:03:10 curt // Changes contributed by Bernie Bright <bbright@c031.aone.net.au> // - The new classes in libmisc.tgz define a stream interface into zlib. diff --git a/Scenery/scenery.hxx b/Scenery/scenery.hxx index 0aa0e552e..7e069e950 100644 --- a/Scenery/scenery.hxx +++ b/Scenery/scenery.hxx @@ -33,16 +33,17 @@ #endif -#include <Include/fg_types.h> +// #include <Include/fg_types.h> +#include <Math/point3d.hxx> /* Define a structure containing global scenery parameters */ struct fgSCENERY { /* center of current scenery chunk */ - fgPoint3d center; + Point3D center; /* next center of current scenery chunk */ - fgPoint3d next_center; + Point3D next_center; /* angle of sun relative to current local horizontal */ double sun_angle; @@ -72,14 +73,17 @@ void fgSceneryRender( void ); /* $Log$ -/* Revision 1.4 1998/07/12 03:18:28 curt -/* Added ground collision detection. This involved: -/* - saving the entire vertex list for each tile with the tile records. -/* - saving the face list for each fragment with the fragment records. -/* - code to intersect the current vertical line with the proper face in -/* an efficient manner as possible. -/* Fixed a bug where the tiles weren't being shifted to "near" (0,0,0) +/* Revision 1.5 1998/10/16 00:55:44 curt +/* Converted to Point3D class. /* + * Revision 1.4 1998/07/12 03:18:28 curt + * Added ground collision detection. This involved: + * - saving the entire vertex list for each tile with the tile records. + * - saving the face list for each fragment with the fragment records. + * - code to intersect the current vertical line with the proper face in + * an efficient manner as possible. + * Fixed a bug where the tiles weren't being shifted to "near" (0,0,0) + * * Revision 1.3 1998/07/08 14:47:22 curt * Fix GL_MODULATE vs. GL_DECAL problem introduced by splash screen. * polare3d.h renamed to polar3d.hxx diff --git a/Scenery/tile.cxx b/Scenery/tile.cxx index 1837a13b7..2b55082f8 100644 --- a/Scenery/tile.cxx +++ b/Scenery/tile.cxx @@ -23,7 +23,6 @@ #include <Include/fg_constants.h> -#include <Include/fg_types.h> #include <Math/mat3.h> #include "tile.hxx" @@ -161,8 +160,8 @@ static double fg_max3 (double a, double b, double c) // intersection found, 0 otherwise. If it intesects, result is the // point of intersection -int fgFRAGMENT::intersect( fgPoint3d *end0, fgPoint3d *end1, int side_flag, - fgPoint3d *result) +int fgFRAGMENT::intersect( const Point3D& end0, Point3D& end1, int side_flag, + Point3D& result) { fgTILE *t; fgFACE face; @@ -225,9 +224,9 @@ int fgFRAGMENT::intersect( fgPoint3d *end0, fgPoint3d *end1, int side_flag, // printf("p3(d) = %.2f\n", a * p3[0] + b * p3[1] + c * p3[2]); // calculate the line coefficients for the specified line - x0 = end0->x; x1 = end1->x; - y0 = end0->y; y1 = end1->y; - z0 = end0->z; z1 = end1->z; + x0 = end0.x(); x1 = end1.x(); + y0 = end0.y(); y1 = end1.y(); + z0 = end0.z(); z1 = end1.z(); if ( fabs(x1 - x0) > FG_EPSILON ) { a1 = 1.0 / (x1 - x0); @@ -449,6 +448,9 @@ fgTILE::~fgTILE ( void ) { // $Log$ +// Revision 1.12 1998/10/16 00:55:45 curt +// Converted to Point3D class. +// // Revision 1.11 1998/09/02 14:37:08 curt // Use erase() instead of while ( size() ) pop_front(); // diff --git a/Scenery/tile.hxx b/Scenery/tile.hxx index a070001b5..d0bd74281 100644 --- a/Scenery/tile.hxx +++ b/Scenery/tile.hxx @@ -49,8 +49,9 @@ extern "C" void *memset(void *, int, size_t); #include <list> // STL list #include <Bucket/bucketutils.h> -#include <Include/fg_types.h> +// #include <Include/fg_types.h> #include <Math/mat3.h> +#include <Math/point3d.hxx> #include <Objects/fragment.hxx> #ifdef NEEDNAMESPACESTD @@ -68,9 +69,9 @@ public: int ncount; // culling data for whole tile (course grain culling) - fgPoint3d center; + Point3D center; double bounding_radius; - fgPoint3d offset; + Point3D offset; GLdouble model_view[16]; // this tile's official location in the world @@ -89,11 +90,9 @@ public: // Calculate this tile's offset void - fgTILE::SetOffset( fgPoint3d *off) + fgTILE::SetOffset( const Point3D& off) { - offset.x = center.x - off->x; - offset.y = center.y - off->y; - offset.z = center.z - off->z; + offset = center - off; } @@ -109,12 +108,12 @@ public: #endif // This is equivalent to doing a glTranslatef(x, y, z); - model_view[12] += (model_view[0]*offset.x + model_view[4]*offset.y + - model_view[8]*offset.z); - model_view[13] += (model_view[1]*offset.x + model_view[5]*offset.y + - model_view[9]*offset.z); - model_view[14] += (model_view[2]*offset.x + model_view[6]*offset.y + - model_view[10]*offset.z); + model_view[12] += (model_view[0]*offset.x() + model_view[4]*offset.y() + + model_view[8]*offset.z()); + model_view[13] += (model_view[1]*offset.x() + model_view[5]*offset.y() + + model_view[9]*offset.z()); + model_view[14] += (model_view[2]*offset.x() + model_view[6]*offset.y() + + model_view[10]*offset.z() ); // m[15] += (m[3]*x + m[7]*y + m[11]*z); // m[3] m7[] m[11] are 0.0 see LookAt() in views.cxx // so m[15] is unchanged @@ -127,6 +126,9 @@ public: // $Log$ +// Revision 1.20 1998/10/16 00:55:46 curt +// Converted to Point3D class. +// // Revision 1.19 1998/09/17 18:36:17 curt // Tweaks and optimizations by Norman Vine. // diff --git a/Scenery/tilecache.cxx b/Scenery/tilecache.cxx index e0d38c8b7..a5e2a95da 100644 --- a/Scenery/tilecache.cxx +++ b/Scenery/tilecache.cxx @@ -172,8 +172,9 @@ int fgTILECACHE::next_avail( void ) { fgVIEW *v; + Point3D delta; int i; - float dx, dy, dz, max, med, min, tmp; + float max, med, min, tmp; float dist, max_dist; int max_index; @@ -189,17 +190,16 @@ fgTILECACHE::next_avail( void ) // calculate approximate distance from view point fgPrintf( FG_TERRAIN, FG_DEBUG, "DIST Abs view pos = %.4f, %.4f, %.4f\n", - v->abs_view_pos.x, v->abs_view_pos.y, v->abs_view_pos.z ); + v->abs_view_pos.x(), v->abs_view_pos.y(), + v->abs_view_pos.z() ); fgPrintf( FG_TERRAIN, FG_DEBUG, " ref point = %.4f, %.4f, %.4f\n", - tile_cache[i].center.x, tile_cache[i].center.y, - tile_cache[i].center.z); + tile_cache[i].center.x(), tile_cache[i].center.y(), + tile_cache[i].center.z()); - dx = fabs(tile_cache[i].center.x - v->abs_view_pos.x); - dy = fabs(tile_cache[i].center.y - v->abs_view_pos.y); - dz = fabs(tile_cache[i].center.z - v->abs_view_pos.z); + delta = tile_cache[i].center - v->abs_view_pos; - max = dx; med = dy; min = dz; + max = delta.x(); med = delta.y(); min = delta.z(); if ( max < med ) { tmp = max; max = med; med = tmp; } @@ -232,6 +232,9 @@ fgTILECACHE::~fgTILECACHE( void ) { // $Log$ +// Revision 1.17 1998/10/16 00:55:48 curt +// Converted to Point3D class. +// // Revision 1.16 1998/09/14 12:45:23 curt // minor tweaks. // diff --git a/Scenery/tilecache.hxx b/Scenery/tilecache.hxx index 62c863d75..473ed1b51 100644 --- a/Scenery/tilecache.hxx +++ b/Scenery/tilecache.hxx @@ -43,7 +43,8 @@ #include <XGL/xgl.h> #include <Bucket/bucketutils.h> -#include <Include/fg_types.h> +// #include <Include/fg_types.h> +#include <Math/point3d.hxx> #include "tile.hxx" @@ -108,6 +109,9 @@ extern fgTILECACHE global_tile_cache; // $Log$ +// Revision 1.12 1998/10/16 00:55:49 curt +// Converted to Point3D class. +// // Revision 1.11 1998/09/14 12:45:25 curt // minor tweaks. // diff --git a/Scenery/tilemgr.cxx b/Scenery/tilemgr.cxx index f0906324c..b9a9ee809 100644 --- a/Scenery/tilemgr.cxx +++ b/Scenery/tilemgr.cxx @@ -38,11 +38,12 @@ #include <Bucket/bucketutils.h> #include <Debug/fg_debug.h> #include <Include/fg_constants.h> -#include <Include/fg_types.h> +// #include <Include/fg_types.h> #include <Main/options.hxx> #include <Main/views.hxx> #include <Math/fg_geodesy.h> #include <Math/mat3.h> +#include <Math/point3d.hxx> #include <Math/polar3d.hxx> #include <Math/vector.hxx> #include <Objects/material.hxx> @@ -231,14 +232,14 @@ int fgTileMgrUpdate( void ) { // Calculate shortest distance from point to line -static double point_line_dist_squared( fgPoint3d *tc, fgPoint3d *vp, +static double point_line_dist_squared( const Point3D& tc, const Point3D& vp, MAT3vec d ) { MAT3vec p, p0; double dist; - p[0] = tc->x; p[1] = tc->y; p[2] = tc->z; - p0[0] = vp->x; p0[1] = vp->y; p0[2] = vp->z; + p[0] = tc.x(); p[1] = tc.y(); p[2] = tc.z(); + p0[0] = vp.x(); p0[1] = vp.y(); p0[2] = vp.z(); dist = fgPointLineSquared(p, p0, d); @@ -249,7 +250,7 @@ static double point_line_dist_squared( fgPoint3d *tc, fgPoint3d *vp, // Calculate if point/radius is inside view frustum -static int viewable( fgPoint3d *cp, double radius ) { +static int viewable( const Point3D& cp, double radius ) { int viewable = 1; // start by assuming it's viewable double x1, y1; @@ -261,9 +262,9 @@ static int viewable( fgPoint3d *cp, double radius ) { double *mat; double x, y, z; - x = cp->x; - y = cp->y; - z = cp->z; + x = cp.x(); + y = cp.y(); + z = cp.z(); mat = (double *)(current_view.WORLD_TO_EYE); @@ -376,16 +377,16 @@ static int viewable( fgPoint3d *cp, double radius ) { // the compiler should inline this for us static int -inrange( const double radius, const fgPoint3d *center, const fgPoint3d *vp, +inrange( const double radius, const Point3D& center, const Point3D& vp, const MAT3vec up) { MAT3vec u, u1, v; // double tmp; // u = p - p0 - u[0] = center->x - vp->x; - u[1] = center->y - vp->y; - u[2] = center->z - vp->z; + u[0] = center.x() - vp.x(); + u[1] = center.y() - vp.y(); + u[2] = center.z() - vp.z(); // calculate the projection, u1, of u along d. // u1 = ( dot_prod(u, d) / dot_prod(d, d) ) * d; @@ -405,14 +406,14 @@ inrange( const double radius, const fgPoint3d *center, const fgPoint3d *vp, // render the scene, but we'd also like to be able to do this // explicitely. lat & lon are in radians. abs_view_pos in meters. // Returns result in meters. -double fgTileMgrCurElev( double lon, double lat, fgPoint3d *abs_view_pos ) { +double fgTileMgrCurElev( double lon, double lat, const Point3D& abs_view_pos ) { fgTILECACHE *c; fgTILE *t; // fgVIEW *v; fgFRAGMENT *frag_ptr; fgBUCKET p; - fgPoint3d earth_center, result; - fgPoint3d pp; + Point3D earth_center, result; + Point3D pp; MAT3vec local_up; list < fgFRAGMENT > :: iterator current; list < fgFRAGMENT > :: iterator last; @@ -423,22 +424,18 @@ double fgTileMgrCurElev( double lon, double lat, fgPoint3d *abs_view_pos ) { c = &global_tile_cache; // v = ¤t_view; - local_up[0] = abs_view_pos->x; - local_up[1] = abs_view_pos->y; - local_up[2] = abs_view_pos->z; + local_up[0] = abs_view_pos.x(); + local_up[1] = abs_view_pos.y(); + local_up[2] = abs_view_pos.z(); // Find current translation offset fgBucketFind(lon * RAD_TO_DEG, lat * RAD_TO_DEG, &p); index = c->exists(&p); t = c->get_tile(index); - scenery.next_center.x = t->center.x; - scenery.next_center.y = t->center.y; - scenery.next_center.z = t->center.z; + scenery.next_center = t->center; - earth_center.x = 0.0; - earth_center.y = 0.0; - earth_center.z = 0.0; + earth_center.setvals(0.0, 0.0, 0.0); fgPrintf( FG_TERRAIN, FG_DEBUG, "Pos = (%.2f, %.2f) Current bucket = %d %d %d %d Index = %ld\n", @@ -458,8 +455,7 @@ double fgTileMgrCurElev( double lon, double lat, fgPoint3d *abs_view_pos ) { point_line_dist_squared(&(t->offset), &(v->view_pos), v->local_up), t->bounding_radius); */ - dist = point_line_dist_squared( &(t->center), abs_view_pos, - local_up ); + dist = point_line_dist_squared( t->center, abs_view_pos, local_up ); if ( dist < FG_SQUARE(t->bounding_radius) ) { // traverse fragment list for tile @@ -473,15 +469,16 @@ double fgTileMgrCurElev( double lon, double lat, fgPoint3d *abs_view_pos ) { &abs_view_pos), local_up), frag_ptr->bounding_radius); */ - dist = point_line_dist_squared( &(frag_ptr->center), - abs_view_pos, local_up); + dist = point_line_dist_squared( frag_ptr->center, + abs_view_pos, + local_up); if ( dist <= FG_SQUARE(frag_ptr->bounding_radius) ) { if ( frag_ptr->intersect( abs_view_pos, - &earth_center, 0, &result ) ) { + earth_center, 0, result ) ) { // compute geocentric coordinates of tile center pp = fgCartToPolar3d(result); // convert to geodetic coordinates - fgGeocToGeod(pp.lat, pp.radius, &lat_geod, + fgGeocToGeod(pp.lat(), pp.radius(), &lat_geod, &alt, &sea_level_r); // printf("alt = %.2f\n", alt); // exit since we found an intersection @@ -507,9 +504,11 @@ update_tile_geometry( fgTILE *t, GLdouble *MODEL_VIEW) double x, y, z; // calculate tile offset - x = (t->offset.x = t->center.x - scenery.center.x); - y = (t->offset.y = t->center.y - scenery.center.y); - z = (t->offset.z = t->center.z - scenery.center.z); + t->offset = t->center - scenery.center; + + x = t->offset.x(); + y = t->offset.y(); + z = t->offset.z(); m = t->model_view; @@ -532,7 +531,7 @@ void fgTileMgrRender( void ) { fgTILECACHE *c; fgTILE *t; fgVIEW *v; - fgPoint3d frag_offset; + Point3D frag_offset; fgFRAGMENT *frag_ptr; fgMATERIAL *mtl_ptr; list < fgFRAGMENT > :: iterator current; @@ -550,7 +549,7 @@ void fgTileMgrRender( void ) { tile_diameter = current_options.get_tile_diameter(); scenery.cur_elev = fgTileMgrCurElev( FG_Longitude, FG_Latitude, - &(v->abs_view_pos) ); + v->abs_view_pos ); // initialize the transient per-material fragment lists material_mgr.init_transient_material_lists(); @@ -563,10 +562,10 @@ void fgTileMgrRender( void ) { t = c->get_tile(index); // calculate tile offset - t->SetOffset( &(scenery.center) ); + t->SetOffset( scenery.center ); // Course (tile based) culling - if ( viewable(&(t->offset), t->bounding_radius) ) { + if ( viewable(t->offset, t->bounding_radius) ) { // at least a portion of this tile could be viewable // Calculate the model_view transformation matrix for this tile @@ -585,11 +584,9 @@ void fgTileMgrRender( void ) { if ( frag_ptr->display_list >= 0 ) { // Fine (fragment based) culling - frag_offset.x = frag_ptr->center.x - scenery.center.x; - frag_offset.y = frag_ptr->center.y - scenery.center.y; - frag_offset.z = frag_ptr->center.z - scenery.center.z; + frag_offset = frag_ptr->center - scenery.center; - if ( viewable(&frag_offset, frag_ptr->bounding_radius*2) ) { + if ( viewable(frag_offset, frag_ptr->bounding_radius*2) ) { // add to transient per-material property fragment list // frag_ptr->tile_offset.x = t->offset.x; // frag_ptr->tile_offset.y = t->offset.y; @@ -637,6 +634,9 @@ void fgTileMgrRender( void ) { // $Log$ +// Revision 1.39 1998/10/16 00:55:50 curt +// Converted to Point3D class. +// // Revision 1.38 1998/09/17 18:36:18 curt // Tweaks and optimizations by Norman Vine. // diff --git a/Scenery/tilemgr.hxx b/Scenery/tilemgr.hxx index 62efaf414..e024bea24 100644 --- a/Scenery/tilemgr.hxx +++ b/Scenery/tilemgr.hxx @@ -44,7 +44,7 @@ int fgTileMgrUpdate( void ); // render the scene, but we'd also like to be able to do this // explicitely. lat & lon are in radians. abs_view_pos in meters. // Returns result in meters. -double fgTileMgrCurElev( double lon, double lat, fgPoint3d *abs_view_pos ); +double fgTileMgrCurElev( double lon, double lat, const Point3D& abs_view_pos ); // Render the local tiles --- hack, hack, hack @@ -55,6 +55,9 @@ void fgTileMgrRender( void ); // $Log$ +// Revision 1.5 1998/10/16 00:55:52 curt +// Converted to Point3D class. +// // Revision 1.4 1998/09/09 20:58:11 curt // Tweaks to loop constructs with STL usage. // diff --git a/Time/event.hxx b/Time/event.hxx index 1d7fb61c5..53915f9aa 100644 --- a/Time/event.hxx +++ b/Time/event.hxx @@ -43,7 +43,7 @@ extern "C" void *memset(void *, int, size_t); #include "Include/fg_stl_config.h" -#ifdef _FG_NEED_AUTO_PTR +#ifdef FG_NEED_AUTO_PTR # include "Include/auto_ptr.hxx" #else # include <memory> @@ -169,6 +169,9 @@ extern fgEVENT_MGR global_events; // $Log$ +// Revision 1.12 1998/10/16 00:56:08 curt +// Converted to Point3D class. +// // Revision 1.11 1998/09/15 02:09:30 curt // Include/fg_callback.hxx // Moved code inline to stop g++ 2.7 from complaining. diff --git a/Time/fg_time.hxx b/Time/fg_time.hxx index 1c282c743..d1ba002c2 100644 --- a/Time/fg_time.hxx +++ b/Time/fg_time.hxx @@ -43,7 +43,6 @@ #include <GL/glut.h> #include <time.h> -#include <Include/fg_types.h> #include <Flight/flight.h> @@ -118,6 +117,9 @@ void fgTimeUpdate(fgFLIGHT *f, fgTIME *t); // $Log$ +// Revision 1.7 1998/10/16 00:56:09 curt +// Converted to Point3D class. +// // Revision 1.6 1998/07/27 18:42:22 curt // Added a pause option. // diff --git a/Time/light.hxx b/Time/light.hxx index ac3d330a2..1d058edf1 100644 --- a/Time/light.hxx +++ b/Time/light.hxx @@ -41,8 +41,9 @@ #include <GL/glut.h> #include <XGL/xgl.h> -#include <Include/fg_types.h> +// #include <Include/fg_types.h> #include <Math/interpolater.hxx> +#include <Math/point3d.hxx> // Define a structure containing the global lighting parameters @@ -62,7 +63,7 @@ public: double sun_lon, sun_gc_lat; // in cartesian coordiantes - fgPoint3d fg_sunpos; + Point3D fg_sunpos; // (in view coordinates) GLfloat sun_vec[4]; @@ -122,6 +123,9 @@ extern fgLIGHT cur_light_params; // $Log$ +// Revision 1.8 1998/10/16 00:56:10 curt +// Converted to Point3D class. +// // Revision 1.7 1998/08/29 13:11:33 curt // Bernie Bright writes: // I've created some new classes to enable pointers-to-functions and diff --git a/Time/sunpos.cxx b/Time/sunpos.cxx index af40285cd..0157a9321 100644 --- a/Time/sunpos.cxx +++ b/Time/sunpos.cxx @@ -49,6 +49,7 @@ #include <Main/views.hxx> #include <Math/fg_geodesy.h> #include <Math/mat3.h> +#include <Math/point3d.hxx> #include <Math/polar3d.hxx> #include <Math/vector.hxx> #include <Scenery/scenery.hxx> @@ -328,7 +329,7 @@ void fgUpdateSunPos( void ) { fgTIME *t; fgVIEW *v; MAT3vec nup, nsun, v0; - fgPoint3d p; + Point3D p, rel_sunpos; double dot, east_dot; double sun_gd_lat, sl_radius; double ntmp; @@ -345,9 +346,7 @@ void fgUpdateSunPos( void ) { fgGeodToGeoc(sun_gd_lat, 0.0, &sl_radius, &l->sun_gc_lat); - p.lon = l->sun_lon; - p.lat = l->sun_gc_lat; - p.radius = sl_radius; + p.setvals( l->sun_lon, l->sun_gc_lat, sl_radius ); l->fg_sunpos = fgPolarToCart3d(p); printf( " t->cur_time = %ld\n", t->cur_time); @@ -355,9 +354,9 @@ void fgUpdateSunPos( void ) { sun_gd_lat, l->sun_gc_lat); // I think this will work better for generating the sun light vector - l->sun_vec[0] = l->fg_sunpos.x; - l->sun_vec[1] = l->fg_sunpos.y; - l->sun_vec[2] = l->fg_sunpos.z; + l->sun_vec[0] = l->fg_sunpos.x(); + l->sun_vec[1] = l->fg_sunpos.y(); + l->sun_vec[2] = l->fg_sunpos.z(); MAT3_NORMALIZE_VEC(l->sun_vec, ntmp); MAT3_SCALE_VEC(l->sun_vec_inv, l->sun_vec, -1.0); @@ -370,9 +369,9 @@ void fgUpdateSunPos( void ) { // calculate the sun's relative angle to local up MAT3_COPY_VEC(nup, v->local_up); - nsun[0] = l->fg_sunpos.x; - nsun[1] = l->fg_sunpos.y; - nsun[2] = l->fg_sunpos.z; + nsun[0] = l->fg_sunpos.x(); + nsun[1] = l->fg_sunpos.y(); + nsun[2] = l->fg_sunpos.z(); MAT3_NORMALIZE_VEC(nup, ntmp); MAT3_NORMALIZE_VEC(nsun, ntmp); @@ -381,14 +380,15 @@ void fgUpdateSunPos( void ) { // l->sun_angle); // calculate vector to sun's position on the earth's surface - v->to_sun[0] = l->fg_sunpos.x - (v->view_pos.x + scenery.center.x); - v->to_sun[1] = l->fg_sunpos.y - (v->view_pos.y + scenery.center.y); - v->to_sun[2] = l->fg_sunpos.z - (v->view_pos.z + scenery.center.z); + rel_sunpos = l->fg_sunpos - (v->view_pos + scenery.center); + v->to_sun[0] = rel_sunpos.x(); + v->to_sun[1] = rel_sunpos.y(); + v->to_sun[2] = rel_sunpos.z(); // printf( "Vector to sun = %.2f %.2f %.2f\n", // v->to_sun[0], v->to_sun[1], v->to_sun[2]); // make a vector to the current view position - MAT3_SET_VEC(v0, v->view_pos.x, v->view_pos.y, v->view_pos.z); + MAT3_SET_VEC(v0, v->view_pos.x(), v->view_pos.y(), v->view_pos.z()); // Given a vector from the view position to the point on the // earth's surface the sun is directly over, map into onto the @@ -423,6 +423,9 @@ void fgUpdateSunPos( void ) { // $Log$ +// Revision 1.13 1998/10/16 00:56:12 curt +// Converted to Point3D class. +// // Revision 1.12 1998/09/15 04:27:50 curt // Changes for new astro code. // diff --git a/Time/sunpos.hxx b/Time/sunpos.hxx index fec268658..878dde130 100644 --- a/Time/sunpos.hxx +++ b/Time/sunpos.hxx @@ -47,8 +47,6 @@ #include <time.h> -#include <Include/fg_types.h> - /* update the cur_time_params structure with the current sun position */ void fgUpdateSunPos( void );