From: curt Date: Wed, 20 Oct 1999 22:19:07 +0000 (+0000) Subject: Updates by Christian Mayer. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=275154500802cc9405b5905b3b055e5c4a17b33f;p=flightgear.git Updates by Christian Mayer. --- diff --git a/src/WeatherCM/FGAirPressureItem.cpp b/src/WeatherCM/FGAirPressureItem.cpp index 916f36f45..7f981e0bd 100644 --- a/src/WeatherCM/FGAirPressureItem.cpp +++ b/src/WeatherCM/FGAirPressureItem.cpp @@ -5,7 +5,7 @@ Date started: 28.05.99 Called by: FGMicroWeather - ---------- Copyright (C) 1999 Christian Mayer (vader@t-online.de) ---------- + -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) -------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -35,6 +35,8 @@ HISTORY 20.06.1999 Christian Mayer added lots of consts 11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's suggestion +19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D + and lots of wee code cleaning *****************************************************************************/ /****************************************************************************/ diff --git a/src/WeatherCM/FGAirPressureItem.h b/src/WeatherCM/FGAirPressureItem.h index 9040b5705..3b4d422f0 100644 --- a/src/WeatherCM/FGAirPressureItem.h +++ b/src/WeatherCM/FGAirPressureItem.h @@ -4,7 +4,7 @@ Author: Christian Mayer Date started: 28.05.99 - ---------- Copyright (C) 1999 Christian Mayer (vader@t-online.de) ---------- + -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) -------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -35,6 +35,8 @@ HISTORY 20.06.1999 Christian Mayer added lots of consts 11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's suggestion +19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D + and lots of wee code cleaning *****************************************************************************/ /****************************************************************************/ @@ -46,8 +48,9 @@ HISTORY /****************************************************************************/ /* INCLUDES */ /****************************************************************************/ -#include "FGWeatherDefs.h" #include + +#include "FGWeatherDefs.h" /****************************************************************************/ /* DEFINES */ @@ -64,31 +67,30 @@ FGAirPressureItem operator-(const FGAirPressureItem& arg); class FGAirPressureItem { private: - WeatherPrecition value; + WeatherPrecision value; + protected: public: - FGAirPressureItem(const WeatherPrecition& v) {value = v;} - FGAirPressureItem() {value = FG_WEATHER_DEFAULT_AIRPRESSURE;} - - //WeatherPrecition getValue(WeatherPrecition alt) { return value * pow(1.0 - 0.0065*alt/288.0, 5.255); }; + FGAirPressureItem(const WeatherPrecision v) {value = v;} + FGAirPressureItem() {value = FG_WEATHER_DEFAULT_AIRPRESSURE;} - WeatherPrecition getValue(const WeatherPrecition& alt) const + WeatherPrecision getValue(const WeatherPrecision& alt) const { - return (WeatherPrecition)((value / 101325.0) * + return (WeatherPrecision)((value / 101325.0) * ( 1.01325e5 + alt * (-1.19459535223623e1 + alt * (5.50461110007561e-4 + alt * (-1.13574703113648e-8 + alt * 8.61601726143988e-14))) )); }; - FGAirPressureItem& operator*=(const WeatherPrecition& arg); + FGAirPressureItem& operator*=(const WeatherPrecision arg); FGAirPressureItem& operator+=(const FGAirPressureItem& arg); FGAirPressureItem& operator-=(const FGAirPressureItem& arg); friend FGAirPressureItem operator-(const FGAirPressureItem& arg); }; -inline FGAirPressureItem& FGAirPressureItem::operator*= (const WeatherPrecition& arg) +inline FGAirPressureItem& FGAirPressureItem::operator*= (const WeatherPrecision arg) { value *= arg; return *this; diff --git a/src/WeatherCM/FGCloud.h b/src/WeatherCM/FGCloud.h index 29f39b36c..2995e0892 100644 --- a/src/WeatherCM/FGCloud.h +++ b/src/WeatherCM/FGCloud.h @@ -4,7 +4,7 @@ Author: Christian Mayer Date started: 28.05.99 - ---------- Copyright (C) 1999 Christian Mayer (vader@t-online.de) ---------- + -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) -------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -34,6 +34,8 @@ HISTORY 20.06.1999 Christian Mayer added lots of consts 11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's suggestion +19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D + and lots of wee code cleaning *****************************************************************************/ /****************************************************************************/ diff --git a/src/WeatherCM/FGCloudItem.cpp b/src/WeatherCM/FGCloudItem.cpp index 7626fd4a4..d3d74e915 100644 --- a/src/WeatherCM/FGCloudItem.cpp +++ b/src/WeatherCM/FGCloudItem.cpp @@ -5,7 +5,7 @@ Date started: 28.05.99 Called by: FGMicroWeather - ---------- Copyright (C) 1999 Christian Mayer (vader@t-online.de) ---------- + -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) -------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -36,6 +36,8 @@ HISTORY 09.10.1999 Christian Mayer changed CloudItem on Durks request 11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's suggestion +19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D + and lots of wee code cleaning *****************************************************************************/ /****************************************************************************/ diff --git a/src/WeatherCM/FGCloudItem.h b/src/WeatherCM/FGCloudItem.h index 8ef3c1a9b..652ddccd7 100644 --- a/src/WeatherCM/FGCloudItem.h +++ b/src/WeatherCM/FGCloudItem.h @@ -4,7 +4,7 @@ Author: Christian Mayer Date started: 28.05.99 - ---------- Copyright (C) 1999 Christian Mayer (vader@t-online.de) ---------- + -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) -------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -25,7 +25,7 @@ FUNCTIONAL DESCRIPTION ------------------------------------------------------------------------------ -Air pressure item that is stored in the micro weather class +Cloud item that is stored in the micro weather class HISTORY ------------------------------------------------------------------------------ @@ -35,6 +35,8 @@ HISTORY 09.10.1999 Christian Mayer changed CloudItem on Durks request 11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's suggestion +19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D + and lots of wee code cleaning *****************************************************************************/ /****************************************************************************/ @@ -58,17 +60,17 @@ HISTORY class FGCloudItem { private: - WeatherPrecition thickness; - WeatherPrecition density; + WeatherPrecision thickness; + WeatherPrecision density; protected: public: - FGCloudItem(const WeatherPrecition& t, const WeatherPrecition& d) {thickness = t; density = d;} - FGCloudItem() {thickness = 0.0; density = 0.0;} + FGCloudItem(const WeatherPrecision t, const WeatherPrecision d) {thickness = t; density = d;} + FGCloudItem() {thickness = 0.0; density = 0.0;} - WeatherPrecition getThickness(void) const { return thickness; } - WeatherPrecition getDensity (void) const { return density; } + WeatherPrecision getThickness(void) const { return thickness; } + WeatherPrecision getDensity (void) const { return density; } }; /****************************************************************************/ diff --git a/src/WeatherCM/FGGlobalWeatherDatabase.cpp b/src/WeatherCM/FGGlobalWeatherDatabase.cpp index 7818e6adf..10b9b984a 100644 --- a/src/WeatherCM/FGGlobalWeatherDatabase.cpp +++ b/src/WeatherCM/FGGlobalWeatherDatabase.cpp @@ -5,7 +5,7 @@ Date started: 28.05.99 Called by: main program - ---------- Copyright (C) 1999 Christian Mayer (vader@t-online.de) ---------- + -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) -------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -37,6 +37,8 @@ HISTORY 20.06.1999 Christian Mayer added lots of consts 11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's suggestion +19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D + and lots of wee code cleaning *****************************************************************************/ /****************************************************************************/ @@ -60,23 +62,28 @@ HISTORY /* | \ \ If p isn't in the triangle the algoritm */ /* x1------q------x2 extrapolates it's value */ /****************************************************************************/ -template -V triangle_interpolate(const P& x1, const V& v1, const P& x2, const V& v2, const P& x3, const V& v3, const P& p) +template +V triangle_interpolate(const sgVec2& x1, const V& v1, const sgVec2& x2, const V& v2, const sgVec2& x3, const V& v3, const sgVec2& p) { - P q; + sgVec2 q; V q_value; - q = x1 + (x2 - x1)*( ((x3-x1).x()*(x1-x2).y() - (x1-x2).x()*(x3-x1).y())/((p-x3).x()*(x2-x1).y() - (x2-x1).x()*(p-x3).y()) ); + //q = x1 + (x2 - x1)*( ((x3-x1).x()*(x1-x2).y() - (x1-x2).x()*(x3-x1).y())/((p-x3).x()*(x2-x1).y() - (x2-x1).x()*(p-x3).y()) ); - q_value = v1 + (v2 - v1) * (x1.distance3D(q) / x1.distance3D(x2)); + sgSubVec2 (q, x2, x1); + sgScaleVec2(q, (x3[0]-x1[0])*(x1[1]-x2[1]) - (x1[0]-x2[0])*(x3[1]-x1[1]) ); + sgScaleVec2(q, 1.0 / ( (p [0]-x3[0])*(x2[1]-x1[1]) - (x2[0]-x1[0])*(p [1]-x3[1]) ) ); + sgAddVec2 (q, x1); + + q_value = v1 + (v2 - v1) * ( sgDistanceVec2(x1, q) / sgDistanceVec2(x1, x2) ); - return q_value + (v3 - q_value) * (q.distance3D(p) / q.distance3D(x3)); + return q_value + (v3 - q_value) * ( sgDistanceVec2(q, p) / sgDistanceVec2(q, x3)); } /****************************************************************************/ /* Constructor and Destructor */ /****************************************************************************/ -FGGlobalWeatherDatabase::FGGlobalWeatherDatabase(const FGGlobalWeatherDatabaseStatus& s) +FGGlobalWeatherDatabase::FGGlobalWeatherDatabase(const FGGlobalWeatherDatabaseStatus s) { DatabaseStatus = s; } @@ -89,11 +96,11 @@ FGGlobalWeatherDatabase::~FGGlobalWeatherDatabase() /* Get the physical properties on the specified point p */ /* do this by interpolating between the 3 closest points */ /****************************************************************************/ -FGPhysicalProperties FGGlobalWeatherDatabase::get(const Point2D& p) const +FGPhysicalProperties FGGlobalWeatherDatabase::get(const sgVec2& p) const { - WeatherPrecition distance[3]; //store the 3 closest distances + WeatherPrecision distance[3]; //store the 3 closest distances FGPhysicalProperties2DVectorConstIt iterator[3]; //and the coresponding iterators - WeatherPrecition d; + WeatherPrecision d; distance[0] = 9.46e15; //init with a distance that every calculated distance[1] = 9.46e15; //distance is guranteed to be shorter as @@ -101,7 +108,7 @@ FGPhysicalProperties FGGlobalWeatherDatabase::get(const Point2D& p) const for (FGPhysicalProperties2DVectorConstIt it=database.begin(); it!=database.end(); it++) { //go through the whole database - d = it->p.distance2Dsquared(p); + d = sgScalarProductVec2(it->p, p); if (dp.distance3Dsquared(p.p) < (tolerance*tolerance)) + if (sgScalarProductVec2(it->p, p.p) < (tolerance*tolerance)) { //assume that's my point (*it) = p; return true; @@ -185,25 +192,25 @@ bool FGGlobalWeatherDatabase::change(const FGPhysicalProperties2D& p, const Weat /* Get all, but at least min, stored point in the circle around p with the */ /* radius r */ /****************************************************************************/ -FGPhysicalProperties2DVector FGGlobalWeatherDatabase::getAll(const Point2D& p, const WeatherPrecition& r, const unsigned int& min) +FGPhysicalProperties2DVector FGGlobalWeatherDatabase::getAll(const sgVec2& p, const WeatherPrecision r, const unsigned int min) { FGPhysicalProperties2DVector ret_list; - if ((DatabaseStatus == FGGlobalWeatherDatabase_only_static) - ||(DatabaseStatus == FGGlobalWeatherDatabase_working) ) + if ( (DatabaseStatus == FGGlobalWeatherDatabase_only_static) + ||(DatabaseStatus == FGGlobalWeatherDatabase_working ) ) { //doest it make sense? FGPhysicalProperties2DVectorIt *it; //store the closest entries - WeatherPrecition *d; + WeatherPrecision *d; unsigned int act_it = 0; int i; it = new FGPhysicalProperties2DVectorIt[min+1]; - d = new WeatherPrecition[min+1]; + d = new WeatherPrecision[min+1]; for (it[0]=database.begin(); it[act_it]!=database.end(); it[act_it]++) { //go through the whole database - d[act_it] = it[act_it]->p.distance2Dsquared(p); + d[act_it] = sgScalarProductVec2(it[act_it]->p, p); if (r >= d[act_it]) { //add it @@ -213,7 +220,7 @@ FGPhysicalProperties2DVector FGGlobalWeatherDatabase::getAll(const Point2D& p, c { if (act_it>0) { //figure out if this distance belongs to the closest ones - WeatherPrecition dummy; + WeatherPrecision dummy; FGPhysicalProperties2DVectorIt dummyIt; for (i = act_it++; i >= 0;) diff --git a/src/WeatherCM/FGGlobalWeatherDatabase.h b/src/WeatherCM/FGGlobalWeatherDatabase.h index e231af2a4..33449b117 100644 --- a/src/WeatherCM/FGGlobalWeatherDatabase.h +++ b/src/WeatherCM/FGGlobalWeatherDatabase.h @@ -4,7 +4,7 @@ Author: Christian Mayer Date started: 28.05.99 - ---------- Copyright (C) 1999 Christian Mayer (vader@t-online.de) ---------- + -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) -------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -37,6 +37,8 @@ HISTORY 30.06.1999 Christian Mayer STL portability 11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's suggestion +19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D + and lots of wee code cleaning *****************************************************************************/ /****************************************************************************/ @@ -48,18 +50,27 @@ HISTORY /****************************************************************************/ /* INCLUDES */ /****************************************************************************/ -#include "FGPhysicalProperties.h" -#include "FGPhysicalProperty.h" -#include "sg.h" +#ifdef HAVE_CONFIG_H +# include +#endif + #include + #include #include STL_IOSTREAM + +#include + +#include "FGPhysicalProperties.h" +#include "FGPhysicalProperty.h" /****************************************************************************/ /* DEFINES */ /****************************************************************************/ FG_USING_STD(vector); +#ifndef FG_HAVE_NATIVE_SGI_COMPILERS FG_USING_STD(iostream); +#endif FG_USING_NAMESPACE(std); enum FGGlobalWeatherDatabaseStatus { @@ -86,50 +97,63 @@ public: /************************************************************************/ /* Constructor and Destructor */ /************************************************************************/ - FGGlobalWeatherDatabase(const FGGlobalWeatherDatabaseStatus& s = FGGlobalWeatherDatabase_not_used); + FGGlobalWeatherDatabase(const FGGlobalWeatherDatabaseStatus s = FGGlobalWeatherDatabase_not_used); ~FGGlobalWeatherDatabase(); /************************************************************************/ /* Get the physical properties on the specified point p */ /************************************************************************/ - FGPhysicalProperties get(const Point2D& p) const; - FGPhysicalProperties get(const sgVec2& p) const {return get(Point2D(p[0], p[1]));} - inline FGPhysicalProperty get(const Point3D& p) const {return FGPhysicalProperty(get(Point2D(p)), p.elev());} - inline FGPhysicalProperty get(const sgVec3& p) const {return FGPhysicalProperty(get(Point2D(p[0], p[1])), p[3]);} + FGPhysicalProperties get(const sgVec2& p) const; + FGPhysicalProperty get(const sgVec3& p) const + { + sgVec2 temp; + sgSetVec2( temp, p[0], p[1] ); + + return FGPhysicalProperty( get(temp), p[3] ); + } /************************************************************************/ /* update the database. Since the last call we had dt seconds */ /************************************************************************/ - void update(const WeatherPrecition& dt); + void update(const WeatherPrecision dt); /************************************************************************/ /* Add a physical property on the specified point p */ /************************************************************************/ - void add(const Point2D& p, const FGPhysicalProperties& x); - inline void add(const FGPhysicalProperties2D& x) {database.push_back(x);} + void add(const sgVec2& p, const FGPhysicalProperties& x); + void add(const FGPhysicalProperties2D& x) + { + database.push_back(x); + } /************************************************************************/ /* Change the closest physical property to p. If p is further away than */ /* tolerance I'm returning false otherwise true */ /************************************************************************/ - bool change(const FGPhysicalProperties2D& p, const WeatherPrecition& tolerance = 0.0000001); + bool change(const FGPhysicalProperties2D& p, const WeatherPrecision tolerance = 0.0000001); /************************************************************************/ /* Get all stored points in the circle around p with the radius r, but */ /* at least min points. */ /************************************************************************/ - FGPhysicalProperties2DVector getAll(const Point2D& p, const WeatherPrecition& r, const unsigned int& min = 0); + FGPhysicalProperties2DVector getAll(const sgVec2& p, const WeatherPrecision r, const unsigned int min = 0); + FGPhysicalProperties2DVector getAll(const sgVec3& p, const WeatherPrecision r, const unsigned int min = 0) + { + sgVec2 temp; + sgSetVec2(temp, p[0], p[1]); + + return getAll(temp, r, min); + } /************************************************************************/ /* get/set the operating status of the database */ /************************************************************************/ - FGGlobalWeatherDatabaseStatus getDatabaseStatus(void) const { return DatabaseStatus; } + FGGlobalWeatherDatabaseStatus getDatabaseStatus(void) const { return DatabaseStatus; } void setDatabaseStatus(const FGGlobalWeatherDatabaseStatus& s) { DatabaseStatus = s; } /************************************************************************/ /* Dump the whole database */ /************************************************************************/ - //friend istream& operator>> ( istream&, Point3D& ); friend ostream& operator<< ( ostream& out, const FGGlobalWeatherDatabase& p ); }; @@ -146,4 +170,4 @@ inline ostream& operator<< ( ostream& out, const FGGlobalWeatherDatabase& p ) } /****************************************************************************/ -#endif /*FGGlobalWeatherDatabase_H*/ \ No newline at end of file +#endif /*FGGlobalWeatherDatabase_H*/ diff --git a/src/WeatherCM/FGLocalWeatherDatabase.cpp b/src/WeatherCM/FGLocalWeatherDatabase.cpp index 7d284e011..f88e87b7e 100644 --- a/src/WeatherCM/FGLocalWeatherDatabase.cpp +++ b/src/WeatherCM/FGLocalWeatherDatabase.cpp @@ -5,7 +5,7 @@ Date started: 28.05.99 Called by: main program - ---------- Copyright (C) 1999 Christian Mayer (vader@t-online.de) ---------- + -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) -------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -36,17 +36,21 @@ HISTORY 20.06.1999 Christian Mayer added lots of consts 11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's suggestion +19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D + and lots of wee code cleaning *****************************************************************************/ /****************************************************************************/ /* INCLUDES */ /****************************************************************************/ +#include +#include + +#include + #include "FGLocalWeatherDatabase.h" #include "FGVoronoi.h" -#include "fg_constants.h" -#include -#include /****************************************************************************/ /********************************** CODE ************************************/ @@ -55,7 +59,7 @@ HISTORY /****************************************************************************/ /* return the index (better: ID) of the area with point p */ /****************************************************************************/ -unsigned int FGLocalWeatherDatabase::AreaWith(const Point2D& p) const +unsigned int FGLocalWeatherDatabase::AreaWith(const sgVec2& p) const { for (FGMicroWeatherList::size_type i = 0; i != WeatherAreas.size(); i++) @@ -74,7 +78,7 @@ void FGLocalWeatherDatabase::tileLocalWeather(const FGPhysicalProperties2DVector { FGVoronoiInputList input; - for (FGPhysicalProperties2DVector::const_iterator it1 = EntryList.begin(); it1 != EntryList.end(); it1++) + for (FGPhysicalProperties2DVectorConstIt it1 = EntryList.begin(); it1 != EntryList.end(); it1++) input.push_back(FGVoronoiInput(it1->p, *it1)); FGVoronoiOutputList output = Voronoiate(input); @@ -89,7 +93,7 @@ void FGLocalWeatherDatabase::tileLocalWeather(const FGPhysicalProperties2DVector FGLocalWeatherDatabase* FGLocalWeatherDatabase::theFGLocalWeatherDatabase = 0; FGLocalWeatherDatabase *WeatherDatabase; -FGLocalWeatherDatabase::FGLocalWeatherDatabase(const Point3D& posititon, const WeatherPrecition& visibility, const DatabaseWorkingType& type) +FGLocalWeatherDatabase::FGLocalWeatherDatabase(const sgVec3& posititon, const WeatherPrecision visibility, const DatabaseWorkingType type) { cerr << "Initializing FGLocalWeatherDatabase\n"; cerr << "-----------------------------------\n"; @@ -102,10 +106,10 @@ FGLocalWeatherDatabase::FGLocalWeatherDatabase(const Point3D& posititon, const W } setWeatherVisibility(visibility); - //WeatherVisibility = visibility; + DatabaseStatus = type; global = 0; //just get sure... - last_known_position = posititon; + sgCopyVec3(last_known_position, posititon); theFGLocalWeatherDatabase = this; @@ -127,7 +131,7 @@ FGLocalWeatherDatabase::FGLocalWeatherDatabase(const Point3D& posititon, const W case manual: case default_mode: { - vector emptyList; + vector emptyList; WeatherAreas.push_back(FGMicroWeather(FGPhysicalProperties2D(), emptyList)); //in these cases I've only got one tile } break; @@ -152,7 +156,7 @@ FGLocalWeatherDatabase::~FGLocalWeatherDatabase() /****************************************************************************/ /* reset the whole database */ /****************************************************************************/ -void FGLocalWeatherDatabase::reset(const DatabaseWorkingType& type) +void FGLocalWeatherDatabase::reset(const DatabaseWorkingType type) { //delete global database if necessary if ((DatabaseStatus == use_global) && (type != use_global)) @@ -169,23 +173,23 @@ void FGLocalWeatherDatabase::reset(const DatabaseWorkingType& type) /****************************************************************************/ /* update the database. Since the last call we had dt seconds */ /****************************************************************************/ -void FGLocalWeatherDatabase::update(const WeatherPrecition& dt) +void FGLocalWeatherDatabase::update(const WeatherPrecision dt) { if (DatabaseStatus==use_global) global->update(dt); } -void FGLocalWeatherDatabase::update(const Point3D& p) //position has changed +void FGLocalWeatherDatabase::update(const sgVec3& p) //position has changed { - last_known_position = p; + sgCopyVec3(last_known_position, p); //cerr << "****\nupdate inside\n"; //cerr << "Parameter: " << p << "\n"; //cerr << "****\n"; } -void FGLocalWeatherDatabase::update(const Point3D& p, const WeatherPrecition& dt) //time and/or position has changed +void FGLocalWeatherDatabase::update(const sgVec3& p, const WeatherPrecision dt) //time and/or position has changed { - last_known_position = p; + sgCopyVec3(last_known_position, p); if (DatabaseStatus==use_global) global->update(dt); @@ -194,29 +198,19 @@ void FGLocalWeatherDatabase::update(const Point3D& p, const WeatherPrecition& dt /****************************************************************************/ /* Get the physical properties on the specified point p out of the database */ /****************************************************************************/ -FGPhysicalProperty FGLocalWeatherDatabase::get(const Point3D& p) const +FGPhysicalProperty FGLocalWeatherDatabase::get(const sgVec3& p) const { unsigned int a = AreaWith(p); if (a != 0) - return WeatherAreas[a-1].get(p.elev()); + return WeatherAreas[a-1].get(p[3]); else //point is outside => ask GlobalWeatherDatabase return global->get(p); } -FGPhysicalProperty FGLocalWeatherDatabase::get(const sgVec3& p) const -{ - Point3D temp(p[0], p[1], p[2]); - - unsigned int a = AreaWith(temp); - if (a != 0) - return WeatherAreas[a-1].get(temp.elev()); - else //point is outside => ask GlobalWeatherDatabase - return global->get(temp); -} - FGPhysicalProperties FGLocalWeatherDatabase::get(const sgVec2& p) const { - Point3D temp(p[0], p[1], 0.0); + sgVec3 temp; + sgSetVec3(temp, p[0], p[1], 0.0); unsigned int a = AreaWith(temp); if (a != 0) @@ -225,12 +219,12 @@ FGPhysicalProperties FGLocalWeatherDatabase::get(const sgVec2& p) const return global->get(p); } -WeatherPrecition FGLocalWeatherDatabase::getAirDensity(const Point3D& p) const +WeatherPrecision FGLocalWeatherDatabase::getAirDensity(const sgVec3& p) const { FGPhysicalProperty dummy; unsigned int a = AreaWith(p); if (a != 0) - dummy = WeatherAreas[a-1].get(p.elev()); + dummy = WeatherAreas[a-1].get(p[3]); else //point is outside => ask GlobalWeatherDatabase dummy = global->get(p); @@ -239,82 +233,66 @@ WeatherPrecition FGLocalWeatherDatabase::getAirDensity(const Point3D& p) const (dummy.Temperature*FG_WEATHER_DEFAULT_AIRPRESSURE); } -WeatherPrecition FGLocalWeatherDatabase::getAirDensity(const sgVec3& p) const -{ - Point3D temp(p[0], p[1], p[2]); - - FGPhysicalProperty dummy; - unsigned int a = AreaWith(temp); - if (a != 0) - dummy = WeatherAreas[a-1].get(temp.elev()); - else //point is outside => ask GlobalWeatherDatabase - dummy = global->get(temp); - - return - (dummy.AirPressure*FG_WEATHER_DEFAULT_AIRDENSITY*FG_WEATHER_DEFAULT_TEMPERATURE) / - (dummy.Temperature*FG_WEATHER_DEFAULT_AIRPRESSURE); -} - /****************************************************************************/ /* Add a weather feature at the point p and surrounding area */ /****************************************************************************/ -void FGLocalWeatherDatabase::addWind(const WeatherPrecition alt, const Point3D& x, const Point2D& p) +void FGLocalWeatherDatabase::addWind(const WeatherPrecision alt, const sgVec3& x, const sgVec2& p) { unsigned int a = AreaWith(p); if (a != 0) WeatherAreas[a-1].addWind(alt, x); } -void FGLocalWeatherDatabase::addTurbulence(const WeatherPrecition alt, const Point3D& x, const Point2D& p) +void FGLocalWeatherDatabase::addTurbulence(const WeatherPrecision alt, const sgVec3& x, const sgVec2& p) { unsigned int a = AreaWith(p); if (a != 0) WeatherAreas[a-1].addTurbulence(alt, x); } -void FGLocalWeatherDatabase::addTemperature(const WeatherPrecition alt, const WeatherPrecition x, const Point2D& p) +void FGLocalWeatherDatabase::addTemperature(const WeatherPrecision alt, const WeatherPrecision x, const sgVec2& p) { unsigned int a = AreaWith(p); if (a != 0) WeatherAreas[a-1].addTemperature(alt, x); } -void FGLocalWeatherDatabase::addAirPressure(const WeatherPrecition alt, const WeatherPrecition x, const Point2D& p) +void FGLocalWeatherDatabase::addAirPressure(const WeatherPrecision alt, const WeatherPrecision x, const sgVec2& p) { unsigned int a = AreaWith(p); if (a != 0) WeatherAreas[a-1].addAirPressure(alt, x); } -void FGLocalWeatherDatabase::addVaporPressure(const WeatherPrecition alt, const WeatherPrecition x, const Point2D& p) +void FGLocalWeatherDatabase::addVaporPressure(const WeatherPrecision alt, const WeatherPrecision x, const sgVec2& p) { unsigned int a = AreaWith(p); if (a != 0) WeatherAreas[a-1].addVaporPressure(alt, x); } -void FGLocalWeatherDatabase::addCloud(const WeatherPrecition alt, const FGCloudItem& x, const Point2D& p) +void FGLocalWeatherDatabase::addCloud(const WeatherPrecision alt, const FGCloudItem& x, const sgVec2& p) { unsigned int a = AreaWith(p); if (a != 0) WeatherAreas[a-1].addCloud(alt, x); } -void FGLocalWeatherDatabase::setSnowRainIntensity(const WeatherPrecition& x, const Point2D& p) +void FGLocalWeatherDatabase::setSnowRainIntensity(const WeatherPrecision x, const sgVec2& p) { unsigned int a = AreaWith(p); if (a != 0) WeatherAreas[a-1].setSnowRainIntensity(x); } -void FGLocalWeatherDatabase::setSnowRainType(const SnowRainType& x, const Point2D& p) +void FGLocalWeatherDatabase::setSnowRainType(const SnowRainType x, const sgVec2& p) { unsigned int a = AreaWith(p); if (a != 0) WeatherAreas[a-1].setSnowRainType(x); } -void FGLocalWeatherDatabase::setLightningProbability(const WeatherPrecition& x, const Point2D& p) +void FGLocalWeatherDatabase::setLightningProbability(const WeatherPrecision x, const sgVec2& p) { unsigned int a = AreaWith(p); if (a != 0) @@ -370,9 +348,12 @@ void FGLocalWeatherDatabase::setProperties(const FGPhysicalProperties2D& x) void fgUpdateWeatherDatabase(void) { //cerr << "FGLocalWeatherDatabase::update()\n"; - WeatherDatabase->update( Point3D( + sgVec3 position; + sgSetVec3(position, current_aircraft.fdm_state->get_Latitude(), current_aircraft.fdm_state->get_Longitude(), - current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER) ); + current_aircraft.fdm_state->get_Altitude() * FEET_TO_METER); + + WeatherDatabase->update( position ); } diff --git a/src/WeatherCM/FGLocalWeatherDatabase.h b/src/WeatherCM/FGLocalWeatherDatabase.h index aa0c008e0..dcd6c016b 100644 --- a/src/WeatherCM/FGLocalWeatherDatabase.h +++ b/src/WeatherCM/FGLocalWeatherDatabase.h @@ -4,7 +4,7 @@ Author: Christian Mayer Date started: 28.05.99 - ---------- Copyright (C) 1999 Christian Mayer (vader@t-online.de) ---------- + -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) -------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -36,6 +36,8 @@ HISTORY 30.06.1999 Christian Mayer STL portability 11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's suggestion +19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D + and lots of wee code cleaning *****************************************************************************/ /****************************************************************************/ @@ -56,6 +58,7 @@ HISTORY #include #include + #include "sg.h" #include "FGPhysicalProperties.h" @@ -79,10 +82,10 @@ private: protected: FGGlobalWeatherDatabase *global; //point to the global database - typedef vector FGMicroWeatherList; + typedef vector FGMicroWeatherList; typedef FGMicroWeatherList::iterator FGMicroWeatherListIt; - typedef vector pointVector; + typedef vector pointVector; typedef vector tileVector; /************************************************************************/ @@ -92,9 +95,22 @@ protected: FGMicroWeatherList WeatherAreas; - WeatherPrecition WeatherVisibility; //how far do I need to simulate the + WeatherPrecision WeatherVisibility; //how far do I need to simulate the //local weather? Unit: metres - Point3D last_known_position; + sgVec3 last_known_position; + + + /************************************************************************/ + /* return the index of the area with point p */ + /************************************************************************/ + unsigned int AreaWith(const sgVec2& p) const; + unsigned int AreaWith(const sgVec3& p) const + { + sgVec2 temp; + sgSetVec2(temp, p[0], p[1]); + + return AreaWith(temp); + } public: static FGLocalWeatherDatabase *theFGLocalWeatherDatabase; @@ -108,60 +124,65 @@ public: default_mode //use only default values }; -protected: DatabaseWorkingType DatabaseStatus; - /************************************************************************/ - /* return the index of the area with point p */ - /************************************************************************/ - unsigned int AreaWith(const Point2D& p) const; - -public: /************************************************************************/ /* Constructor and Destructor */ /************************************************************************/ FGLocalWeatherDatabase( - const Point3D& posititon, - const WeatherPrecition& visibility = DEFAULT_WEATHER_VISIBILIY, - const DatabaseWorkingType& type = PREFERED_WORKING_TYPE); + const sgVec3& posititon, + const WeatherPrecision visibility = DEFAULT_WEATHER_VISIBILIY, + const DatabaseWorkingType type = PREFERED_WORKING_TYPE); + + FGLocalWeatherDatabase( + const WeatherPrecision posititon_lat, + const WeatherPrecision posititon_lon, + const WeatherPrecision posititon_alt, + const WeatherPrecision visibility = DEFAULT_WEATHER_VISIBILIY, + const DatabaseWorkingType type = PREFERED_WORKING_TYPE) + { + sgVec3 position; + sgSetVec3( position, posititon_lat, posititon_lon, posititon_alt ); + + FGLocalWeatherDatabase( position, visibility, type ); + } + ~FGLocalWeatherDatabase(); /************************************************************************/ /* reset the whole database */ /************************************************************************/ - void reset(const DatabaseWorkingType& type = PREFERED_WORKING_TYPE); + void reset(const DatabaseWorkingType type = PREFERED_WORKING_TYPE); /************************************************************************/ /* update the database. Since the last call we had dt seconds */ /************************************************************************/ - void update(const WeatherPrecition& dt); //time has changed - void update(const Point3D& p); //position has changed - void update(const Point3D& p, const WeatherPrecition& dt); //time and/or position has changed + void update(const WeatherPrecision dt); //time has changed + void update(const sgVec3& p); //position has changed + void update(const sgVec3& p, const WeatherPrecision dt); //time and/or position has changed /************************************************************************/ /* Get the physical properties on the specified point p */ /************************************************************************/ - FGPhysicalProperty get(const Point3D& p) const; - FGPhysicalProperty get(const sgVec3& p) const; FGPhysicalProperties get(const sgVec2& p) const; + FGPhysicalProperty get(const sgVec3& p) const; - WeatherPrecition getAirDensity(const Point3D& p) const; - WeatherPrecition getAirDensity(const sgVec3& p) const; + WeatherPrecision getAirDensity(const sgVec3& p) const; /************************************************************************/ /* Add a weather feature at the point p and surrounding area */ /************************************************************************/ - void addWind(const WeatherPrecition alt, const Point3D& x, const Point2D& p); - void addTurbulence(const WeatherPrecition alt, const Point3D& x, const Point2D& p); - void addTemperature(const WeatherPrecition alt, const WeatherPrecition x, const Point2D& p); - void addAirPressure(const WeatherPrecition alt, const WeatherPrecition x, const Point2D& p); - void addVaporPressure(const WeatherPrecition alt, const WeatherPrecition x, const Point2D& p); - void addCloud(const WeatherPrecition alt, const FGCloudItem& x, const Point2D& p); + void addWind (const WeatherPrecision alt, const sgVec3& x, const sgVec2& p); + void addTurbulence (const WeatherPrecision alt, const sgVec3& x, const sgVec2& p); + void addTemperature (const WeatherPrecision alt, const WeatherPrecision x, const sgVec2& p); + void addAirPressure (const WeatherPrecision alt, const WeatherPrecision x, const sgVec2& p); + void addVaporPressure(const WeatherPrecision alt, const WeatherPrecision x, const sgVec2& p); + void addCloud (const WeatherPrecision alt, const FGCloudItem& x, const sgVec2& p); - void setSnowRainIntensity(const WeatherPrecition& x, const Point2D& p); - void setSnowRainType(const SnowRainType& x, const Point2D& p); - void setLightningProbability(const WeatherPrecition& x, const Point2D& p); + void setSnowRainIntensity (const WeatherPrecision x, const sgVec2& p); + void setSnowRainType (const SnowRainType x, const sgVec2& p); + void setLightningProbability(const WeatherPrecision x, const sgVec2& p); void addProperties(const FGPhysicalProperties2D& x); //add a property void setProperties(const FGPhysicalProperties2D& x); //change a property @@ -169,8 +190,8 @@ public: /************************************************************************/ /* get/set weather visibility */ /************************************************************************/ - void setWeatherVisibility(const WeatherPrecition& visibility); - WeatherPrecition getWeatherVisibility(void) const; + void setWeatherVisibility(const WeatherPrecision visibility); + WeatherPrecision getWeatherVisibility(void) const; }; extern FGLocalWeatherDatabase *WeatherDatabase; @@ -179,7 +200,7 @@ void fgUpdateWeatherDatabase(void); /****************************************************************************/ /* get/set weather visibility */ /****************************************************************************/ -void inline FGLocalWeatherDatabase::setWeatherVisibility(const WeatherPrecition& visibility) +void inline FGLocalWeatherDatabase::setWeatherVisibility(const WeatherPrecision visibility) { if (visibility >= MINIMUM_WEATHER_VISIBILIY) WeatherVisibility = visibility; @@ -210,7 +231,7 @@ void inline FGLocalWeatherDatabase::setWeatherVisibility(const WeatherPrecition& } -WeatherPrecition inline FGLocalWeatherDatabase::getWeatherVisibility(void) const +WeatherPrecision inline FGLocalWeatherDatabase::getWeatherVisibility(void) const { //cerr << "FGLocalWeatherDatabase::getWeatherVisibility() = " << WeatherVisibility << "\n"; return WeatherVisibility; diff --git a/src/WeatherCM/FGMicroWeather.cpp b/src/WeatherCM/FGMicroWeather.cpp index 6ee133fc3..600e72581 100644 --- a/src/WeatherCM/FGMicroWeather.cpp +++ b/src/WeatherCM/FGMicroWeather.cpp @@ -5,7 +5,7 @@ Date started: 28.05.99 Called by: FGLocalWeatherDatabase - ---------- Copyright (C) 1999 Christian Mayer (vader@t-online.de) ---------- + -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) -------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -35,13 +35,17 @@ HISTORY 20.06.1999 Christian Mayer added lots of consts 11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's suggestion +19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D + and lots of wee code cleaning *****************************************************************************/ /****************************************************************************/ /* INCLUDES */ /****************************************************************************/ +#include +#include + #include "FGMicroWeather.h" -#include "fg_constants.h" /****************************************************************************/ /********************************** CODE ************************************/ @@ -60,48 +64,48 @@ FGMicroWeather::~FGMicroWeather() /* Add the features to the micro weather */ /* return succss */ /****************************************************************************/ -void FGMicroWeather::addWind(const WeatherPrecition alt, const Point3D& x) +void FGMicroWeather::addWind(const WeatherPrecision alt, const FGWindItem& x) { StoredWeather.Wind[alt] = x; } -void FGMicroWeather::addTurbulence(const WeatherPrecition alt, const Point3D& x) +void FGMicroWeather::addTurbulence(const WeatherPrecision alt, const FGTurbulenceItem& x) { StoredWeather.Turbulence[alt] = x; } -void FGMicroWeather::addTemperature(const WeatherPrecition alt, const WeatherPrecition x) +void FGMicroWeather::addTemperature(const WeatherPrecision alt, const WeatherPrecision x) { StoredWeather.Temperature[alt] = x; } -void FGMicroWeather::addAirPressure(const WeatherPrecition alt, const WeatherPrecition x) +void FGMicroWeather::addAirPressure(const WeatherPrecision alt, const WeatherPrecision x) { cerr << "Error: caught attempt to add AirPressure which is logical wrong\n"; //StoredWeather.AirPressure[alt] = x; } -void FGMicroWeather::addVaporPressure(const WeatherPrecition alt, const WeatherPrecition x) +void FGMicroWeather::addVaporPressure(const WeatherPrecision alt, const WeatherPrecision x) { StoredWeather.VaporPressure[alt] = x; } -void FGMicroWeather::addCloud(const WeatherPrecition alt, const FGCloudItem& x) +void FGMicroWeather::addCloud(const WeatherPrecision alt, const FGCloudItem& x) { StoredWeather.Clouds[alt] = x; } -void FGMicroWeather::setSnowRainIntensity(const WeatherPrecition& x) +void FGMicroWeather::setSnowRainIntensity(const WeatherPrecision x) { StoredWeather.SnowRainIntensity = x; } -void FGMicroWeather::setSnowRainType(const SnowRainType& x) +void FGMicroWeather::setSnowRainType(const SnowRainType x) { StoredWeather.snowRainType = x; } -void FGMicroWeather::setLightningProbability(const WeatherPrecition& x) +void FGMicroWeather::setLightningProbability(const WeatherPrecision x) { StoredWeather.LightningProbability = x; } @@ -122,7 +126,7 @@ inline const int FG_SIGN(const T& x) { return x < T(0) ? -1 : 1; } -bool FGMicroWeather::hasPoint(const Point2D& p) const +bool FGMicroWeather::hasPoint(const sgVec2& p) const { if (position.size()==0) return true; //no border => this tile is infinite @@ -132,7 +136,7 @@ bool FGMicroWeather::hasPoint(const Point2D& p) const //when I'm here I've got at least 2 points - WeatherPrecition t; + WeatherPrecision t; signed char side1, side2; const_positionListIt it = position.begin(); const_positionListIt it2 = it; it2++; @@ -143,19 +147,21 @@ bool FGMicroWeather::hasPoint(const Point2D& p) const if (it2 == position.end()) break; - if (fabs(it->x() - it2->x()) >= FG_EPSILON) + if (fabs(it->p[0] - it2->p[0]) >= FG_EPSILON) { - t = (it->y() - it2->y()) / (it->x() - it2->x()); - side1 = FG_SIGN (t * (StoredWeather.p.x() - it2->x()) + it2->y() - StoredWeather.p.y()); - side2 = FG_SIGN (t * ( p.x() - it2->x()) + it2->y() - p.y()); + t = (it->p[1] - it2->p[1]) / (it->p[0] - it2->p[0]); + + side1 = FG_SIGN (t * (StoredWeather.p[0] - it2->p[0]) + it2->p[1] - StoredWeather.p[1]); + side2 = FG_SIGN (t * ( p[0] - it2->p[0]) + it2->p[1] - p[1]); if ( side1 != side2 ) return false; //cout << "failed side check\n"; } else { - t = (it->x() - it2->x()) / (it->y() - it2->y()); - side1 = FG_SIGN (t * (StoredWeather.p.y() - it2->y()) + it2->x() - StoredWeather.p.x()); - side2 = FG_SIGN (t * ( p.y() - it2->y()) + it2->x() - p.x()); + t = (it->p[0] - it2->p[0]) / (it->p[1] - it2->p[1]); + + side1 = FG_SIGN (t * (StoredWeather.p[1] - it2->p[1]) + it2->p[0] - StoredWeather.p[0]); + side2 = FG_SIGN (t * ( p[1] - it2->p[1]) + it2->p[0] - p[0]); if ( side1 != side2 ) return false; //cout << "failed side check\n"; } diff --git a/src/WeatherCM/FGMicroWeather.h b/src/WeatherCM/FGMicroWeather.h index 3f55c3404..18e37e19a 100644 --- a/src/WeatherCM/FGMicroWeather.h +++ b/src/WeatherCM/FGMicroWeather.h @@ -4,7 +4,7 @@ Author: Christian Mayer Date started: 28.05.99 - ---------- Copyright (C) 1999 Christian Mayer (vader@t-online.de) ---------- + -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) -------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -35,6 +35,8 @@ HISTORY 30.06.1999 Christian Mayer STL portability 11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's suggestion +19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D + and lots of wee code cleaning *****************************************************************************/ /****************************************************************************/ @@ -46,22 +48,23 @@ HISTORY /****************************************************************************/ /* INCLUDES */ /****************************************************************************/ +#include + +#include "sg.h" +#include "FGWeatherVectorWrap.h" + +#include "FGWeatherDefs.h" + //Include all the simulated weather features #include "FGCloud.h" #include "FGSnowRain.h" #include "FGAirPressureItem.h" -#include "FGTemperatureItem.h" #include "FGWindItem.h" #include "FGTurbulenceItem.h" -#include "FGVaporPressureItem.h" -#include "FGWeatherDefs.h" #include "FGPhysicalProperties.h" #include "FGPhysicalProperty.h" -#include - -#include /****************************************************************************/ /* DEFINES */ @@ -76,13 +79,12 @@ class FGMicroWeather { private: protected: - typedef vector positionList; - typedef positionList::iterator positionListIt; + typedef vector positionList; + typedef positionList::iterator positionListIt; typedef positionList::const_iterator const_positionListIt; positionList position; //the points that specify the outline of the //micro weather (lat/lon) - FGPhysicalProperties2D StoredWeather; //property if nothing is specified public: @@ -95,39 +97,45 @@ public: /************************************************************************/ /* Add a feature to the micro weather */ /************************************************************************/ - void addWind(const WeatherPrecition alt, const Point3D& x); - void addTurbulence(const WeatherPrecition alt, const Point3D& x); - void addTemperature(const WeatherPrecition alt, const WeatherPrecition x); - void addAirPressure(const WeatherPrecition alt, const WeatherPrecition x); - void addVaporPressure(const WeatherPrecition alt, const WeatherPrecition x); - void addCloud(const WeatherPrecition alt, const FGCloudItem& x); + void addWind (const WeatherPrecision alt, const FGWindItem& x); + void addTurbulence (const WeatherPrecision alt, const FGTurbulenceItem& x); + void addTemperature (const WeatherPrecision alt, const WeatherPrecision x); + void addAirPressure (const WeatherPrecision alt, const WeatherPrecision x); + void addVaporPressure(const WeatherPrecision alt, const WeatherPrecision x); + void addCloud (const WeatherPrecision alt, const FGCloudItem& x); - void setSnowRainIntensity(const WeatherPrecition& x); - void setSnowRainType(const SnowRainType& x); - void setLightningProbability(const WeatherPrecition& x); + void setSnowRainIntensity (const WeatherPrecision x); + void setSnowRainType (const SnowRainType x); + void setLightningProbability(const WeatherPrecision x); - void setStoredWeather(const FGPhysicalProperties2D& x); + void setStoredWeather (const FGPhysicalProperties2D& x); /************************************************************************/ /* get physical properties in the micro weather */ /* NOTE: I don't neet to speify a positon as the properties don't */ /* change in a micro weather */ /************************************************************************/ - inline FGPhysicalProperty get(const WeatherPrecition& altitude) const + FGPhysicalProperties get(void) const { - return FGPhysicalProperty(StoredWeather, altitude); + return FGPhysicalProperties(); } - inline FGPhysicalProperties get(void) const + FGPhysicalProperty get(const WeatherPrecision altitude) const { - return FGPhysicalProperties(); + return FGPhysicalProperty(StoredWeather, altitude); } /************************************************************************/ /* return true if p is inside this micro weather */ /************************************************************************/ - inline bool hasPoint(const Point3D& p) const { return hasPoint((Point2D) p); } - bool hasPoint(const Point2D& p) const; + bool hasPoint(const sgVec2& p) const; + bool hasPoint(const sgVec3& p) const + { + sgVec2 temp; + sgSetVec2(temp, p[0], p[1]); + + return hasPoint( temp ); + } }; /****************************************************************************/ diff --git a/src/WeatherCM/FGPhysicalProperties.cpp b/src/WeatherCM/FGPhysicalProperties.cpp index 3acb90cb2..df3d1c7b2 100644 --- a/src/WeatherCM/FGPhysicalProperties.cpp +++ b/src/WeatherCM/FGPhysicalProperties.cpp @@ -5,7 +5,7 @@ Date started: 28.05.99 Called by: main program - ---------- Copyright (C) 1999 Christian Mayer (vader@t-online.de) ---------- + -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) -------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -35,6 +35,8 @@ HISTORY 20.06.1999 Christian Mayer added lots of consts 11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's suggestion +19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D + and lots of wee code cleaning *****************************************************************************/ /****************************************************************************/ @@ -48,15 +50,17 @@ HISTORY /****************************************************************************/ FGPhysicalProperties::FGPhysicalProperties() { + sgVec3 zero; + sgZeroVec3( zero ); /************************************************************************/ /* This standart constructor fills the class with a standard weather */ /************************************************************************/ - Wind[-1000.0] = Point3D(0.0); //no Wind by default - Wind[10000.0] = Point3D(0.0); //no Wind by default + Wind[-1000.0] = FGWindItem(zero); //no Wind by default + Wind[10000.0] = FGWindItem(zero); //no Wind by default - Turbulence[-1000.0] = Point3D(0.0); //no Turbulence by default - Turbulence[10000.0] = Point3D(0.0); //no Turbulence by default + Turbulence[-1000.0] = FGTurbulenceItem(zero); //no Turbulence by default + Turbulence[10000.0] = FGTurbulenceItem(zero); //no Turbulence by default //Initialice with the CINA atmosphere Temperature[ 0.0] = +15.0 + 273.16; @@ -81,7 +85,7 @@ unsigned int FGPhysicalProperties::getNumberOfCloudLayers(void) const FGCloudItem FGPhysicalProperties::getCloudLayer(unsigned int nr) const { - map::const_iterator CloudsIt = Clouds.begin(); + map::const_iterator CloudsIt = Clouds.begin(); //set the iterator to the 'nr'th entry for (; nr > 0; nr--) diff --git a/src/WeatherCM/FGPhysicalProperties.h b/src/WeatherCM/FGPhysicalProperties.h index 9e62be9e8..3d235f291 100644 --- a/src/WeatherCM/FGPhysicalProperties.h +++ b/src/WeatherCM/FGPhysicalProperties.h @@ -1,10 +1,10 @@ -/*******-*- Mode: C++ -*-************************************************************ +/***************************************************************************** Header: FGPhysicalProperties.h Author: Christian Mayer Date started: 28.05.99 - ---------- Copyright (C) 1999 Christian Mayer (vader@t-online.de) ---------- + -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) -------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -36,6 +36,8 @@ HISTORY 30.06.1999 Christian Mayer STL portability 11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's suggestion +19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D + and lots of wee code cleaning *****************************************************************************/ /****************************************************************************/ @@ -48,124 +50,136 @@ HISTORY /* INCLUDES */ /****************************************************************************/ #include + +#include #include #include -FG_USING_STD(vector); -FG_USING_STD(map); -FG_USING_NAMESPACE(std); +#include "sg.h" -#include -#include #include "FGWeatherDefs.h" #include "FGAirPressureItem.h" +#include "FGWindItem.h" +#include "FGTurbulenceItem.h" #include "FGCloudItem.h" #include "FGSnowRain.h" +FG_USING_STD(vector); +FG_USING_STD(map); +FG_USING_NAMESPACE(std); + +/****************************************************************************/ +/* FOREWARD DEFINITIONS */ +/****************************************************************************/ +class FGPhysicalProperties2D; +ostream& operator<< ( ostream& out, const FGPhysicalProperties2D& p ); + class FGPhysicalProperties { public: - typedef WeatherPrecition Altitude; + typedef WeatherPrecision Altitude; - map Wind; //all Wind vectors - map Turbulence; //all Turbulence vectors - map Temperature; //in deg. Kelvin (I *only* accept SI!) - FGAirPressureItem AirPressure; //in Pascal (I *only* accept SI!) - map VaporPressure; //in Pascal (I *only* accept SI!) + map Wind; //all Wind vectors + map Turbulence; //all Turbulence vectors + map Temperature; //in deg. Kelvin (I *only* accept SI!) + FGAirPressureItem AirPressure; //in Pascal (I *only* accept SI!) + map VaporPressure; //in Pascal (I *only* accept SI!) - map Clouds; //amount of covering and type + map Clouds; //amount of covering and type - WeatherPrecition SnowRainIntensity; //this also stands for hail, snow,... - SnowRainType snowRainType; - WeatherPrecition LightningProbability; + WeatherPrecision SnowRainIntensity; //this also stands for hail, snow,... + SnowRainType snowRainType; + WeatherPrecision LightningProbability; FGPhysicalProperties(); //consructor to fill it with FG standart weather //return values at specified altitudes - Point3D WindAt(const WeatherPrecition& a) const; - Point3D TurbulenceAt(const WeatherPrecition& a) const; - WeatherPrecition TemperatureAt(const WeatherPrecition& a) const; - WeatherPrecition AirPressureAt(const WeatherPrecition& a) const; - WeatherPrecition VaporPressureAt(const WeatherPrecition& a) const; + void WindAt (sgVec3 ret, const WeatherPrecision a) const; + void TurbulenceAt (sgVec3 ret, const WeatherPrecision a) const; + WeatherPrecision TemperatureAt (const WeatherPrecision a) const; + WeatherPrecision AirPressureAt (const WeatherPrecision a) const; + WeatherPrecision VaporPressureAt(const WeatherPrecision a) const; //for easier access to the cloud stuff: unsigned int getNumberOfCloudLayers(void) const; - FGCloudItem getCloudLayer(unsigned int nr) const; + FGCloudItem getCloudLayer(unsigned int nr) const; - FGPhysicalProperties& operator = ( const FGPhysicalProperties& p ); - FGPhysicalProperties& operator *= ( const WeatherPrecition& d ); - FGPhysicalProperties& operator += ( const FGPhysicalProperties& p); - FGPhysicalProperties& operator -= ( const FGPhysicalProperties& p); + FGPhysicalProperties& operator = ( const FGPhysicalProperties& p ); + FGPhysicalProperties& operator *= ( const WeatherPrecision d ); + FGPhysicalProperties& operator += ( const FGPhysicalProperties& p ); + FGPhysicalProperties& operator -= ( const FGPhysicalProperties& p ); }; -typedef vector FGPhysicalPropertiesVector; -typedef FGPhysicalPropertiesVector::iterator FGPhysicalPropertiesVectorIt; -typedef FGPhysicalPropertiesVector::const_iterator FGPhysicalPropertiesVectorConstIt; - -class FGPhysicalProperties2D; -ostream& operator<< ( ostream& out, const FGPhysicalProperties2D& p ); - class FGPhysicalProperties2D : public FGPhysicalProperties { public: - Point2D p; //position of the property (lat/lon) + sgVec2 p; //position of the property (lat/lon) friend ostream& operator<< ( ostream& out, const FGPhysicalProperties2D& p ); FGPhysicalProperties2D() {} - FGPhysicalProperties2D(const FGPhysicalProperties& prop, const Point2D& pos) + FGPhysicalProperties2D(const FGPhysicalProperties& prop, const sgVec2& pos) { - Wind = prop.Wind; Turbulence = prop.Turbulence; Temperature = prop.Temperature; - AirPressure = prop.AirPressure; VaporPressure = prop.VaporPressure; p = pos; + Wind = prop.Wind; + Turbulence = prop.Turbulence; + Temperature = prop.Temperature; + AirPressure = prop.AirPressure; + VaporPressure = prop.VaporPressure; + sgCopyVec2(p, pos); } }; -typedef vector FGPhysicalProperties2DVector; -typedef FGPhysicalProperties2DVector::iterator FGPhysicalProperties2DVectorIt; +typedef vector FGPhysicalPropertiesVector; +typedef FGPhysicalPropertiesVector::iterator FGPhysicalPropertiesVectorIt; +typedef FGPhysicalPropertiesVector::const_iterator FGPhysicalPropertiesVectorConstIt; + +typedef vector FGPhysicalProperties2DVector; +typedef FGPhysicalProperties2DVector::iterator FGPhysicalProperties2DVectorIt; typedef FGPhysicalProperties2DVector::const_iterator FGPhysicalProperties2DVectorConstIt; inline ostream& operator<< ( ostream& out, const FGPhysicalProperties2D& p ) { - typedef map::const_iterator vector_iterator; - typedef map::const_iterator scalar_iterator; + typedef map::const_iterator wind_iterator; + typedef map::const_iterator turbulence_iterator; + typedef map::const_iterator scalar_iterator; - out << "Position: " << p.p << endl; + out << "Position: (" << p.p[0] << ", " << p.p[1] << ", " << p.p[2] << ")\n"; out << "Stored Wind: "; - for (vector_iterator WindIt = p.Wind.begin(); - WindIt != p.Wind.end(); - WindIt++) - out << "(" << WindIt->first << ") at " << WindIt->second << "m; "; - out << endl; + for (wind_iterator WindIt = p.Wind.begin(); + WindIt != p.Wind.end(); + WindIt++) + out << "(" << WindIt->first << ") at (" << WindIt->second.x() << ", " << WindIt->second.y() << ", " << WindIt->second.z() << ") m; "; + out << "\n"; out << "Stored Turbulence: "; - for (vector_iterator TurbulenceIt = p.Turbulence.begin(); - TurbulenceIt != p.Turbulence.end(); - TurbulenceIt++) - out << "(" << TurbulenceIt->first << ") at " << TurbulenceIt->second << "m; "; - out << endl; + for (turbulence_iterator TurbulenceIt = p.Turbulence.begin(); + TurbulenceIt != p.Turbulence.end(); + TurbulenceIt++) + out << "(" << TurbulenceIt->first << ") at (" << TurbulenceIt->second.x() << ", " << TurbulenceIt->second.y() << ", " << TurbulenceIt->second.z() << ") m; "; + out << "\n"; out << "Stored Temperature: "; - for (scalar_iterator TemperatureIt = p.Temperature.begin(); - TemperatureIt != p.Temperature.end(); - TemperatureIt++) + for (scalar_iterator TemperatureIt = p.Temperature.begin(); + TemperatureIt != p.Temperature.end(); + TemperatureIt++) out << TemperatureIt->first << " at " << TemperatureIt->second << "m; "; - out << endl; + out << "\n"; out << "Stored AirPressure: "; out << p.AirPressure.getValue(0) << " at " << 0.0 << "m; "; - out << endl; + out << "\n"; out << "Stored VaporPressure: "; - for (scalar_iterator VaporPressureIt = p.VaporPressure.begin(); - VaporPressureIt != p.VaporPressure.end(); - VaporPressureIt++) + for (scalar_iterator VaporPressureIt = p.VaporPressure.begin(); + VaporPressureIt != p.VaporPressure.end(); + VaporPressureIt++) out << VaporPressureIt->first << " at " << VaporPressureIt->second << "m; "; - out << endl; + out << "\n"; - return out << endl; + return out << "\n"; } @@ -179,31 +193,32 @@ inline FGPhysicalProperties& FGPhysicalProperties::operator = ( const FGPhysical return *this; } -inline FGPhysicalProperties& FGPhysicalProperties::operator *= ( const WeatherPrecition& d ) +inline FGPhysicalProperties& FGPhysicalProperties::operator *= ( const WeatherPrecision d ) { - typedef map::iterator vector_iterator; - typedef map::iterator scalar_iterator; - - for (vector_iterator WindIt = Wind.begin(); - WindIt != Wind.end(); - WindIt++) - WindIt->second *= d; - - for (vector_iterator TurbulenceIt = Turbulence.begin(); - TurbulenceIt != Turbulence.end(); - TurbulenceIt++) - TurbulenceIt->second *= d; - - for (scalar_iterator TemperatureIt = Temperature.begin(); - TemperatureIt != Temperature.end(); - TemperatureIt++) + typedef map::iterator wind_iterator; + typedef map::iterator turbulence_iterator; + typedef map::iterator scalar_iterator; + + for (wind_iterator WindIt = Wind.begin(); + WindIt != Wind.end(); + WindIt++) + WindIt->second*= d; + + for (turbulence_iterator TurbulenceIt = Turbulence.begin(); + TurbulenceIt != Turbulence.end(); + TurbulenceIt++) + TurbulenceIt->second *= d; + + for (scalar_iterator TemperatureIt = Temperature.begin(); + TemperatureIt != Temperature.end(); + TemperatureIt++) TemperatureIt->second *= d; AirPressure *= d; - for (scalar_iterator VaporPressureIt = VaporPressure.begin(); - VaporPressureIt != VaporPressure.end(); - VaporPressureIt++) + for (scalar_iterator VaporPressureIt = VaporPressure.begin(); + VaporPressureIt != VaporPressure.end(); + VaporPressureIt++) VaporPressureIt->second *= d; return *this; @@ -211,32 +226,33 @@ inline FGPhysicalProperties& FGPhysicalProperties::operator *= ( const WeatherPr inline FGPhysicalProperties& FGPhysicalProperties::operator += (const FGPhysicalProperties& p) { - typedef map::const_iterator vector_iterator; - typedef map::const_iterator scalar_iterator; + typedef map::const_iterator wind_iterator; + typedef map::const_iterator turbulence_iterator; + typedef map::const_iterator scalar_iterator; - for (vector_iterator WindIt = p.Wind.begin(); - WindIt != p.Wind.end(); - WindIt++ ) + for (wind_iterator WindIt = p.Wind.begin(); + WindIt != p.Wind.end(); + WindIt++) if (!Wind.insert(*WindIt).second) //when it's not inserted => it's already existing Wind[WindIt->first] += WindIt->second; //=> add the value - for (vector_iterator TurbulenceIt = p.Turbulence.begin(); - TurbulenceIt != p.Turbulence.end(); - TurbulenceIt++) + for (turbulence_iterator TurbulenceIt = p.Turbulence.begin(); + TurbulenceIt != p.Turbulence.end(); + TurbulenceIt++) if (!Turbulence.insert(*TurbulenceIt).second) Turbulence[TurbulenceIt->first] += TurbulenceIt->second; - - for (scalar_iterator TemperatureIt = p.Temperature.begin(); - TemperatureIt != p.Temperature.end(); - TemperatureIt++) + + for (scalar_iterator TemperatureIt = p.Temperature.begin(); + TemperatureIt != p.Temperature.end(); + TemperatureIt++) if (!Temperature.insert(*TemperatureIt).second) Temperature[TemperatureIt->first] += TemperatureIt->second; AirPressure += p.AirPressure.getValue(0.0); - for (scalar_iterator VaporPressureIt = p.VaporPressure.begin(); - VaporPressureIt != p.VaporPressure.end(); - VaporPressureIt++) + for (scalar_iterator VaporPressureIt = p.VaporPressure.begin(); + VaporPressureIt != p.VaporPressure.end(); + VaporPressureIt++) if (!VaporPressure.insert(*VaporPressureIt).second) VaporPressure[VaporPressureIt->first] += VaporPressureIt->second; @@ -245,32 +261,33 @@ inline FGPhysicalProperties& FGPhysicalProperties::operator += (const FGPhysical inline FGPhysicalProperties& FGPhysicalProperties::operator -= (const FGPhysicalProperties& p) { - typedef map::const_iterator vector_iterator; - typedef map::const_iterator scalar_iterator; + typedef map::const_iterator wind_iterator; + typedef map::const_iterator turbulence_iterator; + typedef map::const_iterator scalar_iterator; - for (vector_iterator WindIt = p.Wind.begin(); - WindIt != p.Wind.end(); - WindIt++ ) + for (wind_iterator WindIt = p.Wind.begin(); + WindIt != p.Wind.end(); + WindIt++) if (!Wind.insert( make_pair(WindIt->first, -WindIt->second) ).second) //when it's not inserted => it's already existing Wind[WindIt->first] -= WindIt->second; //=> substract the value - for (vector_iterator TurbulenceIt = p.Turbulence.begin(); - TurbulenceIt != p.Turbulence.end(); - TurbulenceIt++) + for (turbulence_iterator TurbulenceIt = p.Turbulence.begin(); + TurbulenceIt != p.Turbulence.end(); + TurbulenceIt++) if (!Turbulence.insert( make_pair(TurbulenceIt->first, -TurbulenceIt->second) ).second) Turbulence[TurbulenceIt->first] -= TurbulenceIt->second; - for (scalar_iterator TemperatureIt = p.Temperature.begin(); - TemperatureIt != p.Temperature.end(); - TemperatureIt++) + for (scalar_iterator TemperatureIt = p.Temperature.begin(); + TemperatureIt != p.Temperature.end(); + TemperatureIt++) if (!Temperature.insert( make_pair(TemperatureIt->first, -TemperatureIt->second) ).second) Temperature[TemperatureIt->first] -= TemperatureIt->second; AirPressure -= p.AirPressure.getValue(0.0); - for (scalar_iterator VaporPressureIt = p.VaporPressure.begin(); - VaporPressureIt != p.VaporPressure.end(); - VaporPressureIt++) + for (scalar_iterator VaporPressureIt = p.VaporPressure.begin(); + VaporPressureIt != p.VaporPressure.end(); + VaporPressureIt++) if (!VaporPressure.insert( make_pair(VaporPressureIt->first, -VaporPressureIt->second) ).second) VaporPressure[VaporPressureIt->first] -= VaporPressureIt->second; @@ -279,33 +296,37 @@ inline FGPhysicalProperties& FGPhysicalProperties::operator -= (const FGPhysical } -inline Point3D FGPhysicalProperties::WindAt(const WeatherPrecition& a) const +inline void FGPhysicalProperties::WindAt(sgVec3 ret, const WeatherPrecision a) const { - typedef map::const_iterator vector_iterator; + typedef map::const_iterator vector_iterator; vector_iterator it = Wind.lower_bound(a); vector_iterator it2 = it; it--; //now I've got it->alt < a < it2->alt so I can interpolate - return ( (it2->second - it->second)/(it2->first - it->first) ) * (a - it2->first) + it2->second; + sgSubVec3(ret, *it2->second.getValue(), *it->second.getValue()); + sgScaleVec3(ret, (a - it2->first) / (it2->first - it->first)); + sgAddVec3(ret, *it2->second.getValue()); } -inline Point3D FGPhysicalProperties::TurbulenceAt(const WeatherPrecition& a) const +inline void FGPhysicalProperties::TurbulenceAt(sgVec3 ret, const WeatherPrecision a) const { - typedef map::const_iterator vector_iterator; + typedef map::const_iterator vector_iterator; vector_iterator it = Turbulence.lower_bound(a); vector_iterator it2 = it; it--; //now I've got it->alt < a < it2->alt so I can interpolate - return ( (it2->second - it->second)/(it2->first - it->first) ) * (a - it2->first) + it2->second; + sgSubVec3(ret, *it2->second.getValue(), *it->second.getValue()); + sgScaleVec3(ret, (a - it2->first) / (it2->first - it->first)); + sgAddVec3(ret, *it2->second.getValue()); } -inline WeatherPrecition FGPhysicalProperties::TemperatureAt(const WeatherPrecition& a) const +inline WeatherPrecision FGPhysicalProperties::TemperatureAt(const WeatherPrecision a) const { - typedef map::const_iterator scalar_iterator; + typedef map::const_iterator scalar_iterator; scalar_iterator it = Temperature.lower_bound(a); scalar_iterator it2 = it; @@ -315,14 +336,14 @@ inline WeatherPrecition FGPhysicalProperties::TemperatureAt(const WeatherPreciti return ( (it2->second - it->second)/(it2->first - it->first) ) * (a - it2->first) + it2->second; } -inline WeatherPrecition FGPhysicalProperties::AirPressureAt(const WeatherPrecition& a) const +inline WeatherPrecision FGPhysicalProperties::AirPressureAt(const WeatherPrecision a) const { return AirPressure.getValue(a); } -inline WeatherPrecition FGPhysicalProperties::VaporPressureAt(const WeatherPrecition& a) const +inline WeatherPrecision FGPhysicalProperties::VaporPressureAt(const WeatherPrecision a) const { - typedef map::const_iterator scalar_iterator; + typedef map::const_iterator scalar_iterator; scalar_iterator it = VaporPressure.lower_bound(a); scalar_iterator it2 = it; @@ -333,12 +354,12 @@ inline WeatherPrecition FGPhysicalProperties::VaporPressureAt(const WeatherPreci } -inline FGPhysicalProperties operator * (FGPhysicalProperties a, const WeatherPrecition& b) +inline FGPhysicalProperties operator * (FGPhysicalProperties a, const WeatherPrecision b) { return a *= b; } -inline FGPhysicalProperties operator * (const WeatherPrecition& b, FGPhysicalProperties a) +inline FGPhysicalProperties operator * (const WeatherPrecision b, FGPhysicalProperties a) { return a *= b; } diff --git a/src/WeatherCM/FGPhysicalProperty.cpp b/src/WeatherCM/FGPhysicalProperty.cpp index a28c27caa..54c4a4879 100644 --- a/src/WeatherCM/FGPhysicalProperty.cpp +++ b/src/WeatherCM/FGPhysicalProperty.cpp @@ -5,7 +5,7 @@ Date started: 28.05.99 Called by: main program - ---------- Copyright (C) 1999 Christian Mayer (vader@t-online.de) ---------- + -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) -------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -35,36 +35,34 @@ HISTORY 20.06.1999 Christian Mayer added lots of consts 11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's suggestion +19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D + and lots of wee code cleaning *****************************************************************************/ /****************************************************************************/ /* INCLUDES */ /****************************************************************************/ -#include "FGPhysicalProperty.h" #include "FGWeatherDefs.h" +#include "FGPhysicalProperty.h" /****************************************************************************/ /********************************** CODE ************************************/ /****************************************************************************/ FGPhysicalProperty::FGPhysicalProperty() { - Wind.setx(0.0); //Wind vector - Wind.sety(0.0); //Wind vector - Wind.setz(0.0); //Wind vector + sgZeroVec3(Wind); //Wind vector - Turbulence.setx(0.0); //Turbulence vector - Turbulence.sety(0.0); //Turbulence vector - Turbulence.setz(0.0); //Turbulence vector + sgZeroVec3(Turbulence); //Turbulence vector Temperature = FG_WEATHER_DEFAULT_TEMPERATURE; //a nice warm day AirPressure = FG_WEATHER_DEFAULT_AIRPRESSURE; //mbar, that's ground level VaporPressure = FG_WEATHER_DEFAULT_VAPORPRESSURE; //that gives about 50% relatvie humidity } -FGPhysicalProperty::FGPhysicalProperty(const FGPhysicalProperties& p, const WeatherPrecition& altitude) +FGPhysicalProperty::FGPhysicalProperty(const FGPhysicalProperties& p, const WeatherPrecision altitude) { - Wind = p.WindAt(altitude); - Turbulence = p.TurbulenceAt(altitude); + p.WindAt(Wind, altitude); + p.TurbulenceAt(Turbulence, altitude); Temperature = p.TemperatureAt(altitude); AirPressure = p.AirPressureAt(altitude); VaporPressure = p.VaporPressureAt(altitude); diff --git a/src/WeatherCM/FGPhysicalProperty.h b/src/WeatherCM/FGPhysicalProperty.h index 3452dfdf3..e54658803 100644 --- a/src/WeatherCM/FGPhysicalProperty.h +++ b/src/WeatherCM/FGPhysicalProperty.h @@ -4,7 +4,7 @@ Author: Christian Mayer Date started: 28.05.99 - ---------- Copyright (C) 1999 Christian Mayer (vader@t-online.de) ---------- + -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) -------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -36,6 +36,8 @@ HISTORY 30.06.1999 Christian Mayer STL portability 11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's suggestion +19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D + and lots of wee code cleaning *****************************************************************************/ /****************************************************************************/ @@ -48,63 +50,68 @@ HISTORY /* INCLUDES */ /****************************************************************************/ #include + #include -FG_USING_STD(vector); -FG_USING_NAMESPACE(std); -#include -#include +#include "sg.h" + #include "FGWeatherDefs.h" #include "FGPhysicalProperties.h" +FG_USING_STD(vector); +FG_USING_NAMESPACE(std); + /****************************************************************************/ /* used for output: */ /****************************************************************************/ +class FGPhysicalProperty; +bool operator == (const FGPhysicalProperty& a, const FGPhysicalProperty& b); // p1 == p2? + class FGPhysicalProperty { private: protected: public: - Point3D Wind; //Wind vector - Point3D Turbulence; //Turbulence vector - WeatherPrecition Temperature; //in deg. Kelvin (I *only* accept SI!) - WeatherPrecition AirPressure; //in Pascal (I *only* accept SI!) - WeatherPrecition VaporPressure; //in Pascal (I *only* accept SI!) + sgVec3 Wind; //Wind vector + sgVec3 Turbulence; //Turbulence vector + WeatherPrecision Temperature; //in deg. Kelvin (I *only* accept SI!) + WeatherPrecision AirPressure; //in Pascal (I *only* accept SI!) + WeatherPrecision VaporPressure; //in Pascal (I *only* accept SI!) FGPhysicalProperty(); //consructor to fill it with FG standart weather - FGPhysicalProperty(const FGPhysicalProperties& p, const WeatherPrecition& altitude); + FGPhysicalProperty(const FGPhysicalProperties& p, const WeatherPrecision altitude); //allow calculations for easier handling such as interpolating - FGPhysicalProperty& operator = ( const FGPhysicalProperty& p ); // assignment of a Point3D - FGPhysicalProperty& operator += ( const FGPhysicalProperty& p ); // incrementation by a Point3D - FGPhysicalProperty& operator -= ( const FGPhysicalProperty& p ); // decrementation by a Point3D - FGPhysicalProperty& operator *= ( const double& d ); // multiplication by a constant - FGPhysicalProperty& operator /= ( const double& d ); // division by a constant - - friend FGPhysicalProperty operator - (const FGPhysicalProperty& p); // -p1 - friend bool operator == (const FGPhysicalProperty& a, const FGPhysicalProperty& b); // p1 == p2? + FGPhysicalProperty& operator = ( const FGPhysicalProperty& p ); // assignment of a FGPhysicalProperty + FGPhysicalProperty& operator += ( const FGPhysicalProperty& p ); // incrementation by a FGPhysicalProperty + FGPhysicalProperty& operator -= ( const FGPhysicalProperty& p ); // decrementation by a FGPhysicalProperty + FGPhysicalProperty& operator *= ( const double d ); // multiplication by a constant + FGPhysicalProperty& operator /= ( const double d ); // division by a constant + + friend FGPhysicalProperty operator - (const FGPhysicalProperty& p); // -p1 + friend bool operator == (const FGPhysicalProperty& a, const FGPhysicalProperty& b); // p1 == p2? }; -typedef vector FGPhysicalPropertyVector; -typedef FGPhysicalPropertyVector::iterator FGPhysicalPropertyVectorIt; -typedef FGPhysicalPropertyVector::const_iterator FGPhysicalPropertyVectorConstIt; - class FGPhysicalProperty3D : public FGPhysicalProperty { private: protected: public: - Point3D p; //position of the property (lat/lon/alt) + sgVec3 p; //position of the property (lat/lon/alt) }; -typedef vector FGPhysicalProperty3DVector; -typedef FGPhysicalProperty3DVector::iterator FGPhysicalProperty3DVectorIt; +typedef vector FGPhysicalPropertyVector; +typedef FGPhysicalPropertyVector::iterator FGPhysicalPropertyVectorIt; +typedef FGPhysicalPropertyVector::const_iterator FGPhysicalPropertyVectorConstIt; + +typedef vector FGPhysicalProperty3DVector; +typedef FGPhysicalProperty3DVector::iterator FGPhysicalProperty3DVectorIt; typedef FGPhysicalProperty3DVector::const_iterator FGPhysicalProperty3DVectorConstIt; inline FGPhysicalProperty& FGPhysicalProperty::operator = ( const FGPhysicalProperty& p ) { - Wind = p.Wind; - Turbulence = p.Turbulence; + sgCopyVec3(Wind, p.Wind); + sgCopyVec3(Turbulence, p.Turbulence); Temperature = p.Temperature; AirPressure = p.AirPressure; VaporPressure = p.VaporPressure; @@ -113,8 +120,8 @@ inline FGPhysicalProperty& FGPhysicalProperty::operator = ( const FGPhysicalProp inline FGPhysicalProperty& FGPhysicalProperty::operator += ( const FGPhysicalProperty& p ) { - Wind += p.Wind; - Turbulence += p.Turbulence; + sgAddVec3(Wind, p.Wind); + sgAddVec3(Turbulence, p.Turbulence); Temperature += p.Temperature; AirPressure += p.AirPressure; VaporPressure += p.VaporPressure; @@ -123,28 +130,28 @@ inline FGPhysicalProperty& FGPhysicalProperty::operator += ( const FGPhysicalPro inline FGPhysicalProperty& FGPhysicalProperty::operator -= ( const FGPhysicalProperty& p ) { - Wind -= p.Wind; - Turbulence -= p.Turbulence; + sgSubVec3(Wind, p.Wind); + sgSubVec3(Turbulence, p.Turbulence); Temperature -= p.Temperature; AirPressure -= p.AirPressure; VaporPressure -= p.VaporPressure; return *this; } -inline FGPhysicalProperty& FGPhysicalProperty::operator *= ( const double& d ) +inline FGPhysicalProperty& FGPhysicalProperty::operator *= ( const double d ) { - Wind *= d; - Turbulence *= d; + sgScaleVec3(Wind, d); + sgScaleVec3(Turbulence, d); Temperature *= d; AirPressure *= d; VaporPressure *= d; return *this; } -inline FGPhysicalProperty& FGPhysicalProperty::operator /= ( const double& d ) +inline FGPhysicalProperty& FGPhysicalProperty::operator /= ( const double d ) { - Wind /= d; - Turbulence /= d; + sgScaleVec3(Wind, 1.0 / d); + sgScaleVec3(Turbulence, 1.0 / d); Temperature /= d; AirPressure /= d; VaporPressure /= d; @@ -154,8 +161,8 @@ inline FGPhysicalProperty& FGPhysicalProperty::operator /= ( const double& d ) inline FGPhysicalProperty operator - (const FGPhysicalProperty& p) { FGPhysicalProperty x; - x.Wind = -p.Wind; - x.Turbulence = -p.Turbulence; + sgNegateVec3(x.Wind, p.Wind); + sgNegateVec3(x.Turbulence, p.Turbulence); x.Temperature = -p.Temperature; x.AirPressure = -p.AirPressure; x.VaporPressure = -p.VaporPressure; @@ -165,8 +172,8 @@ inline FGPhysicalProperty operator - (const FGPhysicalProperty& p) inline bool operator == (const FGPhysicalProperty& a, const FGPhysicalProperty& b) { return ( - (a.Wind == b.Wind) && - (a.Turbulence == b.Turbulence) && + sgEqualVec3(a.Wind, b.Wind) && + sgEqualVec3(a.Turbulence, b.Turbulence) && (a.Temperature == b.Temperature) && (a.AirPressure == b.AirPressure) && (a.VaporPressure == b.VaporPressure)); @@ -187,21 +194,20 @@ inline FGPhysicalProperty operator - (const FGPhysicalProperty& a, const FGPhysi return FGPhysicalProperty(a) -= b; } -inline FGPhysicalProperty operator * (const FGPhysicalProperty& a, const WeatherPrecition& b) +inline FGPhysicalProperty operator * (const FGPhysicalProperty& a, const WeatherPrecision b) { return FGPhysicalProperty(a) *= b; } -inline FGPhysicalProperty operator * (const WeatherPrecition& b, const FGPhysicalProperty& a) +inline FGPhysicalProperty operator * (const WeatherPrecision b, const FGPhysicalProperty& a) { return FGPhysicalProperty(a) *= b; } -inline FGPhysicalProperty operator / (const FGPhysicalProperty& a, const WeatherPrecition& b) +inline FGPhysicalProperty operator / (const FGPhysicalProperty& a, const WeatherPrecision b) { return FGPhysicalProperty(a) *= (1.0/b); } - /****************************************************************************/ #endif /*FGPhysicalProperty_H*/ diff --git a/src/WeatherCM/FGSnowRain.h b/src/WeatherCM/FGSnowRain.h index 6cdd0079d..b1dd713d4 100644 --- a/src/WeatherCM/FGSnowRain.h +++ b/src/WeatherCM/FGSnowRain.h @@ -4,7 +4,7 @@ Author: Christian Mayer Date started: 28.05.99 - ---------- Copyright (C) 1999 Christian Mayer (vader@t-online.de) ---------- + -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) -------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -34,6 +34,8 @@ HISTORY 20.06.1999 Christian Mayer added lots of consts 11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's suggestion +19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D + and lots of wee code cleaning *****************************************************************************/ /****************************************************************************/ diff --git a/src/WeatherCM/FGTemperatureItem.h b/src/WeatherCM/FGTemperatureItem.h index 063acbf1f..8e519902a 100644 --- a/src/WeatherCM/FGTemperatureItem.h +++ b/src/WeatherCM/FGTemperatureItem.h @@ -48,7 +48,7 @@ HISTORY /****************************************************************************/ #include "FGWeatherDefs.h" -//for the case that mutable isn't supported: +// for the case that mutable isn't supported: #include "Include/compiler.h" /****************************************************************************/ @@ -63,20 +63,20 @@ FGTemperatureItem operator-(const FGTemperatureItem& arg); class FGTemperatureItem { private: - mutable WeatherPrecition value; - WeatherPrecition alt; + mutable WeatherPrecision value; + WeatherPrecision alt; protected: public: - FGTemperatureItem(const WeatherPrecition& a, const WeatherPrecition& v) {alt = a; value = v;} - FGTemperatureItem(const WeatherPrecition& v) {alt = 0.0; value = v;} - FGTemperatureItem() {alt = 0.0; value = (WeatherPrecition)FG_WEATHER_DEFAULT_TEMPERATURE;} + FGTemperatureItem(const WeatherPrecision& a, const WeatherPrecision& v) {alt = a; value = v;} + FGTemperatureItem(const WeatherPrecision& v) {alt = 0.0; value = v;} + FGTemperatureItem() {alt = 0.0; value = (WeatherPrecision)FG_WEATHER_DEFAULT_TEMPERATURE;} - WeatherPrecition getValue() const { return value; }; - WeatherPrecition getAlt() const { return alt; }; + WeatherPrecision getValue() const { return value; }; + WeatherPrecision getAlt() const { return alt; }; - FGTemperatureItem& operator*= (const WeatherPrecition& arg); + FGTemperatureItem& operator*= (const WeatherPrecision& arg); FGTemperatureItem& operator+= (const FGTemperatureItem& arg); FGTemperatureItem& operator-= (const FGTemperatureItem& arg); @@ -85,7 +85,7 @@ public: }; -inline FGTemperatureItem& FGTemperatureItem::operator*= (const WeatherPrecition& arg) +inline FGTemperatureItem& FGTemperatureItem::operator*= (const WeatherPrecision& arg) { value *= arg; return *this; diff --git a/src/WeatherCM/FGTurbulenceItem.cpp b/src/WeatherCM/FGTurbulenceItem.cpp index 8595b4ad1..0b66fd32e 100644 --- a/src/WeatherCM/FGTurbulenceItem.cpp +++ b/src/WeatherCM/FGTurbulenceItem.cpp @@ -5,7 +5,7 @@ Date started: 28.05.99 Called by: FGMicroWeather - ---------- Copyright (C) 1999 Christian Mayer (vader@t-online.de) ---------- + -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) -------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -35,6 +35,8 @@ HISTORY 20.06.1999 Christian Mayer added lots of consts 11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's suggestion +19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D + and lots of wee code cleaning *****************************************************************************/ /****************************************************************************/ @@ -45,8 +47,4 @@ HISTORY /****************************************************************************/ /********************************** CODE ************************************/ /****************************************************************************/ -bool operator<(const FGTurbulenceItem& arg1, const FGTurbulenceItem& arg2) -{ - return arg1.alt < arg2.alt; -} diff --git a/src/WeatherCM/FGTurbulenceItem.h b/src/WeatherCM/FGTurbulenceItem.h index 4cc927a61..2b9fa3c7c 100644 --- a/src/WeatherCM/FGTurbulenceItem.h +++ b/src/WeatherCM/FGTurbulenceItem.h @@ -4,7 +4,7 @@ Author: Christian Mayer Date started: 28.05.99 - ---------- Copyright (C) 1999 Christian Mayer (vader@t-online.de) ---------- + -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) -------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -32,9 +32,10 @@ HISTORY 28.05.1999 Christian Mayer Created 16.06.1999 Durk Talsma Portability for Linux 20.06.1999 Christian Mayer added lots of consts -10.10.1999 Christian Mayer added mutable for gcc 2.95 portability 11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's suggestion +19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D + and lots of wee code cleaning *****************************************************************************/ /****************************************************************************/ @@ -46,12 +47,10 @@ HISTORY /****************************************************************************/ /* INCLUDES */ /****************************************************************************/ -#include +#include "sg.h" + #include "FGWeatherDefs.h" -//for the case that mutable isn't supported: -#include "Include/compiler.h" - /****************************************************************************/ /* DEFINES */ /****************************************************************************/ @@ -64,48 +63,52 @@ FGTurbulenceItem operator-(const FGTurbulenceItem& arg); class FGTurbulenceItem { private: - mutable Point3D value; - WeatherPrecition alt; + sgVec3 value; protected: public: - FGTurbulenceItem(const WeatherPrecition& a, const Point3D& v) {alt = a; value = v;} - FGTurbulenceItem(const Point3D& v) {alt = 0.0; value = v;} - FGTurbulenceItem() {alt = 0.0; value = Point3D(0.0);} + FGTurbulenceItem(const sgVec3& v) { sgCopyVec3(value, v);} + FGTurbulenceItem() { sgZeroVec3(value); } + + void getValue(sgVec3 ret) const { sgCopyVec3(ret, value); }; + const sgVec3* getValue(void) const { return &value; }; - Point3D getValue() const { return value; }; - WeatherPrecition getAlt() const { return alt; }; + WeatherPrecision x(void) const { return value[0]; }; + WeatherPrecision y(void) const { return value[1]; }; + WeatherPrecision z(void) const { return value[2]; }; - FGTurbulenceItem& operator*= (const WeatherPrecition& arg); + FGTurbulenceItem& operator*= (const WeatherPrecision arg); FGTurbulenceItem& operator+= (const FGTurbulenceItem& arg); FGTurbulenceItem& operator-= (const FGTurbulenceItem& arg); - friend bool operator<(const FGTurbulenceItem& arg1, const FGTurbulenceItem& arg2 ); friend FGTurbulenceItem operator-(const FGTurbulenceItem& arg); - }; -inline FGTurbulenceItem& FGTurbulenceItem::operator*= (const WeatherPrecition& arg) +inline FGTurbulenceItem& FGTurbulenceItem::operator*= (const WeatherPrecision arg) { - value *= arg; + sgScaleVec3(value, arg); return *this; } inline FGTurbulenceItem& FGTurbulenceItem::operator+= (const FGTurbulenceItem& arg) { - value += arg.value; + sgAddVec3(value, *arg.getValue()); return *this; } inline FGTurbulenceItem& FGTurbulenceItem::operator-= (const FGTurbulenceItem& arg) { - value -= arg.value; + sgSubVec3(value, *arg.getValue()); return *this; } inline FGTurbulenceItem operator-(const FGTurbulenceItem& arg) { - return FGTurbulenceItem(arg.alt, -arg.value); + sgVec3 temp; + + sgNegateVec3(temp, *arg.getValue()); + + return FGTurbulenceItem(temp); } /****************************************************************************/ diff --git a/src/WeatherCM/FGVaporPressureItem.h b/src/WeatherCM/FGVaporPressureItem.h index 1a990e1e9..d9709aafb 100644 --- a/src/WeatherCM/FGVaporPressureItem.h +++ b/src/WeatherCM/FGVaporPressureItem.h @@ -63,20 +63,20 @@ FGVaporPressureItem operator-(const FGVaporPressureItem& arg); class FGVaporPressureItem { private: - mutable WeatherPrecition value; - WeatherPrecition alt; + mutable WeatherPrecision value; + WeatherPrecision alt; protected: public: - FGVaporPressureItem(const WeatherPrecition& a, const WeatherPrecition& v) {alt = a; value = v;} - FGVaporPressureItem(const WeatherPrecition& v) {alt = 0.0; value = v;} + FGVaporPressureItem(const WeatherPrecision& a, const WeatherPrecision& v) {alt = a; value = v;} + FGVaporPressureItem(const WeatherPrecision& v) {alt = 0.0; value = v;} FGVaporPressureItem() {alt = 0.0; value = FG_WEATHER_DEFAULT_VAPORPRESSURE;} - WeatherPrecition getValue() const { return value; }; - WeatherPrecition getAlt() const { return alt; }; + WeatherPrecision getValue() const { return value; }; + WeatherPrecision getAlt() const { return alt; }; - FGVaporPressureItem& operator*= (const WeatherPrecition& arg); + FGVaporPressureItem& operator*= (const WeatherPrecision& arg); FGVaporPressureItem& operator+= (const FGVaporPressureItem& arg); FGVaporPressureItem& operator-= (const FGVaporPressureItem& arg); @@ -85,7 +85,7 @@ public: }; -inline FGVaporPressureItem& FGVaporPressureItem::operator*= (const WeatherPrecition& arg) +inline FGVaporPressureItem& FGVaporPressureItem::operator*= (const WeatherPrecision& arg) { value *= arg; return *this; diff --git a/src/WeatherCM/FGVoronoi.cpp b/src/WeatherCM/FGVoronoi.cpp index f645d19fc..903b23f19 100644 --- a/src/WeatherCM/FGVoronoi.cpp +++ b/src/WeatherCM/FGVoronoi.cpp @@ -3,9 +3,8 @@ Module: FGVoronoi.cpp Author: Christian Mayer Date started: 28.05.99 - Called by: main program - ---------- Copyright (C) 1999 Christian Mayer (vader@t-online.de) ---------- + -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) -------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -38,6 +37,8 @@ HISTORY 16.06.99 Durk Talsma Portability for Linux 11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's suggestion +19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D + and lots of wee code cleaning *****************************************************************************/ /****************************************************************************/ @@ -67,12 +68,12 @@ FGVoronoiOutputList Voronoiate(const FGVoronoiInputList& input) PointList p2ds; - FGVoronoiInputList::iterator it1; + FGVoronoiInputList::const_iterator it1; //get the points - for (it1 = (FGVoronoiInputList::iterator)input.begin(); it1 != input.end(); it1++) + for (it1 = input.begin(); it1 != input.end(); it1++) { - p2ds.push_back(VoronoiPoint(it1->position.x(), it1->position.y())); + p2ds.push_back(VoronoiPoint(it1->position[0], it1->position[1])); } cl.clear(); //make sure that it's empty @@ -104,28 +105,35 @@ FGVoronoiOutputList Voronoiate(const FGVoronoiInputList& input) PointList::iterator it3 = it2->boundary.begin(); if (it3->infinity == false) - boundary.push_back( *it3 ); + boundary.push_back( sgVec2Wrap(it3->p) ); else { - Point2D direction_vector = *it3; + sgVec2 direction_vector; + sgCopyVec2(direction_vector, it3->p); + it3++; - boundary.push_back( (*it3) + direction_vector); + sgAddVec2(direction_vector, it3->p); + + boundary.push_back( direction_vector ); } for (; it3 != it2->boundary.end(); it3++) { - boundary.push_back( *it3 ); + boundary.push_back( sgVec2Wrap(it3->p) ); } it3--; if (it3->infinity == true) { - Point2D direction_vector = *it3; + sgVec2 direction_vector; + sgCopyVec2(direction_vector, it3->p); + it3--; - Point2D value = *it3; + sgAddVec2(direction_vector, it3->p); + boundary.pop_back(); - boundary.push_back(value + direction_vector); + boundary.push_back(direction_vector); } ret_list.push_back(FGVoronoiOutput(boundary, input[it2->ID].value)); @@ -182,8 +190,8 @@ bool readsites(PointList input) while(It != input.end()) { - sites[nsites].coord.x = It->x(); - sites[nsites].coord.y = It->y(); + sites[nsites].coord.x = It->p[0]; + sites[nsites].coord.y = It->p[1]; sites[nsites].sitenbr = nsites; sites[nsites].refcnt = 0; diff --git a/src/WeatherCM/FGVoronoi.h b/src/WeatherCM/FGVoronoi.h index 178e0efc3..c96894ee1 100644 --- a/src/WeatherCM/FGVoronoi.h +++ b/src/WeatherCM/FGVoronoi.h @@ -4,7 +4,7 @@ Author: Christian Mayer Date started: 28.05.99 - ---------- Copyright (C) 1999 Christian Mayer (vader@t-online.de) ---------- + -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) -------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -39,6 +39,8 @@ HISTORY 30.06.1999 Christian Mayer STL portability 11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's suggestion +19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D + and lots of wee code cleaning *****************************************************************************/ /****************************************************************************/ @@ -51,27 +53,32 @@ HISTORY /* INCLUDES */ /****************************************************************************/ #include "compiler.h" + #include -#include -#include +#include "sg.h" + +#include "FGWeatherVectorWrap.h" #include "FGPhysicalProperties.h" /****************************************************************************/ /* DEFINES */ /****************************************************************************/ FG_USING_STD(vector); -FG_USING_STD(set); FG_USING_NAMESPACE(std); -typedef vector Point2DList; +typedef vector Point2DList; struct FGVoronoiInput { - Point2D position; + sgVec2 position; FGPhysicalProperties2D value; - FGVoronoiInput(const Point2D& p, const FGPhysicalProperties2D& v) { position = p; value = v; } + FGVoronoiInput(const sgVec2& p, const FGPhysicalProperties2D& v) + { + sgCopyVec2(position, p); + value = v; + } }; struct FGVoronoiOutput @@ -79,10 +86,14 @@ struct FGVoronoiOutput Point2DList boundary; FGPhysicalProperties2D value; - FGVoronoiOutput(const Point2DList& b, const FGPhysicalProperties2D& v) {boundary = b; value = v;}; + FGVoronoiOutput(const Point2DList& b, const FGPhysicalProperties2D& v) + { + boundary = b; + value = v; + }; }; -typedef vector FGVoronoiInputList; +typedef vector FGVoronoiInputList; typedef vector FGVoronoiOutputList; /****************************************************************************/ diff --git a/src/WeatherCM/FGWeatherDefs.h b/src/WeatherCM/FGWeatherDefs.h index 8b3063bd3..49a6c774f 100644 --- a/src/WeatherCM/FGWeatherDefs.h +++ b/src/WeatherCM/FGWeatherDefs.h @@ -4,7 +4,7 @@ Author: Christian Mayer Date started: 28.05.99 - ---------- Copyright (C) 1999 Christian Mayer (vader@t-online.de) ---------- + -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) -------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -34,6 +34,8 @@ HISTORY 20.06.1999 Christian Mayer added lots of consts 11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's suggestion +19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D + and lots of wee code cleaning *****************************************************************************/ /****************************************************************************/ @@ -49,7 +51,7 @@ HISTORY /****************************************************************************/ /* DEFINES */ /****************************************************************************/ -typedef float WeatherPrecition; +typedef float WeatherPrecision; //set the minimum visibility to get a at least half way realistic weather #define MINIMUM_WEATHER_VISIBILIY 10.0 /* metres */ @@ -57,10 +59,11 @@ typedef float WeatherPrecition; //prefered way the database is working #define PREFERED_WORKING_TYPE default_mode -#define FG_WEATHER_DEFAULT_TEMPERATURE (15.0+273.16) /*15°C or 288.16°K*/ +#define FG_WEATHER_DEFAULT_TEMPERATURE (15.0+273.16) /*15°C or 288.16°K*/ #define FG_WEATHER_DEFAULT_VAPORPRESSURE (0.0) /*in Pascal 1 Pa = N/m^2*/ -#define FG_WEATHER_DEFAULT_AIRPRESSURE (1013.25*100.0) /*in Pascal 1 Pa = N/m^2*/ -#define FG_WEATHER_DEFAULT_AIRDENSITY (1.22501) /*in kg/m^3*/ +#define FG_WEATHER_DEFAULT_AIRPRESSURE (1013.25*100.0) /*in Pascal 1 Pa = N/m^2*/ +#define FG_WEATHER_DEFAULT_AIRDENSITY (1.22501) /*in kg/m^3*/ + /****************************************************************************/ /* CLASS DECLARATION */ /****************************************************************************/ diff --git a/src/WeatherCM/FGWeatherFeature.h b/src/WeatherCM/FGWeatherFeature.h index c0a261ad9..4f5836744 100644 --- a/src/WeatherCM/FGWeatherFeature.h +++ b/src/WeatherCM/FGWeatherFeature.h @@ -4,7 +4,7 @@ Author: Christian Mayer Date started: 28.05.99 - ---------- Copyright (C) 1999 Christian Mayer (vader@t-online.de) ---------- + -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) -------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -36,6 +36,8 @@ HISTORY 30.06.1999 Christian Mayer STL portability 11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's suggestion +19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D + and lots of wee code cleaning *****************************************************************************/ /****************************************************************************/ @@ -48,11 +50,9 @@ HISTORY /* INCLUDES */ /****************************************************************************/ #include -#include -FG_USING_STD(vector); -FG_USING_NAMESPACE(std); -#include +#include "sg.h" + #include "FGWeatherDefs.h" /****************************************************************************/ @@ -74,15 +74,15 @@ class FGWeatherFeature { private: protected: - Point3D position; //middle of the feature in lat/lon/alt - WeatherPrecition minSize; //smalest size of the feature + sgVec3 position; //middle of the feature in lat/lon/alt + WeatherPrecision minSize; //smalest size of the feature //=> a disk is specifies LayerType FeatureType; public: - LayerType getFeature(void) const { return FeatureType; } - bool isFeature(const LayerType& f) const {return (f == FeatureType);} + LayerType getFeature(void) const { return FeatureType; } + bool isFeature(const LayerType& f) const { return (f == FeatureType); } }; /****************************************************************************/ diff --git a/src/WeatherCM/FGWeatherUtils.h b/src/WeatherCM/FGWeatherUtils.h index 5e3ca61f8..502120960 100644 --- a/src/WeatherCM/FGWeatherUtils.h +++ b/src/WeatherCM/FGWeatherUtils.h @@ -4,7 +4,7 @@ Author: Christian Mayer Date started: 28.05.99 - ---------- Copyright (C) 1999 Christian Mayer (vader@t-online.de) ---------- + -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) -------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -35,6 +35,8 @@ HISTORY 20.06.1999 Christian Mayer added lots of consts 11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's suggestion +19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D + and lots of wee code cleaning *****************************************************************************/ /****************************************************************************/ @@ -78,7 +80,7 @@ HISTORY #define SAT_VP_CONST2 7.444072452 #define SAT_VP_CONST3 235.3120919 -inline WeatherPrecition sat_vp(const WeatherPrecition& temp) +inline WeatherPrecision sat_vp(const WeatherPrecision temp) { //old: //return 6.112 * pow( 10, (7.5*dp)/(237.7+dp) ); //in mbar @@ -90,21 +92,21 @@ inline WeatherPrecition sat_vp(const WeatherPrecition& temp) return SAT_VP_CONST1 * pow( 10, (SAT_VP_CONST2*temp)/(SAT_VP_CONST3+temp) ); //in pascal } -inline WeatherPrecition rel_hum(const WeatherPrecition& act_vp, const WeatherPrecition& sat_vp) +inline WeatherPrecision rel_hum(const WeatherPrecision act_vp, const WeatherPrecision sat_vp) { return (act_vp / sat_vp) * 100; //in % } -inline WeatherPrecition dp(const WeatherPrecition& sat_vp) +inline WeatherPrecision dp(const WeatherPrecision sat_vp) { return (SAT_VP_CONST3*log10(sat_vp/SAT_VP_CONST1))/(SAT_VP_CONST2-log10(sat_vp/SAT_VP_CONST1)); //in °C } -inline WeatherPrecition wb(const WeatherPrecition& t, const WeatherPrecition& p, const WeatherPrecition& dp) +inline WeatherPrecision wb(const WeatherPrecision t, const WeatherPrecision p, const WeatherPrecision dp) { - WeatherPrecition e = sat_vp(dp); - WeatherPrecition tcur, tcvp, peq, diff; - WeatherPrecition tmin, tmax; + WeatherPrecision e = sat_vp(dp); + WeatherPrecision tcur, tcvp, peq, diff; + WeatherPrecision tmin, tmax; if (t > dp) { @@ -137,37 +139,37 @@ inline WeatherPrecition wb(const WeatherPrecition& t, const WeatherPrecition& p, } -inline WeatherPrecition Celsius(const WeatherPrecition& celsius) +inline WeatherPrecision Celsius(const WeatherPrecision celsius) { return celsius + 273.16; //Kelvin } -inline WeatherPrecition Fahrenheit(const WeatherPrecition& fahrenheit) +inline WeatherPrecision Fahrenheit(const WeatherPrecision fahrenheit) { return (fahrenheit * 9.0 / 5.0) + 32.0 + 273.16; //Kelvin } -inline WeatherPrecition Kelvin2Celsius(const WeatherPrecition& kelvin) +inline WeatherPrecision Kelvin2Celsius(const WeatherPrecision kelvin) { return kelvin - 273.16; //Celsius } -inline WeatherPrecition Kelvin2Fahrenheit(const WeatherPrecition& kelvin) +inline WeatherPrecision Kelvin2Fahrenheit(const WeatherPrecision kelvin) { return ((kelvin - 273.16) * 9.0 / 5.0) + 32.0; //Fahrenheit } -inline WeatherPrecition Celsius2Fahrenheit(const WeatherPrecition& celsius) +inline WeatherPrecision Celsius2Fahrenheit(const WeatherPrecision celsius) { return (celsius * 9.0 / 5.0) + 32.0; //Fahrenheit } -inline WeatherPrecition Fahrenheit2Celsius(const WeatherPrecition& fahrenheit) +inline WeatherPrecision Fahrenheit2Celsius(const WeatherPrecision fahrenheit) { return (fahrenheit - 32.0) * 5.0 / 9.0; //Celsius } -inline WeatherPrecition Torr2Pascal(const WeatherPrecition& torr) +inline WeatherPrecision Torr2Pascal(const WeatherPrecision torr) { return (101325.0/760.0)*torr; } diff --git a/src/WeatherCM/FGWindItem.cpp b/src/WeatherCM/FGWindItem.cpp index 47bcd9d52..88d01345b 100644 --- a/src/WeatherCM/FGWindItem.cpp +++ b/src/WeatherCM/FGWindItem.cpp @@ -5,7 +5,7 @@ Date started: 28.05.99 Called by: FGMicroWeather - ---------- Copyright (C) 1999 Christian Mayer (vader@t-online.de) ---------- + -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) -------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -35,6 +35,8 @@ HISTORY 20.06.1999 Christian Mayer added lots of consts 11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's suggestion +19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D + and lots of wee code cleaning *****************************************************************************/ /****************************************************************************/ @@ -45,8 +47,4 @@ HISTORY /****************************************************************************/ /********************************** CODE ************************************/ /****************************************************************************/ -bool operator<(const FGWindItem& arg1, const FGWindItem& arg2) -{ - return arg1.alt < arg2.alt; -} diff --git a/src/WeatherCM/FGWindItem.h b/src/WeatherCM/FGWindItem.h index 5bd7e9ff7..b06dbd2c5 100644 --- a/src/WeatherCM/FGWindItem.h +++ b/src/WeatherCM/FGWindItem.h @@ -4,7 +4,7 @@ Author: Christian Mayer Date started: 28.05.99 - ---------- Copyright (C) 1999 Christian Mayer (vader@t-online.de) ---------- + -------- Copyright (C) 1999 Christian Mayer (fgfs@christianmayer.de) -------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -32,9 +32,10 @@ HISTORY 28.05.1999 Christian Mayer Created 16.06.1999 Durk Talsma Portability for Linux 20.06.1999 Christian Mayer added lots of consts -10.10.1999 Christian Mayer added mutable for gcc 2.95 portability 11.10.1999 Christian Mayer changed set<> to map<> on Bernie Bright's suggestion +19.10.1999 Christian Mayer change to use PLIB's sg instead of Point[2/3]D + and lots of wee code cleaning *****************************************************************************/ /****************************************************************************/ @@ -46,12 +47,10 @@ HISTORY /****************************************************************************/ /* INCLUDES */ /****************************************************************************/ -#include +#include "sg.h" + #include "FGWeatherDefs.h" -//for the case that mutable isn't supported: -#include "Include/compiler.h" - /****************************************************************************/ /* DEFINES */ /****************************************************************************/ @@ -64,50 +63,55 @@ FGWindItem operator-(const FGWindItem& arg); class FGWindItem { private: - mutable Point3D value; - WeatherPrecition alt; + sgVec3 value; protected: public: - FGWindItem(const WeatherPrecition& a, const Point3D& v) {alt = a; value = v;} - FGWindItem(const Point3D& v) {alt = 0.0; value = v;} - FGWindItem() {alt = 0.0; value = Point3D(0.0);} + FGWindItem(const sgVec3& v) { sgCopyVec3(value, v); } + FGWindItem() { sgZeroVec3(value); } - Point3D getValue() const { return value; }; - WeatherPrecition getAlt() const { return alt; }; + void getValue(sgVec3 ret) const { sgCopyVec3(ret, value); }; + const sgVec3* getValue(void) const { return &value; }; - FGWindItem& operator*= (const WeatherPrecition& arg); - FGWindItem& operator+= (const FGWindItem& arg); - FGWindItem& operator-= (const FGWindItem& arg); + WeatherPrecision x(void) const { return value[0]; }; + WeatherPrecision y(void) const { return value[1]; }; + WeatherPrecision z(void) const { return value[2]; }; - friend bool operator<(const FGWindItem& arg1, const FGWindItem& arg2); - friend FGWindItem operator-(const FGWindItem& arg); + FGWindItem& operator*= (const WeatherPrecision arg); + FGWindItem& operator+= (const FGWindItem& arg); + FGWindItem& operator-= (const FGWindItem& arg); + friend FGWindItem operator-(const FGWindItem& arg); }; -inline FGWindItem& FGWindItem::operator*= (const WeatherPrecition& arg) +inline FGWindItem& FGWindItem::operator*= (const WeatherPrecision arg) { - value *= arg; + sgScaleVec3(value, arg); return *this; } inline FGWindItem& FGWindItem::operator+= (const FGWindItem& arg) { - value += arg.value; + sgAddVec3(value, *arg.getValue()); return *this; } inline FGWindItem& FGWindItem::operator-= (const FGWindItem& arg) { - value -= arg.value; + sgSubVec3(value, *arg.getValue()); return *this; } inline FGWindItem operator-(const FGWindItem& arg) { - return FGWindItem(arg.alt, -arg.value); + sgVec3 temp; + + sgNegateVec3(temp, *arg.getValue()); + + return FGWindItem(temp); } + /****************************************************************************/ #endif /*FGWindItem_H*/