Update SDRender & SDCar (material ambiant for car is scene_ambiant now)
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@5461 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 087930fc443a2049395d6517738feb7c23056aff Former-commit-id: d4d2149d26442ebb42f67fef2da62593a7a3b275
This commit is contained in:
parent
970a1ce702
commit
773a5bb32b
6 changed files with 480 additions and 7 deletions
|
@ -27,7 +27,6 @@
|
||||||
|
|
||||||
SDBackground::SDBackground(void)
|
SDBackground::SDBackground(void)
|
||||||
{
|
{
|
||||||
_background = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SDBackground::~SDBackground(void)
|
SDBackground::~SDBackground(void)
|
||||||
|
|
|
@ -89,7 +89,7 @@ public :
|
||||||
SDRender * ren = (SDRender *)getRender();
|
SDRender * ren = (SDRender *)getRender();
|
||||||
osg::Vec3f sun_pos= ren->getSky()->getSun()->getSunPosition();
|
osg::Vec3f sun_pos= ren->getSky()->getSun()->getSunPosition();
|
||||||
osg::Vec4f sun_color = ren->getSky()->get_sun_color();
|
osg::Vec4f sun_color = ren->getSky()->get_sun_color();
|
||||||
osg::Vec4f scene_color = ren->getSky()->get_scene_color();
|
osg::Vec4f scene_color = ren->getSceneColor();
|
||||||
|
|
||||||
/* GfOut("Sun Position : %f %f %f\n",sun_pos._v[0],sun_pos._v[1],sun_pos._v[2]);
|
/* GfOut("Sun Position : %f %f %f\n",sun_pos._v[0],sun_pos._v[1],sun_pos._v[2]);
|
||||||
GfOut("Sun Color : %f %f %f %f\n",sun_color._v[0],sun_color._v[1],sun_color._v[2],sun_color._v[3]);
|
GfOut("Sun Color : %f %f %f %f\n",sun_color._v[0],sun_color._v[1],sun_color._v[2],sun_color._v[3]);
|
||||||
|
@ -113,7 +113,7 @@ public :
|
||||||
this->viewPoint->set(osg::Vec3f(pv.x(),pv.y(),pv.z()));
|
this->viewPoint->set(osg::Vec3f(pv.x(),pv.y(),pv.z()));
|
||||||
this->lightVector->set(osg::Vec3f(lv.x(),lv.y(),lv.z()));
|
this->lightVector->set(osg::Vec3f(lv.x(),lv.y(),lv.z()));
|
||||||
this->lightPower->set(sun_color);
|
this->lightPower->set(sun_color);
|
||||||
this->ambientColor->set(scene_color*0.5f);
|
this->ambientColor->set(scene_color);
|
||||||
|
|
||||||
//osg::StateSet* stateset = pCar->getOrCreateStateSet();
|
//osg::StateSet* stateset = pCar->getOrCreateStateSet();
|
||||||
//stateset->setAttributeAndModes( program.get() );
|
//stateset->setAttributeAndModes( program.get() );
|
||||||
|
|
|
@ -62,6 +62,11 @@ SDRender::SDRender(void)
|
||||||
BaseSkyColor = osg::Vec3f( 0.31f, 0.43f, 0.69f );
|
BaseSkyColor = osg::Vec3f( 0.31f, 0.43f, 0.69f );
|
||||||
BaseFogColor = osg::Vec3f( 0.84f, 0.84f, 1.0f );
|
BaseFogColor = osg::Vec3f( 0.84f, 0.84f, 1.0f );
|
||||||
|
|
||||||
|
Scene_ambiant = osg::Vec4f( 0.8f, 0.8f, 0.8f, 1.0f);
|
||||||
|
Scene_Specular = osg::Vec4f( 0.05f, 0.05f, 0.05f, 1.0f);
|
||||||
|
Scene_Diffuse = osg::Vec4f( 0.6f, 0.6f, 0.6f, 1.0f);
|
||||||
|
Scene_Emit = osg::Vec4f( 0.2f, 0.2f, 0.2f, 1.0f);
|
||||||
|
|
||||||
SDSkyDomeDistance = 0;
|
SDSkyDomeDistance = 0;
|
||||||
SDSkyDomeDistThresh = 12000;
|
SDSkyDomeDistThresh = 12000;
|
||||||
SDNbCloudLayers = 0;
|
SDNbCloudLayers = 0;
|
||||||
|
@ -369,8 +374,9 @@ void SDRender::Init(tTrack *track)
|
||||||
float ambian = 0.8f * sky_brightness;
|
float ambian = 0.8f * sky_brightness;
|
||||||
osg::ref_ptr<osg::Material> material = new osg::Material;
|
osg::ref_ptr<osg::Material> material = new osg::Material;
|
||||||
//material->setColorMode(osg::Material::OFF); // switch glColor usage off
|
//material->setColorMode(osg::Material::OFF); // switch glColor usage off
|
||||||
|
Scene_ambiant = osg::Vec4f( ambian, ambian, ambian, 1.0f);
|
||||||
material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(emis, emis, emis, 1.0f));
|
material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(emis, emis, emis, 1.0f));
|
||||||
material->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(ambian, ambian, ambian, 1.0f));
|
material->setAmbient(osg::Material::FRONT_AND_BACK, Scene_ambiant);
|
||||||
stateSet->setAttributeAndModes(material, osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
stateSet->setAttributeAndModes(material, osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||||
stateSet->setMode(GL_LIGHTING, osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
stateSet->setMode(GL_LIGHTING, osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||||
|
|
||||||
|
@ -702,10 +708,11 @@ void SDRender::UpdateSky(double currentTime, double accelTime)
|
||||||
float emis = 0.5f * sky_brightness;
|
float emis = 0.5f * sky_brightness;
|
||||||
float ambian = 0.8f * sky_brightness;
|
float ambian = 0.8f * sky_brightness;
|
||||||
|
|
||||||
|
Scene_ambiant = osg::Vec4f(ambian, ambian, ambian, 1.0f);
|
||||||
osg::ref_ptr<osg::Material> material = new osg::Material;
|
osg::ref_ptr<osg::Material> material = new osg::Material;
|
||||||
//material->setColorMode(osg::Material::OFF); // switch glColor usage off
|
//material->setColorMode(osg::Material::OFF); // switch glColor usage off
|
||||||
material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(emis, emis, emis, 1.0f));
|
material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(emis, emis, emis, 1.0f));
|
||||||
material->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(ambian, ambian, ambian, 1.0f));
|
material->setAmbient(osg::Material::FRONT_AND_BACK, Scene_ambiant);
|
||||||
stateSet->setAttributeAndModes(material, osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
stateSet->setAttributeAndModes(material, osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||||
stateSet->setMode(GL_LIGHTING, osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
stateSet->setMode(GL_LIGHTING, osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
|
||||||
|
|
||||||
|
@ -716,3 +723,8 @@ void SDRender::UpdateSky(double currentTime, double accelTime)
|
||||||
sunLight->getLight()->setDirection(sun_direction);
|
sunLight->getLight()->setDirection(sun_direction);
|
||||||
|
|
||||||
}//grUpdateSky
|
}//grUpdateSky
|
||||||
|
|
||||||
|
osg::Vec4f SDRender::getSceneColor(void)
|
||||||
|
{
|
||||||
|
return Scene_ambiant;
|
||||||
|
}
|
||||||
|
|
|
@ -56,6 +56,11 @@ private:
|
||||||
osg::Vec4f SceneSpecular;
|
osg::Vec4f SceneSpecular;
|
||||||
osg::Vec4f SceneFog;
|
osg::Vec4f SceneFog;
|
||||||
|
|
||||||
|
osg::Vec4f Scene_ambiant;
|
||||||
|
osg::Vec4f Scene_Diffuse;
|
||||||
|
osg::Vec4f Scene_Specular;
|
||||||
|
osg::Vec4f Scene_Emit;
|
||||||
|
|
||||||
unsigned SDSkyDomeDistance;
|
unsigned SDSkyDomeDistance;
|
||||||
unsigned SDNbCloudLayers;
|
unsigned SDNbCloudLayers;
|
||||||
unsigned SDSkyDomeDistThresh;
|
unsigned SDSkyDomeDistThresh;
|
||||||
|
@ -85,6 +90,7 @@ public:
|
||||||
|
|
||||||
void Init(tTrack *track);
|
void Init(tTrack *track);
|
||||||
osg::ref_ptr< osg::StateSet> setFogState();
|
osg::ref_ptr< osg::StateSet> setFogState();
|
||||||
|
osg::Vec4f getSceneColor(void);
|
||||||
void UpdateTime(tSituation *s);
|
void UpdateTime(tSituation *s);
|
||||||
void UpdateLight(void);
|
void UpdateLight(void);
|
||||||
void addCars(osg::Node* cars);
|
void addCars(osg::Node* cars);
|
||||||
|
|
|
@ -236,3 +236,459 @@ bool SDScenery::LoadTrack(std::string strTrack)
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CreatePit(tTrack *track)
|
||||||
|
{
|
||||||
|
/*char buf[512];
|
||||||
|
osg::ref_ptr<osg::Node> ThePits = new osg::Node;
|
||||||
|
osg::ref_ptr<osg::Group> PitsAnchor = new osg::Group;
|
||||||
|
PitsAnchor->addChild(ThePits);
|
||||||
|
|
||||||
|
tTrackPitInfo *pits = &(SDTrack->pits);
|
||||||
|
|
||||||
|
// Draw the pit identification on the wall if any.
|
||||||
|
switch (pits->type)
|
||||||
|
{
|
||||||
|
case TR_PIT_ON_TRACK_SIDE:
|
||||||
|
GfLogTrace("Creating track side pit buildings (%d slots) ...\n", pits->nMaxPits);
|
||||||
|
for (int i = 0; i < pits->nMaxPits; i++)
|
||||||
|
{
|
||||||
|
//GfLogDebug("Pit Nbr: %d\n", i);
|
||||||
|
osg::Vec3Array *pit_vtx = new osg::Vec3Array;
|
||||||
|
osg::Vec2Array *pit_tex = new osg::Vec2Array;
|
||||||
|
osg::Vec4Array *pit_clr = new osg::Vec4Array;
|
||||||
|
osg::Vec3Array *pit_nrm = new osg::Vec3Array;
|
||||||
|
|
||||||
|
osg::Vec4 clr = {0, 0, 0, 1};
|
||||||
|
pit_clr = clr;
|
||||||
|
|
||||||
|
// Default driver logo file name (pit door).
|
||||||
|
std::string strLogoFileName("logo");
|
||||||
|
|
||||||
|
// If we have at least one car in the pit, use the team pit logo of driver 0.
|
||||||
|
osg::ref_ptr<osg::StateSet> statePit = new osg::StateSet;
|
||||||
|
//statePit->get
|
||||||
|
//ssgState *st = 0;
|
||||||
|
if (pits->driversPits[i].car[0])
|
||||||
|
{
|
||||||
|
snprintf(buf, sizeof(buf),
|
||||||
|
"%sdrivers/%s/%d;%sdrivers/%s;drivers/%s/%d;drivers/%s",
|
||||||
|
GfLocalDir(),
|
||||||
|
pits->driversPits[i].car[0]->_modName,
|
||||||
|
pits->driversPits[i].car[0]->_driverIndex,
|
||||||
|
GfLocalDir(),
|
||||||
|
pits->driversPits[i].car[0]->_modName,
|
||||||
|
pits->driversPits[i].car[0]->_modName,
|
||||||
|
pits->driversPits[i].car[0]->_driverIndex,
|
||||||
|
pits->driversPits[i].car[0]->_modName);
|
||||||
|
|
||||||
|
// If a custom skin was selected, and it can apply to the pit door,
|
||||||
|
// update the logo file name accordingly.
|
||||||
|
int skinnedLogo = FALSE;
|
||||||
|
if (strlen(pits->driversPits[i].car[0]->_skinName) != 0
|
||||||
|
&& pits->driversPits[i].car[0]->_skinTargets & RM_CAR_SKIN_TARGET_PIT_DOOR)
|
||||||
|
{
|
||||||
|
skinnedLogo = TRUE;
|
||||||
|
strLogoFileName += '-';
|
||||||
|
strLogoFileName += pits->driversPits[i].car[0]->_skinName;
|
||||||
|
GfLogTrace("Using skinned pit door logo %s\n", strLogoFileName.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load logo texture (only rgbs - pngs cause pit transparency bug # 387)
|
||||||
|
#ifdef PNG_LOGO_SUPPORT
|
||||||
|
const std::string strPNGLogoFileName = strLogoFileName + ".png";
|
||||||
|
st = grSsgLoadTexStateEx(strPNGLogoFileName.c_str(), buf, FALSE, FALSE, FALSE);
|
||||||
|
#endif
|
||||||
|
if (!st)
|
||||||
|
{
|
||||||
|
const std::string strRGBLogoFileName = strLogoFileName + ".rgb";
|
||||||
|
st = grSsgLoadTexStateEx(strRGBLogoFileName.c_str(), buf, FALSE, FALSE, skinnedLogo);
|
||||||
|
}
|
||||||
|
} // if pits->driverPits[i].car[0]
|
||||||
|
|
||||||
|
// If no car in the pit, or logo file not found, hope for the .rgb in data/textures.
|
||||||
|
if (!st)
|
||||||
|
{
|
||||||
|
snprintf(buf, sizeof(buf), "data/textures");
|
||||||
|
const std::string strRGBLogoFileName = strLogoFileName + ".rgb";
|
||||||
|
st = grSsgLoadTexStateEx(strRGBLogoFileName.c_str(), buf, FALSE, FALSE, TRUE);
|
||||||
|
}
|
||||||
|
st->setOpaque();
|
||||||
|
reinterpret_cast<ssgSimpleState*>(st)->setShininess(50);
|
||||||
|
reinterpret_cast<ssgSimpleState*>(st)->disable(GL_BLEND);
|
||||||
|
|
||||||
|
// Pit wall texturing : the loaded 'logo*.rgb/.png' image file is supposed to consist
|
||||||
|
// of 4 distinct parts :
|
||||||
|
//
|
||||||
|
// **************************************************** 1.0
|
||||||
|
// *..................................................*
|
||||||
|
// *. .*
|
||||||
|
// *. Pit door (dots included) .*
|
||||||
|
// *. .*
|
||||||
|
// *. .*
|
||||||
|
// *..................................................*
|
||||||
|
// ##########################$$$$$$$$$$$$$$$$$$$$$$$$$$ 0.33
|
||||||
|
// # #$ $
|
||||||
|
// # Team logo #$ Team name $
|
||||||
|
// # #$ $
|
||||||
|
// ##########################$$$$$$$$$$$$$$$$$$$$$$$$$$ 0.0
|
||||||
|
// 0.0 0.5 1.0
|
||||||
|
//
|
||||||
|
// - the stars '*' : Left, top and right 1-pixel-wide line :
|
||||||
|
// the pit wall (will be repeated respectively in the left, top and right
|
||||||
|
// direction in order to cover the pit-wall outside of the rectangle of the pit-door
|
||||||
|
// - the dots '.' : the real pit door texture (actually includes the stars part)
|
||||||
|
// - the hashes '#' : the team name texture
|
||||||
|
// - the dollars '$' : the team logo texture
|
||||||
|
//
|
||||||
|
// More details here : http://www.berniw.org/torcs/robot/ch6/pitlogo.html
|
||||||
|
|
||||||
|
// Determine the position of the pit wall, and its normal vector.
|
||||||
|
tdble x, y;
|
||||||
|
t3Dd normalvector;
|
||||||
|
RtTrackLocal2Global(&(pits->driversPits[i].pos), &x, &y,
|
||||||
|
pits->driversPits[i].pos.type);
|
||||||
|
RtTrackSideNormalG(pits->driversPits[i].pos.seg, x, y,
|
||||||
|
pits->side, &normalvector);
|
||||||
|
|
||||||
|
// Normal
|
||||||
|
{
|
||||||
|
osg::Vec3 nrm = { normalvector.x, normalvector.y, 0 };
|
||||||
|
pit_nrm->add(nrm);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine the position of the first, bottom vertex of the triangle strip
|
||||||
|
tdble x2 = x - pits->width / 2.0 * normalvector.x
|
||||||
|
+ pits->len / 2.0 * normalvector.y;
|
||||||
|
tdble y2 = y - pits->width / 2.0 * normalvector.y
|
||||||
|
- pits->len / 2.0 * normalvector.x;
|
||||||
|
tdble z2 = RtTrackHeightG(pits->driversPits[i].pos.seg, x2, y2);
|
||||||
|
|
||||||
|
// First, bottom vertex of the triangle strip
|
||||||
|
{
|
||||||
|
osg::Vec2 tex( -0.7, 42.0 / 128 );
|
||||||
|
osg::Vec3 vtx( x2, y2, z2 );
|
||||||
|
pit_tex->add(tex);
|
||||||
|
pit_vtx->add(vtx);
|
||||||
|
}
|
||||||
|
|
||||||
|
// First, top vertex of the triangle strip
|
||||||
|
{
|
||||||
|
osg::Vec2 tex( -0.7, 1.1 );
|
||||||
|
osg::Vec3 vtx( x2, y2, z2 + 4.8f );
|
||||||
|
pit_tex->add(tex);
|
||||||
|
pit_vtx->add(vtx);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine the position of the second, bottom vertex of the triangle strip
|
||||||
|
x2 -= pits->len * normalvector.y;
|
||||||
|
y2 += pits->len * normalvector.x;
|
||||||
|
z2 = RtTrackHeightG(pits->driversPits[i].pos.seg, x2, y2);
|
||||||
|
|
||||||
|
// Second, bottom vertex of the triangle strip
|
||||||
|
{
|
||||||
|
osg::Vec2 tex( -0.7 + 2.0, 42.0 / 128 );
|
||||||
|
osg::Vec3 vtx( x2, y2, z2 );
|
||||||
|
pit_tex->add(tex);
|
||||||
|
pit_vtx->add(vtx);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Second, top vertex of the triangle strip
|
||||||
|
{
|
||||||
|
osg::Vec2 tex( -0.7 + 2.0, 1.1 );
|
||||||
|
osg::Vec3 vtx( x2, y2, z2 + 4.8f );
|
||||||
|
pit_tex->add(tex);
|
||||||
|
pit_vtx->add(vtx);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build-up the vertex array.
|
||||||
|
ssgVtxTable *pit = new ssgVtxTable(GL_TRIANGLE_STRIP, pit_vtx,
|
||||||
|
pit_nrm, pit_tex, pit_clr);
|
||||||
|
|
||||||
|
// Attach the texture state to it.
|
||||||
|
pit->setState(st);
|
||||||
|
pit->setCullFace(0);
|
||||||
|
|
||||||
|
// Done.
|
||||||
|
ThePits->addKid(pit);
|
||||||
|
} // for i
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TR_PIT_NO_BUILDING:
|
||||||
|
{
|
||||||
|
GfLogTrace("Creating low pit wall (%d slots) ...\n", pits->nMaxPits);
|
||||||
|
// This mode draws a white, low wall (about 3ft high) with logos
|
||||||
|
|
||||||
|
// First we load the low wall's texture, as it is the same
|
||||||
|
// for all the drivers
|
||||||
|
snprintf(buf, sizeof(buf), "data/textures");
|
||||||
|
const std::string strWallFileName = "tr-bar-gr.png";
|
||||||
|
ssgState *stWall = grSsgLoadTexStateEx(strWallFileName.c_str(), buf,
|
||||||
|
FALSE, FALSE, FALSE);
|
||||||
|
reinterpret_cast<ssgSimpleState*>(stWall)->setShininess(100);
|
||||||
|
|
||||||
|
bool bHasLogo = false;
|
||||||
|
// Loop over all the available pits
|
||||||
|
for (int i = 0; i < pits->nMaxPits; i++)
|
||||||
|
{
|
||||||
|
tTrackOwnPit *act_pit = &(pits->driversPits[i]);
|
||||||
|
|
||||||
|
// Get this pit's center coords
|
||||||
|
tdble x0, y0;
|
||||||
|
t3Dd normalvector;
|
||||||
|
RtTrackLocal2Global(&(act_pit->pos), &x0, &y0, act_pit->pos.type);
|
||||||
|
RtTrackSideNormalG(act_pit->pos.seg, x0, y0, pits->side, &normalvector);
|
||||||
|
// This offset needed so the pit walls start at the correct place
|
||||||
|
x0 = x0 - pits->width / 2.0 * normalvector.x
|
||||||
|
- pits->len / 4.0 * normalvector.y;
|
||||||
|
|
||||||
|
// Load this pit's own logo
|
||||||
|
// Default driver logo filename (pit door)
|
||||||
|
std::string strLogoFileName("logo");
|
||||||
|
|
||||||
|
if (act_pit->car[0]) {
|
||||||
|
// If we have more than one car in the pit,
|
||||||
|
// use the team pit logo of driver 0.
|
||||||
|
snprintf(buf, sizeof(buf),
|
||||||
|
"%sdrivers/%s/%d;%sdrivers/%s;drivers/%s/%d;drivers/%s",
|
||||||
|
GfLocalDir(),
|
||||||
|
act_pit->car[0]->_modName,
|
||||||
|
act_pit->car[0]->_driverIndex,
|
||||||
|
GfLocalDir(),
|
||||||
|
act_pit->car[0]->_modName,
|
||||||
|
act_pit->car[0]->_modName,
|
||||||
|
act_pit->car[0]->_driverIndex,
|
||||||
|
act_pit->car[0]->_modName);
|
||||||
|
|
||||||
|
// If a custom skin was selected, and it can apply to the pit door,
|
||||||
|
// update the logo file name accordingly
|
||||||
|
if (strlen(act_pit->car[0]->_skinName) != 0
|
||||||
|
&& act_pit->car[0]->_skinTargets & RM_CAR_SKIN_TARGET_PIT_DOOR) {
|
||||||
|
strLogoFileName += '-';
|
||||||
|
strLogoFileName += act_pit->car[0]->_skinName;
|
||||||
|
GfLogTrace("Using skinned pit door logo %s\n",
|
||||||
|
strLogoFileName.c_str());
|
||||||
|
}
|
||||||
|
bHasLogo = true;
|
||||||
|
} else {
|
||||||
|
snprintf(buf, sizeof(buf), "data/textures");
|
||||||
|
strLogoFileName = "tr-bar-gr";
|
||||||
|
bHasLogo = false;
|
||||||
|
} // if act_pit->car[0]
|
||||||
|
|
||||||
|
// Let's draw the low wall
|
||||||
|
// It is drawn in 3 parts.
|
||||||
|
// First some small wall, then the logo, then some more wall.
|
||||||
|
// Small wall bounds: (x1, y1) - (x2, y2)
|
||||||
|
// Logo part bounds: (x2, y2) - (x3, y3)
|
||||||
|
// Small wall bounds: (x3, y3) - (x4, y4)
|
||||||
|
|
||||||
|
tdble x1 = x0 - pits->width / 2.0 * normalvector.x
|
||||||
|
+ pits->len / 2.0 * normalvector.y;
|
||||||
|
tdble y1 = y0 - pits->width / 2.0 * normalvector.y
|
||||||
|
- pits->len / 2.0 * normalvector.x;
|
||||||
|
tdble z1 = RtTrackHeightG(act_pit->pos.seg, x1, y1);
|
||||||
|
|
||||||
|
tdble x2 = x0 - pits->width / 2.0 * normalvector.x
|
||||||
|
+ pits->len / 4.0 * normalvector.y;
|
||||||
|
tdble y2 = y0 - pits->width / 2.0 * normalvector.y
|
||||||
|
- pits->len / 4.0 * normalvector.x;
|
||||||
|
tdble z2 = RtTrackHeightG(act_pit->pos.seg, x2, y2);
|
||||||
|
|
||||||
|
tdble x3 = x0 - pits->width / 2.0 * normalvector.x
|
||||||
|
- pits->len / 4.0 * normalvector.y;
|
||||||
|
tdble y3 = y0 - pits->width / 2.0 * normalvector.y
|
||||||
|
+ pits->len / 4.0 * normalvector.x;
|
||||||
|
tdble z3 = RtTrackHeightG(act_pit->pos.seg, x3, y3);
|
||||||
|
|
||||||
|
tdble x4 = x0 - pits->width / 2.0 * normalvector.x
|
||||||
|
- pits->len / 2.0 * normalvector.y;
|
||||||
|
tdble y4 = y0 - pits->width / 2.0 * normalvector.y
|
||||||
|
+ pits->len / 2.0 * normalvector.x;
|
||||||
|
tdble z4 = RtTrackHeightG(act_pit->pos.seg, x4, y4);
|
||||||
|
|
||||||
|
osg::Vec3Array *pit_vtx1 = new osg::Vec3Array;
|
||||||
|
osg::Vec2Array *pit_tex1 = new osg::Vec2Array;
|
||||||
|
osg::Vec4Array *pit_clr1 = new osg::Vec4Array;
|
||||||
|
osg::Vec3Array *pit_nrm1 = new osg::Vec3Array;
|
||||||
|
|
||||||
|
osg::Vec4 clr1( 1, 1, 1, 1 );
|
||||||
|
pit_clr1 = clr1;
|
||||||
|
osg::Vec3 nrm1( normalvector.x, normalvector.y, 0.0 );
|
||||||
|
pit_nrm1->add(nrm1);
|
||||||
|
|
||||||
|
// First, bottom vertex
|
||||||
|
{
|
||||||
|
osg::Vec2 tex( 0.0, 0.0 );
|
||||||
|
osg::Vec3 vtx( x1, y1, z1 );
|
||||||
|
pit_tex1->add(tex);
|
||||||
|
pit_vtx1->add(vtx);
|
||||||
|
}
|
||||||
|
|
||||||
|
// First, top vertex
|
||||||
|
{
|
||||||
|
osg::Vec2 tex( 0.0, 0.25 );
|
||||||
|
osg::Vec3 vtx( x1, y1, z1 + 0.9f );
|
||||||
|
pit_tex1->add(tex);
|
||||||
|
pit_vtx1->add(vtx);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Second, bottom vertex
|
||||||
|
{
|
||||||
|
osg::Vec2 tex( 1.0, 0.0 );
|
||||||
|
osg::Vec3 vtx( x2, y2, z2 );
|
||||||
|
pit_tex1->add(tex);
|
||||||
|
pit_vtx1->add(vtx);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Second, top vertex
|
||||||
|
{
|
||||||
|
osg::Vec2 tex( 1.0, 0.25 );
|
||||||
|
osg::Vec3 vtx( x2, y2, z2 + 0.9f );
|
||||||
|
pit_tex1->add(tex);
|
||||||
|
pit_vtx1->add(vtx);
|
||||||
|
}
|
||||||
|
|
||||||
|
ssgVtxTable *pit = new ssgVtxTable(GL_TRIANGLE_STRIP, pit_vtx1,
|
||||||
|
pit_nrm1, pit_tex1, pit_clr1);
|
||||||
|
pit->setState(stWall);
|
||||||
|
pit->setCullFace(0);
|
||||||
|
ThePits->addKid(pit);
|
||||||
|
|
||||||
|
// Let's draw the logo
|
||||||
|
// Load logo texture (.png first, then .rgb for backwards compatibility)
|
||||||
|
const std::string strPNGLogoFileName = strLogoFileName + ".png";
|
||||||
|
ssgState *stLogo = grSsgLoadTexStateEx(strPNGLogoFileName.c_str(),
|
||||||
|
buf, FALSE, FALSE, FALSE);
|
||||||
|
if (!stLogo) {
|
||||||
|
const std::string strRGBLogoFileName = strLogoFileName + ".rgb";
|
||||||
|
stLogo = grSsgLoadTexStateEx(strRGBLogoFileName.c_str(), buf,
|
||||||
|
FALSE, FALSE);
|
||||||
|
}
|
||||||
|
reinterpret_cast<ssgSimpleState*>(stLogo)->setShininess(50);
|
||||||
|
|
||||||
|
osg::Vec3Array *pit_vtx2 = new osg::Vec3Array;
|
||||||
|
osg::Vec2Array *pit_tex2 = new osg::Vec2Array;
|
||||||
|
osg::Vec4Array *pit_clr2 = new osg::Vec4Array;
|
||||||
|
osg::Vec3Array *pit_nrm2 = new osg::Vec3Array;
|
||||||
|
|
||||||
|
osg::Vec4 clr2( 1, 1, 1, 1 );
|
||||||
|
pit_clr2 = clr2;
|
||||||
|
osg::Vec3 nrm2( normalvector.x, normalvector.y, 0.0 );
|
||||||
|
pit_nrm2 = nrm2;
|
||||||
|
|
||||||
|
// If bHasLogo is false, there is no team/driver logo,
|
||||||
|
// we should display a plain concrete wall then without decals.
|
||||||
|
// In that case strLogoFileName == strWallFileName,
|
||||||
|
//but we also must care for different coord mapping.
|
||||||
|
|
||||||
|
// First, bottom vertex
|
||||||
|
{
|
||||||
|
osg::Vec2 tex( 0.0, 0.0 );
|
||||||
|
osg::Vec3 vtx( x2, y2, z2 );
|
||||||
|
pit_tex2 = tex;
|
||||||
|
pit_vtx2 = vtx;
|
||||||
|
}
|
||||||
|
|
||||||
|
// First, top vertex
|
||||||
|
{
|
||||||
|
osg::Vec2 tex = { 0.0, (bHasLogo ? 0.33f : 0.25f) };
|
||||||
|
osg::Vec3 vtx = { x2, y2, z2 + 0.9f };
|
||||||
|
pit_tex2 = tex;
|
||||||
|
pit_vtx2 = vtx;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Second, bottom vertex
|
||||||
|
{
|
||||||
|
osg::Vec2 tex( 1.0, 0.0 );
|
||||||
|
osg::Vec3 vtx( x3, y3, z3 );
|
||||||
|
pit_tex2 = tex;
|
||||||
|
pit_vtx2 = vtx;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Second, top vertex
|
||||||
|
{
|
||||||
|
osg::Vec2 tex( 1.0, (bHasLogo ? 0.33f : 0.25f));
|
||||||
|
osg::Vec3 vtx( x3, y3, z3 + 0.9f );
|
||||||
|
pit_tex2 = tex;
|
||||||
|
pit_vtx2 = vtx;
|
||||||
|
}
|
||||||
|
|
||||||
|
ssgVtxTable *pit2 = new ssgVtxTable(GL_TRIANGLE_STRIP, pit_vtx2,
|
||||||
|
pit_nrm2, pit_tex2, pit_clr2);
|
||||||
|
pit2->setState(stLogo);
|
||||||
|
pit2->setCullFace(0);
|
||||||
|
ThePits->addKid(pit2);
|
||||||
|
|
||||||
|
// Draw 2nd wall
|
||||||
|
osg::Vec3Array *pit_vtx3 = new osg::Vec3Array;
|
||||||
|
osg::Vec2Array *pit_tex3 = new osg::Vec2Array;
|
||||||
|
osg::Vec4Array *pit_clr3 = new osg::Vec4Array;
|
||||||
|
osg::Vec3Array *pit_nrm3 = new osg::Vec3Array;
|
||||||
|
osg::Vec4 clr3 = { 1, 1, 1, 1 };
|
||||||
|
pit_clr3->add(clr3);
|
||||||
|
osg::Vec3 nrm3 = { normalvector.x, normalvector.y, 0.0 };
|
||||||
|
pit_nrm3->add(nrm3);
|
||||||
|
// First, bottom vertex
|
||||||
|
{
|
||||||
|
osg::Vec2 tex = { 0.0, 0.0 };
|
||||||
|
osg::Vec3 vtx = { x3, y3, z3 };
|
||||||
|
pit_tex3->add(tex);
|
||||||
|
pit_vtx3->add(vtx);
|
||||||
|
}
|
||||||
|
|
||||||
|
// First, top vertex
|
||||||
|
{
|
||||||
|
osg::Vec2 tex = { 0.0, 0.25 };
|
||||||
|
osg::Vec3 vtx = { x3, y3, z3 + 0.9f };
|
||||||
|
pit_tex3->add(tex);
|
||||||
|
pit_vtx3->add(vtx);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Second, bottom vertex
|
||||||
|
{
|
||||||
|
osg::Vec2 tex = { 1.0, 0.0 };
|
||||||
|
osg::Vec3 vtx = { x4, y4, z4 };
|
||||||
|
pit_tex3->add(tex);
|
||||||
|
pit_vtx3->add(vtx);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Second, top vertex
|
||||||
|
{
|
||||||
|
osg::Vec2 tex = { 1.0, 0.25 };
|
||||||
|
osg::Vec3 vtx = { x4, y4, z4 + 0.9f };
|
||||||
|
pit_tex3->add(tex);
|
||||||
|
pit_vtx3->add(vtx);
|
||||||
|
}
|
||||||
|
|
||||||
|
geometry->setUseDisplayList(false);
|
||||||
|
geometry->setVertexArray(pit_vtx3);
|
||||||
|
geometry->setNormalArray(pit_nrm3);
|
||||||
|
geometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
|
||||||
|
geometry->setTexCoordArray(0, pit_tex3);
|
||||||
|
geometry->setColorArray(pit_clr3);
|
||||||
|
geometry->setColorBinding(osg::Geometry::BIND_OVERALL);
|
||||||
|
geometry->addPrimitiveSet(new osg::DrawArrays(GL_TRIANGLE_STRIP, 0, pit_vtx3->size()));
|
||||||
|
geode->addDrawable(geometry);
|
||||||
|
|
||||||
|
ssgVtxTable *pit3 = new ssgVtxTable(GL_TRIANGLE_STRIP, pit_vtx3,
|
||||||
|
pit_nrm3, pit_tex3, pit_clr3);
|
||||||
|
pit3->setState(stWall);
|
||||||
|
pit3->setCullFace(0);
|
||||||
|
ThePits->addKid(pit3);
|
||||||
|
} // for i
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TR_PIT_ON_SEPARATE_PATH:
|
||||||
|
// Not implemented yet
|
||||||
|
GfLogTrace("Creating separate path pits (%d slots) ...\n", pits->nMaxPits);
|
||||||
|
GfLogWarning("Separate path pits are not yet implemented.\n");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TR_PIT_NONE:
|
||||||
|
// Nothing to do
|
||||||
|
GfLogTrace("Creating no pits.\n");
|
||||||
|
break;
|
||||||
|
} // switch pit->type*/
|
||||||
|
}
|
||||||
|
|
|
@ -132,10 +132,10 @@ public:
|
||||||
~SDScenery(void);
|
~SDScenery(void);
|
||||||
|
|
||||||
void LoadScene(tTrack *track);
|
void LoadScene(tTrack *track);
|
||||||
void CreatePit(tTrack *track);
|
void CreatePit(tTrack *track);
|
||||||
//void addSpectators(SDSpectators->build(number, tTrack *track));
|
//void addSpectators(SDSpectators->build(number, tTrack *track));
|
||||||
//void addTrees(SDTrees->build(tTrack *track));
|
//void addTrees(SDTrees->build(tTrack *track));
|
||||||
void ShutdownScene(void);
|
void ShutdownScene(void);
|
||||||
//void
|
//void
|
||||||
|
|
||||||
inline static int getWorldX(){return grWrldX;}
|
inline static int getWorldX(){return grWrldX;}
|
||||||
|
|
Loading…
Reference in a new issue