- fix bug mirror with OsgGraph (Ivan's patch)

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

Former-commit-id: f27739afc28009efe9332f001f0ca536e26da5bd
Former-commit-id: bed4524d634526fa2546439e7e7ad5301202594b
This commit is contained in:
torcs-ng 2019-11-17 19:31:43 +00:00
parent 0fe87f869c
commit b429f67d16
12 changed files with 243 additions and 306 deletions

View file

@ -753,33 +753,17 @@ osg::ref_ptr<osg::Node> SDCar::initOcclusionQuad(tCarElt *car)
return root.get();
}*/
void SDCar::deactivateCar(tCarElt *Car)
{
if(this->car == Car)
{
this->car_root->setNodeMask(NODE_MASK_NONE);
}
}
void SDCar::activateCar(tCarElt *Car)
{
if(this->car == Car)
{
this->car_root->setNodeMask(NODE_MASK_ALL);
}
}
void SDCar::markCarCurrent(tCarElt *Car)
{
if(this->car == Car)
{
pDriver->setNodeMask(NODE_MASK_CAR_DRIVER);
car_branch->setNodeMask(NODE_MASK_CAR_CURRENT);
car_branch->setNodeMask(NODE_MASK_CURCAR);
pDriver->setNodeMask(NODE_MASK_CURDRV);
}
else
{
pDriver->setNodeMask(NODE_MASK_ALL);
car_branch->setNodeMask(NODE_MASK_ALL);
pDriver->setNodeMask(NODE_MASK_ALL);
}
}
@ -942,25 +926,6 @@ void SDCars::loadCars(tSituation *pSituation, bool trackType, bool subCat)
return;
}
void SDCars::deactivateCar(tCarElt *car)
{
std::vector<SDCar *>::iterator it;
for(it = the_cars.begin(); it!= the_cars.end(); it++)
{
(*it)->deactivateCar(car);
}
}
void SDCars::activateCar(tCarElt *car)
{
std::vector<SDCar *>::iterator it;
for(it = the_cars.begin(); it!= the_cars.end(); it++)
{
(*it)->activateCar(car);
}
}
SDCar *SDCars::getCar(tCarElt *car)
{
std::vector<SDCar *>::iterator it;

View file

@ -62,7 +62,6 @@ public :
SDCar(void);
~SDCar(void);
osg::ref_ptr<osg::Node> loadCar(tCarElt *Car, bool tracktype, bool subcat, int carshader);
void deactivateCar(tCarElt *Car);
bool isCar(tCarElt*c);
bool _cockpit;
@ -80,7 +79,6 @@ public :
tCarElt *getCar();
void activateCar(tCarElt *Car);
void markCarCurrent(tCarElt *Car);
void updateCar();
void updateShadingParameters(osg::Matrixf modelview);
@ -102,8 +100,6 @@ public :
void loadCars(tSituation * pSituation, bool trackType, bool subCat);
void updateCars();
void deactivateCar(tCarElt*car);
void activateCar(tCarElt*car);
void markCarCurrent(tCarElt*car);
SDCar *getCar(tCarElt*car);
void unLoad();

View file

@ -30,8 +30,6 @@
osg::ref_ptr<osg::Node> SDCockpit::initCockpit(tCarElt *car, void *handle)
{
rcvShadowMask = 0x1;
castShadowMask = 0x2;
this->car = car;
const char *param;

View file

@ -44,4 +44,4 @@ public :
void updateWheels();
};
#endif /* _OSGCAR_H_ */
#endif /* _OSGWHEEL_H_ */

View file

@ -1,10 +1,10 @@
/***************************************************************************
file : OsgMain.cpp
created : Thu Aug 17 23:23:49 CEST 2000
copyright : (C)2013 by Xavier Bertaux
email : bertauxx@yahoo.fr
version : $Id: OsgMain.cpp 4712 2012-05-10 06:02:49Z mungewell $
file : OsgMain.cpp
created : Thu Aug 17 23:23:49 CEST 2000
copyright : (C)2013 by Xavier Bertaux
email : bertauxx@yahoo.fr
version : $Id: OsgMain.cpp 4712 2012-05-10 06:02:49Z mungewell $
***************************************************************************/
@ -51,27 +51,27 @@ SDHUD hud;
/*oid *getOptions()
{
return Options;
return Options;
}*/
void *getScreens()
{
return screens;
return screens;
}
void *getRender()
{
return render;
return render;
}
void * getCars()
{
return cars;
return cars;
}
void * getScenery()
{
return scenery;
return scenery;
}
static osg::Timer m_timer;
@ -106,238 +106,233 @@ static int m_CurrentScreenIndex = 0;
static void SDPrevCar(void * /* dummy */)
{
screens->getActiveView()->selectPrevCar();
screens->getActiveView()->selectPrevCar();
}
static void SDNextCar(void * /* dummy */)
{
screens->getActiveView()->selectNextCar();
screens->getActiveView()->selectNextCar();
}
void SDSelectCamera(void * vp)
{
long t = (long)vp;
screens->changeCamera(t);
long t = (long)vp;
screens->changeCamera(t);
}
void SDSetZoom(void * vp)
{
long t = (long)vp;
screens->getActiveView()->getCameras()->getSelectedCamera()->setZoom(t);
long t = (long)vp;
screens->getActiveView()->getCameras()->getSelectedCamera()->setZoom(t);
}
void SDSwitchMirror(void * vp)
{
screens->getActiveView()->switchMirror();
screens->getActiveView()->switchMirror();
}
void SDToggleHUD(void * vp)
{
screens->toggleDebugHUD();
screens->toggleDebugHUD();
}
int initView(int x, int y, int width, int height, int /* flag */, void *screen)
{
screens = new SDScreens();
screens = new SDScreens();
m_Winx = x;
m_Winy = y;
m_Winw = width;
m_Winh = height;
m_Winx = x;
m_Winy = y;
m_Winw = width;
m_Winh = height;
fMouseRatioX = width / 640.0;
fMouseRatioY = height / 480.0;
fMouseRatioX = width / 640.0;
fMouseRatioY = height / 480.0;
frameInfo.fInstFps = 0.0;
frameInfo.fAvgFps = 0.0;
frameInfo.nInstFrames = 0;
frameInfo.nTotalFrames = 0;
fFPSPrevInstTime = GfTimeClock();
nFPSTotalSeconds = 0;
frameInfo.fInstFps = 0.0;
frameInfo.fAvgFps = 0.0;
frameInfo.nInstFrames = 0;
frameInfo.nTotalFrames = 0;
fFPSPrevInstTime = GfTimeClock();
nFPSTotalSeconds = 0;
screens->Init(x,y,width,height, render->getRoot(), render->getFogColor());
screens->Init(x,y,width,height, render->getRoot(), render->getFogColor());
GfuiAddKey(screen, GFUIK_END, "Zoom Minimum", (void*)GR_ZOOM_MIN, SDSetZoom, NULL);
GfuiAddKey(screen, GFUIK_HOME, "Zoom Maximum", (void*)GR_ZOOM_MAX, SDSetZoom, NULL);
GfuiAddKey(screen, '*', "Zoom Default", (void*)GR_ZOOM_DFLT, SDSetZoom, NULL);
GfuiAddKey(screen, GFUIK_END, "Zoom Minimum", (void*)GR_ZOOM_MIN, SDSetZoom, NULL);
GfuiAddKey(screen, GFUIK_HOME, "Zoom Maximum", (void*)GR_ZOOM_MAX, SDSetZoom, NULL);
GfuiAddKey(screen, '*', "Zoom Default", (void*)GR_ZOOM_DFLT, SDSetZoom, NULL);
GfuiAddKey( screen, GFUIK_PAGEUP, "Select Previous Car", (void*)0, SDPrevCar, NULL);
GfuiAddKey( screen, GFUIK_PAGEDOWN, "Select Next Car", (void*)0, SDNextCar, NULL);
GfuiAddKey( screen, GFUIK_PAGEUP, "Select Previous Car", (void*)0, SDPrevCar, NULL);
GfuiAddKey( screen, GFUIK_PAGEDOWN, "Select Next Car", (void*)0, SDNextCar, NULL);
GfuiAddKey(screen, GFUIK_F2, "Driver Views", (void*)0, SDSelectCamera, NULL);
GfuiAddKey(screen, GFUIK_F3, "Car Views", (void*)1, SDSelectCamera, NULL);
GfuiAddKey(screen, GFUIK_F4, "Side Car Views", (void*)2, SDSelectCamera, NULL);
GfuiAddKey(screen, GFUIK_F5, "Up Car View", (void*)3, SDSelectCamera, NULL);
GfuiAddKey(screen, GFUIK_F6, "Persp Car View", (void*)4, SDSelectCamera, NULL);
GfuiAddKey(screen, GFUIK_F7, "All Circuit Views", (void*)5, SDSelectCamera, NULL);
GfuiAddKey(screen, GFUIK_F8, "Track View", (void*)6, SDSelectCamera, NULL);
GfuiAddKey(screen, GFUIK_F9, "Track View Zoomed", (void*)7, SDSelectCamera, NULL);
GfuiAddKey(screen, GFUIK_F10, "Follow Car Zoomed", (void*)8, SDSelectCamera, NULL);
GfuiAddKey(screen, GFUIK_F11, "TV Director View", (void*)9, SDSelectCamera, NULL);
GfuiAddKey(screen, GFUIK_F2, "Driver Views", (void*)0, SDSelectCamera, NULL);
GfuiAddKey(screen, GFUIK_F3, "Car Views", (void*)1, SDSelectCamera, NULL);
GfuiAddKey(screen, GFUIK_F4, "Side Car Views", (void*)2, SDSelectCamera, NULL);
GfuiAddKey(screen, GFUIK_F5, "Up Car View", (void*)3, SDSelectCamera, NULL);
GfuiAddKey(screen, GFUIK_F6, "Persp Car View", (void*)4, SDSelectCamera, NULL);
GfuiAddKey(screen, GFUIK_F7, "All Circuit Views", (void*)5, SDSelectCamera, NULL);
GfuiAddKey(screen, GFUIK_F8, "Track View", (void*)6, SDSelectCamera, NULL);
GfuiAddKey(screen, GFUIK_F9, "Track View Zoomed", (void*)7, SDSelectCamera, NULL);
GfuiAddKey(screen, GFUIK_F10, "Follow Car Zoomed", (void*)8, SDSelectCamera, NULL);
GfuiAddKey(screen, GFUIK_F11, "TV Director View", (void*)9, SDSelectCamera, NULL);
GfuiAddKey(screen, 'h', "Activate DEBUG HUD", (void*)0, SDToggleHUD, NULL);
GfuiAddKey(screen, 'h', "Activate DEBUG HUD", (void*)0, SDToggleHUD, NULL);
/*GfuiAddKey(screen, '5', "Debug Info", (void*)3, grSelectBoard, NULL);
GfuiAddKey(screen, '4', "G/Cmd Graph", (void*)4, grSelectBoard, NULL);
GfuiAddKey(screen, '3', "Leaders Board", (void*)2, grSelectBoard, NULL);
GfuiAddKey(screen, '2', "Driver Counters", (void*)1, grSelectBoard, NULL);
GfuiAddKey(screen, '1', "Driver Board", (void*)0, grSelectBoard, NULL);*/
GfuiAddKey(screen, '9', "Mirror", (void*)0, SDSwitchMirror, NULL);
//GfuiAddKey(screen, '0', "Arcade Board", (void*)5, grSelectBoard, NULL);*/
GfuiAddKey(screen, '+', GFUIM_CTRL, "Zoom In", (void*)GR_ZOOM_IN, SDSetZoom, NULL);
GfuiAddKey(screen, '=', GFUIM_CTRL, "Zoom In", (void*)GR_ZOOM_IN, SDSetZoom, NULL);
GfuiAddKey(screen, '-', GFUIM_CTRL, "Zoom Out", (void*)GR_ZOOM_OUT, SDSetZoom, NULL);
GfuiAddKey(screen, '>', "Zoom In", (void*)GR_ZOOM_IN, SDSetZoom, NULL);
GfuiAddKey(screen, '<', "Zoom Out", (void*)GR_ZOOM_OUT, SDSetZoom, NULL);
//GfuiAddKey(screen, '(', "Split Screen", (void*)SD_SPLIT_ADD, SDSplitScreen, NULL);
//GfuiAddKey(screen, ')', "UnSplit Screen", (void*)SD_SPLIT_REM, SDSplitScreen, NULL);
//GfuiAddKey(screen, '_', "Split Screen Arrangement", (void*)SD_SPLIT_ARR, SDSplitScreen, NULL);
//GfuiAddKey(screen, GFUIK_TAB, "Next (split) Screen", (void*)SD_NEXT_SCREEN, SDChangeScreen, NULL);
/*GfuiAddKey(screen, 'm', "Track Maps", (void*)0, grSelectTrackMap, NULL);*/
/*GfuiAddKey(screen, '5', "Debug Info", (void*)3, grSelectBoard, NULL);
GfuiAddKey(screen, '4', "G/Cmd Graph", (void*)4, grSelectBoard, NULL);
GfuiAddKey(screen, '3', "Leaders Board", (void*)2, grSelectBoard, NULL);
GfuiAddKey(screen, '2', "Driver Counters", (void*)1, grSelectBoard, NULL);
GfuiAddKey(screen, '1', "Driver Board", (void*)0, grSelectBoard, NULL);*/
GfuiAddKey(screen, '9', "Mirror", (void*)0, SDSwitchMirror, NULL);
//GfuiAddKey(screen, '0', "Arcade Board", (void*)5, grSelectBoard, NULL);*/
GfuiAddKey(screen, '+', GFUIM_CTRL, "Zoom In", (void*)GR_ZOOM_IN, SDSetZoom, NULL);
GfuiAddKey(screen, '=', GFUIM_CTRL, "Zoom In", (void*)GR_ZOOM_IN, SDSetZoom, NULL);
GfuiAddKey(screen, '-', GFUIM_CTRL, "Zoom Out", (void*)GR_ZOOM_OUT, SDSetZoom, NULL);
GfuiAddKey(screen, '>', "Zoom In", (void*)GR_ZOOM_IN, SDSetZoom, NULL);
GfuiAddKey(screen, '<', "Zoom Out", (void*)GR_ZOOM_OUT, SDSetZoom, NULL);
//GfuiAddKey(screen, '(', "Split Screen", (void*)SD_SPLIT_ADD, SDSplitScreen, NULL);
//GfuiAddKey(screen, ')', "UnSplit Screen", (void*)SD_SPLIT_REM, SDSplitScreen, NULL);
//GfuiAddKey(screen, '_', "Split Screen Arrangement", (void*)SD_SPLIT_ARR, SDSplitScreen, NULL);
//GfuiAddKey(screen, GFUIK_TAB, "Next (split) Screen", (void*)SD_NEXT_SCREEN, SDChangeScreen, NULL);
/*GfuiAddKey(screen, 'm', "Track Maps", (void*)0, grSelectTrackMap, NULL);*/
GfLogInfo("Current screen is #%d (out of %d)\n", m_CurrentScreenIndex, m_NbActiveScreens);
GfLogInfo("Current screen is #%d (out of %d)\n", m_CurrentScreenIndex, m_NbActiveScreens);
return 0; // true;
return 0; // true;
}
int refresh(tSituation *s)
{
// Compute F/S indicators every second.
frameInfo.nInstFrames++;
frameInfo.nTotalFrames++;
const double dCurTime = GfTimeClock();
const double dDeltaTime = dCurTime - fFPSPrevInstTime;
if (dDeltaTime > 1.0)
{
++nFPSTotalSeconds;
fFPSPrevInstTime = dCurTime;
frameInfo.fInstFps = frameInfo.nInstFrames / dDeltaTime;
frameInfo.nInstFrames = 0;
frameInfo.fAvgFps = (double)frameInfo.nTotalFrames / nFPSTotalSeconds;
// Trace F/S every 5 seconds.
if (nFPSTotalSeconds % 5 == 2)
GfLogInfo("Frame rate (F/s) : Instant = %.1f (Average %.1f)\n",
frameInfo.fInstFps, frameInfo.fAvgFps);
}
// Compute F/S indicators every second.
frameInfo.nInstFrames++;
frameInfo.nTotalFrames++;
const double dCurTime = GfTimeClock();
const double dDeltaTime = dCurTime - fFPSPrevInstTime;
if (dDeltaTime > 1.0)
{
++nFPSTotalSeconds;
fFPSPrevInstTime = dCurTime;
frameInfo.fInstFps = frameInfo.nInstFrames / dDeltaTime;
frameInfo.nInstFrames = 0;
frameInfo.fAvgFps = (double)frameInfo.nTotalFrames / nFPSTotalSeconds;
// Trace F/S every 5 seconds.
if (nFPSTotalSeconds % 5 == 2)
GfLogInfo("Frame rate (F/s) : Instant = %.1f (Average %.1f)\n",
frameInfo.fInstFps, frameInfo.fAvgFps);
}
cars->updateCars();
cam = screens->getActiveView()->getCameras()->getSelectedCamera();
osg::Vec3d eye = cam->getCameraPosition();
double X = eye[0];
double Y = eye[1];
double Z = eye[2];
scenery->reposition(X, Y, Z );
render->UpdateSky(s->currentTime, s->accelTime, X, Y);
screens->update(s, &frameInfo);
cars->updateCars();
cam = screens->getActiveView()->getCameras()->getSelectedCamera();
osg::Vec3d eye = cam->getCameraPosition();
double X = eye[0];
double Y = eye[1];
double Z = eye[2];
scenery->reposition(X, Y, Z );
render->UpdateSky(s->currentTime, s->accelTime, X, Y);
screens->update(s, &frameInfo);
//refresh the hud
tCarElt* curCar = screens->getActiveView()->getCurrentCar();
hud.Refresh(s, &frameInfo, curCar);
//refresh the hud
tCarElt* curCar = screens->getActiveView()->getCurrentCar();
hud.Refresh(s, &frameInfo, curCar);
return 0;
return 0;
}
void shutdownCars(void)
{
if (cars)
{
cars->unLoad();
delete cars;
cars = NULL;
GfLogInfo("Delete cars in OsgMain\n");
}
if (cars)
{
cars->unLoad();
delete cars;
cars = NULL;
GfLogInfo("Delete cars in OsgMain\n");
}
// Trace final mean F/s.
if (nFPSTotalSeconds > 0)
GfLogTrace("Average frame rate: %.2f F/s\n",
(double)frameInfo.nTotalFrames/((double)nFPSTotalSeconds + GfTimeClock() - fFPSPrevInstTime));
// Trace final mean F/s.
if (nFPSTotalSeconds > 0)
GfLogTrace("Average frame rate: %.2f F/s\n",
(double)frameInfo.nTotalFrames/((double)nFPSTotalSeconds + GfTimeClock() - fFPSPrevInstTime));
}
int initTrack(tTrack *track)
{
// The inittrack does as well init the context, that is highly inconsistent, IMHO.
// TODO: Find a solution to init the graphics first independent of objects.
// The inittrack does as well init the context, that is highly inconsistent, IMHO.
// TODO: Find a solution to init the graphics first independent of objects.
// Now, do the real track loading job.
grTrackHandle = GfParmReadFile(track->filename, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT);
// Now, do the real track loading job.
grTrackHandle = GfParmReadFile(track->filename, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT);
//Options = new SDOptions;
//Options = new SDOptions;
scenery = new SDScenery;
render = new SDRender;
//cam = new SDCamera;
scenery = new SDScenery;
render = new SDRender;
//cam = new SDCamera;
scenery->LoadScene(track);
render->Init(track);
scenery->LoadScene(track);
render->Init(track);
return 0;
return 0;
}
int initCars(tSituation *s)
{
GfLogInfo("InitCars\n");
char buf[1024];
cars = new SDCars;
cars->loadCars(s, scenery->getSpeedWay(), scenery->getSpeedWayLong());
render->addCars(cars->getCarsNode());
GfLogInfo("All cars loaded\n");
GfLogInfo("InitCars\n");
char buf[1024];
cars = new SDCars;
cars->loadCars(s, scenery->getSpeedWay(), scenery->getSpeedWayLong());
render->addCars(cars->getCarsNode());
GfLogInfo("All cars loaded\n");
screens->InitCars(s);
screens->InitCars(s);
if (!grHandle)
{
snprintf(buf, sizeof(buf), "%s%s", GfLocalDir(), GR_PARAM_FILE);
grHandle = GfParmReadFile(buf, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT);
}
if (!grHandle)
{
snprintf(buf, sizeof(buf), "%s%s", GfLocalDir(), GR_PARAM_FILE);
grHandle = GfParmReadFile(buf, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT);
}
return 0;
return 0;
}
void shutdownTrack(void)
{
// Do the real track termination job.
osgDB::Registry::instance()->clearObjectCache();
// Do the real track termination job.
osgDB::Registry::instance()->clearObjectCache();
if (grTrackHandle)
{
GfParmReleaseHandle(grTrackHandle);
grTrackHandle = 0;
}
if (grTrackHandle)
{
GfParmReleaseHandle(grTrackHandle);
grTrackHandle = 0;
}
if (scenery)
{
scenery->ShutdownScene();
delete scenery;
scenery = NULL;
GfLogInfo("Delete scenery in OsgMain\n");
}
if (scenery)
{
scenery->ShutdownScene();
delete scenery;
scenery = NULL;
GfLogInfo("Delete scenery in OsgMain\n");
}
}
void shutdownView(void)
{
if (screens)
{
delete screens;
screens = NULL;
GfLogInfo("Delete screens in OsgMain\n");
}
if (screens)
{
delete screens;
screens = NULL;
GfLogInfo("Delete screens in OsgMain\n");
}
if (render)
{
delete render;
render = NULL;
GfLogInfo("Delete render in OsgMain\n");
}
if (render)
{
delete render;
render = NULL;
GfLogInfo("Delete render in OsgMain\n");
}
}
Camera * getCamera(void)
{
return screens->getActiveView()->getCamera();
}
void markCarCurrent(tCarElt *curCar)
{
cars->markCarCurrent(curCar);
return screens->getActiveView()->getCamera();
}

View file

@ -52,7 +52,7 @@ extern tdble grMaxDammage;
// Number of active screens.
extern int m_NbActiveScreens;
//static
//static
#define SD_SPLIT_ADD 0
#define SD_SPLIT_REM 1
#define SD_SPLIT_ARR 2
@ -77,6 +77,5 @@ void * getScreens();
void * getRender();
void * getCars();
void * getScenery();
void markCarCurrent(tCarElt *curCar);
#endif /* _OSGMAIN_H_ */

View file

@ -30,45 +30,6 @@
#include <car.h>
class CameraPreCallback : public osg::Camera::DrawCallback
{
private:
tCarElt * car;
public:
void setCar(tCarElt *c)
{
car = c;
}
virtual void operator()(const osg::Camera& cam) const
{
SDCars * cars = (SDCars *)getCars();
cars->deactivateCar(car);
}
};
class CameraPostCallback : public osg::Camera::DrawCallback
{
private:
tCarElt * car;
public:
void setCar(tCarElt *c)
{
car = c;
}
virtual void operator()(const osg::Camera& cam) const
{
SDCars * cars = (SDCars *)getCars();
cars->activateCar(car);
}
};
CameraPreCallback *pre_cam = new CameraPreCallback;
CameraPostCallback *post_cam = new CameraPostCallback;
SDReflectionMapping::SDReflectionMapping(SDCar *c):
camerasRoot(NULL),
reflectionMap(NULL),
@ -127,9 +88,9 @@ SDReflectionMapping::SDReflectionMapping(SDCar *c):
camera->addChild( m_sceneroot );
camera->setProjectionMatrixAsPerspective(90.0, 1.0, 1.0, 80000.0);
if (reflectionShader > 1)
if (reflectionShader > 1)
camera->setNodeMask(NODE_MASK_NONE);
camerasRoot->addChild(camera);
cameras.push_back(camera);
@ -154,9 +115,6 @@ void SDReflectionMapping::update()
tCarElt *Car = this->car->getCar();
pre_cam->setCar(Car);
post_cam->setCar(Car);
sgVec3 p;
osg::Vec3 eye, center, up;

View file

@ -383,19 +383,19 @@ void SDRender::Init(tTrack *track)
case 0:
break;
case 1:
scene->setNodeMask(NODE_MASK_SHADOW_RECV);
scene->setNodeMask(~NODE_MASK_SHADOW_CAST);
background->setNodeMask(~(NODE_MASK_SHADOW_RECV | NODE_MASK_SHADOW_CAST));
cargroup->setNodeMask(NODE_MASK_SHADOW_CAST);
cargroup->setNodeMask(~NODE_MASK_SHADOW_RECV);
break;
case 2:
scene->setNodeMask(NODE_MASK_SHADOW_RECV);
scene->setNodeMask(~NODE_MASK_SHADOW_CAST);
background->setNodeMask(~(NODE_MASK_SHADOW_RECV | NODE_MASK_SHADOW_CAST));
cargroup->setNodeMask(NODE_MASK_SHADOW_RECV | NODE_MASK_SHADOW_CAST);
cargroup->setNodeMask(NODE_MASK_ALL);
break;
case 3:
scene->setNodeMask(NODE_MASK_SHADOW_RECV | NODE_MASK_SHADOW_CAST);
scene->setNodeMask(NODE_MASK_ALL);
background->setNodeMask(~(NODE_MASK_SHADOW_RECV | NODE_MASK_SHADOW_CAST));
cargroup->setNodeMask(NODE_MASK_SHADOW_RECV | NODE_MASK_SHADOW_CAST);
cargroup->setNodeMask(NODE_MASK_ALL);
break;
default:
break;
@ -454,7 +454,7 @@ void SDRender::Init(tTrack *track)
skyGroup = new osg::Group;
skyGroup->setName("skyCloudsGroup");
skyGroup->setNodeMask(NODE_MASK_SKY_BACKGROUND);
skyGroup->setNodeMask(NODE_MASK_SKY_BACKGROUND);
skyGroup->addChild(thesky->getPreRoot());
skyGroup->addChild((thesky->getCloudRoot()));
@ -493,7 +493,7 @@ void SDRender::ShadowedScene()
vdsm->setTextureSize(osg::Vec2s(ShadowTexSize, ShadowTexSize));
vdsm->setTextureUnit(shadowTexUnit);
shadowRoot = new osgShadow::ShadowedScene;
shadowRoot->setReceivesShadowTraversalMask(NODE_MASK_SHADOW_RECV);
shadowRoot->setReceivesShadowTraversalMask(NODE_MASK_SHADOW_RECV);
shadowRoot->setCastsShadowTraversalMask(NODE_MASK_SHADOW_CAST);
shadowRoot->setShadowTechnique((vdsm.get()));
}
@ -538,7 +538,7 @@ void SDRender::ShadowedScene()
lspsm->setBaseTextureUnit(baseTexUnit);
shadowRoot = new osgShadow::ShadowedScene;
shadowRoot->setReceivesShadowTraversalMask(NODE_MASK_SHADOW_RECV);
shadowRoot->setReceivesShadowTraversalMask(NODE_MASK_SHADOW_RECV);
shadowRoot->setCastsShadowTraversalMask(NODE_MASK_SHADOW_CAST);
shadowRoot->setShadowTechnique((lspsm.get()));
}

