- Update MPA1 (normalize driver loaded)

- added animate driver on Osg
- added brake lights on MPA1 (on OSG)

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

Former-commit-id: aedae61cddd2a4c076ede1737c8e8b6a2d631365
Former-commit-id: ec0833f305085fa587afbccfed50593d7238d6b8
This commit is contained in:
torcs-ng 2015-09-23 22:24:55 +00:00
parent 22aed795ed
commit d35c68de73
9 changed files with 225 additions and 67 deletions

View file

@ -75,6 +75,7 @@ SET(OSGGRAPH_SOURCES Utils/OsgMath.cpp
Car/OsgCar.cpp
Car/OsgWheel.cpp
Car/OsgBrake.cpp
Car/OsgCarLight.cpp
OsgGraph.cpp
OsgMain.cpp

View file

@ -147,7 +147,7 @@ osg::ref_ptr<osg::Geode> SDBrakes::initBrake(int wheelIndex)
for (i = 0; i < (brakeBranch / 2 + 2); i++)
{
alpha = curAngle + (float)i * 2.0 * SD_PI / (float)(brakeBranch - 1);
alpha = curAngle + (float)i * 2.0 * M_PI / (float)(brakeBranch - 1);
vtx[0] = car->_brakeDiskRadius(wheelIndex) * cos(alpha);
vtx[1] = b_offset;
vtx[2] = car->_brakeDiskRadius(wheelIndex) * sin(alpha);

View file

@ -21,14 +21,15 @@
#include <osg/MatrixTransform>
#include <osg/Switch>
#include <osg/Group>
#include <osg/LOD>
#include <osgUtil/Simplifier>
#include <osgViewer/Viewer>
#include <osg/Program>
#include <osg/Geode>
#include <osg/Geometry>
#include <osg/Texture2D>
#include <osg/AlphaFunc>
#include <osg/BlendFunc>
#include <osg/Material>
#include <osg/Depth>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
@ -51,6 +52,11 @@ class SDRender;
SDCar::SDCar(void) :
car_branch(NULL),
car_root(NULL),
pLight(NULL),
pLightBrake(NULL),
pWing3(NULL),
pDriver(NULL),
pSteer(NULL),
shader(NULL),
reflectionMapping(NULL)
{
@ -59,6 +65,8 @@ SDCar::SDCar(void) :
_wing1 = false;
_wing3 = false;
_steer = false;
_light = false;
_lightbrake = false;
_carShader = 0;
}
@ -167,15 +175,15 @@ osg::ref_ptr<osg::Node> SDCar::loadCar(tCarElt *car, bool tracktype, bool subcat
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;
pLight = new osg::Switch;
pLightBrake = new osg::Switch;
pWing->setName("WING");
osg::ref_ptr<osg::Switch> pWing3 = new osg::Switch;
pWing->setName("WINGREAR");
osg::ref_ptr<osg::Switch> pDriver = new osg::Switch;
pWing3 = new osg::Switch;
pWing3->setName("WINGREAR");
pDriver = new osg::Switch;
pDriver->setName("DRIVER");
osg::ref_ptr<osg::Switch> pSteer = new osg::Switch;
pSteer->setName("STEER");
osg::ref_ptr<osg::Group> pHiSteer = new osg::Switch;
pHiSteer->setName("HISTEER");
pSteer = new osg::LOD;
pSteer->setName("STEER");
strPath+=buf;
GfLogInfo("Chemin Textures : %s\n", strTPath.c_str());
@ -344,8 +352,10 @@ osg::ref_ptr<osg::Node> SDCar::loadCar(tCarElt *car, bool tracktype, bool subcat
steer_transform->setMatrix(pos);
steer_transform->addChild(steerEntityLo.get());
pSteer->addChild(steer_transform.get(), true);
pSteer->addChild(steer_transform.get(), 1.0f, FLT_MAX);
GfLogTrace("Low Steer Loading \n");
}
snprintf(path, nMaxTexPathSize, "%s/%s", SECT_GROBJECTS, SECT_STEERWHEEL);
@ -374,13 +384,10 @@ osg::ref_ptr<osg::Node> SDCar::loadCar(tCarElt *car, bool tracktype, bool subcat
steer_transform->setMatrix(pos);
steer_transform->addChild(steerEntityHi.get());
pSteer->addChild(steer_transform.get(), false);
pSteer->addChild(steer_transform.get(), 0.0f, 1.0f);
GfLogTrace("High Steer Loading \n");
}
pSteer->setSingleChildOn(0);
// separate driver models for animation according to steering wheel angle ...
snprintf(path, nMaxTexPathSize, "%s/%s", SECT_GROBJECTS, LST_DRIVER);
nranges = GfParmGetEltNb(handle, path) + 1;
@ -426,7 +433,98 @@ osg::ref_ptr<osg::Node> SDCar::loadCar(tCarElt *car, bool tracktype, bool subcat
pDriver_path = pDriver_path+"driver.osg";
osgDB::writeNodeFile( *pDriver, pDriver_path );
#endif
}
}
_light = false;
_lightbrake = false;
snprintf(path, 256, "%s/%s", SECT_GROBJECTS, SECT_LIGHT);
int lightNum = GfParmGetEltNb(handle, path);
const char *lightType;
for (int i = 0; i < lightNum; i++)
{
snprintf(path, 256, "%s/%s/%d", SECT_GROBJECTS, SECT_LIGHT, i + 1);
lightType = GfParmGetStr(handle, path, PRM_TYPE, "");
if (!strcmp(lightType, VAL_LIGHT_HEAD1))
{
_light = true;
} else if (!strcmp(lightType, VAL_LIGHT_HEAD2))
{
_light = true;
} else if (!strcmp(lightType, VAL_LIGHT_BRAKE))
{
_lightbrake = true;
} else if (!strcmp(lightType, VAL_LIGHT_BRAKE2))
{
_lightbrake = true;
} else if (!strcmp(lightType, VAL_LIGHT_REAR))
{
_light = true;
}
}
if (_light)
{
osg::ref_ptr<osg::Node> light1 = new osg::Node;
std::string tmp = GetDataDir();
snprintf(buf, nMaxTexPathSize, "cars/models/%s/", car->_carName);
tmp = tmp+buf;
strPath=tmp+"light.ac";
light1 = loader.Load3dFile(strPath, false);
light1->setName("LIGHT");
osg::ref_ptr<osg::StateSet> light1state = light1->getOrCreateStateSet();
osg::ref_ptr<osg::Material> light1_material = new osg::Material;
light1_material->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE);
light1_material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(1, 1, 1, 1));
light1_material->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(0, 0, 0, 1));
light1state->setAttribute(light1_material.get());
osg::ref_ptr<osg::AlphaFunc> lightalphaFunc = new osg::AlphaFunc;
lightalphaFunc->setFunction(osg::AlphaFunc::ALWAYS);
light1state->setAttributeAndModes(lightalphaFunc);
osg::ref_ptr<osg::BlendFunc> lightblendFunc = new osg::BlendFunc;
lightblendFunc->setSource(osg::BlendFunc::SRC_ALPHA);
lightblendFunc->setDestination(osg::BlendFunc::ONE_MINUS_SRC_ALPHA);
light1state->setAttributeAndModes(lightblendFunc);
light1state->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
light1state->setMode(GL_FOG, osg::StateAttribute::ON);
light1state->setMode(GL_CULL_FACE, osg::StateAttribute::OFF);
pLight->addChild(light1.get(), false);
pLight->setSingleChildOn(1);
GfLogInfo("Loaded LIGHT CAR OSG !\n");
}
if (_lightbrake)
{
osg::ref_ptr<osg::Node> light2 = new osg::Node;
osg::ref_ptr<osg::StateSet> light2state = light2->getOrCreateStateSet();
light2state->setMode(GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED);
light2state->setMode(GL_FOG, osg::StateAttribute::ON | osg::StateAttribute::PROTECTED );
light2state->setMode(GL_CULL_FACE, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED);
light2->setNodeMask(~(0x1 | 0x2));
std::string tmp = GetDataDir();
snprintf(buf, nMaxTexPathSize, "cars/models/%s/", car->_carName);
tmp = tmp+buf;
strPath=tmp+"brakelight.ac";
light2 = loader.Load3dFile(strPath, false);
light2->setName("BRAKELIGHT");
pLightBrake->addChild(light2.get(), false);
pLightBrake->setSingleChildOn(1);
GfLogInfo("Loaded BRAKE LIGHT CAR OSG !\n");
}
gCar->addChild(pCar.get());
gCar->addChild(pDriver.get());
@ -434,6 +532,7 @@ osg::ref_ptr<osg::Node> SDCar::loadCar(tCarElt *car, bool tracktype, bool subcat
if(_wing1)
gCar->addChild(pWing.get());
if(_wing3)
gCar->addChild(pWing3.get());
#else
@ -477,6 +576,12 @@ osg::ref_ptr<osg::Node> SDCar::loadCar(tCarElt *car, bool tracktype, bool subcat
pBody->setSingleChildOn(1);
#if 1
osg::ref_ptr<osg::MatrixTransform> transform1 = new osg::MatrixTransform;
if(_light)
transform1->addChild(pLight.get());
if(_lightbrake)
transform1->addChild(pLightBrake.get());
transform1->addChild(pBody.get());
// GfOut("loaded car %d",pCar.get());
@ -656,6 +761,8 @@ void SDCar::activateCar(tCarElt *car)
void SDCar::updateCar()
{
osg::Vec3 p;
float wingangle = car->_wingRCmd * 180 / PI;
float steerangle = car->_steerCmd;
p[0] = car->_pos_X;//+ car->_drvPos_x;
p[1] = car->_pos_Y;//+car->_drvPos_y;
@ -666,6 +773,77 @@ void SDCar::updateCar()
car->_posMat[2][0],car->_posMat[2][1],car->_posMat[2][2],car->_posMat[2][3],
car->_posMat[3][0],car->_posMat[3][1],car->_posMat[3][2],car->_posMat[3][3]);
if (_wing3)
{
if ((wingangle > 0.0) && (wingangle < 10.0))
pWing3->setSingleChildOn(0);
else if ((wingangle > 10.0) && (wingangle < 35.0))
pWing3->setSingleChildOn(1);
else
pWing3->setSingleChildOn(2);
}
if (_driver)
{
if((steerangle > 0.0f) && (steerangle < 0.03f))
pDriver->setSingleChildOn(1);
else if((steerangle > 0.03f) && (steerangle < 0.07f))
pDriver->setSingleChildOn(2);
else if((steerangle > 0.07f) && (steerangle < 0.13f))
pDriver->setSingleChildOn(3);
else if((steerangle > 0.13f) && (steerangle < 0.21f))
pDriver->setSingleChildOn(4);
else if((steerangle > 0.21f) && (steerangle < 0.30f))
pDriver->setSingleChildOn(5);
else if((steerangle > 0.13f) && (steerangle < 0.21f))
pDriver->setSingleChildOn(6);
else if((steerangle > 0.30f) && (steerangle < 0.45f))
pDriver->setSingleChildOn(7);
else if(steerangle > 0.45f)
pDriver->setSingleChildOn(8);
else if((steerangle < 0.0f) && (steerangle > -0.03f))
pDriver->setSingleChildOn(9);
else if((steerangle < 0.03f) && (steerangle > -0.07f))
pDriver->setSingleChildOn(10);
else if((steerangle < 0.07f) && (steerangle > -0.13f))
pDriver->setSingleChildOn(11);
else if((steerangle < 0.13f) && (steerangle > -0.21f))
pDriver->setSingleChildOn(12);
else if((steerangle < 0.21f) && (steerangle > -0.30f))
pDriver->setSingleChildOn(13);
else if((steerangle < 0.30f) && (steerangle > -0.45f))
pDriver->setSingleChildOn(14);
else if(steerangle < 0.45f)
pDriver->setSingleChildOn(15);
else
pDriver->setSingleChildOn(0);
}
if(_steer)
{
steerangle = (-steerangle * 1.2);
osg::ref_ptr<osg::MatrixTransform> movt = new osg::MatrixTransform;
osg::Matrix rotation = osg::Matrix::rotate(steerangle, osg::Y_AXIS);
movt->setMatrix(rotation);
movt->addChild(pSteer);
}
if(_light)
{
if(car->_lightCmd)
pLight->setSingleChildOn(0);
else
pLight->setSingleChildOn(1);
}
if(_lightbrake)
{
if(car->_brakeCmd>0 || car->_ebrakeCmd>0)
pLightBrake->setSingleChildOn(0);
else
pLightBrake->setSingleChildOn(1);
}
wheels.updateWheels();
this->car_branch->setMatrix(mat);
@ -690,7 +868,7 @@ void SDCar::updateCar()
}*/
}
void SDCar::updateShadingParameters(osg::Matrixf modelview)
void SDCar::updateShadingParameters2(osg::Matrixf modelview)
{
shader->update(modelview);
}
@ -790,7 +968,7 @@ void SDCars::updateShadingParameters(osg::Matrixf modelview)
for(it = the_cars.begin(); it!= the_cars.end(); it++)
{
(*it)->updateShadingParameters(modelview);
(*it)->updateShadingParameters2(modelview);
}
}

