Prevent 'twitching' with glancing controlled by axis
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@4271 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: b2df1af542d925d9f5b1624758cc4c19a6d98a34 Former-commit-id: dcbaf270235dc5e9e17722d8b1209901dd36ff99
This commit is contained in:
parent
51ca0d007f
commit
c98d46013f
3 changed files with 21 additions and 5 deletions
|
@ -548,6 +548,10 @@ newrace(int index, tCarElt* car, tSituation *s)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set up glancing
|
||||||
|
car->_oldglance = 0;
|
||||||
|
car->_glance = 0;
|
||||||
|
|
||||||
//GfOut("SteerCmd : Left : sens=%4.1f, spSens=%4.2f, deadZ=%4.2f\n",
|
//GfOut("SteerCmd : Left : sens=%4.1f, spSens=%4.2f, deadZ=%4.2f\n",
|
||||||
// cmd[CMD_LEFTSTEER].sens, cmd[CMD_LEFTSTEER].spdSens, cmd[CMD_LEFTSTEER].deadZone);
|
// cmd[CMD_LEFTSTEER].sens, cmd[CMD_LEFTSTEER].spdSens, cmd[CMD_LEFTSTEER].deadZone);
|
||||||
//GfOut("SteerCmd : Right: sens=%4.1f, spSens=%4.2f, deadZ=%4.2f\n",
|
//GfOut("SteerCmd : Right: sens=%4.1f, spSens=%4.2f, deadZ=%4.2f\n",
|
||||||
|
@ -936,10 +940,10 @@ common_drive(const int index, tCarElt* car, tSituation *s)
|
||||||
|| (cmd[CMD_RIGHTGLANCE].type == GFCTRL_TYPE_JOY_ATOB && cmd[CMD_RIGHTGLANCE].deadZone != 0))
|
|| (cmd[CMD_RIGHTGLANCE].type == GFCTRL_TYPE_JOY_ATOB && cmd[CMD_RIGHTGLANCE].deadZone != 0))
|
||||||
{
|
{
|
||||||
newGlance = newGlance + GLANCERATE * s->deltaTime;
|
newGlance = newGlance + GLANCERATE * s->deltaTime;
|
||||||
} else if (cmd[CMD_RIGHTGLANCE].type == GFCTRL_TYPE_JOY_AXIS && joyInfo->ax[cmd[CMD_RIGHTGLANCE].val] > 0)
|
} else if (cmd[CMD_RIGHTGLANCE].type == GFCTRL_TYPE_JOY_AXIS && joyInfo->ax[cmd[CMD_RIGHTGLANCE].val] > cmd[CMD_RIGHTGLANCE].min)
|
||||||
{
|
{
|
||||||
newGlance = joyInfo->ax[cmd[CMD_RIGHTGLANCE].val] * 2*PI/3;
|
newGlance = joyInfo->ax[cmd[CMD_RIGHTGLANCE].val] * 2*PI/3;
|
||||||
} else if (cmd[CMD_LEFTGLANCE].type == GFCTRL_TYPE_JOY_AXIS && joyInfo->ax[cmd[CMD_LEFTGLANCE].val] < 0)
|
} else if (cmd[CMD_LEFTGLANCE].type == GFCTRL_TYPE_JOY_AXIS && joyInfo->ax[cmd[CMD_LEFTGLANCE].val] < cmd[CMD_LEFTGLANCE].max)
|
||||||
{
|
{
|
||||||
newGlance = joyInfo->ax[cmd[CMD_LEFTGLANCE].val] * 2*PI/3;
|
newGlance = joyInfo->ax[cmd[CMD_LEFTGLANCE].val] * 2*PI/3;
|
||||||
} else {
|
} else {
|
||||||
|
@ -958,7 +962,17 @@ common_drive(const int index, tCarElt* car, tSituation *s)
|
||||||
if (newGlance > 2*PI/3) newGlance=2*PI/3;
|
if (newGlance > 2*PI/3) newGlance=2*PI/3;
|
||||||
if (newGlance < -2*PI/3) newGlance=-2*PI/3;
|
if (newGlance < -2*PI/3) newGlance=-2*PI/3;
|
||||||
|
|
||||||
|
// Limit twitching between values
|
||||||
|
if (newGlance != 0) {
|
||||||
|
if (newGlance != car->_oldglance) {
|
||||||
|
car->_oldglance = car->_glance;
|
||||||
car->_glance = newGlance;
|
car->_glance = newGlance;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
car->_oldglance = 0;
|
||||||
|
car->_glance = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
switch (cmd[CMD_BRAKE].type) {
|
switch (cmd[CMD_BRAKE].type) {
|
||||||
case GFCTRL_TYPE_JOY_AXIS:
|
case GFCTRL_TYPE_JOY_AXIS:
|
||||||
|
|
|
@ -254,6 +254,7 @@ typedef struct {
|
||||||
#define RM_CAR_STATE_SIMU_NO_MOVE 0x00010000 /**< Simulation without car move (i.e. clutch applied and no wheel move) */
|
#define RM_CAR_STATE_SIMU_NO_MOVE 0x00010000 /**< Simulation without car move (i.e. clutch applied and no wheel move) */
|
||||||
tPosd corner[4];
|
tPosd corner[4];
|
||||||
tdble glance; /* Glance angle degrees, left -ve, right +ve */
|
tdble glance; /* Glance angle degrees, left -ve, right +ve */
|
||||||
|
tdble oldglance;
|
||||||
} tPublicCar;
|
} tPublicCar;
|
||||||
/* structure access */
|
/* structure access */
|
||||||
#define _DynGC pub.DynGC
|
#define _DynGC pub.DynGC
|
||||||
|
@ -279,6 +280,7 @@ typedef struct {
|
||||||
#define _corner_y(i) pub.corner[i].ay
|
#define _corner_y(i) pub.corner[i].ay
|
||||||
#define _posMat pub.posMat
|
#define _posMat pub.posMat
|
||||||
#define _glance pub.glance
|
#define _glance pub.glance
|
||||||
|
#define _oldglance pub.oldglance
|
||||||
|
|
||||||
/** Dynamic wheel information */
|
/** Dynamic wheel information */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
|
@ -71,8 +71,8 @@ static tCmdInfo Cmd[] = {
|
||||||
{HM_ATT_EBRAKE_CMD, {-1, GFCTRL_TYPE_NOT_AFFECTED}, 0, 0, HM_ATT_EBRAKE_MIN, 0, HM_ATT_EBRAKE_MAX, 0, 0, 0, 1, HM_ATT_JOY_REQ_BUT, 0},
|
{HM_ATT_EBRAKE_CMD, {-1, GFCTRL_TYPE_NOT_AFFECTED}, 0, 0, HM_ATT_EBRAKE_MIN, 0, HM_ATT_EBRAKE_MAX, 0, 0, 0, 1, HM_ATT_JOY_REQ_BUT, 0},
|
||||||
{HM_ATT_HBOX_X, {-1, GFCTRL_TYPE_NOT_AFFECTED}, 0, 0, HM_ATT_HBOX_X_MIN, -1, HM_ATT_HBOX_X_MAX, 1, 0, 0, 1, HM_ATT_JOY_REQ_AXIS, 0},
|
{HM_ATT_HBOX_X, {-1, GFCTRL_TYPE_NOT_AFFECTED}, 0, 0, HM_ATT_HBOX_X_MIN, -1, HM_ATT_HBOX_X_MAX, 1, 0, 0, 1, HM_ATT_JOY_REQ_AXIS, 0},
|
||||||
{HM_ATT_HBOX_Y, {-1, GFCTRL_TYPE_NOT_AFFECTED}, 0, 0, HM_ATT_HBOX_Y_MIN, -1, HM_ATT_HBOX_Y_MAX, 1, 0, 0, 1, HM_ATT_JOY_REQ_AXIS, 0},
|
{HM_ATT_HBOX_Y, {-1, GFCTRL_TYPE_NOT_AFFECTED}, 0, 0, HM_ATT_HBOX_Y_MIN, -1, HM_ATT_HBOX_Y_MAX, 1, 0, 0, 1, HM_ATT_JOY_REQ_AXIS, 0},
|
||||||
{HM_ATT_LEFTGLANCE, {-1, GFCTRL_TYPE_NOT_AFFECTED}, 0, 0, HM_ATT_L_GLANCE_MIN, 0, HM_ATT_L_GLANCE_MAX, 0, 0, 0, 1, HM_ATT_JOY_PREF_ANY, 0},
|
{HM_ATT_LEFTGLANCE, {-1, GFCTRL_TYPE_NOT_AFFECTED}, 0, 0, HM_ATT_L_GLANCE_MIN, -1, HM_ATT_L_GLANCE_MAX,-0.1, 0, 0, 1, HM_ATT_JOY_PREF_ANY, 0},
|
||||||
{HM_ATT_RIGHTGLANCE,{-1, GFCTRL_TYPE_NOT_AFFECTED}, 0, 0, HM_ATT_R_GLANCE_MIN, 0, HM_ATT_R_GLANCE_MAX, 0, 0, 0, 1, HM_ATT_JOY_PREF_ANY, 0}
|
{HM_ATT_RIGHTGLANCE,{-1, GFCTRL_TYPE_NOT_AFFECTED}, 0, 0, HM_ATT_R_GLANCE_MIN, 0.1, HM_ATT_R_GLANCE_MAX, 1, 0, 0, 1, HM_ATT_JOY_PREF_ANY, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
static const int MaxCmd = sizeof(Cmd) / sizeof(Cmd[0]);
|
static const int MaxCmd = sizeof(Cmd) / sizeof(Cmd[0]);
|
||||||
|
|
Loading…
Reference in a new issue