From: curt Date: Thu, 3 Oct 2002 02:52:55 +0000 (+0000) Subject: John Wojnaroski: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=f08ae9f2ea3cee314c749854a09addd9c451ab56;p=simgear.git John Wojnaroski: Attached are the new files to transform the cloud field for local lat/lon. --- diff --git a/simgear/scene/sky/clouds3d/SkyCloud.cpp b/simgear/scene/sky/clouds3d/SkyCloud.cpp index 48275bb3..dedd8044 100644 --- a/simgear/scene/sky/clouds3d/SkyCloud.cpp +++ b/simgear/scene/sky/clouds3d/SkyCloud.cpp @@ -618,92 +618,9 @@ SkyMinMaxBox* SkyCloud::CopyBoundingVolume() const return pBox; } - -//------------------------------------------------------------------------------ -// Function : SkyCloud::Load -// Description : -//------------------------------------------------------------------------------ -/** - * @fn SkyCloud::Load(const SkyArchive &archive, float rScale, bool bLocal) - * @brief Loads the cloud data from @a archive. - * - * If @a rScale does not equal 1.0, then the cloud is scaled by an amount rScale. - */ -SKYRESULT SkyCloud::Load(const SkyArchive &archive, - const sgVec4 *mat, - float rScale /* = 1.0f */, - bool bLocal /* = false */) -{ - unsigned int iNumParticles; - Vec3f vecCenter = Vec3f::ZERO; - //Vec3f vecCenter; - //float rRadius; - //archive.FindVec3f("CldCenter", &vecCenter); - //archive.FindFloat32("CldRadius", &rRadius); - - //_boundingBox.SetMin(vecCenter - Vec3f(rRadius, rRadius, rRadius)); - //_boundingBox.SetMax(vecCenter + Vec3f(rRadius, rRadius, rRadius)); - - archive.FindUInt32("CldNumParticles", &iNumParticles); - if (!bLocal) - archive.FindVec3f("CldCenter", &vecCenter); - - Vec3f *pParticlePositions = new Vec3f[iNumParticles]; - float *pParticleRadii = new float[iNumParticles]; - Vec4f *pParticleColors = new Vec4f[iNumParticles]; - - unsigned int iNumBytes; - archive.FindData("CldParticlePositions", ANY_TYPE, (void**const)&pParticlePositions, &iNumBytes); - archive.FindData("CldParticleRadii", ANY_TYPE, (void**const)&pParticleRadii, &iNumBytes); - archive.FindData("CldParticleColors", ANY_TYPE, (void**const)&pParticleColors, &iNumBytes); - - for (unsigned int i = 0; i < iNumParticles; ++i) - { - SkyCloudParticle *pParticle = new SkyCloudParticle((pParticlePositions[i] + vecCenter) * rScale, - pParticleRadii[i] * rScale, - pParticleColors[i]); - _boundingBox.AddPoint(pParticle->GetPosition()); - - _particles.push_back(pParticle); - } - // this is just a bad hack to align cloud field from skyworks with local horizon at KSFO - // this "almost" works not quite the right solution okay to get some up and running - // we need to develop our own scheme for loading and positioning clouds - Mat33f rot_mat; - Vec3f moveit; - - rot_mat.Set( 1, 0, 0, - 0, 0, -1, - 0, 1, 0); - // flip the y and z axis, clouds now sit in the x-y plane - Rotate( rot_mat ); -// rot_mat.Set(mat[0][0], mat[0][1],mat[0][2], -// mat[1][0], mat[1][1],mat[1][2], -// mat[2][0], mat[2][1],mat[2][2] ); - // adjust for lon af KSFO plus -122.357 -// rot_mat.Set( -0.84473f, 0.53519f, 0.0f, -// -0.53519f, -0.84473f, 0.0f, -// 0.0f, 0.0f, 1.0f); - - //Rotate( rot_mat ); - - // and about x for latitude 37.6135 -// rot_mat.Set( 1.0f, 0.0, 0.0f, -// 0.0f, 0.7921f, -0.6103f, -// 0.0f, 0.6103f, 0.7921f); - -// Rotate( rot_mat ); - - moveit.Set( 1000.0, 0.0, 4050.0 ); - - Translate( moveit ); - - return SKYRESULT_OK; -} - SKYRESULT SkyCloud::Load(const SkyArchive &archive, float rScale /* = 1.0f */, - bool bLocal /* = false */) + double latitude, double longitude) { unsigned int iNumParticles; Vec3f vecCenter = Vec3f::ZERO; @@ -716,7 +633,7 @@ SKYRESULT SkyCloud::Load(const SkyArchive &archive, //_boundingBox.SetMax(vecCenter + Vec3f(rRadius, rRadius, rRadius)); archive.FindUInt32("CldNumParticles", &iNumParticles); - if (!bLocal) + //if (!bLocal) archive.FindVec3f("CldCenter", &vecCenter); Vec3f *pParticlePositions = new Vec3f[iNumParticles]; @@ -737,36 +654,47 @@ SKYRESULT SkyCloud::Load(const SkyArchive &archive, _particles.push_back(pParticle); } - // this is just a bad hack to align cloud field from skyworks with local horizon at KSFO - // this "almost" works not quite the right solution okay to get some up and running - // we need to develop our own scheme for loading and positioning clouds - Mat33f rot_mat; + +// This is an interim solution to transform clouds specified in SkyWorks files that are loaded relative to the fgfs +// earth-centered Cartesian system to new fgfs coordinates that place and orient the cloud field for proper +// viewing based on the center of the local tile center and local vertical specified at init time. + + Mat33f R; Vec3f moveit; - - rot_mat.Set( 1, 0, 0, - 0, 0, -1, - 0, 1, 0); - // flip the y and z axis, clouds now sit in the x-y plane - Rotate( rot_mat ); - - // adjust for lon af KSFO plus -122.357 - rot_mat.Set( -0.84473f, 0.53519f, 0.0f, - -0.53519f, -0.84473f, 0.0f, - 0.0f, 0.0f, 1.0f); - - //Rotate( rot_mat ); - - // and about x for latitude 37.6135 - rot_mat.Set( 1.0f, 0.0, 0.0f, - 0.0f, 0.7921f, -0.6103f, - 0.0f, 0.6103f, 0.7921f); - - Rotate( rot_mat ); - - moveit.Set( 1000.0, 0.0, 4050.0 ); + // invert cloud height vector + R.Set( 1, 0, 0, 0, -1, 0, 0, 0, 1 ); + Rotate( R ); - Translate( moveit ); +float ex = 1.0; +float ey = 0.0; +float ez = 0.0; +float phi = -latitude / 57.29578; +float one_min_cos = 1 - cos(phi); +R.Set( +cos(phi) + one_min_cos*ex*ex, one_min_cos*ex*ey - ez*sin(phi), one_min_cos*ex*ez + ey*sin(phi), +one_min_cos*ex*ey + ez*sin(phi), cos(phi) + one_min_cos*ey*ey, one_min_cos*ey*ez - ex*sin(phi), +one_min_cos*ex*ez - ey*sin(phi), one_min_cos*ey*ez + ex*sin(phi), cos(phi) + one_min_cos*ez*ez ); + +Rotate( R ); + +ex = 0.0; +ey = sin( latitude ); +ez = cos( latitude ); +phi = (longitude + 90.0)/ 57.29578; +one_min_cos = 1 - cos(phi); + +R.Set( +cos(phi) + one_min_cos*ex*ex, one_min_cos*ex*ey - ez*sin(phi), one_min_cos*ex*ez + ey*sin(phi), +one_min_cos*ex*ey + ez*sin(phi), cos(phi) + one_min_cos*ey*ey, one_min_cos*ey*ez - ex*sin(phi), +one_min_cos*ex*ez - ey*sin(phi), one_min_cos*ey*ez + ex*sin(phi), cos(phi) + one_min_cos*ez*ez ); + +Rotate( R ); +// this sets the cloud height to around 3500 feet MSL @ KSFO +moveit.Set( 13000.0, 0.0, 10500.0 ); + +Translate( moveit ); + return SKYRESULT_OK; } diff --git a/simgear/scene/sky/clouds3d/SkyCloud.hpp b/simgear/scene/sky/clouds3d/SkyCloud.hpp index de7332c8..d48bd5b4 100644 --- a/simgear/scene/sky/clouds3d/SkyCloud.hpp +++ b/simgear/scene/sky/clouds3d/SkyCloud.hpp @@ -98,9 +98,7 @@ public: bool IsPhaseFunctionEnabled() const { return _bUsePhaseFunction; } SKYRESULT Save(SkyArchive &archive) const; - SKYRESULT Load(const SkyArchive &archive, float rScale = 1.0f, bool bLocal = false); - SKYRESULT Load(const SkyArchive &archive, const sgVec4 *mat, - float rScale = 1.0f, bool bLocal = false); + SKYRESULT Load(const SkyArchive &archive, float rScale = 1.0f,double latitude=0.0, double longitude=0.0); void Rotate(const Mat33f& rot); void Translate(const Vec3f& trans); diff --git a/simgear/scene/sky/clouds3d/SkySceneLoader.cpp b/simgear/scene/sky/clouds3d/SkySceneLoader.cpp index 066af327..099eb54b 100644 --- a/simgear/scene/sky/clouds3d/SkySceneLoader.cpp +++ b/simgear/scene/sky/clouds3d/SkySceneLoader.cpp @@ -102,7 +102,7 @@ SkySceneLoader::~SkySceneLoader() + */ //bool SkySceneLoader::Load(std::string filepath) -bool SkySceneLoader::Load( SGPath filename ) +bool SkySceneLoader::Load( SGPath filename, double latitude, double longitude ) { SkyArchive archive; @@ -135,12 +135,12 @@ bool SkySceneLoader::Load( SGPath filename ) base.append( pFilename ); const char *FilePath = base.c_str(); - float rScale = 1.0; - FAIL_RETURN(archive.FindFloat32("CloudScale", &rScale, i)); - rScale = 30.0; + //float rScale = 1.0; + //FAIL_RETURN(archive.FindFloat32("CloudScale", &rScale, i)); + float rScale = 40.0; SkyArchive cloudArchive; FAIL_RETURN(cloudArchive.Load(FilePath)); - FAIL_RETURN(SceneManager::InstancePtr()->LoadClouds(cloudArchive, rScale)); + FAIL_RETURN(SceneManager::InstancePtr()->LoadClouds(cloudArchive, rScale, latitude, longitude)); } } @@ -174,8 +174,8 @@ void SkySceneLoader::Update( double *view_pos ) { double wind_x, wind_y, wind_z; - wind_x = -0.05; wind_z = 0.05; - // just a dumb test to see if we can move the clouds en masse via the camera + wind_x = 0.0; wind_z = 0.0; + // just a dumb test to see what happens if we can move the clouds en masse via the camera delta[0] += wind_x; delta[2] += wind_z; sgdSubVec3( cam_pos, view_pos, delta ); diff --git a/simgear/scene/sky/clouds3d/SkySceneLoader.hpp b/simgear/scene/sky/clouds3d/SkySceneLoader.hpp index d98555b3..7255ad3e 100644 --- a/simgear/scene/sky/clouds3d/SkySceneLoader.hpp +++ b/simgear/scene/sky/clouds3d/SkySceneLoader.hpp @@ -48,7 +48,7 @@ public: SkySceneLoader(); ~SkySceneLoader(); - bool Load( SGPath fileroot ); + bool Load( SGPath fileroot, double latitude, double longitude ); void Set_Cloud_Orig( Point3D *posit ); diff --git a/simgear/scene/sky/clouds3d/SkySceneManager.cpp b/simgear/scene/sky/clouds3d/SkySceneManager.cpp index 45316f95..722a0eda 100644 --- a/simgear/scene/sky/clouds3d/SkySceneManager.cpp +++ b/simgear/scene/sky/clouds3d/SkySceneManager.cpp @@ -410,7 +410,7 @@ SKYRESULT SkySceneManager::Display( const Camera &cam ) //if (_bDrawTree)// force the issue and draw //_VisualizeCloudBVTree(cam, _cloudBVTree.GetRoot()); - +/* glLineWidth(2.0); glBegin(GL_LINES); // red is Cartesian y-axis @@ -426,14 +426,14 @@ SKYRESULT SkySceneManager::Display( const Camera &cam ) glVertex3f( 0.0, 0.0, 0.0); glVertex3f( -104000.0, 0.0, 0.0); glEnd(); - +*/ // draw all container clouds and "free" objects not in clouds. - int i = 0; + //int i = 0; for (InstanceIterator iter = _visibleInstances.begin(); iter != _visibleInstances.end(); ++iter) { FAIL_RETURN_MSG((*iter)->Display(), "SkySceneManager::Display(): instance display failed."); - i++; + //i++; } //cout << "There are " << i << " visible clouds\n"; @@ -508,7 +508,7 @@ SKYRESULT SkySceneManager::ShadeClouds() * * @todo */ -SKYRESULT SkySceneManager::LoadClouds(SkyArchive& cloudArchive, float rScale /* = 1.0f */) +SKYRESULT SkySceneManager::LoadClouds(SkyArchive& cloudArchive, float rScale, double latitude, double longitude) { unsigned int iNumClouds = 0; cloudArchive.FindUInt32("CldNumClouds", &iNumClouds); @@ -519,7 +519,7 @@ SKYRESULT SkySceneManager::LoadClouds(SkyArchive& cloudArchive, float rScale /* {printf("Loading # %d of %d clouds\n", i+1, iNumClouds); cloudArchive.FindArchive("Cloud", &subArchive, i); SkyCloud *pCloud = new SkyCloud(); - pCloud->Load(subArchive, rScale); + pCloud->Load(subArchive, rScale, latitude, longitude); SkyRenderableInstanceCloud *pInstance = new SkyRenderableInstanceCloud(pCloud, false); AddCloud(pCloud); AddCloudInstance(pInstance); diff --git a/simgear/scene/sky/clouds3d/SkySceneManager.hpp b/simgear/scene/sky/clouds3d/SkySceneManager.hpp index 8926d396..75b44286 100644 --- a/simgear/scene/sky/clouds3d/SkySceneManager.hpp +++ b/simgear/scene/sky/clouds3d/SkySceneManager.hpp @@ -104,7 +104,7 @@ public: static void SortInstances(InstanceArray& instances, const Vec3f& vecSortPoint); // load a set of clouds from an archive file. - SKYRESULT LoadClouds(SkyArchive& cloudArchive, float rScale = 1.0f); + SKYRESULT LoadClouds(SkyArchive& cloudArchive, float rScale = 1.0f, double latitude=0.0, double longitude=0.0); protected: // datatypes // Typedef the vectors into cleaner names