View file

@ -25,6 +25,7 @@
#include <vector>
#include <osg/TextureCubeMap>
#include <osg/LOD>
#include "OsgDriver.h"
#include "OsgWheel.h"
@ -38,6 +39,11 @@ class SDCar
private :
osg::ref_ptr<osg::MatrixTransform> car_branch;
osg::ref_ptr<osg::Group> car_root;
osg::ref_ptr<osg::Switch> pLight;
osg::ref_ptr<osg::Switch> pLightBrake;
osg::ref_ptr<osg::Switch> pWing3;
osg::ref_ptr<osg::Switch> pDriver;
osg::ref_ptr<osg::LOD> pSteer;
//osg::ref_ptr<osg::Vec3Array> shadowVertices;
//osg::ref_ptr<osg::Geometry> quad;
//osg::ref_ptr<osg::Node> initOcclusionQuad(tCarElt *car);
@ -63,6 +69,8 @@ public :
bool _wing1;
bool _wing3;
bool _steer;
bool _light;
bool _lightbrake;
int _carShader;
SDReflectionMapping *getReflectionMap();
@ -73,7 +81,7 @@ public :
void activateCar(tCarElt *car);
void updateCar();
void updateShadingParameters(osg::Matrixf modelview);
void updateShadingParameters2(osg::Matrixf modelview);
};
class SDCars

