update OsgBackground / OsgScenery / OsgRender - loading background in root and push in render
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@5458 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 529f8f29e89a40c4db79e1b8a18ef57b85d39f71 Former-commit-id: f75fec7242eb8ee47600d7749fad96ba5af5d5f2
This commit is contained in:
parent
58459871e4
commit
d0c72321df
4 changed files with 22 additions and 23 deletions
|
@ -27,15 +27,16 @@
|
||||||
|
|
||||||
SDBackground::SDBackground(void)
|
SDBackground::SDBackground(void)
|
||||||
{
|
{
|
||||||
|
_background = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDBackground::~SDBackground(void)
|
SDBackground::~SDBackground(void)
|
||||||
{
|
{
|
||||||
_background_transform->removeChildren(0, _background_transform->getNumChildren());
|
_background->removeChildren(0, _background->getNumChildren());
|
||||||
_background_transform = NULL;
|
_background = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
osg::Node *SDBackground::build(bool type, int grWrldX, int grWrldY, int grWrldZ, const std::string TrackPath)
|
void SDBackground::build(bool type, int grWrldX, int grWrldY, int grWrldZ, const std::string TrackPath)
|
||||||
{
|
{
|
||||||
bool land = type;
|
bool land = type;
|
||||||
|
|
||||||
|
@ -47,7 +48,7 @@ osg::Node *SDBackground::build(bool type, int grWrldX, int grWrldY, int grWrldZ,
|
||||||
pathList.push_back(LocalPath+"data/textures");
|
pathList.push_back(LocalPath+"data/textures");
|
||||||
osgDB::Registry::instance()->setDataFilePathList(pathList);
|
osgDB::Registry::instance()->setDataFilePathList(pathList);
|
||||||
|
|
||||||
_background_transform = new osg::MatrixTransform;
|
osg::ref_ptr<osg::MatrixTransform> _background_transform = new osg::MatrixTransform;
|
||||||
osg::Matrix mat( 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
|
osg::Matrix mat( 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);
|
0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
|
|
||||||
|
@ -58,14 +59,18 @@ osg::Node *SDBackground::build(bool type, int grWrldX, int grWrldY, int grWrldZ,
|
||||||
osg::Matrix t = osg::Matrix::translate(grWrldX /2, grWrldY /2, grWrldZ /2);
|
osg::Matrix t = osg::Matrix::translate(grWrldX /2, grWrldY /2, grWrldZ /2);
|
||||||
mat = mat * t;
|
mat = mat * t;
|
||||||
_background_transform->setMatrix(mat);
|
_background_transform->setMatrix(mat);
|
||||||
_background_transform->addChild( m_background );
|
_background_transform->addChild( m_background.get() );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
osg::ref_ptr<osg::Node> m_background = osgDB::readNodeFile("land.ac");
|
osg::ref_ptr<osg::Node> m_background = osgDB::readNodeFile("land.ac");
|
||||||
_background_transform->setMatrix(mat);
|
_background_transform->setMatrix(mat);
|
||||||
_background_transform->addChild( m_background );
|
_background_transform->addChild( m_background.get() );
|
||||||
}
|
}
|
||||||
|
|
||||||
return _background_transform.get();
|
osg::ref_ptr<osg::StateSet> bgstate = _background_transform->getOrCreateStateSet();
|
||||||
|
bgstate->setRenderBinDetails(-1, "RenderBin");
|
||||||
|
|
||||||
|
_background = new osg::Group;
|
||||||
|
_background->addChild(_background_transform.get());
|
||||||
}
|
}
|
||||||
|
|
|
@ -351,6 +351,7 @@ void SDRender::Init(tTrack *track)
|
||||||
}
|
}
|
||||||
|
|
||||||
m_scene->addChild(scenery->getScene());
|
m_scene->addChild(scenery->getScene());
|
||||||
|
m_scene->addChild(scenery->getBackground());
|
||||||
m_scene->setNodeMask(rcvShadowMask);
|
m_scene->setNodeMask(rcvShadowMask);
|
||||||
sceneGroup->addChild(m_scene);
|
sceneGroup->addChild(m_scene);
|
||||||
//sceneGroup->addChild(scenery->getScene());
|
//sceneGroup->addChild(scenery->getScene());
|
||||||
|
@ -457,13 +458,12 @@ void SDRender::UpdateLight( void )
|
||||||
{
|
{
|
||||||
sol_angle = (float)thesky->getSA();
|
sol_angle = (float)thesky->getSA();
|
||||||
moon_angle = (float)thesky->getMA();
|
moon_angle = (float)thesky->getMA();
|
||||||
//float deg = sol_angle * SD_RADIANS_TO_DEGREES;
|
|
||||||
sky_brightness = (float)(1.0 + cos(sol_angle)) / 2.0f;
|
sky_brightness = (float)(1.0 + cos(sol_angle)) / 2.0f;
|
||||||
|
|
||||||
GfOut("Sun Angle in Render = %f - sky brightness = %f\n", sol_angle, sky_brightness);
|
GfOut("Sun Angle in Render = %f - sky brightness = %f\n", sol_angle, sky_brightness);
|
||||||
|
|
||||||
|
|
||||||
if (SDTrack->local.rain > 0) // TODO: Different values for each rain strength value ?
|
if (SDTrack->local.rain > 0)
|
||||||
{
|
{
|
||||||
BaseFogColor = osg::Vec3f(0.42f, 0.44f, 0.50f);
|
BaseFogColor = osg::Vec3f(0.42f, 0.44f, 0.50f);
|
||||||
sky_brightness = (float)pow(sky_brightness, 0.5f);
|
sky_brightness = (float)pow(sky_brightness, 0.5f);
|
||||||
|
|
|
@ -53,7 +53,6 @@ SDScenery::SDScenery(void)
|
||||||
_bgsky = false;
|
_bgsky = false;
|
||||||
|
|
||||||
_scenery = NULL;
|
_scenery = NULL;
|
||||||
_background = NULL;
|
|
||||||
//_spectators = 0;
|
//_spectators = 0;
|
||||||
//_trees = 0;
|
//_trees = 0;
|
||||||
//_pits = 0;
|
//_pits = 0;
|
||||||
|
@ -70,7 +69,6 @@ SDScenery::~SDScenery(void)
|
||||||
|
|
||||||
delete SDTrack;
|
delete SDTrack;
|
||||||
|
|
||||||
_background = NULL;
|
|
||||||
_scenery = NULL;
|
_scenery = NULL;
|
||||||
SDTrack = NULL;
|
SDTrack = NULL;
|
||||||
}
|
}
|
||||||
|
@ -125,11 +123,7 @@ void SDScenery::LoadScene(tTrack *track)
|
||||||
std::string strPath = PathTmp;
|
std::string strPath = PathTmp;
|
||||||
sprintf(buf, "tracks/%s/%s", SDTrack->category, SDTrack->internalname);
|
sprintf(buf, "tracks/%s/%s", SDTrack->category, SDTrack->internalname);
|
||||||
strPath += buf;
|
strPath += buf;
|
||||||
osg::ref_ptr<osg::Node> bg= m_background->build(_bgtype, _grWrldX, _grWrldY, _grWrldZ, strPath);
|
m_background->build(_bgtype, _grWrldX, _grWrldY, _grWrldZ, strPath);
|
||||||
osg::ref_ptr<osg::StateSet> bgstate = bg->getOrCreateStateSet();
|
|
||||||
bgstate->setRenderBinDetails(-1, "RenderBin");
|
|
||||||
//bg->getOrCreateStateSet()->setRenderingHint( osg::StateSet::OPAQUE_BIN );
|
|
||||||
_scenery->addChild(bg.get());
|
|
||||||
GfOut("Background loaded\n");
|
GfOut("Background loaded\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,8 +39,6 @@ class osgLoader;
|
||||||
class SDBackground
|
class SDBackground
|
||||||
{
|
{
|
||||||
osg::ref_ptr<osg::Group> _background;
|
osg::ref_ptr<osg::Group> _background;
|
||||||
osg::ref_ptr<osg::Group> _scenery;
|
|
||||||
osg::ref_ptr<osg::MatrixTransform> _background_transform;
|
|
||||||
|
|
||||||
tTrack *SDTrack;
|
tTrack *SDTrack;
|
||||||
|
|
||||||
|
@ -54,8 +52,10 @@ public:
|
||||||
// Destructor
|
// Destructor
|
||||||
~SDBackground(void);
|
~SDBackground(void);
|
||||||
|
|
||||||
osg::Node *build(bool type, int X, int Y, int Z, const std::string strTrack);
|
void build(bool type, int X, int Y, int Z, const std::string strTrack);
|
||||||
void reposition(int X, int Y);
|
void reposition(int X, int Y);
|
||||||
|
|
||||||
|
osg::Group* getBackground() { return _background.get(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
/*class SDSpectators
|
/*class SDSpectators
|
||||||
|
@ -98,7 +98,6 @@ private:
|
||||||
//SDSpectators *m_spectators;
|
//SDSpectators *m_spectators;
|
||||||
//SDTrees *m_trees;
|
//SDTrees *m_trees;
|
||||||
osg::ref_ptr<osg::Group> _scenery;
|
osg::ref_ptr<osg::Group> _scenery;
|
||||||
osg::ref_ptr<osg::Group> _background;
|
|
||||||
|
|
||||||
tTrack *SDTrack;
|
tTrack *SDTrack;
|
||||||
|
|
||||||
|
@ -146,7 +145,8 @@ public:
|
||||||
inline static int getWorldZ(){return grWrldZ;}
|
inline static int getWorldZ(){return grWrldZ;}
|
||||||
inline static int getWorldMaxSize(){return grWrldMaxSize;}
|
inline static int getWorldMaxSize(){return grWrldMaxSize;}
|
||||||
|
|
||||||
osg::Node* getScene() { return _scenery.get(); }
|
osg::Group* getScene() { return _scenery.get(); }
|
||||||
|
osg::Group* getBackground() { return m_background->getBackground(); }
|
||||||
|
|
||||||
//osg::ref_ptr<osg::Group> getSDScenery { return _scenery };
|
//osg::ref_ptr<osg::Group> getSDScenery { return _scenery };
|
||||||
//osg::Group getSDBackground { return SDBackground->getbackground; }
|
//osg::Group getSDBackground { return SDBackground->getbackground; }
|
||||||
|
|
Loading…
Reference in a new issue