All bottles have the same mass, just have a different size. I don't use Newton scaling.
Moderators: Sascha Willems, Thomas
void Entity::PhysicsSetRotation(const Quat& quat, const float strength)
{
if (body)
{
Quat currentrotation = body->nextquat;
Quat desiredrotation = quat;
Quat omega = GetOmega();
Vec3 torque = desiredrotation.GetAverageOmega(currentrotation, strength);
torque *= 1.0 * GetMass();
body->SetTorque(torque*60.0);
body->SetOmega(0, 0, 0);
}
}
pHySiQuE wrote:torque *= 1.0 * GetMass();
vector torque = targetAngVel / timestep;
torque = matrix.Unrotate (torque); // matrix = BodyGetMatrix
torque[0] *= Ixx; // Inertia from BodyGetMassMatrix
torque[1] *= Iyy;
torque[2] *= Izz;
torque = matrix.Rotate (torque);
void CalculatePickForceAndTorque (const NewtonBody* const body, const dVector& pointOnBodyInGlobalSpace, const dVector& targetPositionInGlobalSpace, dFloat timestep)
void Entity::PhysicsSetPosition(const float x, const float y, const float z, const float strength)
{
if (body)
{
Vec3 d;
d.x = (x - body->nextmat[3][0]) * 60.0;
d.y = (y - body->nextmat[3][1]) * 60.0;
d.z = (z - body->nextmat[3][2]) * 60.0;
d *= strength;
body->SetVelocity(d.x,d.y,d.z);
}
}
void Entity::PhysicsSetRotation(const Quat& quat, const float strength)
{
if (body)
{
Quat currentrotation = body->nextquat;
Quat desiredrotation = quat;
Vec3 omega = desiredrotation.GetAverageOmega(currentrotation, strength*60.0);
body->SetOmega(omega.x, omega.y, omega.z);
}
}
void Entity::PhysicsSetRotation(const Quat& quat, const float strength)
{
if (body)
{
Quat currentrotation = body->nextquat;
Quat desiredrotation = quat;
Vec3 omega = desiredrotation.GetAverageOmega(currentrotation, 1.0 / strength);
body->SetOmega(omega.x, omega.y, omega.z);
}
}
BodyData *data = (BodyData*) BodyGetUserData (pickedBody);
sVec3 targetPos = handPos;
sQuat targetOrn = handOrn;
float mass, Ixx, Iyy, Izz; BodyGetMassMatrix (pickedBody, mass, Ixx, Iyy, Izz);
sMat4 matrix; BodyGetMatrix(pickedBody, matrix);
sVec3 curLinvel; BodyGetVelocity (pickedBody, curLinvel);
sVec3 com = matrix[3]; // assuming there's no offset
sQuat orn; BodyGetRotation (pickedBody, orn);
sVec3 curAngvel; BodyGetAngVel (pickedBody, curAngvel); // NewtonBodyGetOmega
sVec3 targetLinvel = (targetPos - com) / timestep; // would move move target distance in one step
targetLinvel -= curLinvel; // subtract current velocity - we want to change it, but we should not ignore it
sVec3 force = 0.3 * targetLinvel * (mass / timestep); // soften by factor 0.3 to avoid oszillation
sVec3 gravity (0.0f, mass * propsPhysics::f[propsPhysics::gravity], 0.0f);
force -= gravity; // apply reverse gravity, otherwise it seems some force is pulling the body downwards (optional)
// note that there is no upper limit on force - this should be added, either by automatic value related to body mass,
// or a user param like max friction in joints
sVec3 targetAngVel = AngVelFromAToB (orn, targetOrn) / timestep;
sVec3 torque = 0.3 * ConvertAngVelToTorque (sVec3(targetAngVel - curAngvel), matrix, timestep, Ixx, Iyy, Izz);
data->force += force;
data->torque += torque; // I add (not set) those later in force torque callback
void Entity::PhysicsSetRotation(const Quat& quat, const float strength)
{
if (body)
{
Quat currentrotation = body->nextquat;
Quat desiredrotation = quat;
//Quat omega = GetOmega();
// the the average velocity to get to the desired location
Vec3 omega = desiredrotation.GetAverageOmega(currentrotation, strength) - GetOmega();
// strneg muyst be less than one (0.2 or 0.3 is a goo value)
Vec3 alpha (omega * (strength / timestep));
// get the moment of inertia matrix of the body
dMatrix inertiaMatrix;
NewtonBodyGetInertiaMatrix(body, inertiaMatrix);
Vec3 torque = inertiaMatrix.RotateVector(omega);
body->SetTorque(torque);
//body->SetOmega(0, 0, 0);
}
}
Users browsing this forum: No registered users and 6 guests