Ok I just test your demo and there are few problem, some in my side but some in your size.
Let us first go with the one in your side.
1-you have a wrong matrix, you cannot make non orthonormal matrix
This code make a matrix with a negative determinant, that completely wack out the engine
- Code: Select all
dVector front(sinf(angle), cosf(angle), 0.0f);
dVector right(0.0f, 0.0f, 1.0f);
dVector up = front * right;
I changed to this,
- Code: Select all
dVector front(sinf(angle), cosf(angle), 0.0f);
dVector right(0.0f, 0.0f, 1.0f);
// dVector up = front * right;
dVector up = right * front;
in case you are wondering how to know if the rotation part is right or wrong, a matrix is right if the deternimat is positive 1.0
that is: dotproduct (cross product (right, up), right) = 1.0
2-if you are going to place a body to scrapl overthe ground you cannot really measure the velocity by substrating the current position from the previus position and divide that by the timestep.
If you remember from phsyics 101 in college, there is a difference between instanataneus velocity and average velocity. You are measuring the average velocity. Not the instantaneus velocity.
Consider a body bouncing on a floor with in a perfect elastic collision.
If that happens, the position before and after the collision are identical, if you use your method, the velocity will be zero. However in both positions the velocity is very different than zero.
Similarlly if you have a body scraping along the ground with a non zero friction coeficient, then the friction will reduced the speed at each step.
So what you are getting is the body with high speed but the velocity is reduced at the end of each frame,
You will need to set the static and kinetic friction to zero to make it a frictionless test.
3- and this is an engine limitation. Whe you make the collsion shape, you are making a cylinder with thickness 0.1 unit in length.
That means that the maximun distance the body can move conservativatly is 0.05 of a unit.
With that data, when Newton predict how much a body can move before it hits a contact, the allowed time is very, very small.
this is because the body in too thin, it is in contact with the ground, and it is traveling very fast (14 meters per secund is abput 55 kilometer per hour),
the velocity in horizontal therfore the body does not bounce from the floor but the grapvity keeps polling it down,
all this factor combined makes that the next prediction the same thing happens.
The engine keeps doing predictions until is use all teh time step, but for practical reasons the engine only do that up to 8 times.
After that is bailout and this is why you see that it does not move as it should.
You can fix that by making the collision shape a litle thicker, I did that by making it twice as sick. change thsi line.
dVector cylSize (0.5f, 0.1f, 0.0f, 0.0f);
to this
dVector cylSize (0.5f, 0.2f, 0.0f, 0.0f);
those are the compromise we most make in order to make a real time engine.
Leaving the prediction runs until it completel resolve the collision, bogs down the performance to almost zero fps.