Force Feedback: add initial implementation of engineRevvingEffect.
also only play effects if enabled in configuration. git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@6451 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 11ce0b30c415667dc0bdeab1ffbdd9a8fcbe117c Former-commit-id: 358f47662782b446c962b42193e28d9bea77d9a6
This commit is contained in:
parent
c22d277782
commit
f4c4fc6bf5
2 changed files with 61 additions and 4 deletions
|
@ -27,6 +27,11 @@
|
|||
#include "tgfclient.h"
|
||||
#include "forcefeedback.h"
|
||||
|
||||
bool timeLogged = false;
|
||||
clock_t effectStart = std::clock();
|
||||
clock_t effectCurTime = std::clock();
|
||||
|
||||
|
||||
int filterPositiveNumbers (int number){
|
||||
if (number > 0){
|
||||
return number;
|
||||
|
@ -180,10 +185,18 @@ void ForceFeedbackManager::saveConfiguration(){
|
|||
}
|
||||
int ForceFeedbackManager::updateForce(tCarElt* car, tSituation *s){
|
||||
|
||||
//calculate autocenter
|
||||
this->force = this->autocenterEffect(car, s);
|
||||
GfLogInfo("After autocenter: (%i)\n", this->force);
|
||||
|
||||
//calculate autocenter if enabled
|
||||
if (this->effectsConfig["autocenterEffect"]["enabled"]){
|
||||
this->force = this->autocenterEffect(car, s);
|
||||
GfLogInfo("After autocenter: (%i)\n", this->force);
|
||||
}
|
||||
|
||||
//calculate engine revving if enabled
|
||||
if (this->effectsConfig["engineRevvingEffect"]["enabled"]){
|
||||
this->force += this->engineRevvingEffect(car, s);
|
||||
GfLogInfo("After engineRevving: (%i)\n", this->force);
|
||||
}
|
||||
|
||||
//calculate bump
|
||||
//this->force += this->bumpsEffect(car, s);
|
||||
//GfLogInfo("After bump: (%i)\n", this->force);
|
||||
|
@ -329,6 +342,49 @@ int ForceFeedbackManager::bumpsEffect(tCarElt* car, tSituation *s){
|
|||
*/
|
||||
return effectForce;
|
||||
|
||||
}
|
||||
|
||||
int ForceFeedbackManager::engineRevvingEffect(tCarElt* car, tSituation *s){
|
||||
|
||||
int effectForce;
|
||||
double changeTimeInterval = 20;
|
||||
|
||||
if(timeLogged != true){
|
||||
effectStart = std::clock();
|
||||
timeLogged = true;
|
||||
GfLogInfo("StartTime: (%f)\n",(double)effectStart);
|
||||
GfLogInfo("###############new time\n");
|
||||
GfLogInfo("StartTime: (%f)\n",(double)effectStart);
|
||||
|
||||
}
|
||||
effectCurTime = std::clock();
|
||||
|
||||
double timeDiff = (((double)effectCurTime - (double)effectStart )) / CLOCKS_PER_SEC * 1000;
|
||||
|
||||
GfLogInfo("CurTime: (%f)\n", (double)effectCurTime);
|
||||
GfLogInfo("StartTime: (%f)\n",(double)effectStart);
|
||||
GfLogInfo("TimeDiff: (%f)\n", timeDiff);
|
||||
|
||||
if (timeDiff > 40){
|
||||
if( this->effectsConfig["engineRevvingEffect"]["previousSign"] > 0 ){
|
||||
this->effectsConfig["engineRevvingEffect"]["previousSign"] = -1;
|
||||
}else{
|
||||
this->effectsConfig["engineRevvingEffect"]["previousSign"] = 1;
|
||||
}
|
||||
|
||||
effectStart = std::clock();
|
||||
}
|
||||
|
||||
GfLogInfo("Sign: (%i)\n", this->effectsConfig["engineRevvingEffect"]["previousSign"]);
|
||||
|
||||
//force acting on the front wheels
|
||||
effectForce = 50000 / (int)car->_enginerpm * 2 * this->effectsConfig["engineRevvingEffect"]["previousSign"];
|
||||
|
||||
GfLogInfo("RPM: (%i)\n", (int)car->_enginerpm);
|
||||
GfLogInfo("Efect: (%i)\n", effectForce);
|
||||
|
||||
return effectForce;
|
||||
|
||||
}
|
||||
//initialize the force feedback
|
||||
TGFCLIENT_API ForceFeedbackManager forceFeedback;
|
||||
|
|
|
@ -83,6 +83,7 @@ class TGFCLIENT_API ForceFeedbackManager {
|
|||
std::clock_t animationRestStartTime; //when the animation started
|
||||
|
||||
int autocenterEffect(tCarElt* car, tSituation *s);
|
||||
int engineRevvingEffect(tCarElt* car, tSituation *s);
|
||||
int bumpsEffect(tCarElt* car, tSituation *s);
|
||||
int globalMultiplier;
|
||||
|
||||
|
|
Loading…
Reference in a new issue