John Wojnaroski:
Attached are the new files to transform the cloud field for local lat/lon.
This commit is contained in:
@@ -618,92 +618,9 @@ SkyMinMaxBox* SkyCloud::CopyBoundingVolume() const
|
|||||||
return pBox;
|
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,
|
SKYRESULT SkyCloud::Load(const SkyArchive &archive,
|
||||||
float rScale /* = 1.0f */,
|
float rScale /* = 1.0f */,
|
||||||
bool bLocal /* = false */)
|
double latitude, double longitude)
|
||||||
{
|
{
|
||||||
unsigned int iNumParticles;
|
unsigned int iNumParticles;
|
||||||
Vec3f vecCenter = Vec3f::ZERO;
|
Vec3f vecCenter = Vec3f::ZERO;
|
||||||
@@ -716,7 +633,7 @@ SKYRESULT SkyCloud::Load(const SkyArchive &archive,
|
|||||||
//_boundingBox.SetMax(vecCenter + Vec3f(rRadius, rRadius, rRadius));
|
//_boundingBox.SetMax(vecCenter + Vec3f(rRadius, rRadius, rRadius));
|
||||||
|
|
||||||
archive.FindUInt32("CldNumParticles", &iNumParticles);
|
archive.FindUInt32("CldNumParticles", &iNumParticles);
|
||||||
if (!bLocal)
|
//if (!bLocal)
|
||||||
archive.FindVec3f("CldCenter", &vecCenter);
|
archive.FindVec3f("CldCenter", &vecCenter);
|
||||||
|
|
||||||
Vec3f *pParticlePositions = new Vec3f[iNumParticles];
|
Vec3f *pParticlePositions = new Vec3f[iNumParticles];
|
||||||
@@ -737,35 +654,46 @@ SKYRESULT SkyCloud::Load(const SkyArchive &archive,
|
|||||||
|
|
||||||
_particles.push_back(pParticle);
|
_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
|
// This is an interim solution to transform clouds specified in SkyWorks files that are loaded relative to the fgfs
|
||||||
// we need to develop our own scheme for loading and positioning clouds
|
// earth-centered Cartesian system to new fgfs coordinates that place and orient the cloud field for proper
|
||||||
Mat33f rot_mat;
|
// viewing based on the center of the local tile center and local vertical specified at init time.
|
||||||
|
|
||||||
|
Mat33f R;
|
||||||
Vec3f moveit;
|
Vec3f moveit;
|
||||||
|
// invert cloud height vector
|
||||||
|
R.Set( 1, 0, 0, 0, -1, 0, 0, 0, 1 );
|
||||||
|
Rotate( R );
|
||||||
|
|
||||||
rot_mat.Set( 1, 0, 0,
|
float ex = 1.0;
|
||||||
0, 0, -1,
|
float ey = 0.0;
|
||||||
0, 1, 0);
|
float ez = 0.0;
|
||||||
// flip the y and z axis, clouds now sit in the x-y plane
|
float phi = -latitude / 57.29578;
|
||||||
Rotate( rot_mat );
|
float one_min_cos = 1 - cos(phi);
|
||||||
|
|
||||||
// adjust for lon af KSFO plus -122.357
|
R.Set(
|
||||||
rot_mat.Set( -0.84473f, 0.53519f, 0.0f,
|
cos(phi) + one_min_cos*ex*ex, one_min_cos*ex*ey - ez*sin(phi), one_min_cos*ex*ez + ey*sin(phi),
|
||||||
-0.53519f, -0.84473f, 0.0f,
|
one_min_cos*ex*ey + ez*sin(phi), cos(phi) + one_min_cos*ey*ey, one_min_cos*ey*ez - ex*sin(phi),
|
||||||
0.0f, 0.0f, 1.0f);
|
one_min_cos*ex*ez - ey*sin(phi), one_min_cos*ey*ez + ex*sin(phi), cos(phi) + one_min_cos*ez*ez );
|
||||||
|
|
||||||
//Rotate( rot_mat );
|
Rotate( R );
|
||||||
|
|
||||||
// and about x for latitude 37.6135
|
ex = 0.0;
|
||||||
rot_mat.Set( 1.0f, 0.0, 0.0f,
|
ey = sin( latitude );
|
||||||
0.0f, 0.7921f, -0.6103f,
|
ez = cos( latitude );
|
||||||
0.0f, 0.6103f, 0.7921f);
|
phi = (longitude + 90.0)/ 57.29578;
|
||||||
|
one_min_cos = 1 - cos(phi);
|
||||||
|
|
||||||
Rotate( rot_mat );
|
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 );
|
||||||
|
|
||||||
moveit.Set( 1000.0, 0.0, 4050.0 );
|
Rotate( R );
|
||||||
|
// this sets the cloud height to around 3500 feet MSL @ KSFO
|
||||||
|
moveit.Set( 13000.0, 0.0, 10500.0 );
|
||||||
|
|
||||||
Translate( moveit );
|
Translate( moveit );
|
||||||
|
|
||||||
return SKYRESULT_OK;
|
return SKYRESULT_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,9 +98,7 @@ public:
|
|||||||
bool IsPhaseFunctionEnabled() const { return _bUsePhaseFunction; }
|
bool IsPhaseFunctionEnabled() const { return _bUsePhaseFunction; }
|
||||||
|
|
||||||
SKYRESULT Save(SkyArchive &archive) const;
|
SKYRESULT Save(SkyArchive &archive) const;
|
||||||
SKYRESULT Load(const SkyArchive &archive, float rScale = 1.0f, bool bLocal = false);
|
SKYRESULT Load(const SkyArchive &archive, float rScale = 1.0f,double latitude=0.0, double longitude=0.0);
|
||||||
SKYRESULT Load(const SkyArchive &archive, const sgVec4 *mat,
|
|
||||||
float rScale = 1.0f, bool bLocal = false);
|
|
||||||
|
|
||||||
void Rotate(const Mat33f& rot);
|
void Rotate(const Mat33f& rot);
|
||||||
void Translate(const Vec3f& trans);
|
void Translate(const Vec3f& trans);
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ SkySceneLoader::~SkySceneLoader()
|
|||||||
+
|
+
|
||||||
*/
|
*/
|
||||||
//bool SkySceneLoader::Load(std::string filepath)
|
//bool SkySceneLoader::Load(std::string filepath)
|
||||||
bool SkySceneLoader::Load( SGPath filename )
|
bool SkySceneLoader::Load( SGPath filename, double latitude, double longitude )
|
||||||
{
|
{
|
||||||
SkyArchive archive;
|
SkyArchive archive;
|
||||||
|
|
||||||
@@ -135,12 +135,12 @@ bool SkySceneLoader::Load( SGPath filename )
|
|||||||
base.append( pFilename );
|
base.append( pFilename );
|
||||||
const char *FilePath = base.c_str();
|
const char *FilePath = base.c_str();
|
||||||
|
|
||||||
float rScale = 1.0;
|
//float rScale = 1.0;
|
||||||
FAIL_RETURN(archive.FindFloat32("CloudScale", &rScale, i));
|
//FAIL_RETURN(archive.FindFloat32("CloudScale", &rScale, i));
|
||||||
rScale = 30.0;
|
float rScale = 40.0;
|
||||||
SkyArchive cloudArchive;
|
SkyArchive cloudArchive;
|
||||||
FAIL_RETURN(cloudArchive.Load(FilePath));
|
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;
|
double wind_x, wind_y, wind_z;
|
||||||
wind_x = -0.05; wind_z = 0.05;
|
wind_x = 0.0; wind_z = 0.0;
|
||||||
// just a dumb test to see if we can move the clouds en masse via the camera
|
// 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;
|
delta[0] += wind_x; delta[2] += wind_z;
|
||||||
|
|
||||||
sgdSubVec3( cam_pos, view_pos, delta );
|
sgdSubVec3( cam_pos, view_pos, delta );
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ public:
|
|||||||
SkySceneLoader();
|
SkySceneLoader();
|
||||||
~SkySceneLoader();
|
~SkySceneLoader();
|
||||||
|
|
||||||
bool Load( SGPath fileroot );
|
bool Load( SGPath fileroot, double latitude, double longitude );
|
||||||
|
|
||||||
void Set_Cloud_Orig( Point3D *posit );
|
void Set_Cloud_Orig( Point3D *posit );
|
||||||
|
|
||||||
|
|||||||
@@ -410,7 +410,7 @@ SKYRESULT SkySceneManager::Display( const Camera &cam )
|
|||||||
|
|
||||||
//if (_bDrawTree)// force the issue and draw
|
//if (_bDrawTree)// force the issue and draw
|
||||||
//_VisualizeCloudBVTree(cam, _cloudBVTree.GetRoot());
|
//_VisualizeCloudBVTree(cam, _cloudBVTree.GetRoot());
|
||||||
|
/*
|
||||||
glLineWidth(2.0);
|
glLineWidth(2.0);
|
||||||
glBegin(GL_LINES);
|
glBegin(GL_LINES);
|
||||||
// red is Cartesian y-axis
|
// red is Cartesian y-axis
|
||||||
@@ -426,14 +426,14 @@ SKYRESULT SkySceneManager::Display( const Camera &cam )
|
|||||||
glVertex3f( 0.0, 0.0, 0.0);
|
glVertex3f( 0.0, 0.0, 0.0);
|
||||||
glVertex3f( -104000.0, 0.0, 0.0);
|
glVertex3f( -104000.0, 0.0, 0.0);
|
||||||
glEnd();
|
glEnd();
|
||||||
|
*/
|
||||||
// draw all container clouds and "free" objects not in clouds.
|
// 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)
|
for (InstanceIterator iter = _visibleInstances.begin(); iter != _visibleInstances.end(); ++iter)
|
||||||
{
|
{
|
||||||
FAIL_RETURN_MSG((*iter)->Display(),
|
FAIL_RETURN_MSG((*iter)->Display(),
|
||||||
"SkySceneManager::Display(): instance display failed.");
|
"SkySceneManager::Display(): instance display failed.");
|
||||||
i++;
|
//i++;
|
||||||
}
|
}
|
||||||
//cout << "There are " << i << " visible clouds\n";
|
//cout << "There are " << i << " visible clouds\n";
|
||||||
|
|
||||||
@@ -508,7 +508,7 @@ SKYRESULT SkySceneManager::ShadeClouds()
|
|||||||
*
|
*
|
||||||
* @todo <WRITE EXTENDED SkySceneManager::LoadClouds FUNCTION DOCUMENTATION>
|
* @todo <WRITE EXTENDED SkySceneManager::LoadClouds FUNCTION DOCUMENTATION>
|
||||||
*/
|
*/
|
||||||
SKYRESULT SkySceneManager::LoadClouds(SkyArchive& cloudArchive, float rScale /* = 1.0f */)
|
SKYRESULT SkySceneManager::LoadClouds(SkyArchive& cloudArchive, float rScale, double latitude, double longitude)
|
||||||
{
|
{
|
||||||
unsigned int iNumClouds = 0;
|
unsigned int iNumClouds = 0;
|
||||||
cloudArchive.FindUInt32("CldNumClouds", &iNumClouds);
|
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);
|
{printf("Loading # %d of %d clouds\n", i+1, iNumClouds);
|
||||||
cloudArchive.FindArchive("Cloud", &subArchive, i);
|
cloudArchive.FindArchive("Cloud", &subArchive, i);
|
||||||
SkyCloud *pCloud = new SkyCloud();
|
SkyCloud *pCloud = new SkyCloud();
|
||||||
pCloud->Load(subArchive, rScale);
|
pCloud->Load(subArchive, rScale, latitude, longitude);
|
||||||
SkyRenderableInstanceCloud *pInstance = new SkyRenderableInstanceCloud(pCloud, false);
|
SkyRenderableInstanceCloud *pInstance = new SkyRenderableInstanceCloud(pCloud, false);
|
||||||
AddCloud(pCloud);
|
AddCloud(pCloud);
|
||||||
AddCloudInstance(pInstance);
|
AddCloudInstance(pInstance);
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ public:
|
|||||||
static void SortInstances(InstanceArray& instances, const Vec3f& vecSortPoint);
|
static void SortInstances(InstanceArray& instances, const Vec3f& vecSortPoint);
|
||||||
|
|
||||||
// load a set of clouds from an archive file.
|
// 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
|
protected: // datatypes
|
||||||
// Typedef the vectors into cleaner names
|
// Typedef the vectors into cleaner names
|
||||||
|
|||||||
Reference in New Issue
Block a user