Skip to content

Commit 1f8d763

Browse files
committed
[car] added anti-roll bars and more on-screen metrics
1 parent 5461ab8 commit 1f8d763

File tree

4 files changed

+254
-60
lines changed

4 files changed

+254
-60
lines changed

source/runtime/Game/Game.cpp

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3838
#include "../Input/Input.h"
3939
#include "../Geometry/GeometryGeneration.h"
4040
#include "../Geometry/GeometryProcessing.h"
41+
#include "../Physics/Car.h"
4142
//==========================================
4243

4344
//= NAMESPACES ===============
@@ -1846,16 +1847,51 @@ namespace spartan
18461847
physics->SetVehicleSteering(steering);
18471848
}
18481849

1849-
// osd
1850-
static char speed_text[64];
1850+
// osd - vehicle info
1851+
static char text_buffer[128];
18511852
Vector3 velocity = physics->GetLinearVelocity();
18521853
float speed_kmh = velocity.Length() * 3.6f;
1853-
snprintf(speed_text, sizeof(speed_text), "Speed: %.1f km/h", speed_kmh);
1854-
1855-
Renderer::DrawString("Vehicle Test (WIP)", Vector2(0.005f, 0.90f));
1856-
Renderer::DrawString("Arrow Keys: Up=Throttle, Down=Brake/Reverse, Left/Right=Steer", Vector2(0.005f, 0.92f));
1857-
Renderer::DrawString(speed_text, Vector2(0.005f, 0.94f));
1858-
Renderer::DrawString("Press PLAY to drive!", Vector2(0.005f, 0.96f));
1854+
1855+
float y_pos = 0.70f;
1856+
const float line_spacing = 0.02f;
1857+
1858+
Renderer::DrawString("Vehicle Test (WIP)", Vector2(0.005f, y_pos));
1859+
y_pos += line_spacing;
1860+
1861+
snprintf(text_buffer, sizeof(text_buffer), "Speed: %.1f km/h", speed_kmh);
1862+
Renderer::DrawString(text_buffer, Vector2(0.005f, y_pos));
1863+
y_pos += line_spacing;
1864+
1865+
snprintf(text_buffer, sizeof(text_buffer), "Throttle: %.0f%% Brake: %.0f%% Steer: %.2f",
1866+
physics->GetVehicleThrottle() * 100.0f, physics->GetVehicleBrake() * 100.0f, physics->GetVehicleSteering());
1867+
Renderer::DrawString(text_buffer, Vector2(0.005f, y_pos));
1868+
y_pos += line_spacing * 1.5f;
1869+
1870+
// per-wheel metrics
1871+
Renderer::DrawString("Wheel Metrics:", Vector2(0.005f, y_pos));
1872+
y_pos += line_spacing;
1873+
1874+
const char* wheel_names[] = { "FL", "FR", "RL", "RR" };
1875+
for (int i = 0; i < static_cast<int>(WheelIndex::Count); i++)
1876+
{
1877+
WheelIndex wheel = static_cast<WheelIndex>(i);
1878+
bool grounded = physics->IsWheelGrounded(wheel);
1879+
float compression = physics->GetWheelCompression(wheel) * 100.0f;
1880+
float force_kn = physics->GetWheelSuspensionForce(wheel) / 1000.0f;
1881+
1882+
snprintf(text_buffer, sizeof(text_buffer), " %s: %s Comp: %.0f%% Force: %.1f kN",
1883+
wheel_names[i],
1884+
grounded ? "GND" : "AIR",
1885+
compression,
1886+
force_kn);
1887+
Renderer::DrawString(text_buffer, Vector2(0.005f, y_pos));
1888+
y_pos += line_spacing;
1889+
}
1890+
1891+
y_pos += line_spacing * 0.5f;
1892+
Renderer::DrawString("Arrow Keys: Up=Throttle, Down=Brake/Reverse, Left/Right=Steer", Vector2(0.005f, y_pos));
1893+
y_pos += line_spacing;
1894+
Renderer::DrawString("Press PLAY to drive!", Vector2(0.005f, y_pos));
18591895
}
18601896
}
18611897
//====================================================================================

0 commit comments

Comments
 (0)