View file

@ -20,16 +20,37 @@
#ifndef _OSGNODEMASK_H
#define _OSGNODEMASK_H 1
enum NodeMask
enum NodeMask : unsigned int
{
NODE_MASK_NONE = 0,
NODE_MASK_ALL = 0xffffffff,
NODE_MASK_SHADOW_RECV = 1 << 0,
NODE_MASK_SHADOW_CAST = 1 << 1,
NODE_MASK_CAR_CURRENT = 1 << 2,
NODE_MASK_CAR_DRIVER = 1 << 3,
NODE_MASK_SKY_BACKGROUND = 1 << 4,
NODE_MASK_SKY_MODEL = 1 << 5,
NODE_MASK_NONE = 0u,
NODE_MASK_ALL = 0xffffffffu,
NODE_MASK_COMMON = 1u << 0,
NODE_MASK_COMMON_CURCAR = 1u << 1,
NODE_MASK_COMMON_CURDRV = 1u << 2,
NODE_MASK_SKY_BACKGROUND = 1u << 3,
NODE_MASK_SKY_MODEL = 1u << 4,
NODE_MASK_SHADOW_RECV_COMMON = 1u << 5,
NODE_MASK_SHADOW_CAST_COMMON = 1u << 6,
NODE_MASK_SHADOW_RECV_CURCAR = 1u << 7,
NODE_MASK_SHADOW_CAST_CURCAR = 1u << 8,
NODE_MASK_SHADOW_RECV_CURDRV = 1u << 9,
NODE_MASK_SHADOW_CAST_CURDRV = 1u << 10,
NODE_MASK_SHADOW_RECV = NODE_MASK_SHADOW_RECV_COMMON
| NODE_MASK_SHADOW_RECV_CURCAR
| NODE_MASK_SHADOW_RECV_CURDRV,
NODE_MASK_SHADOW_CAST = NODE_MASK_SHADOW_CAST_COMMON
| NODE_MASK_SHADOW_CAST_CURCAR
| NODE_MASK_SHADOW_CAST_CURDRV,
NODE_MASK_CURCAR = NODE_MASK_COMMON_CURCAR
| NODE_MASK_SHADOW_RECV_CURCAR
| NODE_MASK_SHADOW_CAST_CURCAR,
NODE_MASK_CURDRV = NODE_MASK_COMMON_CURDRV
| NODE_MASK_SHADOW_RECV_CURDRV
| NODE_MASK_SHADOW_CAST_CURDRV,
};
#endif // _OSGNODEMASK_H

