update OsgGraph

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@5437 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: c435402451d51e2ff7a41bfd73259f586a8ac783
Former-commit-id: e2f8da0cf66e3e75e74e3ef9b784fae8667d77d7
This commit is contained in:
torcs-ng 2013-05-09 19:37:42 +00:00
parent 0e7d744f08
commit 395b71edbe
6 changed files with 123 additions and 22 deletions

View file

@ -60,9 +60,7 @@ class SDCars
void loadCars(tSituation * pSituation);
void updateCars();
void updateShadingParameters(osg::Vec3f eye,osg::Matrixf modelview);
inline osg::ref_ptr<osg::Node> getCarsNode(){
return cars_branch;
}
osg::ref_ptr<osg::Node> getCarsNode(){ return cars_branch; }
};
#endif /* _OSGCAR_H_ */

View file

@ -65,8 +65,8 @@ void * getScenery()
return scenery;
}
static osg::ref_ptr<osg::Group> m_sceneroot = NULL;
static osg::ref_ptr<osg::Group> m_carroot = NULL;
//static osg::ref_ptr<osg::Group> m_sceneroot = NULL;
//static osg::ref_ptr<osg::Group> m_carroot = NULL;
static osg::Timer m_timer;
//static osg::Timer_t m_start_tick;
@ -208,7 +208,7 @@ int initView(int x, int y, int width, int height, int /* flag */, void *screen)
//m_sceneViewer->getUsage();
//m_sceneViewer->realize();
screens->Init(x,y,width,height,m_sceneroot);
screens->Init(x,y,width,height, render->getRoot());
/*GfuiAddKey(screen, GFUIK_END, "Zoom Minimum", (void*)GR_ZOOM_MIN, grSetZoom, NULL);
GfuiAddKey(screen, GFUIK_HOME, "Zoom Maximum", (void*)GR_ZOOM_MAX, grSetZoom, NULL);
@ -364,18 +364,18 @@ int initTrack(tTrack *track)
// Now, do the real track loading job.
grTrackHandle = GfParmReadFile(track->filename, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT);
osg::ref_ptr<osg::Group> sceneroot = NULL;
m_sceneroot = NULL;
//m_sceneroot = NULL;
/*if (m_NbActiveScreens > 0)
return grLoadScene(track);*/
scenery = new SDScenery;
render = new SDRender;
sceneroot = new osg::Group;
m_sceneroot = new osg::Group;
m_sceneroot->removeChildren(0, m_sceneroot->getNumChildren());
//m_sceneroot = new osg::Group;
//m_sceneroot->removeChildren(0, m_sceneroot->getNumChildren());
scenery->LoadScene(track);
render->Init(track);
m_sceneroot->addChild(render->getRoot());
//m_sceneroot->addChild(render->getRoot());
return 0;
}
@ -385,9 +385,9 @@ int initCars(tSituation *s)
char buf[256];
cars = new SDCars;
cars->loadCars(s);
m_sceneroot->addChild(cars->getCarsNode());
osgUtil::Optimizer optimizer;
optimizer.optimize(m_sceneroot);
render->addCars(cars->getCarsNode());
//osgUtil::Optimizer optimizer;
//optimizer.optimize(m_sceneroot);
GfOut("All cars loaded\n");
screens->InitCars(s);
@ -406,10 +406,10 @@ int initCars(tSituation *s)
void shutdownTrack(void)
{
delete scenery;
m_sceneroot->removeChildren(0, m_sceneroot->getNumChildren());
//m_sceneroot->removeChildren(0, m_sceneroot->getNumChildren());
// Do the real track termination job.
osgDB::Registry::instance()->clearObjectCache();
m_sceneroot = NULL;
//m_sceneroot = NULL;
//grShutdownScene();
if (grTrackHandle)

View file

@ -221,7 +221,10 @@ void SDRender::Init(tTrack *track)
osg::ref_ptr<osg::Group> sceneGroup = new osg::Group;
osg::ref_ptr<osg::Group> mRoot = new osg::Group;
m_RealRoot = new osg::Group;
sceneGroup->addChild(scenery->getScene());
//m_CarRoot->addChild(cars->getCarsNode());
sceneGroup->addChild(m_CarRoot.get());
osg::ref_ptr<osg::StateSet> stateSet = sceneGroup->getOrCreateStateSet();
stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);
@ -273,12 +276,21 @@ void SDRender::Init(tTrack *track)
stateSet->setMode(GL_LIGHTING, osg::StateAttribute::ON);
stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);
m_scene = new osg::Group;
m_scene->addChild(mRoot.get());
m_RealRoot = new osg::Group;
m_RealRoot->addChild(mRoot.get());
GfOut("LE POINTEUR %d\n",mRoot.get());
}//SDRender::Init
void SDRender::addCars(osg::Node* cars)
{
m_CarRoot = new osg::Group;
m_CarRoot->addChild(cars);
m_RealRoot->addChild(m_CarRoot.get());
osgUtil::Optimizer optimizer;
optimizer.optimize(m_RealRoot.get());
}
void SDRender::UpdateLight( void )
{
sol_angle = (float)thesky->getSA();
@ -435,3 +447,92 @@ void SDRender::UpdateFogColor(double sol_angle)
//
sd_gamma_correct_rgb( BaseFogColor._v );
}
void SDRender::Update(double currentTime, double accelTime)
{
// Detect first call (in order to initialize "last times").
static bool bInitialized = false;
static double lastTimeHighSpeed = 0;
static int lastTimeLowSpeed = 0;
// Nothing to do if static sky dome, or race not started.
//if (!grDynamicSkyDome) //TODO(kilo): find some meaning for this variable
if (!SDSkyDomeDistance || grTrack->skyversion < 1)
return;
if (currentTime < 0)
{
bInitialized = false;
return;
}
if (!bInitialized)
{
if (SDSkyDomeDistance && grTrack->skyversion > 0)
{
// Ensure the sun and moon positions are reset
const int timeOfDay = (int)grTrack->local.timeofday;
GLfloat sunAscension = grTrack->local.sunascension;
SDSunDeclination = (float)(15 * (double)timeOfDay / 3600 - 90.0);
const float moonAscension = grTrack->local.sunascension;
//SDMoonDeclination = grUpdateMoonPos(timeOfDay);
thesky->setSD( DEG2RAD(SDSunDeclination));
thesky->setSRA( sunAscension );
thesky->setMD( DEG2RAD(SDMoonDeclination) );
thesky->setMRA( DEG2RAD(moonAscension) );
}
lastTimeHighSpeed = currentTime;
lastTimeLowSpeed = 60 * (int)floor(accelTime / 60.0);
bInitialized = true;
return;
}
// At each call, update possibly high speed objects of the sky dome : the clouds.
SDScenery * scenery = (SDScenery *)getScenery();
double r_WrldX = scenery->getWorldX();
double r_WrldY = scenery->getWorldY();
//double r_WrldZ = SDScenery::getWorldZ();
osg::Vec3 viewPos(r_WrldX / 2, r_WrldY/ 2, 0.0 );
thesky->reposition(viewPos, 0, currentTime - lastTimeHighSpeed);
// Now, we are done for high speed objects.
lastTimeHighSpeed = currentTime;
// Check if time to update low speed objects : sun and moon (once every minute).
int nextTimeLowSpeed = 60 * (int)floor((accelTime + 60.0) / 60.0);
/*if (nextTimeLowSpeed == lastTimeLowSpeed)
return;*/
const float deltaTimeLowSpeed = (float)(nextTimeLowSpeed - lastTimeLowSpeed);
//lastTimeLowSpeed = nextTimeLowSpeed;
// Update sun and moon, and thus global lighting / coloring parameters of the scene.
//GfLogDebug("%f : Updating slow objects of the dynamic sky dome (sun and moon)\n", currentTime);
if (nextTimeLowSpeed != lastTimeLowSpeed)
{
// 1) Update sun position
const float deltaDecl = deltaTimeLowSpeed * 360.0f / (24.0f * 60.0f * 60.0f);
SDSunDeclination += deltaDecl;
if (SDSunDeclination >= 360.0f)
SDSunDeclination -= 360.0f;
thesky->setSD( DEG2RAD(SDSunDeclination) );
// 2) Update moon position
SDMoonDeclination += deltaDecl;
if (SDMoonDeclination >= 360.0f)
SDMoonDeclination -= 360.0f;
thesky->setMD( DEG2RAD(SDMoonDeclination) );
lastTimeLowSpeed = nextTimeLowSpeed;
}
// 3) Update scene color and light
UpdateLight();
}//grUpdateSky

