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_WHEEL_TEXTURE "wheel 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 PRM_DRIVERSTEER "steer"
|
||||
|
|
|
@ -249,7 +249,7 @@ class cGrCarCamInside : public cGrPerspCamera
|
|||
float myfovy, float myfovymin, float myfovymax,
|
||||
float myfnear, float myffar = 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,
|
||||
myfnear, myffar, myfogstart, myfogend) {
|
||||
PreA = 0.0f;
|
||||
|
@ -285,8 +285,8 @@ class cGrCarCamInside : public cGrPerspCamera
|
|||
if (car->_accel_x < 0.0)
|
||||
brake = MIN(2.0, fabs(car->_accel_x) / 20.0);
|
||||
|
||||
eye[0] = p[0]; // * CosA;
|
||||
eye[1] = p[1]; // * SinA;
|
||||
eye[0] = p[0];
|
||||
eye[1] = p[1];
|
||||
eye[2] = p[2];
|
||||
|
||||
P[0] = car->_drvPos_x + 30.0;
|
||||
|
@ -296,8 +296,8 @@ class cGrCarCamInside : public cGrPerspCamera
|
|||
|
||||
center[0] = P[0];
|
||||
center[1] = P[1];
|
||||
center[0] = P[0] - (10 - 1) * CosA;
|
||||
center[1] = P[1] - (10 - 1) * SinA;
|
||||
//center[0] = P[0] - (10 - 1) * CosA;
|
||||
//center[1] = P[1] - (10 - 1) * SinA;
|
||||
center[2] = P[2]; // - brake; // this not working yet
|
||||
|
||||
up[0] = car->_posMat[2][0];
|
||||
|
@ -452,7 +452,7 @@ class cGrCarCamInsideFixedCar : public cGrPerspCamera
|
|||
float myfovy, float myfovymin, float myfovymax,
|
||||
float myfnear, float myffar = 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,
|
||||
myfnear, myffar, myfogstart, myfogend) {
|
||||
}
|
||||
|
@ -1339,12 +1339,12 @@ grCamCreateSceneCameraList(class cGrScreen *myscreen, tGrCamHead *cams, tdble fo
|
|||
cam->add(&cams[c]);
|
||||
id++;
|
||||
|
||||
/* cam F2 = car inside with car (bonnet view) */
|
||||
/* cam F2 = car inside with car (driver view) */
|
||||
cam = new cGrCarCamInside(myscreen,
|
||||
id,
|
||||
1, /* drawCurr */
|
||||
1, /* drawBG */
|
||||
67.5, /* fovy */
|
||||
75.5, /* fovy */
|
||||
50.0, /* fovymin */
|
||||
95.0, /* fovymax */
|
||||
0.3, /* near */
|
||||
|
@ -1369,6 +1369,7 @@ grCamCreateSceneCameraList(class cGrScreen *myscreen, tGrCamHead *cams, tdble fo
|
|||
600.0 * fovFactor /* fog */
|
||||
);
|
||||
cam->add(&cams[c]);
|
||||
id++;
|
||||
|
||||
/* cam F2 = behind very near */
|
||||
cam = new cGrCarCamBehind(myscreen,
|
||||
|
@ -1406,7 +1407,6 @@ grCamCreateSceneCameraList(class cGrScreen *myscreen, tGrCamHead *cams, tdble fo
|
|||
25.0 /* relaxation */
|
||||
);
|
||||
cam->add(&cams[c]);
|
||||
id++;
|
||||
|
||||
/* F3 */
|
||||
c++;
|
||||
|
@ -1650,7 +1650,7 @@ grCamCreateSceneCameraList(class cGrScreen *myscreen, tGrCamHead *cams, tdble fo
|
|||
1, /* drawCurr */
|
||||
1, /* drawBG */
|
||||
//12.0, /* fovy */
|
||||
37.5, /* fovy */
|
||||
20.5, /* fovy */
|
||||
1.0, /* fovymin */
|
||||
90.0, /* fovymax */
|
||||
//300.0, /* distz */
|
||||
|
@ -1671,7 +1671,7 @@ grCamCreateSceneCameraList(class cGrScreen *myscreen, tGrCamHead *cams, tdble fo
|
|||
1, /* drawCurr */
|
||||
1, /* drawBG */
|
||||
//12.0, /* fovy */
|
||||
37.5, /* fovy */
|
||||
20.5, /* fovy */
|
||||
1.0, /* fovymin */
|
||||
90.0, /* fovymax */
|
||||
//300.0, /* distz */
|
||||
|
@ -1691,7 +1691,7 @@ grCamCreateSceneCameraList(class cGrScreen *myscreen, tGrCamHead *cams, tdble fo
|
|||
1, /* drawCurr */
|
||||
1, /* drawBG */
|
||||
//12.0, /* fovy */
|
||||
37.5, /* fovy */
|
||||
20.5, /* fovy */
|
||||
1.0, /* fovymin */
|
||||
90.0, /* fovymax */
|
||||
//300.0, /* distz */
|
||||
|
@ -1711,7 +1711,7 @@ grCamCreateSceneCameraList(class cGrScreen *myscreen, tGrCamHead *cams, tdble fo
|
|||
1, /* drawCurr */
|
||||
1, /* drawBG */
|
||||
//12.0, /* fovy */
|
||||
37.5, /* fovy */
|
||||
20.5, /* fovy */
|
||||
1.0, /* fovymin */
|
||||
90.0, /* fovymax */
|
||||
//300.0, /* distz */
|
||||
|
|
|
@ -636,9 +636,9 @@ grInitCar(tCarElt *car)
|
|||
LODSel->addKid(carBody);
|
||||
|
||||
/* 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);
|
||||
sprintf(buf, "drivers/%s/%d;drivers/%s;cars/%s", car->_modName, car->_driverIndex, car->_modName, car->_carName);
|
||||
ssgTexturePath(buf);
|
||||
grTexturePath = strdup(buf);
|
||||
|
||||
|
@ -665,7 +665,6 @@ grInitCar(tCarElt *car)
|
|||
grCarInfo[index].driverSelectorinsg = false;
|
||||
}
|
||||
|
||||
|
||||
DBG_SET_NAME(carEntity, "Body", index, -1);
|
||||
carBody->addKid(carEntity);
|
||||
/* add wheels */
|
||||
|
@ -701,6 +700,44 @@ grInitCar(tCarElt *car)
|
|||
/* default range selection */
|
||||
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 ...
|
||||
sprintf(path, "%s/%s", SECT_GROBJECTS, LST_DRIVER);
|
||||
nranges = GfParmGetEltNb(handle, path) + 1;
|
||||
|
@ -715,11 +752,6 @@ grInitCar(tCarElt *car)
|
|||
grCarInfo[index].DRMSelector = DRMSel = new ssgSelector;
|
||||
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;
|
||||
|
||||
// add the drivers
|
||||
|
@ -750,7 +782,6 @@ grInitCar(tCarElt *car)
|
|||
DRMSel->select( grCarInfo[index].DRMSelectMask[0] );
|
||||
}
|
||||
|
||||
|
||||
CarsAnchor->addKid(grCarInfo[index].carTransform);
|
||||
|
||||
//grCarInfo[index].carTransform->print(stdout, "-", 1);
|
||||
|
@ -843,46 +874,55 @@ grDrawCar(tSituation *s, tCarElt *car, tCarElt *curCar, int dispCarFlag, int dis
|
|||
i++;
|
||||
}
|
||||
grCarInfo[index].LODSelector->select(grCarInfo[index].LODSelectMask[i]);
|
||||
if (dispDrvFlag) {
|
||||
grCarInfo[index].driverSelector->select(1);
|
||||
} else {
|
||||
grCarInfo[index].driverSelector->select(0);
|
||||
}
|
||||
|
||||
// Animated driver model selection according to steering wheel angle
|
||||
if (grCarInfo[index].nDRM > 0 && s->currentTime - grCarInfo[index].lastDRMswitch > 0.2)
|
||||
if (dispDrvFlag || car != curCar)
|
||||
{
|
||||
// choose a driver model to display
|
||||
int curDRM = 0;
|
||||
float curSteer = 0.0f;
|
||||
int lastDRM = grCarInfo[index].DRMSelector->getSelect();
|
||||
|
||||
for (i=0; i<grCarInfo[index].nDRM; i++)
|
||||
{
|
||||
if ((curCar->_steerCmd > 0.0 &&
|
||||
grCarInfo[index].DRMThreshold[i] >= 0.0 &&
|
||||
grCarInfo[index].DRMThreshold[i] <= curCar->_steerCmd &&
|
||||
grCarInfo[index].DRMThreshold[i] >= curSteer) ||
|
||||
(curCar->_steerCmd < 0.0 &&
|
||||
grCarInfo[index].DRMThreshold[i] <= 0.0 &&
|
||||
grCarInfo[index].DRMThreshold[i] >= curCar->_steerCmd &&
|
||||
grCarInfo[index].DRMThreshold[i] <= curSteer))
|
||||
{
|
||||
float fsteer = fabs(curCar->_steerCmd);
|
||||
grCarInfo[index].driverSelector->select(1);
|
||||
|
||||
curDRM = i;
|
||||
curSteer = grCarInfo[index].DRMThreshold[i];
|
||||
// Animated driver model selection according to steering wheel angle
|
||||
if (grCarInfo[index].nDRM > 0 && s->currentTime - grCarInfo[index].lastDRMswitch > 0.1)
|
||||
{
|
||||
// choose a driver model to display
|
||||
int curDRM = 0;
|
||||
float curSteer = 0.0f;
|
||||
int lastDRM = grCarInfo[index].DRMSelector->getSelect();
|
||||
|
||||
for (i=0; i<grCarInfo[index].nDRM; i++)
|
||||
{
|
||||
if ((car->_steerCmd > 0.0 &&
|
||||
grCarInfo[index].DRMThreshold[i] >= 0.0 &&
|
||||
grCarInfo[index].DRMThreshold[i] <= car->_steerCmd &&
|
||||
grCarInfo[index].DRMThreshold[i] >= curSteer) ||
|
||||
(car->_steerCmd < 0.0 &&
|
||||
grCarInfo[index].DRMThreshold[i] <= 0.0 &&
|
||||
grCarInfo[index].DRMThreshold[i] >= car->_steerCmd &&
|
||||
grCarInfo[index].DRMThreshold[i] <= curSteer))
|
||||
{
|
||||
float fsteer = fabs(car->_steerCmd);
|
||||
|
||||
curDRM = i;
|
||||
curSteer = grCarInfo[index].DRMThreshold[i];
|
||||
}
|
||||
}
|
||||
|
||||
grCarInfo[index].DRMSelector->select( grCarInfo[index].DRMSelectMask[curDRM] );
|
||||
if (lastDRM != curDRM)
|
||||
{
|
||||
grCarInfo[index].lastDRMswitch = s->currentTime;
|
||||
}
|
||||
}
|
||||
|
||||
grCarInfo[index].DRMSelector->select( grCarInfo[index].DRMSelectMask[curDRM] );
|
||||
if (lastDRM != curDRM)
|
||||
{
|
||||
grCarInfo[index].lastDRMswitch = s->currentTime;
|
||||
}
|
||||
}
|
||||
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);
|
||||
grCarInfo[index].px=car->_pos_X;
|
||||
|
|
|
@ -45,6 +45,7 @@ typedef struct
|
|||
ssgSelector *LODSelector;
|
||||
ssgSelector *DRMSelector;
|
||||
ssgEntity *carEntity;
|
||||
ssgEntity *steerWheel;
|
||||
int LODSelectMask[32];
|
||||
float LODThreshold[32];
|
||||
int DRMSelectMask[32];
|
||||
|
@ -52,10 +53,12 @@ typedef struct
|
|||
float DRMThreshold[32];
|
||||
float lastDRMswitch;
|
||||
ssgSelector *driverSelector;
|
||||
ssgSelector *steerSelector;
|
||||
bool driverSelectorinsg;
|
||||
ssgStateSelector *envSelector;
|
||||
ssgTransform *wheelPos[4];
|
||||
ssgTransform *wheelRot[4];
|
||||
ssgTransform *steerRot;
|
||||
ssgColourArray *brkColor[4];
|
||||
ssgSelector *wheelselector[4];
|
||||
ssgState *wheelTexture;
|
||||
|
@ -68,6 +71,7 @@ typedef struct
|
|||
tdble distFromStart;
|
||||
tdble envAngle;
|
||||
int fireCount;
|
||||
tdble steerMovt;
|
||||
tdble px;
|
||||
tdble py;
|
||||
tdble sx;
|
||||
|
|
Loading…
Reference in a new issue