- Update OsgBrake (car update)

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

Former-commit-id: 363c892fb5bce002c2791e57bddd32fba5c50011
Former-commit-id: 51bae1154f16bc34a5a030fbb6b5b087db137480
This commit is contained in:
torcs-ng 2015-10-10 21:41:03 +00:00
parent 9ae0a3831a
commit b3329926c0
4 changed files with 608 additions and 533 deletions

View file

@ -32,7 +32,7 @@ void SDBrakes::setCar(tCarElt * car)
this->car = car; this->car = car;
} }
osg::ref_ptr<osg::Geode> SDBrakes::initBrake(int wheelIndex) osg::Node *SDBrakes::initBrake(int wheelIndex)
{ {
float alpha; float alpha;
osg::Vec3 vtx; osg::Vec3 vtx;
@ -43,7 +43,7 @@ osg::ref_ptr<osg::Geode> SDBrakes::initBrake(int wheelIndex)
tdble curAngle = 0.0; tdble curAngle = 0.0;
int i; int i;
osg::ref_ptr<osg::Geode> pBrake = new osg::Geode; osg::Geode *pBrake = new osg::Geode;
pBrake->setName("Brake Assembly"); pBrake->setName("Brake Assembly");
pBrake->setCullingActive(false); pBrake->setCullingActive(false);
@ -88,9 +88,9 @@ osg::ref_ptr<osg::Geode> SDBrakes::initBrake(int wheelIndex)
} }
/* hub */ /* hub */
osg::ref_ptr<osg::Vec3Array> hub_vtx = new osg::Vec3Array(); osg::Vec3Array *hub_vtx = new osg::Vec3Array();
osg::ref_ptr<osg::Vec4Array> hub_clr = new osg::Vec4Array(); osg::Vec4Array *hub_clr = new osg::Vec4Array();
osg::ref_ptr<osg::Vec3Array> hub_nrm = new osg::Vec3Array(); osg::Vec3Array *hub_nrm = new osg::Vec3Array();
tdble hubRadius; tdble hubRadius;
@ -129,21 +129,23 @@ osg::ref_ptr<osg::Geode> SDBrakes::initBrake(int wheelIndex)
hub_nrm->push_back(nrm); hub_nrm->push_back(nrm);
osg::ref_ptr<osg::Geometry> pHub = new osg::Geometry; osg::Geometry *pHub = new osg::Geometry;
pHub->setName("Hub"); pHub->setName("Hub");
pHub->addPrimitiveSet( new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_FAN, 0, brakeBranch+1 )); pHub->addPrimitiveSet( new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_FAN, 0, brakeBranch+1 ));
pHub->setVertexArray(hub_vtx.get());
pHub->setNormalArray(hub_nrm.get());
pHub->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
pHub->setColorArray(hub_clr.get());
pHub->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
pBrake->addDrawable(pHub.get()); pHub->setVertexArray(hub_vtx);
pHub->setColorArray(hub_clr);
pHub->setNormalArray(hub_nrm);
pHub->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
pHub->setNormalBinding(osg::Geometry::BIND_OFF);
pBrake->addDrawable(pHub);
/* Brake disk */ /* Brake disk */
osg::ref_ptr<osg::Vec3Array> brk_vtx = new osg::Vec3Array(); osg::Vec3Array *brk_vtx = new osg::Vec3Array();
osg::ref_ptr<osg::Vec4Array> brk_clr = new osg::Vec4Array(); brk_clr = new osg::Vec4Array();
osg::ref_ptr<osg::Vec3Array> brk_nrm = new osg::Vec3Array(); osg::Vec3Array *brk_nrm = new osg::Vec3Array();
for (i = 0; i < (brakeBranch / 2 + 2); i++) for (i = 0; i < (brakeBranch / 2 + 2); i++)
{ {
@ -163,24 +165,26 @@ osg::ref_ptr<osg::Geode> SDBrakes::initBrake(int wheelIndex)
brk_clr->push_back(clr); brk_clr->push_back(clr);
brk_nrm->push_back(nrm); brk_nrm->push_back(nrm);
osg::ref_ptr<osg::Geometry> pBDisc = new osg::Geometry; osg::Geometry *pBDisc = new osg::Geometry;
pBDisc->setName("Disc Brake"); pBDisc->setName("Disc Brake");
pBDisc->addPrimitiveSet( new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_STRIP, 0, brakeBranch+4 )); pBDisc->addPrimitiveSet( new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_STRIP, 0, brakeBranch+4 ));
pBDisc->setVertexArray(brk_vtx.get());
pBDisc->setNormalArray(brk_nrm.get()); pBDisc->setVertexArray(brk_vtx);
pBDisc->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
pBDisc->setColorArray(brk_clr.get()); pBDisc->setColorArray(brk_clr.get());
pBDisc->setNormalArray(brk_nrm);
pBDisc->setColorBinding(osg::Geometry::BIND_PER_VERTEX); pBDisc->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
pBDisc->setNormalBinding(osg::Geometry::BIND_OFF);
pBrake->addDrawable(pBDisc.get()); pBrake->addDrawable(pBDisc);
this->brake_disks[wheelIndex] = pBDisc.get(); this->brake_disks[wheelIndex] = pBDisc;
/* Brake caliper */ /* Brake caliper */
osg::ref_ptr<osg::Vec3Array> cal_vtx = new osg::Vec3Array(); osg::Vec3Array *cal_vtx = new osg::Vec3Array();
cal_clr = new osg::Vec4Array(); osg::Vec4Array *cal_clr = new osg::Vec4Array();
osg::ref_ptr<osg::Vec3Array> cal_nrm = new osg::Vec3Array(); osg::Vec3Array *cal_nrm = new osg::Vec3Array();
for (i = 0; i < (brakeBranch / 2 - 2); i++) for (i = 0; i < (brakeBranch / 2 - 2); i++)
{ {
@ -202,18 +206,21 @@ osg::ref_ptr<osg::Geode> SDBrakes::initBrake(int wheelIndex)
cal_clr->push_back(clr); cal_clr->push_back(clr);
cal_nrm->push_back(nrm); cal_nrm->push_back(nrm);
osg::ref_ptr<osg::Geometry> pCaliper = new osg::Geometry; osg::Geometry *pCaliper = new osg::Geometry;
pCaliper->setName("Caliper"); pCaliper->setName("Caliper");
pCaliper->addPrimitiveSet( new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_STRIP, 0, brakeBranch-4 )); pCaliper->addPrimitiveSet( new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_STRIP, 0, brakeBranch-4 ));
pCaliper->setVertexArray(cal_vtx.get());
pCaliper->setNormalArray(cal_nrm.get()); pCaliper->setVertexArray(cal_vtx);
pCaliper->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); pCaliper->setColorArray(cal_clr);
pCaliper->setColorArray(cal_clr.get()); pCaliper->setNormalArray(cal_nrm);
pCaliper->setColorBinding(osg::Geometry::BIND_PER_VERTEX); pCaliper->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
pCaliper->setNormalBinding(osg::Geometry::BIND_OFF);
pBrake->addDrawable(pCaliper.get());
return pBrake.get(); pBrake->addDrawable(pCaliper);
return pBrake;
} }
void SDBrakes::updateBrakes() void SDBrakes::updateBrakes()
@ -226,9 +233,10 @@ void SDBrakes::updateBrakes()
clr[1] = 0.1 + car->_brakeTemp(i) * 0.3; clr[1] = 0.1 + car->_brakeTemp(i) * 0.3;
clr[2] = 0.1 - car->_brakeTemp(i) * 0.3; clr[2] = 0.1 - car->_brakeTemp(i) * 0.3;
clr[3] = 1.0; clr[3] = 1.0;
cal_clr->push_back(clr); (*brk_clr)[0] = clr;
brk_clr->dirty();
this->brake_disks[i]->setColorArray(cal_clr.get(), osg::Array::BIND_PER_VERTEX); this->brake_disks[i]->setColorArray(brk_clr.get(), osg::Array::BIND_PER_VERTEX);
//GfLogInfo("brake temp %i = %f\n", i, car->_brakeTemp(i) ); //GfLogInfo("brake temp %i = %f\n", i, car->_brakeTemp(i) );
} }
} }

