Author Topic: Convert RPM  (Read 2732 times)

0 Members and 1 Guest are viewing this topic.

Offline Pot Noodle

  • Sponsor
  • Amiga 1200
  • *******
  • Posts: 271
  • Karma: 15
  • Computers have lots of memory but no imagination
    • View Profile
Convert RPM
« on: May 04, 2012 »
Hi Guys, Still playing around with this car game  ::) I have been sorting out the transmission.
But now that's all good I need a way to convert RPM to a usable floating point value.
The problem is that the RPM are high integers and my road speed is low floats like 0.1+
Can someone show me the light? Please.

Code + Sound Included in Zip.

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Convert RPM
« Reply #1 on: May 05, 2012 »
Revolutions Per Minute

One Revolution as an angle is 2.0*pi radians. That's the easy part. The hard part is determining exactly how long a minute is in ticks. If you know that your game renders at 30 frames per second you can take that as a rough estimate of the speed.
Minute = 60*Second/30 (frames)

So RPM = 2.0*pi / (60*Second/30)

You could get this far more accurate but it's alot of work and this estimate should be good enough for your needs.

Here's my c++ for calculating the same (uses win32)

Code: [Select]
// set up the high resolution timer
if (!QueryPerformanceFrequency((LARGE_INTEGER*)&tick.TicksPerSecond)) {
return Error("MetricStartUp - Failed to obtain the CPU speed!");
}
if (!QueryPerformanceCounter((LARGE_INTEGER*)&tick.FirstTick)) {
return Error("MetricStartUp - Failed to read the high resolution time stamp counter!");
}
tick.OldTick  = tick.FirstTick;
tick.CurTick  = tick.FirstTick;
tick.NumTicks = tick.CurTick - tick.FirstTick;
tick.TicksPerSecond = max(tick.TicksPerSecond, 1);

// calculate durations and speeds in clock cycles
metric.second      = (unsigned __int32)(tick.TicksPerSecond&0x00000000FFFFFFFF);
metric.millisecond = metric.second / 1000;
metric.minute      = 60*metric.second;
metric.hour        = 60*metric.minute;
metric.rpm         = 2*Π/metric.minute;  // revolutions per minute
metric.mps         = 1.0f/metric.second; // meters per second
« Last Edit: May 05, 2012 by rain_storm »

Challenge Trophies Won: