From cd67b9d0d64e1fc48baf4159ed4cb7b7bc7bd974 Mon Sep 17 00:00:00 2001 From: madbad Date: Sun, 12 Dec 2021 17:51:29 +0000 Subject: [PATCH] OSGHUD: first implementation of tires temps widget git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@7812 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 82c6bd8480021356ef978ade45e9a94424e2c9e9 Former-commit-id: 20000a55cd0ccf5e87538d0fcbb3e1298bbc7b0c --- .../graphic/osggraph/Viewer/OsgHUD.cpp | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/src/modules/graphic/osggraph/Viewer/OsgHUD.cpp b/src/modules/graphic/osggraph/Viewer/OsgHUD.cpp index 6491e5729..27acaf9af 100644 --- a/src/modules/graphic/osggraph/Viewer/OsgHUD.cpp +++ b/src/modules/graphic/osggraph/Viewer/OsgHUD.cpp @@ -661,6 +661,19 @@ void changeImageSize(osg::Geometry *geom, geom->setTexCoordArray(0,texcoords); } } + +void changeImageAlpha(osg::Geometry *geom, + float newAlpha/*where 1.0 fully visible and 0.0 completely hidden*/ +) +{ + // assign colors + osg::Vec4Array* colors = new osg::Vec4Array(1); + (*colors)[0].set(1.0f,1.0f,1.0f,newAlpha); + geom->setColorArray(colors); + geom->setColorBinding(osg::Geometry::BIND_OVERALL); + +} + // TODO[END]: move this to utils? /src/modules/graphic/osggraph/Utils SDHUD::SDHUD() @@ -1206,11 +1219,104 @@ void SDHUD::Refresh(tSituation *s, const SDFrameInfo* frameInfo, prevSteerAngle = angle; +// tires + + + for (int i = 0; i < 4; i++) { //for each tires + + std::ostringstream tireName; + switch(i) { + case 0: + tireName << "fr-"; + break; + case 1: + tireName << "fl-"; + break; + case 2: + tireName << "rr-"; + break; + case 3: + tireName << "rl-"; + break; + default: + tireName << ""; + } + + for (int h = 0; h < 3; h++) { //for each part of the tire (in-mid-out) + float currentTemp = 0; + std::string tirePartName = ""; + switch(h) { + case 0: + tirePartName = "in"; + currentTemp = currCar->_tyreT_in(i); + break; + case 1: + tirePartName = "mid"; + currentTemp = currCar->_tyreT_mid(i); + break; + case 2: + tirePartName = "out"; + currentTemp = currCar->_tyreT_out(i); + break; + default: + tirePartName = ""; + } + + std::ostringstream tireNameCold; + std::ostringstream tireNameOptimal; + std::ostringstream tireNameHot; + + tireNameCold << "tire-" << tireName.str().c_str() << tirePartName.c_str() << "-cold"; + tireNameOptimal << "tire-" << tireName.str().c_str() << tirePartName.c_str() << "-optimal"; + tireNameHot << "tire-" << tireName.str().c_str() << tirePartName.c_str() << "-hot"; + + float optimalAlpha = 0.0f; + float hotAlpha = 0.0f; + + float tempOptimal = currCar->_tyreT_opt(i); + float tempMaxCold = tempOptimal - ( tempOptimal * 10 / 100 ); //temp at witch we will conside the tire maximun cold + float tempMaxHot = tempOptimal + ( tempOptimal * 10 / 100 ); //temp at witch we will conside the tire maximun hot + + + changeImageAlpha(this->hudImgElements[tireNameCold.str().c_str()], 1.0f); + optimalAlpha = (currentTemp-tempMaxCold) / (tempOptimal-tempMaxCold); + if (optimalAlpha > 1.0f){ + optimalAlpha = 1.0f; + } + if (optimalAlpha < 0.0f){ + optimalAlpha = 0.0f; + } + changeImageAlpha(this->hudImgElements[tireNameOptimal.str().c_str()], optimalAlpha); + + + hotAlpha = (tempMaxHot-currentTemp) / (tempMaxHot-tempOptimal); + if (hotAlpha > 1.0f){ + hotAlpha = 1.0f; + } + if (hotAlpha < 0.0f){ + hotAlpha = 0.0f; + } + + changeImageAlpha(this->hudImgElements[tireNameHot.str().c_str()], 1.0-hotAlpha); + } + //temps string only do this for middle temps? + temp.str(""); + temp << currCar->_tyreT_mid(i); + + std::ostringstream tireNameText; + tireNameText << "tire-" << tireName.str().c_str() << "temps"; + hudTextElements[tireNameText.str().c_str()]->setText(temp.str()); + + } + + + // debug info temp.str(""); temp << "FPS: " << frameInfo->fAvgFps << " (Inst: " << frameInfo->fInstFps << ")"; hudTextElements["debug-info"]->setText(temp.str()); + } void SDHUD::ToggleHUD()