OK, I think I'm supremely confused about torques and angular velocities. I'm going to rehash my understanding of linear velocities a) to make sure I understand how those work and b) because my perceptions of how linear and angular velocities work seem inconsistent, and I'm sure the error is with me.
So, as I understand it (and as seems to be the case) when I apply a linear force, that force is treated as if it were scaled to one second, even though I'm applying it multiple times. So, for instance, applying a force along (0, 0, 1) scales that force down to the number of steps of the physics simulation such that if the step size is 100 and I apply that force 100 times, the force only has a magnitude of 1, not 100. (By "apply," I mean via DynamicPhysicsNode.addForce().) Right so far?
If so, I'm having issues when I try using torques. I'm trying to get away from NodeRotateLeft/RightAction and use forces for rotation. More importantly, I'm trying to use world coordinates translated to local for AI steering.
First, how is angular velocity expressed? I was thinking that the vector components represented the amount of spin, in radians, on their respective axis. Is this correct?
So I have an AI steering behavior. It determines whether its "objective," the entity which it cares about, is to its left or right via getSpatial().worldToLocal(), then applies a torque to aim it toward the entity. So to steer right, I'm doing something like:
private void steerRight() {
System.out.println("Right: "+node.getTorque(null));
Vector3f torque = new Vector3f(0, -angularThrust, 0);
torque.multLocal(getEntity().getMass());
node.addTorque(torque);
}
And almost the exact same thing for left, only the angularThrust variable (2PI/3) is positive.
I notice, however, that after the torque first has the value of 2PI/3, it never does again. I have another println in the controller's update() method that shows the relative X coordinate slowly climbing to 0 (it's initially -10), but it drops much slower than I'd have expected. Assuming my understanding of torques/linear velocities is accurate (and I suspect I've just made an ass out of both of us, so sorry :) then my expectation would be that continuously adding this force would continue showing that the torque is 2.whatever, but as stated, it drops to 0 after the first run. I'm also unclear on the difference between what should be returned by getTorque() and getAngularVelocity(), which also makes me suspect that my understanding is incorrect.
Can anyone point me in the right direction? The ODE tutorials I've found thus far seem more concerned with bouncing balls, or if they use torques, they're used for vehicles with wheels and the like. I'm just trying to aim a spaceship. :)
Oh, and I also tried:
private void steerRight() {
System.out.println("Right: "+node.getTorque(null));
Vector3f torque = getEntity().absolutePositionOf(new Vector3f(0, -angularThrust, 0));
torque.multLocal(getEntity().getMass());
node.addTorque(torque);
}
when I read that torques were supposed to be in world coordinates. Entity.absolutePositionOf(Vector3f) is defined as:
public Vector3f absolutePositionOf(Vector3f position) {
Vector3f store = new Vector3f();
return getSpatial().localToWorld(position, store);
}
but that makes the turn *far* more drastic.
Oh, and yes, I'm aware that I'm creating lots of vectors here, and that optimization is possible, but optimizing first is what got me into this mess, so now I'm trying to understand then optimize.
Thanks a bunch.