- Update OsgGraph

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

Former-commit-id: b2e0376d83258f328ff9b6562105289c9793131e
Former-commit-id: dc289ee7d04fb423cb73975fd1c0b1e49ecc558c
This commit is contained in:
torcs-ng 2015-04-22 21:19:36 +00:00
parent 230949176c
commit ef9d4967fc
5 changed files with 34 additions and 28 deletions

View file

@ -57,18 +57,20 @@ SDCar::SDCar(void) :
_wing1 = false;
_wing3 = false;
_steer = false;
_carShader = 0;
}
SDCar::~SDCar(void)
{
//car_root->removeChildren(0, car_root->getNumChildren());
//car_root = NULL;
car_root->removeChildren(0, car_root->getNumChildren());
car_root = NULL;
delete shader;
delete reflectionMapping;
}
osg::ref_ptr<osg::Node> SDCar::loadCar(tCarElt *car, bool tracktype, bool subcat, unsigned carshader)
osg::ref_ptr<osg::Node> SDCar::loadCar(tCarElt *car, bool tracktype, bool subcat, int carshader)
{
this->car = car;
static const int nMaxTexPathSize = 512;
@ -82,6 +84,8 @@ osg::ref_ptr<osg::Node> SDCar::loadCar(tCarElt *car, bool tracktype, bool subcat
castShadowMask = 0x2;
char path[nMaxTexPathSize];
_carShader = carshader;
#if 1
osgLoader loader;
@ -156,7 +160,8 @@ osg::ref_ptr<osg::Node> SDCar::loadCar(tCarElt *car, bool tracktype, bool subcat
gCar->setName("CAR");
osg::ref_ptr<osg::Switch> pBody =new osg::Switch;
pBody->setName("COCK");
osg::ref_ptr<osg::Group> pCar = new osg::Group;
osg::ref_ptr<osg::Node> pCar = new osg::Node;
osg::ref_ptr<osg::Node> pCockpit = new osg::Node;
osg::ref_ptr<osg::Switch> pWing = new osg::Switch;
pWing->setName("WING");
osg::ref_ptr<osg::Switch> pWing3 = new osg::Switch;
@ -171,10 +176,10 @@ osg::ref_ptr<osg::Node> SDCar::loadCar(tCarElt *car, bool tracktype, bool subcat
strPath+=buf;
GfLogInfo("Chemin Textures : %s\n", strTPath.c_str());
osg::ref_ptr<osg::Node> Car = new osg::Node;
Car = loader.Load3dFile(strPath, true);
//osg::ref_ptr<osg::Node> Car = new osg::Node;
pCar = loader.Load3dFile(strPath, true);
pCar->addChild(Car.get());
//pCar->addChild(Car.get());
#if 0
std::string pCar_path = GetLocalDir();
pCar_path = pCar_path+name+".osg";
@ -303,20 +308,19 @@ osg::ref_ptr<osg::Node> SDCar::loadCar(tCarElt *car, bool tracktype, bool subcat
snprintf(buf, nMaxTexPathSize, "cars/models/%s/", car->_carName);
tmp = tmp+buf;
osg::ref_ptr<osg::Node> cockpit = new osg::Node;
strPath= tmp+param;
cockpit = loader.Load3dFile(strPath, true);
pCockpit = loader.Load3dFile(strPath, true);
GfLogInfo("Cockpit loaded = %s !\n", strPath.c_str());
#if 0
std::string pCockpit_path = GetLocalDir();
pCockpit_path = pCockpit_path+"cockpit.osg";
osgDB::writeNodeFile( *cock, pCockpit_path );
#endif
}
pBody->addChild(pCockpit.get(), false);
/* add Steering Wheel 0 (if one exists) */
snprintf(path, nMaxTexPathSize, "%s/%s", SECT_GROBJECTS, SECT_STEERWHEEL);
param = GfParmGetStr(handle, path, PRM_SW_MODEL, NULL);
@ -426,8 +430,8 @@ osg::ref_ptr<osg::Node> SDCar::loadCar(tCarElt *car, bool tracktype, bool subcat
#endif
}
pCar->addChild(pWing.get());
pCar->addChild(pWing3.get());
gCar->addChild(pWing.get());
gCar->addChild(pWing3.get());
gCar->addChild(pCar.get());
gCar->addChild(pDriver.get());
@ -470,7 +474,7 @@ osg::ref_ptr<osg::Node> SDCar::loadCar(tCarElt *car, bool tracktype, bool subcat
#endif
pBody->addChild(gCar.get(), true);
pBody->setSingleChildOn(0);
pBody->setSingleChildOn(1);
osg::ref_ptr<osg::MatrixTransform> transform1 = new osg::MatrixTransform;
transform1->addChild(pBody.get());
@ -487,13 +491,13 @@ osg::ref_ptr<osg::Node> SDCar::loadCar(tCarElt *car, bool tracktype, bool subcat
this->shader = new SDCarShader(pCar.get(), this);
if (carshader > 1)
if (_carShader > 1)
this->reflectionMappingMethod = REFLECTIONMAPPING_DYNAMIC;
else
this->reflectionMappingMethod = REFLECTIONMAPPING_OFF;
this->reflectionMapping = new SDReflectionMapping(this);
this->setReflectionMap(reflectionMapping->getReflectionMap());
this->setReflectionMap(this->reflectionMapping->getReflectionMap());
return this->car_root;
}
@ -502,14 +506,14 @@ bool SDCar::isCar(tCarElt*c)
{
return c==car;
}
SDReflectionMapping * SDCar::getReflectionMap()
SDReflectionMapping *SDCar::getReflectionMap()
{
return reflectionMapping;
return this->reflectionMapping;
}
int SDCar::getReflectionMappingMethod()
{
return reflectionMappingMethod;
return this->reflectionMappingMethod;
}
tCarElt *SDCar::getCar()

View file

@ -57,7 +57,7 @@ private :
public :
SDCar(void);
~SDCar(void);
osg::ref_ptr<osg::Node> loadCar(tCarElt *car, bool tracktype, bool subcat, unsigned carshader);
osg::ref_ptr<osg::Node> loadCar(tCarElt *car, bool tracktype, bool subcat, int carshader);
void deactivateCar(tCarElt *car);
bool isCar(tCarElt*c);
@ -66,6 +66,7 @@ public :
bool _wing1;
bool _wing3;
bool _steer;
int _carShader;
SDReflectionMapping *getReflectionMap();

View file

@ -68,7 +68,7 @@ private:
unsigned SDSkyDomeDistThresh;
unsigned int rcvShadowMask;
unsigned int castShadowMask;
unsigned carsShader;
int carsShader;
int SDDynamicWeather;
bool SDDynamicSkyDome;
@ -110,7 +110,7 @@ public:
void weather(void);
inline SDSky * getSky() { return thesky; }
inline unsigned getShader() { return carsShader; }
inline int getShader() { return carsShader; }
osg::ref_ptr<osg::Group> getRoot() { return m_RealRoot.get(); }
osg::ref_ptr<osg::Group> getSceneRoot() { return m_scene.get(); }
osg::ref_ptr<osg::Group> getCarRoot() { return m_CarRoot.get(); }

View file

@ -28,7 +28,7 @@
#include "OsgCar.h"
#include "OsgSky.h"
SDCarShader::SDCarShader(osg::Group *car, SDCar *c)
SDCarShader::SDCarShader(osg::Node *car, SDCar *c)
{
std::string TmpPath = GetDataDir();
osg::ref_ptr<osg::Shader> vertShader = new osg::Shader( osg::Shader::VERTEX);
@ -39,7 +39,8 @@ SDCarShader::SDCarShader(osg::Group *car, SDCar *c)
program->addShader( vertShader.get() );
program->addShader( fragShader.get() );
pCar= dynamic_cast<osg::Group *> (car);
//pCar= dynamic_cast<osg::Group *> (car);
pCar = car;
this->pSdCar = c;
stateset = pCar->getOrCreateStateSet();
stateset->setAttributeAndModes(program);
@ -47,7 +48,7 @@ SDCarShader::SDCarShader(osg::Group *car, SDCar *c)
diffuseMap = new osg::Uniform("diffusemap", 0 );
stateset->addUniform(diffuseMap);
specularColor = new osg::Uniform("specularColor", osg::Vec4(0.8f,0.8f,0.8f,1.0f));
specularColor = new osg::Uniform("specularColor", osg::Vec4(0.8f, 0.8f, 0.8f, 1.0f));
stateset->addUniform(specularColor);
lightVector = stateset->getOrCreateUniform("lightvector",osg::Uniform::FLOAT_VEC3);
@ -56,7 +57,7 @@ SDCarShader::SDCarShader(osg::Group *car, SDCar *c)
shininess = new osg::Uniform("smoothness", 300.0f);
stateset->addUniform(shininess);
reflectionMappingMethod = new osg::Uniform("reflectionMappingMethod",pSdCar->getReflectionMappingMethod());
reflectionMappingMethod = new osg::Uniform("reflectionMappingMethod", this->pSdCar->getReflectionMappingMethod());
reflectionMapCube = new osg::Uniform("reflectionMapCube", 2 );
reflectionMap2DSampler = new osg::Uniform("reflectionMap2DSampler", 2 );
reflectionMapStaticOffsetCoords = stateset->getOrCreateUniform("reflectionMapStaticOffsetCoords", osg::Uniform::FLOAT_VEC3);

View file

@ -24,7 +24,7 @@ class SDCar;
class SDCarShader
{
private :
SDCar * pSdCar;
SDCar *pSdCar;
osg::ref_ptr<osg::Program> program ;
osg::ref_ptr<osg::Node> pCar;
@ -45,7 +45,7 @@ private :
osg::ref_ptr<osg::Uniform> reflectionMapStaticOffsetCoords;
public :
SDCarShader(osg::Group *car, SDCar *c);
SDCarShader(osg::Node *car, SDCar *c);
void update(osg::Matrixf view);
};