Arrow flight modeling
Posted: Thu Mar 22, 2012 6:29 pm
I am trying to model a realistic arrow flight path, but i dont know how to. I get the parabolic path (it is easier than I though), but the arrow does not rotate. In real world, an arrow points (or tries to point) in the direction of its linear velocity vector.
I am using this code for creating the arrow
I thought it should work like this, but it does not, because the cylinder has the center of mass in the exact middle, and no force applies (besides the gravity, witch affects the full shape in the same direction).
I have tried to move the center of mass, but it does nothing, bullet cant have a center of mass that is not the center of the shape (at least that is what i read in the wiki).
I tried to use applyTorque, but i do not know how to use the function. I thought getting the difference between orientation of the shape and the linear velocity vector in axis-angle format should work, but it does not (or I did something bad...).
I just have one idea left: to use a fixed constraint to hold a body with weight but no shape (no collisions) to the tail of the arrow. But it feels bad, bullet does not provide fixed constraints, and i think there should be a good reason for that.
Somebody tried this before and can share a tip or two?
I am using this code for creating the arrow
Code: Select all
void shootArrow(double px, double py, double pz, double dx, double dy, double dz, double m)
{
btCylinderShape *capsule = new btCylinderShape(btVector3(0,0.5,0)); //In the start it was a capsule, not a cylinder
btScalar mass(m);
btVector3 localInertia(0,0,0); //I don't know what values to give.
capsule->calculateLocalInertia(mass,localInertia);
btTransform startTransform;
startTransform.setIdentity();
startTransform.setOrigin(btVector3(px,py,pz));
//getDifference returns a quaternion that represents the difference between both vectors.
// It works well. Arrows point same way as the initial linear velocity vector (dx, dy, dz).
startTransform.setRotation(getDifference(btVector3(dx, dy, dz), btVector3(0, 1, 0)));
btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,capsule,localInertia);
btRigidBody* body = new btRigidBody(rbInfo);
body->setLinearVelocity(btVector3(dx, dy, dz));
m_dynamicsWorld->addRigidBody(body);
arrows.push_back(body);
}
I have tried to move the center of mass, but it does nothing, bullet cant have a center of mass that is not the center of the shape (at least that is what i read in the wiki).
I tried to use applyTorque, but i do not know how to use the function. I thought getting the difference between orientation of the shape and the linear velocity vector in axis-angle format should work, but it does not (or I did something bad...).
I just have one idea left: to use a fixed constraint to hold a body with weight but no shape (no collisions) to the tail of the arrow. But it feels bad, bullet does not provide fixed constraints, and i think there should be a good reason for that.
Somebody tried this before and can share a tip or two?