From 8d610787a2054ec18b4a745e391abdeef6070261 Mon Sep 17 00:00:00 2001 From: yourarcade Date: Sun, 25 Sep 2016 17:48:27 -0700 Subject: [PATCH] Fix push/pop mismatch bug;add code to properly rotate, translate and render needle. --- Engine/source/T3D/vehicles/guiSpeedometer.cpp | 47 ++++++++++--------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/Engine/source/T3D/vehicles/guiSpeedometer.cpp b/Engine/source/T3D/vehicles/guiSpeedometer.cpp index 79f3f8bdb..b43f65951 100644 --- a/Engine/source/T3D/vehicles/guiSpeedometer.cpp +++ b/Engine/source/T3D/vehicles/guiSpeedometer.cpp @@ -19,11 +19,11 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. //----------------------------------------------------------------------------- - #include "gui/controls/guiBitmapCtrl.h" #include "console/consoleTypes.h" #include "T3D/gameBase/gameConnection.h" #include "T3D/vehicles/vehicle.h" +#include "T3D/player.h" #include "gfx/primBuilder.h" //----------------------------------------------------------------------------- @@ -173,23 +173,31 @@ void GuiSpeedometerHud::onRender(Point2I offset, const RectI &updateRect) if (mSpeed > mMaxSpeed) mSpeed = mMaxSpeed; - // Render the needle - GFX->pushWorldMatrix(); + // Calculate center point if necessary and roll in offsets Point2F center = mCenter; if (mIsZero(center.x) && mIsZero(center.y)) { center.x = getExtent().x / 2.0f; center.y = getExtent().y / 2.0f; } - MatrixF newMat(1); + F32 fillOffset = GFX->getFillConventionOffset(); // Find the fill offset + Point2F viewCenter(offset.x + fillOffset + center.x, offset.y + fillOffset + center.y); - newMat.setPosition(Point3F(getLeft() + center.x, getTop() + center.y, 0.0f)); - - F32 rotation = mMinAngle + (mMaxAngle - mMinAngle) * (mSpeed / mMaxSpeed); - AngAxisF newRot(Point3F(0.0f,0.0f,-1.0f), rotation); - - newRot.setMatrix(&newMat); + // Handle rotation calculations + F32 rotation, spinAngle; + rotation = mMinAngle + (mMaxAngle - mMinAngle) * (mSpeed / mMaxSpeed); + spinAngle = mDegToRad(rotation); + MatrixF rotMatrix(EulerF(0.0, 0.0, spinAngle)); + // Set up the needle vertex list + Point3F vertList[5]; + vertList[0].set(+mNeedleLength,-mNeedleWidth,0); + vertList[1].set(+mNeedleLength,+mNeedleWidth,0); + vertList[2].set(-mTailLength ,+mNeedleWidth,0); + vertList[3].set(-mTailLength ,-mNeedleWidth,0); + vertList[4].set(+mNeedleLength,-mNeedleWidth,0); //// Get back to the start! + + // Create a GFXStateBlock description if one has not been set. if (mBlendSB.isNull()) { GFXStateBlockDesc desc; @@ -198,22 +206,15 @@ void GuiSpeedometerHud::onRender(Point2I offset, const RectI &updateRect) desc.samplers[0].textureColorOp = GFXTOPDisable; mBlendSB = GFX->createStateBlock(desc); } - GFX->setStateBlock(mBlendSB); - GFX->setTexture(0, NULL); - PrimBuild::begin(GFXLineStrip, 5); + // Render the needle PrimBuild::color4f(mColor.red, mColor.green, mColor.blue, mColor.alpha); - - PrimBuild::vertex2f(+mNeedleLength,-mNeedleWidth); - PrimBuild::vertex2f(+mNeedleLength,+mNeedleWidth); - PrimBuild::vertex2f(-mTailLength ,+mNeedleWidth); - PrimBuild::vertex2f(-mTailLength ,-mNeedleWidth); - - //// Get back to the start! - PrimBuild::vertex2f(+mNeedleLength,-mNeedleWidth); - + PrimBuild::begin(GFXLineStrip, 5); + for(int k=0; k<5; k++){ + rotMatrix.mulP(vertList[k]); + PrimBuild::vertex2f(vertList[k].x + viewCenter.x, vertList[k].y + viewCenter.y); + } PrimBuild::end(); } -