Force Feedback:

* return zero force for autocenterEffect if speed is really low to prevent wheel going crazy while standing still due big forces returned by the physic engine
* implement basic engineRevvingEffect
* implement basic lowSpeedCostantForceEffect
* update config menu

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@6452 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: 2ae4a743476b3dfaceb342aad8c2332d016e62fb
Former-commit-id: 4df3cbd7a9c118fab9367bbb2cc8c65bea7a1d7e
This commit is contained in:
madbad 2016-07-11 18:50:39 +00:00
parent f4c4fc6bf5
commit 3ef5dd8328
3 changed files with 93 additions and 2 deletions

View file

@ -31,6 +31,9 @@ bool timeLogged = false;
clock_t effectStart = std::clock();
clock_t effectCurTime = std::clock();
float prevSteerCmd;
float prevSteerCmdDiff;
int prevDirection = 1;
int filterPositiveNumbers (int number){
if (number > 0){
@ -185,6 +188,8 @@ void ForceFeedbackManager::saveConfiguration(){
}
int ForceFeedbackManager::updateForce(tCarElt* car, tSituation *s){
this->force = 0;
//calculate autocenter if enabled
if (this->effectsConfig["autocenterEffect"]["enabled"]){
this->force = this->autocenterEffect(car, s);
@ -196,6 +201,12 @@ int ForceFeedbackManager::updateForce(tCarElt* car, tSituation *s){
this->force += this->engineRevvingEffect(car, s);
GfLogInfo("After engineRevving: (%i)\n", this->force);
}
//calculate engine revving if enabled
//if (this->effectsConfig["engineRevvingEffect"]["enabled"]){
this->force += this->lowSpeedCostantForceEffect(car, s);
// GfLogInfo("After engineRevving: (%i)\n", this->force);
//}
//calculate bump
//this->force += this->bumpsEffect(car, s);
@ -209,6 +220,8 @@ int ForceFeedbackManager::updateForce(tCarElt* car, tSituation *s){
if(this->effectsConfig["globalEffect"]["reverse"] == 1){
this->force = -1 * this->force;
}
GfLogInfo("Final force: (%i)\n", this->force);
return this->force;
@ -216,6 +229,10 @@ int ForceFeedbackManager::updateForce(tCarElt* car, tSituation *s){
int ForceFeedbackManager::autocenterEffect(tCarElt* car, tSituation *s){
if(car->_speed_xy < 4){
return 0;
}
/*
* car->steerLock
* */
@ -385,6 +402,73 @@ int ForceFeedbackManager::engineRevvingEffect(tCarElt* car, tSituation *s){
return effectForce;
}
int ForceFeedbackManager::lowSpeedCostantForceEffect(tCarElt* car, tSituation *s){
int effectForce;
int sign;
//we need to store the sign of the force
sign = ((car->_steerTqCenter - prevSteerCmd) > 0) - ((car->_steerTqCenter - prevSteerCmd) < 0);
GfLogInfo("test: (%f)\n", car->_steerTqCenter);
GfLogInfo("test: (%f)\n", prevSteerCmd );
int prevDirectionSign = (prevDirection > 0) - (prevDirection < 0);
GfLogInfo("Sign: (%d)\n", sign);
GfLogInfo("Direction sign: (%d)\n", prevDirectionSign);
/*
if(prevDirectionSign == sign || sign == 0){
prevDirection = prevDirection + sign;
}else{
prevDirection = sign;
}
*/
prevDirection = prevDirection + sign;
if (prevDirection > 7) prevDirection =7;
if (prevDirection < -7) prevDirection =-7;
GfLogInfo("Direction score: (%d)\n", prevDirection);
//force calculation
if (car->_speed_xy < this->effectsConfig["lowSpeedCostantForceEffect"]["maxSpeedAtWithcForceIsApplied"]
// && abs(prevDirection) > 8
){
effectForce =
this->effectsConfig["lowSpeedCostantForceEffect"]["maxForce"] / 8 * abs(prevDirection) /
//(car->_speed_xy + 1) *
(pow(car->_speed_xy, (float) 1/2) + 1) *
//sign;
prevDirectionSign;
}else{
effectForce = 1;
}
prevSteerCmdDiff = car->_steerTqCenter - prevSteerCmd;
prevSteerCmd = car->_steerTqCenter;
GfLogInfo("SPEED: (%i)\n", (int)car->_speed_xy);
GfLogInfo("Efect: (%i)\n", effectForce);
return effectForce;
}
//initialize the force feedback
TGFCLIENT_API ForceFeedbackManager forceFeedback;

View file

@ -85,6 +85,7 @@ class TGFCLIENT_API ForceFeedbackManager {
int autocenterEffect(tCarElt* car, tSituation *s);
int engineRevvingEffect(tCarElt* car, tSituation *s);
int bumpsEffect(tCarElt* car, tSituation *s);
int lowSpeedCostantForceEffect(tCarElt* car, tSituation *s);
int globalMultiplier;
};

View file

@ -93,7 +93,10 @@ onSaveForceFeedbackConfig(void * /* dummy */)
GfLogInfo("%s%s.\n", editbox->effectTypeName.c_str(), editbox->effectParameterName.c_str());
if (editbox->effectParameterName.compare("enabled") == 0){
if (
editbox->effectParameterName.compare("enabled") == 0
|| editbox->effectParameterName.compare("reverse") == 0
){
forceFeedback.effectsConfig[editbox->effectTypeName.c_str()][editbox->effectParameterName.c_str()] =
(int)GfuiCheckboxIsChecked(ScrHandle, (int)editbox->id);
@ -186,7 +189,10 @@ ForceFeedbackMenuInit(void *prevMenu, void *nextMenu, int curPlayerIdx, std::str
GfLogInfo("Exist: %s\n", editBoxName.c_str());
//if (iterator2->first.c_str() == "enabled"){
if (iterator2->first.compare("enabled") == 0){
if (
iterator2->first.compare("enabled") == 0
|| iterator2->first.compare("reverse") == 0
){
int checkboxId =
GfuiMenuCreateCheckboxControl(ScrHandle, menuXMLDescHdle, editBoxName.c_str(),