Vehicle demo
-
- Posts: 144
- Joined: Fri Aug 01, 2008 6:36 am
- Location: Bonn, Germany
-
- Posts: 66
- Joined: Sun Jan 30, 2011 8:46 pm
Re: Vehicle demo
Thanks proof, for the code .
@mi076
I was wondering if a torque can be applied on each of the wheels separately after I calculate it using the gear ratio.
@mi076
I was wondering if a torque can be applied on each of the wheels separately after I calculate it using the gear ratio.
-
- Posts: 18
- Joined: Tue Mar 01, 2011 11:00 pm
Re: Vehicle demo
You can, but I don't see the point of applying different torques to different wheels, if that's what you meant. It's something like:dumbo2007 wrote: I was wondering if a torque can be applied on each of the wheels separately after I calculate it using the gear ratio.
Code: Select all
vehicle->applyEngineForce(force, wheelIndex);
Could you explain the math behind the camera? I was looking through the code but you're playing around with matrices too much so it's kinda too complicated for me, I just need the position/look at points

-
- Posts: 66
- Joined: Sun Jan 30, 2011 8:46 pm
Re: Vehicle demo
@proof
Yeah you are right I dont. I was hoping to apply the torque only on the back wheels for a rear wheel drive and use the forward wheel for steering.
By the way the engine is always operated at a particular RPM range correct. The harder the user presses on the accelerator pedal the higher RPM. From Wikipedia I see that the RPM range is about 1000 to 3000 RPM :
http://en.wikipedia.org/wiki/Revolutions_per_minute
So I think I ll assume a linear increase in RPM for the moment based on how long a key is kept pressed. I will not be calculating RPM based on fuel input and engine structure etc. I ll simply apply the gear ratios you have suggested and see how the car behaves for starters.
The only term that I am not sure about is the base torque. How much can I assume it to be ? Is it based on the current engine RPM ?
The way I see it as of now, the calculation goes like this :
Calculate Engine RPM based on any amount of detail about the engine
Calculate the base torque from the current engine RPM
Apply current gear ratio to calculate the output torque
Apply the torque to the rear wheels using applyEngineForce()
Yeah you are right I dont. I was hoping to apply the torque only on the back wheels for a rear wheel drive and use the forward wheel for steering.
By the way the engine is always operated at a particular RPM range correct. The harder the user presses on the accelerator pedal the higher RPM. From Wikipedia I see that the RPM range is about 1000 to 3000 RPM :
http://en.wikipedia.org/wiki/Revolutions_per_minute
So I think I ll assume a linear increase in RPM for the moment based on how long a key is kept pressed. I will not be calculating RPM based on fuel input and engine structure etc. I ll simply apply the gear ratios you have suggested and see how the car behaves for starters.
The only term that I am not sure about is the base torque. How much can I assume it to be ? Is it based on the current engine RPM ?
The way I see it as of now, the calculation goes like this :
Calculate Engine RPM based on any amount of detail about the engine
Calculate the base torque from the current engine RPM
Apply current gear ratio to calculate the output torque
Apply the torque to the rear wheels using applyEngineForce()
-
- Posts: 18
- Joined: Tue Mar 01, 2011 11:00 pm
Re: Vehicle demo
BMW dashboardAutomobile engines are usually operated at around 2500 rpm (41 Hz), with the minimum speed usually around 1000 rpm (16 Hz), and the redline at 6000-10,000 rpm (100–166 Hz).
I'm calculating the RPM currently by adding m_deltaRotation from all wheels, something like this:
Code: Select all
wheelRot += wi.m_deltaRotation;
rpm = std::abs((int)(wheelRot / 2*Ogre::Math::PI * 600 * getCurrentGearRatio()));
On the other side, I don't need a real rpm and gears simulation, because I'm not even going to show them to the end user because it would just clutter up the interface too much. I only need a fictional rpm and gear shifting for sounds

