No idea what's wrong, but i'll bundle up all the angular code to a single snippet:
- Code: Select all
quat targetOrientation = server orientation, or average of all clients, or whatever
quat currentOrientation = BodyGetOrientation (body);
quat rotationFromCurToTarget; // calculate shortest arc rotation between the two...
{
quat qA = currentOrientation
quat qB = targetOrientation;
quat q; // temp
if (qA.Dot(qB) < 0.0f)
{
q[0] = qA[0]; q[1] = qA[1]; q[2] = qA[2];
q[3] = -qA[3];
}
else
{
q[0] = -qA[0]; q[1] = -qA[1]; q[2] = -qA[2];
q[3] = qA[3];
}
rotationFromCurToTarget = qB * q; // EDIT: Newton has opposite multiplication order, would be q * qB
}
vec axis; float angle;
rotationFromCurToTarget.ToAxisAndAngle(axis, angle);
vec targetAngVel = axis * angle / timestep; // to rotate to target in one step
vec currentAngVel = BodyGetOmega(body);
float mass, Ixx, Iyy, Izz; BodyGetMassAndInertia(mass, Ixx, Iyy, Izz);
float duration = timestep * 10; // give it more time than one step to prevent overshoot
vec torque = (targetAngVel - currentAngVel) / duration;
torque = matrix.Unrotate (torque); // rotate to local body space
torque[0] *= Ixx;
torque[1] *= Iyy; // apply nonuniform scale caused by inertia
torque[2] *= Izz;
torque = matrix.Rotate (torque); // rotate back to global space
// the above could be compacted to a single matrix multiplication but i don't know yet if Newton exposes this
BodyAddTorque (body, torque);
I assume the most likely place for a bug is the rotation between body and target, so the section 'calculate shortest arc rotation between the two'.
Notice that i use quaternions in xyzw order, but Newton returns them in wxyz order, so you may need to change the indices (i already reorder in anbstraction layer and i assume returned xyzw here)
Likely you have your own quat stuff that gives rotation between two orientations, but be sure the shortest arc is chosen using the dot product check, which is usually up to the users of quat libraries.
Hope this helps, otherwise post your code...
JoshKlint wrote:Only the master / server computer should calculate collision.
You are making it way too complicated.
I don't think we add compliactions here. There are multiple physics simulations running, but syncing them is not more complicated than syncing input and ouput i would say.
But i'm not experineced with netcode.
However, if each client runs it's own sim, there is no latency issue and no additional 'layer of illusions' presented to the user. I think its a very interesting take on the problem...