[Newton] how apply force?
[Newton] how apply force?
How do I apply force on an object? By this I mean that I have an object and I whant it to get force as if it was hit by another object (but without having to create and simulate the object that hits). Something like Hit( float* posision_of_force, float* force, NewtonBody* target );
This is what i did:
Then you just have to figure out how you wanna add force and torque. I did this by having a force array and a torque array for every body and then just adding the values to the array, and then applying in the force and torque callback. But you could also just use NewtonBodyAddForce and NewtonBodyAddTorque
Code: Select all
addLocalForce(core::vector3df force, core::vector3df position, NewtonBody *body)
{
float com[3];
NewtonBodyGetCentreOfMass(body, com);
core::vector3df r(com[0] - position.X,
com[1] - position.Y,
com[2] - position.Z);
core::vector3df torque;
torque = r.crossProduct(force);
//add force
//add torque
}
Last edited by JonLT on Wed May 23, 2007 1:37 pm, edited 1 time in total.
i can tell way i did it. my dynamic object has float and torque arrays as its members. during runtime i simply set values i to those arrays and callbacks automaticly apply force to body and set those arrays to 0 so we add force just once. callbacks look like this:
as you see in real callback (Player_ForceAndTorque) i get user data from vody and that user data contains pointer to my player class. after that Player_ForceAndTorqueHandler is called and there all fun is done. Why i dont implement handlers functions directly in callbacks? that way i can access all my object members from handler, and from callback i cant because callback is static. i gues you know that static functions can not access non static members of the class
Code: Select all
void Player::Player_ForceAndTorqueHandler(const NewtonBody *body)
{
NewtonBodyAddForce(body, force);
NewtonBodyAddTorque(body, torque);
force[0] = 0.0f;
force[1] = 0.0f;
force[2] = 0.0f;
torque[0] = 0.0f;
torque[1] = 0.0f;
torque[2] = 0.0f;
}
void _cdecl Player::Player_ForceAndTorque(const NewtonBody *body)
{
tmpP = (Player*)NewtonBodyGetUserData(body);
tmpP->Player_ForceAndTorqueHandler(body);
}
or...
extend your SObject by adding vector<vector3df> ForceList and apply forces by adding to that list and in the callback add it's elements to the net force, then .clear() the list
thanks, I didn't know how to calculate the torque deepending on the position
one question: Is the force always F? I mean, doesn't it get smaller if you hit, let's say, the edge?
extend your SObject by adding vector<vector3df> ForceList and apply forces by adding to that list and in the callback add it's elements to the net force, then .clear() the list
thanks, I didn't know how to calculate the torque deepending on the position
one question: Is the force always F? I mean, doesn't it get smaller if you hit, let's say, the edge?
I'm not thaaat good at physics (so correct me if I'm wrong) but you have to apply a momentum by basically rotating your object around it's centroid.
It matters how far besides the centroid you place your force (leverage! think of a seesaw).
Or what do you mean by "calculate how the force should change"? Are you talking about it getting smaller and smaller?
http://en.wikipedia.org/wiki/Impulse + Friction
Take a look at wikipedia - there are tons of entries and formulas about physics.
It matters how far besides the centroid you place your force (leverage! think of a seesaw).
Or what do you mean by "calculate how the force should change"? Are you talking about it getting smaller and smaller?
http://en.wikipedia.org/wiki/Impulse + Friction
Take a look at wikipedia - there are tons of entries and formulas about physics.
The force acting on a body can be devided into components Fx, Fy, Fz. The net force on the body is the sum of these components and is applied at the center of mass.
If you are thinking of something hitting your body and then making it move you might see that the body moves less if the thing hits the body on the edge. That is simply because the thing slides off the body and therefor not all the force is transfered to the body. But if the thing hits the body right at the center the thing does not slide of and all the force is tranfered.
I think this is how it works.
If you are thinking of something hitting your body and then making it move you might see that the body moves less if the thing hits the body on the edge. That is simply because the thing slides off the body and therefor not all the force is transfered to the body. But if the thing hits the body right at the center the thing does not slide of and all the force is tranfered.
I think this is how it works.