I think you're right.
The formula above gives the tagential velocity only if the angular velocity vector is perpendicular to the vector from the origin to the point being tested (radius).
It is much more complicated in the general case.
It seems easier to manually keep track of the angular difference between the last frame and the current frame and divide by time -- voila: angular velocity in degrees per second.
One thing I notice about this last method:
It works fine when I don't have physics turned on.
But when physics is turned on, and I set damping to 0, gravity to 0, and apply an initial torque in more than one direction -- the angular velocity is not constant.
This makes me suspicious about the physics system!
This code produces results I would expect:
Code:
string db[15];
action rotate {
var prev[3];
var total = 0;
vec_set(prev,my.pan);
while(1) {
vec_diff( temp, my.pan, prev );
vec_set(prev,my.pan);
vec_scale( temp, 1/time );
total = vec_length(temp);
str_for_num( db, total );
draw_text( db, 50, 170, vector(100,100,255));
str_for_num( db, temp[0] );
draw_text( db, 50, 50, vector(255,100,100));
str_for_num( db, temp[1] );
draw_text( db, 50, 90, vector(255,100,100));
str_for_num( db, temp[2] );
draw_text( db, 50, 130, vector(255,100,100));
my.pan += 3*time;
my.tilt += 3*time;
my.roll += 3*time;
wait(1);
} //while
} //
Here is the "equivalent" with physics:
Code:
action physics_rotate {
ph_setgravity( nullvector );
phent_settype( my, PH_RIGID, PH_BOX );
phent_setmass( my, 1, PH_SPHERE );
phent_setdamping( my, 0, 0 );
var prev[3];
var total = 0;
vec_set(prev,my.pan);
phent_addtorqueglobal( my, vector( 30, 30, 30 ) );
//for this to work make sure object is not on the floor
while(1) {
vec_diff( temp, my.pan, prev );
vec_set(prev,my.pan);
vec_scale( temp, 1/time );
total = vec_length(temp);
str_for_num( db, total );
draw_text( db, 50, 170, vector(100,100,255));
str_for_num( db, temp[0] );
draw_text( db, 50, 50, vector(255,100,100));
str_for_num( db, temp[1] );
draw_text( db, 50, 90, vector(255,100,100));
str_for_num( db, temp[2] );
draw_text( db, 50, 130, vector(255,100,100));
wait(1);
} //while
} //
The physics version fluctuates much more -- even with mass type set to PH_SPHERE.
Now, with the same settings and mass type set to PH_BOX, the model will actually spin out of control and then freeze within a few seconds. I know that this has something to do with setting damping to 0, but that would be case in a space game, right?
So, even if your code accurately measures angular velocity, when you're using physics, it will still fluctuate a lot so it may not be a reliable measure for determining how constant angular velocity is.
That's enough research for one night!
(Should be 1/time -- not time!)