[gameprogrammer] Re: Tachometer / Analog Gauges
- From: Justin Coleman <jmcoleman@xxxxxxxxx>
- To: gameprogrammer@xxxxxxxxxxxxx
- Date: Fri, 15 Jul 2005 13:24:43 -0400
The way I would make an analog tach would be (assuming you have opengl
support on whatever you're using to display it) this:
1. Make a bitmap with the gauge face (the background, with numbers and
little marker lines and whatnot).
2. Make a bitmap with the needle opaque and the rest transparent.
(Alternatively, you could do this with just a solid colored triangle,
but with a bitmap you get much more control over the appearance).
3. (Before you actually write the code) Determine what the relative
angle is between straight up and each of the tick marks. (0, 1000,
2000, 3000... max rpm).
Actually, if you have a vector graphics tool it *might* be possible to
make a gauge face with the tick marks already at specified angles. I'm
not sure, though.
For example, on most cars I've seen, the speedometer's 0 reading is at
about -120 degrees, and the maximum reading is at about +120 degrees
(if you imagine zero degrees to be straight up on the gauge face).
4. Given those two numbers, now you have your needle range. In the
example I gave, it would be a total of 240 degrees. Now you need to
figure out how many degrees per rpm (or 10, or 100 rpm, whichever
granularity you want to use).
If your maximum reading is 6000 rpm, that would give you 25rpm per
degree of rotation.
5. (In your code) Each frame, display the gauge face bitmap (not
rotated) and then your needle bitmap above / in front of it (depending
on which axes you're using), rotated the appropriate amount.
rotation = (rpm / 25) - 120;
Rotation in degrees equals the current rpm, divided by the number of
rpm per degree, and then minus the degrees for the zero tickmark.
You can do all the above in about 5 lines of code per frame, including
the gl calls.
Perhaps some talented art person here could even help you make the
gauge bitmaps :)
Hope this helps!
-Justin
---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html
- References:
- [gameprogrammer] Tachometer / Analog Gauges
- From: toddjasp
Other related posts:
- » [gameprogrammer] Tachometer / Analog Gauges
- » [gameprogrammer] Re: Tachometer / Analog Gauges
- » [gameprogrammer] Re: Tachometer / Analog Gauges
- » [gameprogrammer] Re: Tachometer / Analog Gauges
- [gameprogrammer] Tachometer / Analog Gauges
- From: toddjasp