Skip to content

Commit

Permalink
new gearbox
Browse files Browse the repository at this point in the history
  • Loading branch information
chrystianfarias committed Jan 16, 2022
1 parent 20fa7e5 commit 31a4f59
Show file tree
Hide file tree
Showing 3 changed files with 215 additions and 95 deletions.
73 changes: 55 additions & 18 deletions GTAFmod/Curve.cpp
Original file line number Diff line number Diff line change
@@ -1,31 +1,68 @@
#include "Curve.h"
#include "RenderWare.h"
#include "CHud.h"

#define MAX_RPM 8000
#define MAX_TORQUE 200
#define POINTS 5

float Curve::Evaluate(float x)
{
int arrSize = 4;
float total = 0;
int arrSize = 3;
float y = 0;

for (int i = 0; i < arrSize; ++i)
{
float totalTop = 0;
float totalButton = 0;
float p = 1;
for (int j = 0; j < arrSize; ++j)
{
if (i != j)
if (i == j)
{
if (i == 0)
{
totalTop = (x - points[j].y);
totalButton = (points[i].y - points[j].y);
}
else
{
totalTop *= (x - points[j].y);
totalButton *= (points[i].y - points[j].y);
}
continue;
}

p *= (x - points[j].x) / (points[i].x - points[j].x);
}
total += points[i].x * (totalTop / totalButton);
y += points[i].y * p;
}
return y;
}
/*
void Curve::Draw(CRect rect, float lineWidth)
{
//Quad
Setup2dVertex(lineQuadVerts[0], rect.left, rect.top, RWRGBALONG(255, 255, 255, 255));
Setup2dVertex(lineQuadVerts[1], rect.left + lineWidth, rect.top, RWRGBALONG(255, 255, 255, 255));
Setup2dVertex(lineQuadVerts[2], rect.left, rect.top + rect.bottom, RWRGBALONG(255, 255, 255, 255));
Setup2dVertex(lineQuadVerts[3], rect.left + lineWidth, rect.top + rect.bottom, RWRGBALONG(255, 255, 255, 255));
Setup2dVertex(lineQuadVerts[4], rect.left + rect.right + lineWidth, rect.top + rect.bottom + lineWidth, RWRGBALONG(255, 255, 255, 255));
Setup2dVertex(lineQuadVerts[5], rect.left + rect.right, rect.top + rect.bottom, RWRGBALONG(255, 255, 255, 255));
//Curve
for (int i = 0; i < POINTS; ++i)
{
float lerp = i / POINTS * MAX_RPM;
RwIm2DVertex lineVerts[4];
float torque = Evaluate(i);
int x = rect.left + (lerp * rect.right);
int y = rect.top + ((torque / MAX_TORQUE) * rect.bottom) + rect.top;
Setup2dVertex(lineVerts[0], x, y, RWRGBALONG(255, 0, 0, 255));
Setup2dVertex(lineVerts[2], x, y + lineWidth, RWRGBALONG(255, 0, 0, 255));
Setup2dVertex(lineVerts[3], x + lineWidth, y + lineWidth, RWRGBALONG(255, 0, 0, 255));
Setup2dVertex(lineVerts[1], x + lineWidth, y, RWRGBALONG(255, 0, 0, 255));
}
}
void Curve::Render()
{
RwIm2DRenderPrimitive(rwPRIMTYPETRISTRIP, lineQuadVerts, 6);
for (int i = 0; i < POINTS; ++i)
{
RwIm2DRenderPrimitive(rwPRIMTYPETRISTRIP, &lineVerts[i], 4);
}
return total;
}
}*/
30 changes: 29 additions & 1 deletion GTAFmod/Curve.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,42 @@
#pragma once
#include "plugin.h"
#include "RenderWare.h"
#include "CHud.h"

#define POINTS 5

class Curve
{
public:
CVector2D (&points)[];
float maxX;
float maxY;
//RwIm2DVertex lineQuadVerts[POINTS];
//RwIm2DVertex lineVerts[POINTS];

Curve(CVector2D (&newPoints)[]) : points(newPoints)
{
maxX = newPoints[0].x;
maxY = newPoints[0].y;
for (int i = 0; i < 3; ++i)
{
if (maxX < newPoints[i].x)
maxX = newPoints[i].x;

if (maxY < newPoints[i].y)
maxY = newPoints[i].y;
}
}
float Evaluate(float value);
};
//void Draw(CRect rect, float lineWidth);
//void Render();
};

static void Setup2dVertex(RwIm2DVertex& vertex, float x, float y, RwUInt32 color) {
vertex.x = x;
vertex.y = y;
vertex.u = vertex.v = 0.0f;
vertex.z = CSprite2d::NearScreenZ + 0.0001f;
vertex.rhw = CSprite2d::RecipNearClip;
vertex.emissiveColor = color;
}
Loading

0 comments on commit 31a4f59

Please sign in to comment.