However, your approach does seem nice, except there's 1 problem. If the vehicle is steering and accelerating, it's not going to speed up much but you would still have linear rpm applied which would lead to being in 6th gear and going extremely slow. You need the velocity in your calculations.
-
- Posts: 66
- Joined: Sun Jan 30, 2011 8:46 pm
Re: Vehicle demo
Yeah see that is the thing. I will not be stepping up gears automatically based on the rpm. I will let the user decide that for the moment. For automatic transmission(I am not aware of how its done so please pardon any silly statementsIf the vehicle is steering and accelerating, it's not going to speed up much but you would still have linear rpm applied which would lead to being in 6th gear and going extremely slow. You need the velocity in your calculations.

So as I understand you are using the rotation of the wheels to calculate the rpm variable, and then use the rpm variable to calculate the gear.
But then how do you calculate the engine force value that you set using applyEngineForce() ?
In a previous post you mentioned that it can be calculated using currentGearRatio * baseTorque. But then how do you get the baseTorque ?
As I said I am planning to let the user set the gear - so manual transmission. Now the current engine RPM(not the current wheel RPM) is the primary input. Using this RPM I must somehow calculate the torque to be applied using applyEngineForce() . However currentGearRatio * baseTorque does not account for the engine RPM.
So I am guessing there is someway to determine the current engine torque from the current engine RPM ?
-
- Posts: 18
- Joined: Tue Mar 01, 2011 11:00 pm
Re: Vehicle demo
Well, I'm setting the baseTorque in my cars config file, and some cars are going to be slow, some are going to be fast. Yes, the torque stays the same for all RPM's for the current gear, but you can modify that to accommodate your needs by using linear interpolation. Here's a class you can use (ripped off from nvidia's sdk ^^):
What this will allow you to do, is set torque for some rpm ranges, like for example:
What this class will allow you to do is interpolate between torque values - this allows you to apply more/less torque at different rpm values.
Code: Select all
#ifndef _LinearInterpolationValues_H_
#define _LinearInterpolationValues_H_
#include <map>
class LinearInterpolationValues
{
public:
LinearInterpolationValues() : min(0), max(0), map() { }
void clear() { map.clear(); }
void insert(float index, float value)
{
if (map.empty())
min = max = index;
else
{
min = std::min(min, index);
max = std::min(max, index);
}
map[index] = value;
}
float getValue(float number) const
{
constMapIterator lower = map.begin();
if (number < min)
return lower->second;
constMapIterator upper = map.end();
upper--;
if (number > max)
return upper->second;
upper = map.lower_bound(number);
if (upper == lower)
return upper->second;
lower = upper;
lower--;
float w1 = number - lower->first;
float w2 = upper->first - number;
return ((w2 * lower->second) + (w1 * upper->second)) / (w1 + w2);
}
float getValueAtIndex(unsigned int index)
{
constMapIterator it = map.begin();
for (unsigned int i = 0; i < index; i++)
++it;
return it->second;
}
unsigned int getSize() { return map.size(); }
protected:
float min, max;
std::map<float, float> map;
typedef std::map<float, float>::iterator mapIterator;
typedef std::map<float, float>::const_iterator constMapIterator;
};
#endif
Code: Select all
LinearInterpolationValues* torqueCurve = new LinearInterpolationValues();
torqueCurve->insert(1000, 300);
torqueCurve->insert(2000, 320);
torqueCurve->insert(3000, 340);
torqueCurve->insert(4000, 320);
torqueCurve->insert(5000, 300);
// when computing the torque to apply, you use this
float torqueToApply = currentGearRatio * torqueCurve->getValue(currentRpm);
-
- Posts: 66
- Joined: Sun Jan 30, 2011 8:46 pm
Re: Vehicle demo
Thanks for the code. I think I ll go ahead and engage 1st gear now
...on to coding

-
- Posts: 18
- Joined: Tue Mar 01, 2011 11:00 pm
Re: Vehicle demo
Also, what just came to mind, manual gear switching will probably be a little tricky because I haven't found a way to limit the speed of the car, so for the reverse gear I set chassis linear damping to 0.3f so it gets limited a little but that's just a hackfix imo :/
-
- Posts: 144
- Joined: Fri Aug 01, 2008 6:36 am
- Location: Bonn, Germany
-
- Posts: 18
- Joined: Tue Mar 01, 2011 11:00 pm
Re: Vehicle demo
I'm applying linear damping to the chassis when the vehicle isn't accelerating, which makes it lose speed over time to make it kinda "realistic". Without it, when you don't accelerate the vehicle keeps it speed for... forever 

-
- Posts: 66
- Joined: Sun Jan 30, 2011 8:46 pm
Re: Vehicle demo
ok I think 4 forces contribute to the deceleration :
1. Rolling Friction
2. Distortion of the shape of the wheel at the area of contact
3. Air Flow around the vehicle
4. Internal friction of the parts transmitting power to the wheels
So for low speeds we neglect 3. 2 & 4 is taken care of by Linear Damping. But I thought 1 would be simulated by Bullet. So if the friction value of the ground and the wheels are made high enough then the vehicle should slow down. In fact the higher the weight of the vehicle the higher the friction.
So isnt this effect visible in btRayCastVehicle ? If there is no friction then how does the vehicle move at all ?
Recently I was trying to simulate a bike and I saw this strange thing too...somehow the wheels do roll but friction does not slow the bike. I ll try once more long enough maybe its just a matter of time.
Edit : In fact friction is the reason why gears are needed in the first place as starting the car from rest means overcoming the greater static friction(more torque less rpm) and then higher gears deal only with lesser rolling friction(less torque high rpm) with the total engine power (which should be torque*rpm) remaining the same.
1. Rolling Friction
2. Distortion of the shape of the wheel at the area of contact
3. Air Flow around the vehicle
4. Internal friction of the parts transmitting power to the wheels
So for low speeds we neglect 3. 2 & 4 is taken care of by Linear Damping. But I thought 1 would be simulated by Bullet. So if the friction value of the ground and the wheels are made high enough then the vehicle should slow down. In fact the higher the weight of the vehicle the higher the friction.
So isnt this effect visible in btRayCastVehicle ? If there is no friction then how does the vehicle move at all ?
Recently I was trying to simulate a bike and I saw this strange thing too...somehow the wheels do roll but friction does not slow the bike. I ll try once more long enough maybe its just a matter of time.
Edit : In fact friction is the reason why gears are needed in the first place as starting the car from rest means overcoming the greater static friction(more torque less rpm) and then higher gears deal only with lesser rolling friction(less torque high rpm) with the total engine power (which should be torque*rpm) remaining the same.
-
- Posts: 144
- Joined: Fri Aug 01, 2008 6:36 am
- Location: Bonn, Germany
-
- Posts: 18
- Joined: Tue Mar 01, 2011 11:00 pm
Re: Vehicle demo
I still don't like the raycast vehicle model
Might try to use joints to connect a car for GTA4 like behavior, has to be better.

Might try to use joints to connect a car for GTA4 like behavior, has to be better.
-
- Posts: 144
- Joined: Fri Aug 01, 2008 6:36 am
- Location: Bonn, Germany