From: curt Date: Mon, 16 Sep 2002 14:55:31 +0000 (+0000) Subject: Latest changes from John Wojnaroski. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=fe5bb76def88abb42773ccf781e3e4bae2103250;p=simgear.git Latest changes from John Wojnaroski. --- diff --git a/simgear/scene/sky/clouds3d/SkyArchive.cpp b/simgear/scene/sky/clouds3d/SkyArchive.cpp index ef19122d..3ca8e5ef 100644 --- a/simgear/scene/sky/clouds3d/SkyArchive.cpp +++ b/simgear/scene/sky/clouds3d/SkyArchive.cpp @@ -957,27 +957,23 @@ bool SkyArchive::IsEmpty() const * @fn SkyArchive::Load(const char* pFileName) * @brief Load the contents of a SkyArchive from file storage. */ -SKYRESULT SkyArchive::Load(const char* pFileName) +bool SkyArchive::Load(const char* pFileName) { - if (!pFileName) + if (!pFileName) { FAIL_RETURN_MSG(SKYRESULT_FAIL, "Error: SkyArchive::Load(): file name is NULL."); - + } FILE* pSrcFile = NULL; - - char buf[512]; - sprintf(buf,"SkyArchive::Load(%s)",pFileName); - SkyTrace(buf); if (NULL == (pSrcFile = fopen(pFileName, "rb"))) // file opened successfully { SkyTrace("Error: SkyArchive::Load(): failed to open file for reading."); - return SKYRESULT_FAIL; + return false; } SKYRESULT retVal = _Load(pSrcFile); fclose(pSrcFile); FAIL_RETURN(retVal); - return SKYRESULT_OK; + return true; } //------------------------------------------------------------------------------ diff --git a/simgear/scene/sky/clouds3d/SkyArchive.hpp b/simgear/scene/sky/clouds3d/SkyArchive.hpp index a93dfbf2..55990c87 100644 --- a/simgear/scene/sky/clouds3d/SkyArchive.hpp +++ b/simgear/scene/sky/clouds3d/SkyArchive.hpp @@ -208,7 +208,7 @@ public: SKYRESULT MakeEmpty(); // Loads the contents from a file. - SKYRESULT Load(const char* pFileName); + bool Load(const char* pFileName); // Commits the contents of a SkyArchive to file storage. SKYRESULT Save(const char* pFileName) const; diff --git a/simgear/scene/sky/clouds3d/SkyCloud.cpp b/simgear/scene/sky/clouds3d/SkyCloud.cpp index 26640d3c..c3cbbd77 100644 --- a/simgear/scene/sky/clouds3d/SkyCloud.cpp +++ b/simgear/scene/sky/clouds3d/SkyCloud.cpp @@ -24,7 +24,6 @@ // warning for truncation of template name for browse info #pragma warning( disable : 4786) -//#include "glvu.hpp" #include "SkyCloud.hpp" #include "SkyRenderableInstance.hpp" #include "SkyContext.hpp" @@ -670,29 +669,28 @@ SKYRESULT SkyCloud::Load(const SkyArchive &archive, // we need to develop out own scheme for loading and positioning clouds Mat33f rot_mat; Vec3f moveit; - - //moveit.Set( -10000.0, 1500.0, 1500.0 ); - moveit.Set( 0.0, 0.0, 1050.0 ); - + rot_mat.Set( 1, 0, 0, 0, 0, -1, 0, 1, 0); - // flip the y and z axis + // flip the y and z axis, clouds now sit in the x-y plane Rotate( rot_mat ); // adjust for lon af KSFO -122.357 - rot_mat.Set( -0.5352f, 0.8447f, 0.0f, - -0.8447f, -0.5352f, 0.0f, - -0.0f, 0.0f, 1.0f); + rot_mat.Set( -0.76604f, 0.64277f, 0.0f, + -0.64277f, -0.76604f, 0.0f, + 0.0f, 0.0f, 1.0f); - Rotate( rot_mat ); + //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 ); + Rotate( rot_mat ); + + moveit.Set( 0.0, 0.0, 4050.0 ); Translate( moveit ); diff --git a/simgear/scene/sky/clouds3d/SkySceneLoader.cpp b/simgear/scene/sky/clouds3d/SkySceneLoader.cpp index 88acc2f6..4ceac499 100644 --- a/simgear/scene/sky/clouds3d/SkySceneLoader.cpp +++ b/simgear/scene/sky/clouds3d/SkySceneLoader.cpp @@ -24,7 +24,10 @@ */ #include +#include #include +#include +#include #include "SkySceneLoader.hpp" #include "SkySceneManager.hpp" @@ -32,20 +35,28 @@ #include "SkySceneManager.hpp" #include "SkyDynamicTextureManager.hpp" #include "SkyContext.hpp" -//#include "SkyViewManager.hpp" -//#include "SkyRenderableInstanceGroup.hpp" #include "SkyLight.hpp" #include "camera.hpp" ssgLight _sky_ssgLights [ 8 ] ; -static Point3D origin; -Point3D offset; -//int _ssgFrameCounter = 0 ; + +sgdVec3 cam_pos; +static sgdVec3 delta; +Point3D origin; + Camera *pCam = new Camera(); // Need to add a light here until we figure out how to use the sun position and color SkyLight::SkyLightType eType = SkyLight::SKY_LIGHT_DIRECTIONAL; SkyLight *pLight = new SkyLight(eType); +// hack +sgMat4 my_copy_of_ssgOpenGLAxisSwapMatrix = +{ + { 1.0f, 0.0f, 0.0f, 0.0f }, + { 0.0f, 0.0f, -1.0f, 0.0f }, + { 0.0f, 1.0f, 0.0f, 0.0f }, + { 0.0f, 0.0f, 0.0f, 1.0f } +}; //------------------------------------------------------------------------------ // Function : SkySceneLoader::SkySceneLoader // Description : @@ -110,7 +121,7 @@ bool SkySceneLoader::Load(std::string filename) FAIL_RETURN(archive.FindString("CloudFile", &pFilename, i)); float rScale = 1.0; FAIL_RETURN(archive.FindFloat32("CloudScale", &rScale, i)); - rScale = 5.0; + rScale = 20.0; SkyArchive cloudArchive; FAIL_RETURN(cloudArchive.Load(pFilename)); FAIL_RETURN(SceneManager::InstancePtr()->LoadClouds(cloudArchive, rScale)); @@ -118,7 +129,7 @@ bool SkySceneLoader::Load(std::string filename) } Vec3f dir(0, 0, 1); - pLight->SetPosition(Vec3f(0, 0, 7000)); + pLight->SetPosition(Vec3f(3000, 0, 7000)); pLight->SetDirection(dir); pLight->SetAmbient(Vec4f( 0.0f, 0.0f, 0.0f, 0.0f)); pLight->SetDiffuse(Vec4f(1.0f, 1.0f, 1.0f, 0.0f)); @@ -137,16 +148,18 @@ bool SkySceneLoader::Load(std::string filename) void SkySceneLoader::Set_Cloud_Orig( Point3D *posit ) { // use this to adjust camera position for a new tile center - origin = *posit; // set origin to current tile center - printf("Cloud marker %f %f %f\n", origin.x(), origin.y(), origin.z() ); + // set origin for cloud coordinates to initial tile center + origin = *posit; + sgdSetVec3( delta, origin[0], origin[1], origin[2]); + //printf("Cloud marker %f %f %f\n", origin[0], origin[1], origin[2] ); } -void SkySceneLoader::Update( sgMat4 viewmat, Point3D *posit ) -//void SkySceneLoader::Update() +void SkySceneLoader::Update( double *view_pos ) { - offset = *posit - origin; - cout << "X: " << offset.x() << "Y: " << offset.y() << "Z: " << offset.z() << endl; + sgdSubVec3( cam_pos, view_pos, delta ); + //cout << "ORIGIN: " << delta[0] << " " << delta[1] << " " << delta[2] << endl; + //cout << "CAM : " << cam_pos[0] << " " << cam_pos[1] << " " << cam_pos[2] << endl; SceneManager::InstancePtr()->Update(*pCam); @@ -162,69 +175,53 @@ void SkySceneLoader::Resize( double w, double h ) } -void SkySceneLoader::Draw() -{ // this is a clone of the plib ssgCullAndDraw except there is no scene graph +void SkySceneLoader::Draw( sgMat4 mat ) +{/* need this if you want to look at FG matrix if ( _ssgCurrentContext == NULL ) { cout<< "ssg: No Current Context: Did you forgot to call ssgInit()?" ; char x; cin >> x; } - //ssgForceBasicState () ; - - sgMat4 test; - - //glMatrixMode ( GL_PROJECTION ); - //glLoadIdentity(); - //_ssgCurrentContext->loadProjectionMatrix (); - // test/debug section - - //_ssgCurrentContext->getProjectionMatrix( test ); - /* - printf( "\nFG Projection matrix\n" ); - cout << test[0][0] << " " << test[1][0] << " " << test[2][0] << " " << test[3][0] << endl; - cout << test[0][1] << " " << test[1][1] << " " << test[2][1] << " " << test[3][1] << endl; - cout << test[0][2] << " " << test[1][2] << " " << test[2][2] << " " << test[3][2] << endl; - cout << test[0][3] << " " << test[1][3] << " " << test[2][3] << " " << test[3][3] << endl; + ssgForceBasicState () ; */ - sgMat4 m, *pm; - sgVec3 temp; - pm = &m; + sgMat4 test, m, *pm, viewmat, cameraMatrix; + pm = &m; + sgSetVec4(mat[3], cam_pos[0], cam_pos[1], cam_pos[2], SG_ONE); + // at this point the view matrix has the cloud camera position relative to cloud origin + // now transform to screen coordinates + sgTransposeNegateMat4 ( viewmat, mat ) ; + + sgCopyMat4 ( cameraMatrix, my_copy_of_ssgOpenGLAxisSwapMatrix ) ; + sgPreMultMat4 ( cameraMatrix, viewmat ) ; + + //sgCopyMat4 ( test, cameraMatrix ); + + //printf( "\nSkyworks ViewModel matrix\n" ); + //cout << test[0][0] << " " << test[1][0] << " " << test[2][0] << " " << test[3][0] << endl; + //cout << test[0][1] << " " << test[1][1] << " " << test[2][1] << " " << test[3][1] << endl; + //cout << test[0][2] << " " << test[1][2] << " " << test[2][2] << " " << test[3][2] << endl; + //cout << test[0][3] << " " << test[1][3] << " " << test[2][3] << " " << test[3][3] << endl; // this is the cameraview matrix used by flightgear to render scene - // need to play with this to build a new matrix that accounts for tile crossings - // for now it resets the clouds when a boundary is crossed - _ssgCurrentContext->getModelviewMatrix( m ); + //_ssgCurrentContext->getModelviewMatrix( m ); - ///pCam->GetProjectionMatrix( (float *) pm ); - //sgCopyMat4( test, m ); - /*printf( "\nSkyworks Projection matrix\n" ); - cout << test[0][0] << " " << test[1][0] << " " << test[2][0] << " " << test[3][0] << endl; - cout << test[0][1] << " " << test[1][1] << " " << test[2][1] << " " << test[3][1] << endl; - cout << test[0][2] << " " << test[1][2] << " " << test[2][2] << " " << test[3][2] << endl; - cout << test[0][3] << " " << test[1][3] << " " << test[2][3] << " " << test[3][3] << endl; - */ glMatrixMode ( GL_MODELVIEW ) ; glLoadIdentity () ; - glLoadMatrixf( (float *) pm ); + glLoadMatrixf( (float *) cameraMatrix ); //sgCopyMat4( test, m ); - pCam->SetModelviewMatrix( (float *) pm ); - - //printf( "\nFG modelview matrix\n" ); + pCam->SetModelviewMatrix( (float *) cameraMatrix ); + + //printf( "\nFG modelview matrix\n" ); //cout << test[0][0] << " " << test[1][0] << " " << test[2][0] << " " << test[3][0] << endl; //cout << test[0][1] << " " << test[1][1] << " " << test[2][1] << " " << test[3][1] << endl; //cout << test[0][2] << " " << test[1][2] << " " << test[2][2] << " " << test[3][2] << endl; //cout << test[0][3] << " " << test[1][3] << " " << test[2][3] << " " << test[3][3] << endl; - - //pCam->Print(); - - //_ssgCurrentContext->cull(r) ; - //_ssgDrawDList () ; - SceneManager::InstancePtr()->Display(*pCam); + SceneManager::InstancePtr()->Display(*pCam); - //pLight->Display(); // draw the light position to debug with sun position + //pLight->Display(); // draw the light position to debug with sun position glMatrixMode ( GL_MODELVIEW ) ; glLoadIdentity () ; diff --git a/simgear/scene/sky/clouds3d/SkySceneLoader.hpp b/simgear/scene/sky/clouds3d/SkySceneLoader.hpp index 7e9cf44d..526173b0 100644 --- a/simgear/scene/sky/clouds3d/SkySceneLoader.hpp +++ b/simgear/scene/sky/clouds3d/SkySceneLoader.hpp @@ -46,13 +46,12 @@ public: void Set_Cloud_Orig( Point3D *posit ); - //void Update(); - void Update( sgMat4 viewmat, Point3D *posit ); + void Update( double *view_pos ); void Resize( double w, double h); - void Draw(); + void Draw( sgMat4 mat ); }; -#endif //__SKYSCENELOADER_HPP__ \ No newline at end of file +#endif //__SKYSCENELOADER_HPP__ diff --git a/simgear/scene/sky/clouds3d/SkySceneManager.cpp b/simgear/scene/sky/clouds3d/SkySceneManager.cpp index 6b1b2a76..a316f19d 100644 --- a/simgear/scene/sky/clouds3d/SkySceneManager.cpp +++ b/simgear/scene/sky/clouds3d/SkySceneManager.cpp @@ -411,7 +411,7 @@ SKYRESULT SkySceneManager::Display( const Camera &cam ) } //if (_bDrawTree) // force the issue and draw - _VisualizeCloudBVTree(cam, _cloudBVTree.GetRoot()); + //_VisualizeCloudBVTree(cam, _cloudBVTree.GetRoot()); glLineWidth(2.0); glBegin(GL_LINES);