Fix disappeared brake light (merged from Torcs r1-3-1)
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@92 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: e6e11c9779f5a1010b2b0139d17110a3b3e40b1d Former-commit-id: e56e533cfff63637da1baeeb47fc676757714482
This commit is contained in:
parent
2a81a5c280
commit
2baf34d66a
2 changed files with 625 additions and 620 deletions
|
@ -1,12 +1,13 @@
|
|||
|
||||
/***************************************************************************
|
||||
|
||||
file : grcar.cpp
|
||||
created : Mon Aug 21 18:24:02 CEST 2000
|
||||
copyright : (C) 2000 by Eric Espie
|
||||
email : torcs@free.fr
|
||||
version : $Id: grcar.cpp,v 1.43 2008/03/24 15:24:01 torcs Exp $
|
||||
version : $Id: grcar.cpp,v 1.42.2.2 2008/08/24 19:26:46 berniw Exp $
|
||||
|
||||
***************************************************************************/
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
|
@ -46,8 +47,8 @@
|
|||
#include "grutil.h"
|
||||
#include "grcarlight.h"
|
||||
|
||||
extern ssgEntity *grssgLoadAC3D(const char *fname, const ssgLoaderOptions* options);
|
||||
extern ssgEntity *grssgCarLoadAC3D(const char *fname, const ssgLoaderOptions* options, int index);
|
||||
extern ssgEntity *grssgLoadAC3D ( const char *fname, const ssgLoaderOptions* options );
|
||||
extern ssgEntity *grssgCarLoadAC3D ( const char *fname, const ssgLoaderOptions* options,int index );
|
||||
extern double carTrackRatioX;
|
||||
extern double carTrackRatioY;
|
||||
|
||||
|
@ -56,16 +57,17 @@ ssgBranch *CarsAnchorTmp = 0;
|
|||
class myLoaderOptions : public ssgLoaderOptions
|
||||
{
|
||||
public:
|
||||
virtual void makeModelPath(char* path, const char *fname) const
|
||||
virtual void makeModelPath ( char* path, const char *fname ) const
|
||||
{
|
||||
ulFindFile(path, model_dir, fname, NULL) ;
|
||||
ulFindFile ( path, model_dir, fname, NULL ) ;
|
||||
}
|
||||
|
||||
virtual void makeTexturePath(char* path, const char *fname) const
|
||||
virtual void makeTexturePath ( char* path, const char *fname ) const
|
||||
{
|
||||
ulFindFile(path, texture_dir, fname, NULL) ;
|
||||
ulFindFile ( path, texture_dir, fname, NULL ) ;
|
||||
}
|
||||
};
|
||||
} ;
|
||||
|
||||
|
||||
static int grCarIndex;
|
||||
|
||||
|
@ -92,6 +94,7 @@ grInitCommonState(void)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
static ssgTransform *
|
||||
initWheel(tCarElt *car, int wheel_index)
|
||||
{
|
||||
|
@ -107,9 +110,9 @@ initWheel(tCarElt *car, int wheel_index)
|
|||
|
||||
#define BRK_BRANCH 16
|
||||
#define BRK_ANGLE (2.0 * M_PI / (tdble)BRK_BRANCH)
|
||||
#define BRK_OFFSET 0.2
|
||||
#define BRK_OFFSET 0.1
|
||||
|
||||
switch (wheel_index) {
|
||||
switch(wheel_index) {
|
||||
case FRNT_RGT:
|
||||
curAngle = -(M_PI / 2.0 + BRK_ANGLE);
|
||||
b_offset = BRK_OFFSET - car->_tireWidth(wheel_index) / 2.0;
|
||||
|
@ -148,13 +151,14 @@ initWheel(tCarElt *car, int wheel_index)
|
|||
brk_vtx->add(vtx);
|
||||
}
|
||||
|
||||
|
||||
clr[0] = clr[1] = clr[2] = 0.0;
|
||||
clr[3] = 1.0;
|
||||
brk_clr->add(clr);
|
||||
nrm[0] = nrm[2] = 0.0;
|
||||
|
||||
// Make normal point outside to have proper lighting.
|
||||
switch (wheel_index) {
|
||||
switch(wheel_index) {
|
||||
case FRNT_RGT:
|
||||
case REAR_RGT:
|
||||
nrm[1] = -1.0;
|
||||
|
@ -191,6 +195,7 @@ initWheel(tCarElt *car, int wheel_index)
|
|||
brk_vtx->add(vtx);
|
||||
}
|
||||
|
||||
|
||||
clr[0] = clr[1] = clr[2] = 0.1;
|
||||
clr[3] = 1.0;
|
||||
brk_clr->add(clr);
|
||||
|
@ -211,7 +216,7 @@ initWheel(tCarElt *car, int wheel_index)
|
|||
brk_nrm = new ssgNormalArray(1);
|
||||
|
||||
for (i = 0; i < (BRK_BRANCH / 2 - 2); i++) {
|
||||
alpha = -curAngle + (float)i * 2.0 * M_PI / (float)(BRK_BRANCH - 1);
|
||||
alpha = - curAngle + (float)i * 2.0 * M_PI / (float)(BRK_BRANCH - 1);
|
||||
vtx[0] = (car->_brakeDiskRadius(wheel_index) + 0.02) * cos(alpha);
|
||||
vtx[1] = b_offset;
|
||||
vtx[2] = (car->_brakeDiskRadius(wheel_index) + 0.02) * sin(alpha);
|
||||
|
@ -222,6 +227,7 @@ initWheel(tCarElt *car, int wheel_index)
|
|||
brk_vtx->add(vtx);
|
||||
}
|
||||
|
||||
|
||||
clr[0] = 0.2;
|
||||
clr[1] = 0.2;
|
||||
clr[2] = 0.2;
|
||||
|
@ -310,7 +316,7 @@ initWheel(tCarElt *car, int wheel_index)
|
|||
alpha = (float)i * 2.0 * M_PI / (float)(WHL_BRANCH - 1);
|
||||
vtx[0] = wheelRadius * cos(alpha);
|
||||
vtx[2] = wheelRadius * sin(alpha);
|
||||
vtx[1] = -car->_tireWidth(wheel_index) / 2.0;
|
||||
vtx[1] = - car->_tireWidth(wheel_index) / 2.0;
|
||||
whl_vtx->add(vtx);
|
||||
vtx[1] = car->_tireWidth(wheel_index) / 2.0;
|
||||
whl_vtx->add(vtx);
|
||||
|
@ -325,15 +331,12 @@ initWheel(tCarElt *car, int wheel_index)
|
|||
ssgVtxTable *whl = new ssgVtxTable(GL_TRIANGLE_STRIP, whl_vtx, whl_nrm, NULL, whl_clr);
|
||||
whl->setState(commonState);
|
||||
whl->setCullFace(0);
|
||||
|
||||
// stripify wheel, should improve performance
|
||||
ssgStripify(whl);
|
||||
|
||||
whl_branch->addKid(whl);
|
||||
}
|
||||
|
||||
|
||||
/* Rim */
|
||||
switch (wheel_index) {
|
||||
switch(wheel_index) {
|
||||
case FRNT_RGT:
|
||||
case REAR_RGT:
|
||||
b_offset = -0.05;
|
||||
|
@ -389,10 +392,6 @@ initWheel(tCarElt *car, int wheel_index)
|
|||
ssgVtxTable *whl = new ssgVtxTable(GL_TRIANGLE_FAN, whl_vtx, whl_nrm, whl_tex, whl_clr);
|
||||
whl->setState(grCarInfo[grCarIndex].wheelTexture);
|
||||
whl->setCullFace(0);
|
||||
|
||||
// stripify rim, should improve performance
|
||||
ssgStripify(whl);
|
||||
|
||||
whl_branch->addKid(whl);
|
||||
|
||||
// Swap normal for "inside" rim face.
|
||||
|
@ -408,6 +407,7 @@ initWheel(tCarElt *car, int wheel_index)
|
|||
return wheel;
|
||||
}
|
||||
|
||||
|
||||
#define GR_SHADOW_POINTS 6
|
||||
|
||||
void
|
||||
|
@ -480,33 +480,33 @@ grInitShadow(tCarElt *car)
|
|||
|
||||
}
|
||||
|
||||
void grPropagateDamage(ssgEntity* l, sgVec3 poc, sgVec3 force, int cnt)
|
||||
void grPropagateDamage (ssgEntity* l, sgVec3 poc, sgVec3 force, int cnt)
|
||||
{
|
||||
//showEntityType (l);
|
||||
if (l->isAKindOf(ssgTypeBranch())) {
|
||||
if (l->isAKindOf (ssgTypeBranch())) {
|
||||
|
||||
ssgBranch* br = (ssgBranch*) l;
|
||||
|
||||
for (int i = 0; i < br -> getNumKids() ; i++) {
|
||||
ssgEntity* ln = br->getKid(i);
|
||||
for (int i = 0 ; i < br -> getNumKids () ; i++ ) {
|
||||
ssgEntity* ln = br->getKid (i);
|
||||
grPropagateDamage(ln, poc, force, cnt+1);
|
||||
}
|
||||
}
|
||||
|
||||
if (l->isAKindOf(ssgTypeVtxTable())) {
|
||||
if (l->isAKindOf (ssgTypeVtxTable())) {
|
||||
sgVec3* v;
|
||||
int Nv;
|
||||
ssgVtxTable* vt = (ssgVtxTable*) l;
|
||||
Nv = vt->getNumVertices();
|
||||
vt->getVertexList((void**) &v);
|
||||
tdble sigma = sgLengthVec3(force);
|
||||
vt->getVertexList ((void**) &v);
|
||||
tdble sigma = sgLengthVec3 (force);
|
||||
tdble invSigma = 5.0;
|
||||
// if (sigma < 0.1)
|
||||
// invSigma = 10.0;
|
||||
// else
|
||||
// invSigma = 1.0/sigma;
|
||||
for (int i=0; i<Nv; i++) {
|
||||
tdble r = sgDistanceSquaredVec3(poc, v[i]);
|
||||
tdble r = sgDistanceSquaredVec3 (poc, v[i]);
|
||||
tdble f = exp(-r*invSigma)*5.0;
|
||||
v[i][0] += force[0]*f;
|
||||
v[i][1] += force[1]*f;
|
||||
|
@ -517,6 +517,7 @@ void grPropagateDamage(ssgEntity* l, sgVec3 poc, sgVec3 force, int cnt)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
grInitCar(tCarElt *car)
|
||||
{
|
||||
|
@ -539,6 +540,7 @@ grInitCar(tCarElt *car)
|
|||
char *lightType;
|
||||
int lightTypeNum;
|
||||
|
||||
|
||||
if (!CarsAnchorTmp) {
|
||||
CarsAnchorTmp = new ssgBranch();
|
||||
}
|
||||
|
@ -547,7 +549,7 @@ grInitCar(tCarElt *car)
|
|||
|
||||
TRACE_GL("loadcar: start");
|
||||
|
||||
ssgSetCurrentOptions( &options) ;
|
||||
ssgSetCurrentOptions ( &options ) ;
|
||||
|
||||
grCarIndex = index = car->index; /* current car's index */
|
||||
handle = car->_carHandle;
|
||||
|
@ -586,6 +588,9 @@ grInitCar(tCarElt *car)
|
|||
grAddCarlight(car, lightTypeNum, lightPos, GfParmGetNum(handle, path, PRM_SIZE, NULL, 0.2));
|
||||
}
|
||||
|
||||
grLinkCarlights(car);
|
||||
|
||||
|
||||
GfOut("[gr] Init(%d) car %s for driver %s index %d\n", index, car->_carName, car->_modName, car->_driverIndex);
|
||||
|
||||
grFilePath = (char*)malloc(4096);
|
||||
|
@ -646,7 +651,7 @@ grInitCar(tCarElt *car)
|
|||
carEntity = grssgCarLoadAC3D(param, NULL, index);
|
||||
grCarInfo[index].carEntity = carEntity;
|
||||
/* Set a selector on the driver */
|
||||
ssgBranch *b = (ssgBranch *)carEntity->getByName("DRIVER");
|
||||
ssgBranch *b = (ssgBranch *)carEntity->getByName( "DRIVER" );
|
||||
grCarInfo[index].driverSelector = new ssgSelector;
|
||||
if (b) {
|
||||
ssgBranch *bp = b->getParent(0);
|
||||
|
@ -659,10 +664,11 @@ grInitCar(tCarElt *car)
|
|||
grCarInfo[index].driverSelectorinsg = false;
|
||||
}
|
||||
|
||||
|
||||
DBG_SET_NAME(carEntity, "Body", index, -1);
|
||||
carBody->addKid(carEntity);
|
||||
/* add wheels */
|
||||
for (i = 0; i < 4; i++) {
|
||||
for (i = 0; i < 4; i++){
|
||||
wheel[i] = initWheel(car, i);
|
||||
carBody->addKid(wheel[i]);
|
||||
}
|
||||
|
@ -683,7 +689,7 @@ grInitCar(tCarElt *car)
|
|||
carBody->addKid(carEntity);
|
||||
if (!strcmp(GfParmGetStr(handle, buf, PRM_WHEELSON, "no"), "yes")) {
|
||||
/* add wheels */
|
||||
for (j = 0; j < 4; j++) {
|
||||
for (j = 0; j < 4; j++){
|
||||
carBody->addKid(wheel[j]);
|
||||
}
|
||||
}
|
||||
|
@ -694,7 +700,7 @@ grInitCar(tCarElt *car)
|
|||
/* default range selection */
|
||||
LODSel->select(grCarInfo[index].LODSelectMask[0]);
|
||||
|
||||
// separate driver models...
|
||||
// separate driver models for animation according to steering wheel angle ...
|
||||
sprintf(path, "%s/%s", SECT_GROBJECTS, LST_DRIVER);
|
||||
nranges = GfParmGetEltNb(handle, path) + 1;
|
||||
grCarInfo[index].nDRM = nranges - 1;
|
||||
|
@ -782,6 +788,7 @@ grDrawShadow(tCarElt *car, int visible)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
tdble grGetDistToStart(tCarElt *car)
|
||||
{
|
||||
tTrackSeg *seg;
|
||||
|
@ -814,14 +821,10 @@ grDrawCar(tCarElt *car, tCarElt *curCar, int dispCarFlag, int dispDrvFlag, doubl
|
|||
index = car->index;
|
||||
if (car->priv.collision_state.collision_count > 0) {
|
||||
tCollisionState* collision_state = &car->priv.collision_state;
|
||||
grPropagateDamage(grCarInfo[index].carEntity, collision_state->pos, collision_state->force, 0);
|
||||
//printf("%d: ",collision_state->collision_count );
|
||||
//for (int i=0; i<3; i++) {
|
||||
//printf ("(%f %f) ", collision_state->pos[i], collision_state->force[i]);
|
||||
//}
|
||||
//printf("\n");
|
||||
grPropagateDamage (grCarInfo[index].carEntity, collision_state->pos, collision_state->force, 0);
|
||||
collision_state->collision_count = 0;
|
||||
}
|
||||
|
||||
grCarInfo[index].distFromStart=grGetDistToStart(car);
|
||||
grCarInfo[index].envAngle=RAD2DEG(car->_yaw);
|
||||
|
||||
|
@ -844,6 +847,7 @@ grDrawCar(tCarElt *car, tCarElt *curCar, int dispCarFlag, int dispDrvFlag, doubl
|
|||
}
|
||||
}
|
||||
|
||||
// Animated driver model selection according to steering wheel angle
|
||||
if (grCarInfo[index].nDRM > 0)
|
||||
{
|
||||
// choose a driver model to display
|
||||
|
@ -881,9 +885,11 @@ grDrawCar(tCarElt *car, tCarElt *curCar, int dispCarFlag, int dispDrvFlag, doubl
|
|||
} else {
|
||||
grDrawShadow(car, 1);
|
||||
}
|
||||
|
||||
grUpdateSkidmarks(car, curTime);
|
||||
grDrawSkidmarks(car);
|
||||
grAddSmoke(car, curTime);
|
||||
|
||||
if ((car == curCar) && (dispCarFlag != 1)) {
|
||||
grUpdateCarlight(car, curCam, 0);
|
||||
} else {
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
//#include <SDL.h>
|
||||
#include <GL/glut.h>
|
||||
#include <plib/ssg.h>
|
||||
|
||||
|
|
Loading…
Reference in a new issue