View file

@ -54,14 +54,11 @@ osg::Node *osgLoader::Load3dFile(std::string strFile, bool car)
{
osg::Node *pNode = NULL;
std::string ext = osgDB::getFileExtension(strFile);
/*if (car)
m_ACCReader2.SetCar(true);*/
m_ACCReader.SetCar(car);
if (ext == "acc")
{
/*if(car)
osgDB::ReaderWriter::ReadResult rr = m_ACCReader2.readNode(strFile, m_pOpt);
else*/
//Use custom ACC file loader
osgDB::ReaderWriter::ReadResult rr = m_ACCReader.readNode(strFile, m_pOpt);
GfOut("Object ACC load = %s - %d \n", strFile.c_str(), rr.validNode());
@ -86,6 +83,7 @@ osg::Node *osgLoader::Load3dFile(std::string strFile, bool car)
else
{
pNode = osgDB::readNodeFile(strFile, m_pOpt);
GfOut("Object AC load = %s\n", strFile.c_str());
}
osg::MatrixTransform *rot = new osg::MatrixTransform;

View file

@ -486,7 +486,7 @@ void SDRender::ShadowedScene()
{
if (ShadowIndex == 1)
{
unsigned int shadowTexUnit = 1;
unsigned int shadowTexUnit = 3;
osg::ref_ptr<osgShadow::ShadowMap> vdsm = new osgShadow::ShadowMap;
vdsm->setLight(sunLight.get());
@ -529,8 +529,8 @@ void SDRender::ShadowedScene()
unsigned int baseTexUnit = 0;
unsigned int shadowTexUnit = 3;
lspsm->setMinLightMargin(5.0f);
lspsm->setMaxFarPlane(4096.0f);
lspsm->setMinLightMargin(0.5f);
lspsm->setMaxFarPlane(2048.0f);
lspsm->setTextureSize(osg::Vec2s(ShadowTexSize, ShadowTexSize));
lspsm->setShadowTextureCoordIndex(shadowTexUnit);
lspsm->setShadowTextureUnit(shadowTexUnit);

View file

@ -387,11 +387,6 @@ void SDCloudLayer::rebuild()
// the cloud layer. This is the difference in altitude between
// the top of the inverted bowl and the edge of the bowl.
const float alt_diff = layer_asl * 1.5f;
//const float layer_to_core = (SD_EARTH_RAD * 1000 + layer_asl);
//const float layer_angle = 0.5*layer_span / layer_to_core; // The angle is half the span
//const float border_to_core = layer_to_core * cos(layer_angle);
//const float alt_diff = layer_asl * 0.8f;
//const float alt_diff = layer_to_core - border_to_core;
for (int i = 0; i < 4; i++)
{
@ -404,9 +399,7 @@ void SDCloudLayer::rebuild()
cl[i] = new osg::Vec4Array;
tl[i] = new osg::Vec2Array;
osg::Vec3 vertex(layer_span*(i-2)/2, -layer_span,
alt_diff * (sin(i*mpi) - 2));
osg::Vec3 vertex(layer_span*(i-2)/2, -layer_span, alt_diff * (sin(i*mpi) - 2));
osg::Vec2 tc(layer_scale * i/4, 0.0f);
osg::Vec4 color(cloudColors[0], (i == 0) ? 0.0f : 0.15f);
@ -416,12 +409,9 @@ void SDCloudLayer::rebuild()
for (int j = 0; j < 4; j++)
{
vertex = osg::Vec3(layer_span*(i-1)/2, layer_span*(j-2)/2,
alt_diff * (sin((i+1)*mpi) + sin(j*mpi) - 2));
vertex = osg::Vec3(layer_span*(i-1)/2, layer_span*(j-2)/2, alt_diff * (sin((i+1)*mpi) + sin(j*mpi) - 2));
tc = osg::Vec2(layer_scale * (i+1)/4, layer_scale * j/4);
color = osg::Vec4(cloudColors[0],
( (j == 0) || (i == 3)) ?
( (j == 0) && (i == 3)) ? 0.0f : 0.15f : 1.0f );
color = osg::Vec4(cloudColors[0], ( (j == 0) || (i == 3)) ? ( (j == 0) && (i == 3)) ? 0.0f : 0.15f : 1.0f );
cl[i]->push_back(color);
vl[i]->push_back(vertex);
@ -464,11 +454,10 @@ void SDCloudLayer::rebuild()
layer_transform->addChild(layer[i].get());
}
//OSGFIXME: true
if ( layer_states[layer_coverage].valid() )
{
osg::CopyOp copyOp; // shallow copy
// render bin will be set in reposition
osg::ref_ptr<osg::StateSet> stateSet = static_cast<osg::StateSet*>(layer_states2[layer_coverage]->clone(copyOp));
stateSet->setDataVariance(osg::Object::DYNAMIC);
group_top->setStateSet(stateSet.get());
@ -476,9 +465,6 @@ void SDCloudLayer::rebuild()
stateSet->setDataVariance(osg::Object::DYNAMIC);
group_bottom->setStateSet(stateSet.get());
}
#if 0
osgDB::writeNodeFile(*layer_transform,"/home/xavier/cloud.ac");
#endif
}
bool SDCloudLayer::repaint( const osg::Vec3f &fog_color )
@ -574,14 +560,10 @@ bool SDCloudLayer::reposition(const osg::Vec3f &p, double dt )
last_pos = p;
last_x = p._v[0];
last_y = p._v[1];
//scale = layer_scale;
}
}
GfLogDebug("CloudLayer Alt = %.f\n", layer_asl);
//osgDB::writeNodeFile(*layer_transform,"/home/xavier/cloud.ac");
//layer3D->reposition( p, up, lon, lat, dt, layer_asl, speed, direction);
return true;
}
@ -597,4 +579,4 @@ void SDCloudLayer::set_enable3dClouds(bool enable)
//cloud_root->setChildValue(layer3D->getNode(), false);
cloud_root->setChildValue(layer_root.get(), true);
}
}
}

