forked from speed-dreams/speed-dreams-code
ssgraph - animated steering wheel, improvements to driver animation and F2 camera views
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@409 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 1b2fd713eaf8159d22bb6641f5ea2c76edbf74d3 Former-commit-id: 87b6ee64128cae609dbc5b2302e6f04adb94eed7
This commit is contained in:
parent
27e908cf63
commit
8646b6a4ef
4 changed files with 105 additions and 55 deletions
|
@ -532,6 +532,12 @@ typedef struct CarElt
|
||||||
#define PRM_BONNET "bonnet"
|
#define PRM_BONNET "bonnet"
|
||||||
#define PRM_WHEEL_TEXTURE "wheel texture"
|
#define PRM_WHEEL_TEXTURE "wheel texture"
|
||||||
#define PRM_SHADOW_TEXTURE "shadow texture"
|
#define PRM_SHADOW_TEXTURE "shadow texture"
|
||||||
|
#define PRM_STEERWHEEL "steer wheel"
|
||||||
|
#define PRM_STEERWHEELX "steer wheel xpos"
|
||||||
|
#define PRM_STEERWHEELY "steer wheel ypos"
|
||||||
|
#define PRM_STEERWHEELZ "steer wheel zpos"
|
||||||
|
#define PRM_STEERWHEELA "steer wheel angle"
|
||||||
|
#define PRM_STEERMOVT "steer wheel movt"
|
||||||
|
|
||||||
#define LST_DRIVER "Driver"
|
#define LST_DRIVER "Driver"
|
||||||
#define PRM_DRIVERSTEER "steer"
|
#define PRM_DRIVERSTEER "steer"
|
||||||
|
|
|
@ -249,7 +249,7 @@ class cGrCarCamInside : public cGrPerspCamera
|
||||||
float myfovy, float myfovymin, float myfovymax,
|
float myfovy, float myfovymin, float myfovymax,
|
||||||
float myfnear, float myffar = 1500.0,
|
float myfnear, float myffar = 1500.0,
|
||||||
float myfogstart = 1400.0, float myfogend = 1500.0)
|
float myfogstart = 1400.0, float myfogend = 1500.0)
|
||||||
: cGrPerspCamera(myscreen, id, drawCurr, 1, drawBG, 1,
|
: cGrPerspCamera(myscreen, id, drawCurr, 0, drawBG, 1,
|
||||||
myfovy, myfovymin, myfovymax,
|
myfovy, myfovymin, myfovymax,
|
||||||
myfnear, myffar, myfogstart, myfogend) {
|
myfnear, myffar, myfogstart, myfogend) {
|
||||||
PreA = 0.0f;
|
PreA = 0.0f;
|
||||||
|
@ -285,8 +285,8 @@ class cGrCarCamInside : public cGrPerspCamera
|
||||||
if (car->_accel_x < 0.0)
|
if (car->_accel_x < 0.0)
|
||||||
brake = MIN(2.0, fabs(car->_accel_x) / 20.0);
|
brake = MIN(2.0, fabs(car->_accel_x) / 20.0);
|
||||||
|
|
||||||
eye[0] = p[0]; // * CosA;
|
eye[0] = p[0];
|
||||||
eye[1] = p[1]; // * SinA;
|
eye[1] = p[1];
|
||||||
eye[2] = p[2];
|
eye[2] = p[2];
|
||||||
|
|
||||||
P[0] = car->_drvPos_x + 30.0;
|
P[0] = car->_drvPos_x + 30.0;
|
||||||
|
@ -296,8 +296,8 @@ class cGrCarCamInside : public cGrPerspCamera
|
||||||
|
|
||||||
center[0] = P[0];
|
center[0] = P[0];
|
||||||
center[1] = P[1];
|
center[1] = P[1];
|
||||||
center[0] = P[0] - (10 - 1) * CosA;
|
//center[0] = P[0] - (10 - 1) * CosA;
|
||||||
center[1] = P[1] - (10 - 1) * SinA;
|
//center[1] = P[1] - (10 - 1) * SinA;
|
||||||
center[2] = P[2]; // - brake; // this not working yet
|
center[2] = P[2]; // - brake; // this not working yet
|
||||||
|
|
||||||
up[0] = car->_posMat[2][0];
|
up[0] = car->_posMat[2][0];
|
||||||
|
@ -452,7 +452,7 @@ class cGrCarCamInsideFixedCar : public cGrPerspCamera
|
||||||
float myfovy, float myfovymin, float myfovymax,
|
float myfovy, float myfovymin, float myfovymax,
|
||||||
float myfnear, float myffar = 1500.0,
|
float myfnear, float myffar = 1500.0,
|
||||||
float myfogstart = 1400.0, float myfogend = 1500.0)
|
float myfogstart = 1400.0, float myfogend = 1500.0)
|
||||||
: cGrPerspCamera(myscreen, id, drawCurr, 1, drawBG, 1,
|
: cGrPerspCamera(myscreen, id, drawCurr, 0, drawBG, 1,
|
||||||
myfovy, myfovymin, myfovymax,
|
myfovy, myfovymin, myfovymax,
|
||||||
myfnear, myffar, myfogstart, myfogend) {
|
myfnear, myffar, myfogstart, myfogend) {
|
||||||
}
|
}
|
||||||
|
@ -1339,12 +1339,12 @@ grCamCreateSceneCameraList(class cGrScreen *myscreen, tGrCamHead *cams, tdble fo
|
||||||
cam->add(&cams[c]);
|
cam->add(&cams[c]);
|
||||||
id++;
|
id++;
|
||||||
|
|
||||||
/* cam F2 = car inside with car (bonnet view) */
|
/* cam F2 = car inside with car (driver view) */
|
||||||
cam = new cGrCarCamInside(myscreen,
|
cam = new cGrCarCamInside(myscreen,
|
||||||
id,
|
id,
|
||||||
1, /* drawCurr */
|
1, /* drawCurr */
|
||||||
1, /* drawBG */
|
1, /* drawBG */
|
||||||
67.5, /* fovy */
|
75.5, /* fovy */
|
||||||
50.0, /* fovymin */
|
50.0, /* fovymin */
|
||||||
95.0, /* fovymax */
|
95.0, /* fovymax */
|
||||||
0.3, /* near */
|
0.3, /* near */
|
||||||
|
@ -1369,6 +1369,7 @@ grCamCreateSceneCameraList(class cGrScreen *myscreen, tGrCamHead *cams, tdble fo
|
||||||
600.0 * fovFactor /* fog */
|
600.0 * fovFactor /* fog */
|
||||||
);
|
);
|
||||||
cam->add(&cams[c]);
|
cam->add(&cams[c]);
|
||||||
|
id++;
|
||||||
|
|
||||||
/* cam F2 = behind very near */
|
/* cam F2 = behind very near */
|
||||||
cam = new cGrCarCamBehind(myscreen,
|
cam = new cGrCarCamBehind(myscreen,
|
||||||
|
@ -1406,7 +1407,6 @@ grCamCreateSceneCameraList(class cGrScreen *myscreen, tGrCamHead *cams, tdble fo
|
||||||
25.0 /* relaxation */
|
25.0 /* relaxation */
|
||||||
);
|
);
|
||||||
cam->add(&cams[c]);
|
cam->add(&cams[c]);
|
||||||
id++;
|
|
||||||
|
|
||||||
/* F3 */
|
/* F3 */
|
||||||
c++;
|
c++;
|
||||||
|
@ -1650,7 +1650,7 @@ grCamCreateSceneCameraList(class cGrScreen *myscreen, tGrCamHead *cams, tdble fo
|
||||||
1, /* drawCurr */
|
1, /* drawCurr */
|
||||||
1, /* drawBG */
|
1, /* drawBG */
|
||||||
//12.0, /* fovy */
|
//12.0, /* fovy */
|
||||||
37.5, /* fovy */
|
20.5, /* fovy */
|
||||||
1.0, /* fovymin */
|
1.0, /* fovymin */
|
||||||
90.0, /* fovymax */
|
90.0, /* fovymax */
|
||||||
//300.0, /* distz */
|
//300.0, /* distz */
|
||||||
|
@ -1671,7 +1671,7 @@ grCamCreateSceneCameraList(class cGrScreen *myscreen, tGrCamHead *cams, tdble fo
|
||||||
1, /* drawCurr */
|
1, /* drawCurr */
|
||||||
1, /* drawBG */
|
1, /* drawBG */
|
||||||
//12.0, /* fovy */
|
//12.0, /* fovy */
|
||||||
37.5, /* fovy */
|
20.5, /* fovy */
|
||||||
1.0, /* fovymin */
|
1.0, /* fovymin */
|
||||||
90.0, /* fovymax */
|
90.0, /* fovymax */
|
||||||
//300.0, /* distz */
|
//300.0, /* distz */
|
||||||
|
@ -1691,7 +1691,7 @@ grCamCreateSceneCameraList(class cGrScreen *myscreen, tGrCamHead *cams, tdble fo
|
||||||
1, /* drawCurr */
|
1, /* drawCurr */
|
||||||
1, /* drawBG */
|
1, /* drawBG */
|
||||||
//12.0, /* fovy */
|
//12.0, /* fovy */
|
||||||
37.5, /* fovy */
|
20.5, /* fovy */
|
||||||
1.0, /* fovymin */
|
1.0, /* fovymin */
|
||||||
90.0, /* fovymax */
|
90.0, /* fovymax */
|
||||||
//300.0, /* distz */
|
//300.0, /* distz */
|
||||||
|
@ -1711,7 +1711,7 @@ grCamCreateSceneCameraList(class cGrScreen *myscreen, tGrCamHead *cams, tdble fo
|
||||||
1, /* drawCurr */
|
1, /* drawCurr */
|
||||||
1, /* drawBG */
|
1, /* drawBG */
|
||||||
//12.0, /* fovy */
|
//12.0, /* fovy */
|
||||||
37.5, /* fovy */
|
20.5, /* fovy */
|
||||||
1.0, /* fovymin */
|
1.0, /* fovymin */
|
||||||
90.0, /* fovymax */
|
90.0, /* fovymax */
|
||||||
//300.0, /* distz */
|
//300.0, /* distz */
|
||||||
|
|
|
@ -636,9 +636,9 @@ grInitCar(tCarElt *car)
|
||||||
LODSel->addKid(carBody);
|
LODSel->addKid(carBody);
|
||||||
|
|
||||||
/* The car's model is under cars/<model> */
|
/* The car's model is under cars/<model> */
|
||||||
sprintf(buf, "cars/%s", car->_carName);
|
//sprintf(buf, "cars/%s", car->_carName);
|
||||||
|
sprintf(buf, "drivers/%s/%s/%d;drivers/%s/%s;drivers/%s/%d;cars/%s", car->_modName, car->_carName, car->_driverIndex, car->_modName, car->_carName, car->_modName, car->_driverIndex, car->_carName);
|
||||||
ssgModelPath(buf);
|
ssgModelPath(buf);
|
||||||
sprintf(buf, "drivers/%s/%d;drivers/%s;cars/%s", car->_modName, car->_driverIndex, car->_modName, car->_carName);
|
|
||||||
ssgTexturePath(buf);
|
ssgTexturePath(buf);
|
||||||
grTexturePath = strdup(buf);
|
grTexturePath = strdup(buf);
|
||||||
|
|
||||||
|
@ -665,7 +665,6 @@ grInitCar(tCarElt *car)
|
||||||
grCarInfo[index].driverSelectorinsg = false;
|
grCarInfo[index].driverSelectorinsg = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DBG_SET_NAME(carEntity, "Body", index, -1);
|
DBG_SET_NAME(carEntity, "Body", index, -1);
|
||||||
carBody->addKid(carEntity);
|
carBody->addKid(carEntity);
|
||||||
/* add wheels */
|
/* add wheels */
|
||||||
|
@ -701,6 +700,44 @@ grInitCar(tCarElt *car)
|
||||||
/* default range selection */
|
/* default range selection */
|
||||||
LODSel->select(grCarInfo[index].LODSelectMask[0]);
|
LODSel->select(grCarInfo[index].LODSelectMask[0]);
|
||||||
|
|
||||||
|
/* add Steering Wheel for car 0 (if one exists) */
|
||||||
|
param = GfParmGetStr(handle, path, PRM_STEERWHEEL, NULL);
|
||||||
|
if (param)
|
||||||
|
{
|
||||||
|
grCarInfo[index].steerWheel = grssgCarLoadAC3D(param, NULL, index);
|
||||||
|
|
||||||
|
if (grCarInfo[index].steerWheel)
|
||||||
|
{
|
||||||
|
ssgBranch *steerBranch = new ssgBranch;
|
||||||
|
ssgTransform *steerLoc = new ssgTransform;
|
||||||
|
|
||||||
|
sgCoord steerpos;
|
||||||
|
tdble xpos = GfParmGetNum(handle, path, PRM_STEERWHEELX, NULL, 0.0);
|
||||||
|
tdble ypos = GfParmGetNum(handle, path, PRM_STEERWHEELY, NULL, 0.0);
|
||||||
|
tdble zpos = GfParmGetNum(handle, path, PRM_STEERWHEELZ, NULL, 0.0);
|
||||||
|
tdble angl = GfParmGetNum(handle, path, PRM_STEERWHEELA, NULL, 0.0);
|
||||||
|
|
||||||
|
grCarInfo[index].steerMovt = GfParmGetNum(handle, path, PRM_STEERMOVT, NULL, 1.0);
|
||||||
|
|
||||||
|
grCarInfo[index].steerRot = new ssgTransform;
|
||||||
|
sgSetCoord(&steerpos, 0, 0, 0, 0, 0, 0);
|
||||||
|
grCarInfo[index].steerRot->setTransform( &steerpos );
|
||||||
|
grCarInfo[index].steerRot->addKid(grCarInfo[index].steerWheel);
|
||||||
|
|
||||||
|
sgSetCoord(&steerpos, xpos, ypos, zpos, 0, 0, angl);
|
||||||
|
steerLoc->setTransform( &steerpos);
|
||||||
|
steerLoc->addKid( grCarInfo[index].steerRot );
|
||||||
|
steerBranch->addKid( steerLoc );
|
||||||
|
|
||||||
|
grCarInfo[index].steerSelector = new ssgSelector;
|
||||||
|
grCarInfo[index].steerSelector->addKid( steerBranch );
|
||||||
|
grCarInfo[index].steerSelector->select(1);
|
||||||
|
grCarInfo[index].carTransform->addKid( grCarInfo[index].steerSelector );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
grCarInfo[index].steerWheel = NULL;
|
||||||
|
|
||||||
// separate driver models for animation according to steering wheel angle ...
|
// separate driver models for animation according to steering wheel angle ...
|
||||||
sprintf(path, "%s/%s", SECT_GROBJECTS, LST_DRIVER);
|
sprintf(path, "%s/%s", SECT_GROBJECTS, LST_DRIVER);
|
||||||
nranges = GfParmGetEltNb(handle, path) + 1;
|
nranges = GfParmGetEltNb(handle, path) + 1;
|
||||||
|
@ -715,11 +752,6 @@ grInitCar(tCarElt *car)
|
||||||
grCarInfo[index].DRMSelector = DRMSel = new ssgSelector;
|
grCarInfo[index].DRMSelector = DRMSel = new ssgSelector;
|
||||||
grCarInfo[index].carTransform->addKid(DRMSel);
|
grCarInfo[index].carTransform->addKid(DRMSel);
|
||||||
|
|
||||||
sprintf(buf, "cars/%s", car->_carName);
|
|
||||||
ssgModelPath(buf);
|
|
||||||
sprintf(buf, "drivers/%s/%d;drivers/%s;cars/%s", car->_modName, car->_driverIndex, car->_modName, car->_carName);
|
|
||||||
ssgTexturePath(buf);
|
|
||||||
grTexturePath = strdup(buf);
|
|
||||||
selIndex = 0;
|
selIndex = 0;
|
||||||
|
|
||||||
// add the drivers
|
// add the drivers
|
||||||
|
@ -750,7 +782,6 @@ grInitCar(tCarElt *car)
|
||||||
DRMSel->select( grCarInfo[index].DRMSelectMask[0] );
|
DRMSel->select( grCarInfo[index].DRMSelectMask[0] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CarsAnchor->addKid(grCarInfo[index].carTransform);
|
CarsAnchor->addKid(grCarInfo[index].carTransform);
|
||||||
|
|
||||||
//grCarInfo[index].carTransform->print(stdout, "-", 1);
|
//grCarInfo[index].carTransform->print(stdout, "-", 1);
|
||||||
|
@ -843,14 +874,12 @@ grDrawCar(tSituation *s, tCarElt *car, tCarElt *curCar, int dispCarFlag, int dis
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
grCarInfo[index].LODSelector->select(grCarInfo[index].LODSelectMask[i]);
|
grCarInfo[index].LODSelector->select(grCarInfo[index].LODSelectMask[i]);
|
||||||
if (dispDrvFlag) {
|
if (dispDrvFlag || car != curCar)
|
||||||
|
{
|
||||||
grCarInfo[index].driverSelector->select(1);
|
grCarInfo[index].driverSelector->select(1);
|
||||||
} else {
|
|
||||||
grCarInfo[index].driverSelector->select(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Animated driver model selection according to steering wheel angle
|
// Animated driver model selection according to steering wheel angle
|
||||||
if (grCarInfo[index].nDRM > 0 && s->currentTime - grCarInfo[index].lastDRMswitch > 0.2)
|
if (grCarInfo[index].nDRM > 0 && s->currentTime - grCarInfo[index].lastDRMswitch > 0.1)
|
||||||
{
|
{
|
||||||
// choose a driver model to display
|
// choose a driver model to display
|
||||||
int curDRM = 0;
|
int curDRM = 0;
|
||||||
|
@ -859,16 +888,16 @@ grDrawCar(tSituation *s, tCarElt *car, tCarElt *curCar, int dispCarFlag, int dis
|
||||||
|
|
||||||
for (i=0; i<grCarInfo[index].nDRM; i++)
|
for (i=0; i<grCarInfo[index].nDRM; i++)
|
||||||
{
|
{
|
||||||
if ((curCar->_steerCmd > 0.0 &&
|
if ((car->_steerCmd > 0.0 &&
|
||||||
grCarInfo[index].DRMThreshold[i] >= 0.0 &&
|
grCarInfo[index].DRMThreshold[i] >= 0.0 &&
|
||||||
grCarInfo[index].DRMThreshold[i] <= curCar->_steerCmd &&
|
grCarInfo[index].DRMThreshold[i] <= car->_steerCmd &&
|
||||||
grCarInfo[index].DRMThreshold[i] >= curSteer) ||
|
grCarInfo[index].DRMThreshold[i] >= curSteer) ||
|
||||||
(curCar->_steerCmd < 0.0 &&
|
(car->_steerCmd < 0.0 &&
|
||||||
grCarInfo[index].DRMThreshold[i] <= 0.0 &&
|
grCarInfo[index].DRMThreshold[i] <= 0.0 &&
|
||||||
grCarInfo[index].DRMThreshold[i] >= curCar->_steerCmd &&
|
grCarInfo[index].DRMThreshold[i] >= car->_steerCmd &&
|
||||||
grCarInfo[index].DRMThreshold[i] <= curSteer))
|
grCarInfo[index].DRMThreshold[i] <= curSteer))
|
||||||
{
|
{
|
||||||
float fsteer = fabs(curCar->_steerCmd);
|
float fsteer = fabs(car->_steerCmd);
|
||||||
|
|
||||||
curDRM = i;
|
curDRM = i;
|
||||||
curSteer = grCarInfo[index].DRMThreshold[i];
|
curSteer = grCarInfo[index].DRMThreshold[i];
|
||||||
|
@ -882,7 +911,18 @@ grDrawCar(tSituation *s, tCarElt *car, tCarElt *curCar, int dispCarFlag, int dis
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
grCarInfo[index].driverSelector->select(0);
|
||||||
|
grCarInfo[index].DRMSelector->select(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (grCarInfo[index].steerWheel)
|
||||||
|
{
|
||||||
|
sgSetCoord( &wheelpos, 0, 0, 0, 0, RAD2DEG(-car->_steerCmd * grCarInfo[index].steerMovt), 0 );
|
||||||
|
grCarInfo[index].steerRot->setTransform( &wheelpos );
|
||||||
|
}
|
||||||
|
|
||||||
sgCopyMat4(grCarInfo[index].carPos, car->_posMat);
|
sgCopyMat4(grCarInfo[index].carPos, car->_posMat);
|
||||||
grCarInfo[index].px=car->_pos_X;
|
grCarInfo[index].px=car->_pos_X;
|
||||||
|
|
|
@ -45,6 +45,7 @@ typedef struct
|
||||||
ssgSelector *LODSelector;
|
ssgSelector *LODSelector;
|
||||||
ssgSelector *DRMSelector;
|
ssgSelector *DRMSelector;
|
||||||
ssgEntity *carEntity;
|
ssgEntity *carEntity;
|
||||||
|
ssgEntity *steerWheel;
|
||||||
int LODSelectMask[32];
|
int LODSelectMask[32];
|
||||||
float LODThreshold[32];
|
float LODThreshold[32];
|
||||||
int DRMSelectMask[32];
|
int DRMSelectMask[32];
|
||||||
|
@ -52,10 +53,12 @@ typedef struct
|
||||||
float DRMThreshold[32];
|
float DRMThreshold[32];
|
||||||
float lastDRMswitch;
|
float lastDRMswitch;
|
||||||
ssgSelector *driverSelector;
|
ssgSelector *driverSelector;
|
||||||
|
ssgSelector *steerSelector;
|
||||||
bool driverSelectorinsg;
|
bool driverSelectorinsg;
|
||||||
ssgStateSelector *envSelector;
|
ssgStateSelector *envSelector;
|
||||||
ssgTransform *wheelPos[4];
|
ssgTransform *wheelPos[4];
|
||||||
ssgTransform *wheelRot[4];
|
ssgTransform *wheelRot[4];
|
||||||
|
ssgTransform *steerRot;
|
||||||
ssgColourArray *brkColor[4];
|
ssgColourArray *brkColor[4];
|
||||||
ssgSelector *wheelselector[4];
|
ssgSelector *wheelselector[4];
|
||||||
ssgState *wheelTexture;
|
ssgState *wheelTexture;
|
||||||
|
@ -68,6 +71,7 @@ typedef struct
|
||||||
tdble distFromStart;
|
tdble distFromStart;
|
||||||
tdble envAngle;
|
tdble envAngle;
|
||||||
int fireCount;
|
int fireCount;
|
||||||
|
tdble steerMovt;
|
||||||
tdble px;
|
tdble px;
|
||||||
tdble py;
|
tdble py;
|
||||||
tdble sx;
|
tdble sx;
|
||||||
|
|
Loading…
Reference in a new issue