View file

@ -28,11 +28,11 @@ class SDBrakes
private : private :
tCarElt *car; tCarElt *car;
osg::ref_ptr<osg::Geometry> brake_disks[4]; osg::ref_ptr<osg::Geometry> brake_disks[4];
osg::ref_ptr<osg::Vec4Array> cal_clr; osg::ref_ptr<osg::Vec4Array> brk_clr;
public : public :
void setCar(tCarElt * car); void setCar(tCarElt * car);
osg::ref_ptr<osg::Geode> initBrake(int wheelIndex); osg::Node *initBrake(int wheelIndex);
void updateBrakes(); void updateBrakes();
}; };

File diff suppressed because it is too large Load diff

View file

@ -1,26 +1,26 @@
/* /*
* grsmoke.h * grsmoke.h
* *
* Created : Fri Mar 22 23:17:54 CET 2002 * Created : Fri Mar 22 23:17:54 CET 2002
* Copyright: (C) 2001 by Christophe Guionneau * Copyright: (C) 2001 by Christophe Guionneau
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA. * MA 02110-1301, USA.
* *
* $Id$ * $Id$
* *
*/ */
#ifndef _GRSMOKE_H_ #ifndef _GRSMOKE_H_
@ -43,61 +43,61 @@
class ssgVtxTableSmoke : public ssgVtxTable class ssgVtxTableSmoke : public ssgVtxTable
{ {
protected: protected:
virtual void copy_from ( ssgVtxTableSmoke *src, int clone_flags ) ; virtual void copy_from ( ssgVtxTableSmoke *src, int clone_flags ) ;
public: public:
inline bool isAlive() const {return cur_life < max_life;} inline bool isAlive() const {return cur_life < max_life;}
double max_life; double max_life;
double step0_max_life; double step0_max_life;
double step1_max_life; double step1_max_life;
double step2_max_life; double step2_max_life;
double cur_life; double cur_life;
tdble vvx, vvy,vvz; tdble vvx, vvy,vvz;
sgVec3 cur_col; sgVec3 cur_col;
tdble vexp; tdble vexp;
int smokeType; int smokeType;
int smokeTypeStep; int smokeTypeStep;
double dt; double dt;
double lastTime; double lastTime;
float sizex; float sizex;
float sizey; float sizey;
float sizez; float sizez;
float init_alpha; float init_alpha;
int stype; int stype;
virtual ssgBase *clone ( int clone_flags = 0 ) ; virtual ssgBase *clone ( int clone_flags = 0 ) ;
ssgVtxTableSmoke () ; ssgVtxTableSmoke () ;
ssgVtxTableSmoke (ssgVertexArray *shd_vtx , float initsize, int type); ssgVtxTableSmoke (ssgVertexArray *shd_vtx , float initsize, int type);
void draw_geometry(); void draw_geometry();
virtual void drawHighlight ( sgVec4 colour ){ssgVtxTable::drawHighlight(colour);} virtual void drawHighlight ( sgVec4 colour ){ssgVtxTable::drawHighlight(colour);}
virtual void drawHighlight ( sgVec4 colour, int i ){ssgVtxTable::drawHighlight(colour,i);} virtual void drawHighlight ( sgVec4 colour, int i ){ssgVtxTable::drawHighlight(colour,i);}
virtual void pick ( int baseName ) { ssgVtxTable::pick(baseName);} virtual void pick ( int baseName ) { ssgVtxTable::pick(baseName);}
virtual void transform ( const sgMat4 m ) { ssgVtxTable::transform(m);} virtual void transform ( const sgMat4 m ) { ssgVtxTable::transform(m);}
virtual void setVertices ( ssgVertexArray *vl ) { ssgVtxTable::setVertices(vl);} virtual void setVertices ( ssgVertexArray *vl ) { ssgVtxTable::setVertices(vl);}
virtual void setNormals ( ssgNormalArray *nl ) { ssgVtxTable::setNormals(nl);} virtual void setNormals ( ssgNormalArray *nl ) { ssgVtxTable::setNormals(nl);}
virtual void setTexCoords ( ssgTexCoordArray *tl ) { ssgVtxTable::setTexCoords(tl);} virtual void setTexCoords ( ssgTexCoordArray *tl ) { ssgVtxTable::setTexCoords(tl);}
virtual void setColours ( ssgColourArray *cl ) { ssgVtxTable::setColours(cl);} virtual void setColours ( ssgColourArray *cl ) { ssgVtxTable::setColours(cl);}
int getNumVertices () { return vertices -> getNum () ; } int getNumVertices () { return vertices -> getNum () ; }
int getNumNormals () { return normals -> getNum () ; } int getNumNormals () { return normals -> getNum () ; }
int getNumColours () { return colours -> getNum () ; } int getNumColours () { return colours -> getNum () ; }
int getNumTexCoords () { return texcoords -> getNum () ; } int getNumTexCoords () { return texcoords -> getNum () ; }
int getNumTriangles () { return ssgVtxTable::getNumTriangles();} int getNumTriangles () { return ssgVtxTable::getNumTriangles();}
void getTriangle ( int n, short *v1, short *v2, short *v3 ) { ssgVtxTable::getTriangle(n,v1,v2,v3);} void getTriangle ( int n, short *v1, short *v2, short *v3 ) { ssgVtxTable::getTriangle(n,v1,v2,v3);}
int getNumLines () {return ssgVtxTable::getNumLines();} int getNumLines () {return ssgVtxTable::getNumLines();}
void getLine ( int n, short *v1, short *v2 ) { ssgVtxTable::getLine(n,v1,v2);} void getLine ( int n, short *v1, short *v2 ) { ssgVtxTable::getLine(n,v1,v2);}
virtual ~ssgVtxTableSmoke (void); virtual ~ssgVtxTableSmoke (void);
virtual const char *getTypeName(void) { return ssgVtxTable::getTypeName();} virtual const char *getTypeName(void) { return ssgVtxTable::getTypeName();}
virtual void print ( FILE *fd = stderr, char *indent = "", int how_much = 2) { ssgVtxTable::print(fd,indent,how_much);} virtual void print ( FILE *fd = stderr, char *indent = "", int how_much = 2) { ssgVtxTable::print(fd,indent,how_much);}
virtual int load ( FILE *fd ) {return ssgVtxTable::load(fd);} virtual int load ( FILE *fd ) {return ssgVtxTable::load(fd);}
virtual int save ( FILE *fd ) {return ssgVtxTable::save(fd);} virtual int save ( FILE *fd ) {return ssgVtxTable::save(fd);}
}; };
@ -106,11 +106,11 @@ class cSmokeDef;
class cGrSmoke class cGrSmoke
{ {
public: public:
bool Add(tCarElt* car, const int i, const double t, int smokeType, bool Add(tCarElt* car, const int i, const double t, int smokeType,
const cSmokeDef *sd); const cSmokeDef *sd);
void Update(const double t); void Update(const double t);
ssgVtxTableSmoke *smoke; ssgVtxTableSmoke *smoke;
}; };