View file

@ -291,14 +291,12 @@ bool SDSkyDome::repaint( const Vec3f& sky_color,
bool SDSkyDome::reposition( const osg::Vec3f &p, double spin )
{
// asl = _asl;
osg::Matrix T, SPIN;
T.makeTranslate( p );
SPIN.makeRotate(spin, osg::Vec3(0, 0, 1));
dome_transform->setMatrix( T*SPIN/*T*/ );
dome_transform->setMatrix( T * SPIN );
return true;
}
}

View file

@ -236,12 +236,10 @@ bool SDSun::repaint( double sun_angle, double new_visibility )
double red_scat_f, /*red_scat_corr_f,*/ green_scat_f, blue_scat_f;
red_scat_f = (aerosol_factor * path_distance * density_avg) / 5E+07;
//red_scat_corr_f = sun_exp2_punch_through / (1 - red_scat_f);
sun_color[0] = 1 -red_scat_f;
//sun_color[0] = 1 - (1.1 * red_scat_f);
i_halo_color[0] = 1 - (1.1 * red_scat_f);
o_halo_color[0] = 1 - (1.4 * red_scat_f);
//scene_color[0] = 1 - red_scat_f;
// Green - 546.1 nm
if (sun_declination > 5.0 || sun_declination < 2.0)
@ -251,24 +249,19 @@ bool SDSun::repaint( double sun_angle, double new_visibility )
else
green_scat_f = ( aerosol_factor * path_distance * density_avg ) / 8.8938E+06;
sun_color[1] = 1 - green_scat_f /* red_scat_corr_f*/;
//sun_color[1] = 1 - (1.1 * (green_scat_f /* red_scat_corr_f*/));
i_halo_color[1] = 1 - (1.1 * (green_scat_f /* red_scat_corr_f*/));
o_halo_color[1] = 1 - (1.4 * (green_scat_f /* red_scat_corr_f*/));
//scene_color[1] = 1 - green_scat_f;
sun_color[1] = 1 - green_scat_f;
i_halo_color[1] = 1 - (1.1 * (green_scat_f));
o_halo_color[1] = 1 - (1.4 * (green_scat_f));
// Blue - 435.8 nm
blue_scat_f = (aerosol_factor * path_distance * density_avg) / 3.607E+06;
sun_color[2] = 1 - blue_scat_f /* red_scat_corr_f*/;
//sun_color[2] = 1 - (1.1 * (blue_scat_f /* red_scat_corr_f*/));
i_halo_color[2] = 1 - (1.1 * (blue_scat_f /* red_scat_corr_f*/));
o_halo_color[2] = 1 - (1.4 * (blue_scat_f /* red_scat_corr_f*/));
//scene_color[2] = 1 - blue_scat_f;
sun_color[2] = 1 - blue_scat_f;
i_halo_color[2] = 1 - (1.1 * (blue_scat_f));
o_halo_color[2] = 1 - (1.4 * (blue_scat_f));
// Alpha
sun_color[3] = 1;
i_halo_color[3] = 1;
//scene_color[3] = 1;
o_halo_color[3] = blue_scat_f;
if ( ( new_visibility < 10000 ) && ( blue_scat_f > 1 ))