View file

@ -31,8 +31,9 @@ class SDScenery;
class SDRender
{
private:
osg::ref_ptr<osg::Group> m_RealRoot;
osg::ref_ptr<osg::Group> m_scene;
//osg::ref_ptr<osg::Group> m_carroot;
osg::ref_ptr<osg::Group> m_CarRoot;
osg::Vec3f BaseSkyColor;
@ -69,13 +70,14 @@ public:
void Init(tTrack *track);
osg::ref_ptr< osg::StateSet> setFogState();
void Update(float speedcar, tSituation *s);
void UpdateTime(tSituation *s);
void UpdateLight(void);
void addCars(osg::Node* cars);
void UpdateFogColor(double angle);
void Update(double currentTime, double accelTime);
SDSky * getSky();
osg::Node* getRoot() { return m_scene.get(); }
osg::Node* getRoot() { return m_RealRoot.get(); }
};
#endif //_OSGRENDER_H_

View file

@ -50,7 +50,7 @@ public:
};
void SDScreens::Init(int x,int y, int width, int height, osg::ref_ptr<osg::Group> m_sceneroot)
void SDScreens::Init(int x,int y, int width, int height, osg::ref_ptr<osg::Node> m_sceneroot)
{
m_Winx = x;
m_Winy = y;

View file

@ -58,7 +58,7 @@ class SDScreens
SDScreens();
~SDScreens();
void Init(int x, int y, int width, int height, osg::ref_ptr<osg::Group> m_sceneroot);
void Init(int x, int y, int width, int height, osg::ref_ptr<osg::Node> m_sceneroot);
void InitCars(tSituation *s);
void update(tSituation *s,SDFrameInfo* fi);
void splitScreen(long p);