Force Feedback: Switch to SDL_HAPTIC_CARTESIAN instead of SDL_HAPTIC_POLAR
for force feedback effects git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@6426 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 471b2949f757c0da856485f44703a737fe7b5dc3 Former-commit-id: cf6419e1b870fd3687ad91c3f7de0326cf17e0f3
This commit is contained in:
parent
80e56de5ab
commit
07f6833add
4 changed files with 46 additions and 25 deletions
|
@ -1178,15 +1178,21 @@ static void common_drive(const int index, tCarElt* car, tSituation *s)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
force = forceFeedback.updateForce(car, s);
|
force = forceFeedback.updateForce(car, s);
|
||||||
|
//force = force * 32767;
|
||||||
/* Force feedback hack
|
/* Force feedback hack
|
||||||
float multiplier = 4;
|
float multiplier = 4;
|
||||||
force = (force + (car->_steerTq*multiplier)) / 2; //make the force smoother
|
force = (force + (car->_steerTq*multiplier)) / 2; //make the force smoother
|
||||||
*/
|
*/
|
||||||
// if force is below 0 we turn anticlock-wise
|
// if force is below 0 we turn anticlock-wise
|
||||||
// if force is over 0 we turn clock-wise
|
// if force is over 0 we turn clock-wise
|
||||||
gfctrlJoyConstantForce(int((cmd[CMD_LEFTSTEER].val) / GFCTRL_JOY_NUMBER), abs((int)force), force < 0 ? 9000 : 27000 );
|
// gfctrlJoyConstantForce(int((cmd[CMD_LEFTSTEER].val) / GFCTRL_JOY_NUMBER), abs((int)force), force < 0 ? 9000 : 27000 );
|
||||||
//gfctrlJoyRumble(int((cmd[CMD_LEFTSTEER].val) / GFCTRL_JOY_NUMBER), 0.9);
|
//gfctrlJoyRumble(int((cmd[CMD_LEFTSTEER].val) / GFCTRL_JOY_NUMBER), 0.9);
|
||||||
|
// if (force > 32760) force = 32760;
|
||||||
|
// if (force < -32760) force = -32760;
|
||||||
|
|
||||||
|
//gfctrlJoyConstantForce(int((cmd[CMD_LEFTSTEER].val) / GFCTRL_JOY_NUMBER), 10000, 10000);
|
||||||
|
|
||||||
|
gfctrlJoyConstantForce(int((cmd[CMD_LEFTSTEER].val) / GFCTRL_JOY_NUMBER), ((int)force), 0 );
|
||||||
|
|
||||||
#define GLANCERATE 3 // speed at which the driver turns his head, ~1/3s to full glance
|
#define GLANCERATE 3 // speed at which the driver turns his head, ~1/3s to full glance
|
||||||
newGlance = car->_glance;
|
newGlance = car->_glance;
|
||||||
|
|
|
@ -313,6 +313,11 @@ gfctrlJoyInit(void)
|
||||||
#if SDL_MAJOR_VERSION >= 2
|
#if SDL_MAJOR_VERSION >= 2
|
||||||
memset(&cfx, 0, sizeof(cfx));
|
memset(&cfx, 0, sizeof(cfx));
|
||||||
|
|
||||||
|
for(int i = 0;i<GFCTRL_JOY_NUMBER;i++)
|
||||||
|
{
|
||||||
|
id[i] = -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC) < 0) {
|
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC) < 0) {
|
||||||
#else
|
#else
|
||||||
if (SDL_Init(SDL_INIT_JOYSTICK) < 0) {
|
if (SDL_Init(SDL_INIT_JOYSTICK) < 0) {
|
||||||
|
@ -350,7 +355,7 @@ gfctrlJoyInit(void)
|
||||||
#if 1
|
#if 1
|
||||||
} else {
|
} else {
|
||||||
// add an CF effect on startup
|
// add an CF effect on startup
|
||||||
gfctrlJoyConstantForce(index, 50000, 9000);
|
gfctrlJoyConstantForce(index, 0, 0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -371,33 +376,43 @@ gfctrlJoyInit(void)
|
||||||
|
|
||||||
#if SDL_JOYSTICK
|
#if SDL_JOYSTICK
|
||||||
void
|
void
|
||||||
gfctrlJoyConstantForce(int index, unsigned int level, int dir)
|
gfctrlJoyConstantForce(int index, int level, int dir)
|
||||||
{
|
{
|
||||||
#if SDL_MAJOR_VERSION >= 2
|
#if SDL_MAJOR_VERSION >= 2
|
||||||
if (!Haptics[index]) return;
|
if (!Haptics[index]) return;
|
||||||
|
|
||||||
if ((SDL_HapticQuery(Haptics[index]) & SDL_HAPTIC_CONSTANT) == 0) return;
|
if ((SDL_HapticQuery(Haptics[index]) & SDL_HAPTIC_CONSTANT) == 0) return;
|
||||||
|
printf("level = %d \r\n",level);
|
||||||
|
if(-1 == id[index])
|
||||||
|
{
|
||||||
cfx[index].type = SDL_HAPTIC_CONSTANT;
|
cfx[index].type = SDL_HAPTIC_CONSTANT;
|
||||||
cfx[index].constant.direction.type = SDL_HAPTIC_POLAR; // Polar coordinates
|
//cfx[index].constant.direction.type = SDL_HAPTIC_POLAR; // Polar coordinates
|
||||||
cfx[index].constant.direction.dir[0] = dir; // direction of the force
|
//cfx[index].constant.direction.dir[0] = dir; // direction of the force
|
||||||
cfx[index].constant.length = 1000; //how log is the effect
|
cfx[index].constant.direction.type = SDL_HAPTIC_CARTESIAN;
|
||||||
|
cfx[index].constant.direction.dir[0] = 1;
|
||||||
|
cfx[index].constant.length = 1000;
|
||||||
cfx[index].constant.level = level; // strength: minimum 0 maximum 32767
|
cfx[index].constant.level = level; // strength: minimum 0 maximum 32767
|
||||||
cfx[index].constant.attack_length = 0; // Takes 0 second (instantly) to get max strength
|
cfx[index].constant.attack_length = 0; // Takes 0 second (instantly) to get max strength
|
||||||
cfx[index].constant.fade_length = 1000; // Takes 1 second to fade away
|
cfx[index].constant.fade_length = 0; // Takes 0 second to fade away
|
||||||
|
//cfx_timeout[index] = SDL_GetTicks() + cfx[index].constant.length;
|
||||||
#if __WIN32__
|
|
||||||
if (SDL_HapticGetEffectStatus(Haptics[index], id[index]) == SDL_TRUE)
|
|
||||||
#else
|
|
||||||
// Linux SDL doesn't support checking status at the moment :-(
|
|
||||||
if (cfx_timeout[index] > SDL_GetTicks())
|
|
||||||
#endif
|
|
||||||
SDL_HapticUpdateEffect(Haptics[index], id[index], &cfx[index]);
|
|
||||||
else {
|
|
||||||
SDL_HapticDestroyEffect(Haptics[index], id[index]);
|
|
||||||
id[index] = SDL_HapticNewEffect(Haptics[index], &cfx[index]);
|
id[index] = SDL_HapticNewEffect(Haptics[index], &cfx[index]);
|
||||||
SDL_HapticRunEffect(Haptics[index], id[index], 1);
|
SDL_HapticRunEffect(Haptics[index], id[index], SDL_HAPTIC_INFINITY);
|
||||||
}
|
}
|
||||||
|
cfx[index].constant.length = 1000; //how log is the effect
|
||||||
|
cfx[index].constant.level = level;
|
||||||
|
|
||||||
|
//#if __WIN32__
|
||||||
|
// if (SDL_HapticGetEffectStatus(Haptics[index], id[index]) == SDL_TRUE)
|
||||||
|
//#else
|
||||||
|
// // Linux SDL doesn't support checking status at the moment :-(
|
||||||
|
// if (cfx_timeout[index] > SDL_GetTicks())
|
||||||
|
//#endif
|
||||||
|
SDL_HapticUpdateEffect(Haptics[index], id[index], &cfx[index]);
|
||||||
|
// else {
|
||||||
|
// SDL_HapticDestroyEffect(Haptics[index], id[index]);
|
||||||
|
// id[index] = SDL_HapticNewEffect(Haptics[index], &cfx[index]);
|
||||||
|
// SDL_HapticRunEffect(Haptics[index], id[index], 1);
|
||||||
|
// }
|
||||||
|
|
||||||
cfx_timeout[index] = SDL_GetTicks() + cfx[index].constant.length;
|
cfx_timeout[index] = SDL_GetTicks() + cfx[index].constant.length;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -220,7 +220,7 @@ int ForceFeedbackManager::autocenterEffect(tCarElt* car, tSituation *s){
|
||||||
int sign;
|
int sign;
|
||||||
|
|
||||||
//force acting on the front wheels
|
//force acting on the front wheels
|
||||||
effectForce = -1 * car->_steerTqAlign * this->effectsConfig["autocenterEffect"]["frontwheelsmultiplier"] / 1000;
|
effectForce = car->_steerTqAlign * this->effectsConfig["autocenterEffect"]["frontwheelsmultiplier"] / 1000;
|
||||||
|
|
||||||
//force action on the back wheels
|
//force action on the back wheels
|
||||||
effectForce += car->_wheelFy(REAR_RGT) * this->effectsConfig["autocenterEffect"]["rearwheelsmultiplier"] / 1000 ;
|
effectForce += car->_wheelFy(REAR_RGT) * this->effectsConfig["autocenterEffect"]["rearwheelsmultiplier"] / 1000 ;
|
||||||
|
@ -239,7 +239,7 @@ int ForceFeedbackManager::autocenterEffect(tCarElt* car, tSituation *s){
|
||||||
//be sure this is a positive number
|
//be sure this is a positive number
|
||||||
effectForce = effectForce * sign;
|
effectForce = effectForce * sign;
|
||||||
|
|
||||||
// effectForce = (int)((pow((double) effectForce, (double) 1/2) * 120) * sign);
|
effectForce = (int)((pow((double) effectForce, (double) 1/2) * 120) * sign);
|
||||||
|
|
||||||
return effectForce;
|
return effectForce;
|
||||||
|
|
||||||
|
|
|
@ -699,7 +699,7 @@ TGFCLIENT_API tCtrlJoyInfo* GfctrlJoyCreate(void);
|
||||||
TGFCLIENT_API void GfctrlJoyRelease(tCtrlJoyInfo* joyInfo);
|
TGFCLIENT_API void GfctrlJoyRelease(tCtrlJoyInfo* joyInfo);
|
||||||
TGFCLIENT_API int GfctrlJoyGetCurrentStates(tCtrlJoyInfo* joyInfo);
|
TGFCLIENT_API int GfctrlJoyGetCurrentStates(tCtrlJoyInfo* joyInfo);
|
||||||
#if SDL_JOYSTICK
|
#if SDL_JOYSTICK
|
||||||
TGFCLIENT_API void gfctrlJoyConstantForce(int index, unsigned int level, int dir);
|
TGFCLIENT_API void gfctrlJoyConstantForce(int index, int level, int dir);
|
||||||
TGFCLIENT_API void gfctrlJoyRumble(int index, float level);
|
TGFCLIENT_API void gfctrlJoyRumble(int index, float level);
|
||||||
TGFCLIENT_API void GfctrlJoySetAxis(int joy, int axis, float value);
|
TGFCLIENT_API void GfctrlJoySetAxis(int joy, int axis, float value);
|
||||||
TGFCLIENT_API void GfctrlJoySetButton(int joy, int button, int value);
|
TGFCLIENT_API void GfctrlJoySetButton(int joy, int button, int value);
|
||||||
|
|
Loading…
Reference in a new issue