View file

@ -54,7 +54,7 @@ SDCamera::SDCamera(SDView * c, int myid, int mydrawCurrent, int mydrawCkt, int
screen = c;
id = myid;
drawCurrent = mydrawCurrent;
drawCockpit = mydrawCkt;
drawCockpit = mydrawCkt;
drawDriver = mydrawdrv;
drawBackground = mydrawBackground;
mirrorAllowed = mymirrorAllowed;
@ -75,16 +75,16 @@ Camera * SDCamera::getGenericCamera()
return c;
}
unsigned int SDCamera::getCullMask()
unsigned int SDCamera::getCullMask()
{
unsigned int mask = NODE_MASK_ALL;
if (!getDrawCurrent())
mask &= ~NODE_MASK_CAR_CURRENT;
mask &= ~NODE_MASK_CURCAR;
if (!getDrawDriver())
mask &= ~NODE_MASK_CAR_DRIVER;
mask &= ~NODE_MASK_CURDRV;
return mask;
}
@ -118,7 +118,7 @@ SDPerspCamera::SDPerspCamera(SDView *myscreen, int id, int drawCurr, int drawCkt
}
void SDPerspCamera::setProjection(void)
{
{
screen->getOsgCam()->setProjectionMatrixAsPerspective(fovy,screen->getViewRatio() / spanaspect,fnear,ffar);
// correct view for split screen spanning

View file

@ -285,7 +285,7 @@ void OSGPLOT::recalculateDrawnPoint()
//find max and min values for our plot
//just draw point that are in our range of time
for(osg::Vec3Array::iterator it = this->dataPoints->begin(); it != this->dataPoints->end(); /*++it*/)
for(osg::Vec3Array::iterator it = this->dataPoints->begin(); it != this->dataPoints->end(); /*++it*/)
{
if((*it).x() <= (GfTimeClock() - this->timeFrame) || (*it).x() <= 0)
{
@ -299,13 +299,13 @@ void OSGPLOT::recalculateDrawnPoint()
{
this->maxValue = (float)(*it).y();
}
//find min
if ((*it).y() < this->minValue)
{
this->minValue = (float)(*it).y();
}
++it;
}
}
@ -401,7 +401,7 @@ void OSGPLOT::drawBackground()
osg::Vec3(this->positionX + this->width, this->positionY + this->height, 0.0f),
osg::Vec3(this->positionX, this->positionY+this->height, 0.0f),
};
int numCoords = sizeof(myCoords)/sizeof(osg::Vec3);
osg::Vec3Array* vertices = new osg::Vec3Array(numCoords,myCoords);
@ -435,19 +435,19 @@ void OSGPLOT::drawBackground()
}
// TODO[START]: move this to utils? /src/modules/graphic/osggraph/Utils
void split(const std::string &s, char delim, std::vector<std::string> &elems)
void split(const std::string &s, char delim, std::vector<std::string> &elems)
{
std::stringstream ss;
ss.str(s);
std::string item;
while (getline(ss, item, delim))
while (getline(ss, item, delim))
{
elems.push_back(item);
}
}
std::vector<std::string> split(const std::string &s, char delim)
std::vector<std::string> split(const std::string &s, char delim)
{
std::vector<std::string> elems;
split(s, delim, elems);
@ -455,7 +455,7 @@ std::vector<std::string> split(const std::string &s, char delim)
}
std::string formatLaptime(tdble sec, int sgn)
std::string formatLaptime(tdble sec, int sgn)
{
std::ostringstream lapTimeString;
@ -481,7 +481,7 @@ std::string formatLaptime(tdble sec, int sgn)
{
lapTimeString << "0";
}
lapTimeString << m;
lapTimeString << ":";
@ -491,7 +491,7 @@ std::string formatLaptime(tdble sec, int sgn)
{
lapTimeString << "0";
}
lapTimeString << s;
lapTimeString << ".";
@ -506,7 +506,7 @@ std::string formatLaptime(tdble sec, int sgn)
{
lapTimeString << "0";
}
lapTimeString << ms;
return lapTimeString.str();
@ -668,7 +668,7 @@ void SDHUD::CreateHUD(int scrH, int scrW)
{
this->hudScale = scaleW;
}
GfLogInfo("OSGHUD: Hud Scale is: %f\n", this->hudScale);
//generate the hud from the relative xml file
@ -690,7 +690,7 @@ void SDHUD::Refresh(tSituation *s, const SDFrameInfo* frameInfo,
//update all the graphs
typedef std::map<std::string,OSGPLOT* >::iterator it_type;
for(it_type iterator = this->plotElements.begin(); iterator != this->plotElements.end(); iterator++)
{
// iterator->first = key
@ -708,7 +708,7 @@ void SDHUD::Refresh(tSituation *s, const SDFrameInfo* frameInfo,
std::vector<tCarElt *> boardCars;
// get pointers for previous and behind cars from us
if (currCar->_pos > 2)
if (currCar->_pos > 2)
{
secondAheadCar = s->cars[currCar->_pos - 3];
boardCars.push_back(secondAheadCar);
@ -726,7 +726,7 @@ void SDHUD::Refresh(tSituation *s, const SDFrameInfo* frameInfo,
boardCars.push_back(firstBehindCar);
}
if (currCar->_pos < (s->_ncars-1) )
if (currCar->_pos < (s->_ncars-1) )
{
secondBehindCar = s->cars[currCar->_pos + 1];
boardCars.push_back(secondBehindCar);
@ -825,7 +825,7 @@ void SDHUD::Refresh(tSituation *s, const SDFrameInfo* frameInfo,
}
hudTextElements[mapKey.str()]->setText(tempStr.str());
hudTextElements[mapKey.str()]->setNodeMask(NODE_MASK_ALL);
hudTextElements[mapKey.str()]->setNodeMask(NODE_MASK_ALL);
//hide time diff for our car
if ((*car) == currCar)
{
@ -940,7 +940,7 @@ void SDHUD::Refresh(tSituation *s, const SDFrameInfo* frameInfo,
this->hudImgElements["laptime-last-background-normal"]->setNodeMask(NODE_MASK_ALL);
this->hudImgElements["laptime-last-background-grey"]->setNodeMask(NODE_MASK_NONE);
this->hudImgElements["laptime-last-background-violet"]->setNodeMask(NODE_MASK_NONE);
this->hudImgElements["laptime-last-background-green"]->setNodeMask(NODE_MASK_NONE);
this->hudImgElements["laptime-last-background-green"]->setNodeMask(NODE_MASK_NONE);
this->hudImgElements["laptime-last-background-red"]->setNodeMask(NODE_MASK_NONE);
//show laptime
@ -1009,16 +1009,16 @@ void SDHUD::Refresh(tSituation *s, const SDFrameInfo* frameInfo,
bool spd = false; // Show speed limiter indicator?
// Parse control messages if they include ABS / TCS / SPD
for (int i = 0; i < 4; i++)
for (int i = 0; i < 4; i++)
{
if (currCar->ctrl.msg[i])
if (currCar->ctrl.msg[i])
{
abs = abs || strstr(currCar->ctrl.msg[i], "ABS");
tcs = tcs || strstr(currCar->ctrl.msg[i], "TCS");
spd = spd || strstr(currCar->ctrl.msg[i], "Speed Limiter On");
}
}
this->hudImgElements["abs-icon"]->setNodeMask(abs ? NODE_MASK_ALL : NODE_MASK_NONE);
this->hudImgElements["tcs-icon"]->setNodeMask(tcs ? NODE_MASK_ALL : NODE_MASK_NONE);
@ -1062,7 +1062,7 @@ void SDHUD::Refresh(tSituation *s, const SDFrameInfo* frameInfo,
//make the camera visible
_cameraHUD->setNodeMask(1-_cameraHUD->getNodeMask());
_cameraHUD->setNodeMask(NODE_MASK_ALL);
}

View file

@ -17,6 +17,10 @@
* *
***************************************************************************/
// include RenderInfo first which contains a word "_style"
// which can be replaced by the same preprocessor definition from <car.h>
// and GCC will raise a strange untrackable compilation error
#include <osg/RenderInfo>
#include <osg/Camera>
#include <tgfclient.h>
@ -24,6 +28,7 @@
#include "OsgMain.h"
#include "OsgView.h"
#include "OsgCar.h"
#include "OsgNodeMask.h"
static char buf[1024];
@ -102,7 +107,7 @@ void SDView::Init(tSituation *s)
void SDView::setCurrentCar(tCarElt *newCurCar)
{
curCar = newCurCar;
markCarCurrent(curCar);
((SDCars*)getCars())->markCarCurrent(curCar);
}
/* Update screen display */
@ -148,7 +153,7 @@ void SDView::update(tSituation *s, const SDFrameInfo* frameInfo)
loadParams (s);
//board->setWidth(fakeWidth);
GfParmWriteFile(NULL, grHandle, "Graph");
markCarCurrent(curCar);
((SDCars*)getCars())->markCarCurrent(curCar);
}
if(hasChangedMirrorFlag)
@ -180,7 +185,7 @@ void SDView::activate(int x, int y, int width, int height, float v)
void SDView::deactivate()
{
cam->setNodeMask(NODE_MASK_NONE);
cam->setNodeMask(NODE_MASK_NONE);
mirrorCam->setNodeMask(NODE_MASK_NONE);
}