Bad refresh rate with schedule()...
by William Ball · in General Discussion · 06/19/2006 (1:18 pm) · 2 replies
I'm trying to create a camera that "elastically" zooms between predefined views. So I wrote the following console function that averages the cameras current position into a target position:
ConsoleFunction(updateTransform, const char *, 4, 4, "Interpolating two transforms")
{
/*
This function updates a given transform towards a target according to:
current[n+1] = current[n]*alpha + target*(1-alpha)
Arguments: [current(n)] [target] [alpha]
Return Value: [current(n+1)]
Kirby Says: no input validation; use at your own risk <('o'<)
*/
Point3F current_position;
AngAxisF current_orient;
dSscanf(argv[1], "%f %f %f %f %f %f %f", ¤t_position.x, ¤t_position.y, ¤t_position.z, ¤t_orient.axis.x, ¤t_orient.axis.y, ¤t_orient.axis.z, ¤t_orient.angle);
Point3F target_position;
AngAxisF target_orient;
dSscanf(argv[2], "%f %f %f %f %f %f %f", &target_position.x, &target_position.y, &target_position.z, &target_orient.axis.x, &target_orient.axis.y, &target_orient.axis.z, &target_orient.angle );
F32 alpha = dAtof(argv[3]);
Point3F final_position;
QuatF current_quat(current_orient);
QuatF target_quat(target_orient);
QuatF final_quat;
final_position.interpolate(current_position, target_position, alpha);
final_quat.interpolate(current_quat, target_quat, alpha);
AngAxisF final_orient(final_quat);
char *buf = Con::getReturnBuffer(256);
dSprintf(buf, 256, "%f %f %f %f %f %f %f", final_position.x, final_position.y, final_position.z, final_orient.axis.x, final_orient.axis.y, final_orient.axis.z, final_orient.angle );
return buf;
}
Then I loop this process using the schedule() method in torquescript, and just move the target with my gui to change the view:
$target = "3.554 -2.468 1.731 0.104 0.050 -0.993 0.902";
function updateCam() {
%cam = LocalClientConnection.camera;
%cam.setTransform(updateTransform(%cam.getTransform(),$target,0.001));
schedule(1, 0, "updateCam");
}
But the refresh rate is HORRIBLE. All the characters in the scene are updating normally, I just get this choppy motion with the camera only updating every five or six frames (not 1ms, as I was lead to believe). If I reduce the schedule time to 0 ms, it just freezes up.
So what's a better method for repeatedly calling a function every frame, since schedule was obviouslt not meant for that kind of continuous update?
ConsoleFunction(updateTransform, const char *, 4, 4, "Interpolating two transforms")
{
/*
This function updates a given transform towards a target according to:
current[n+1] = current[n]*alpha + target*(1-alpha)
Arguments: [current(n)] [target] [alpha]
Return Value: [current(n+1)]
Kirby Says: no input validation; use at your own risk <('o'<)
*/
Point3F current_position;
AngAxisF current_orient;
dSscanf(argv[1], "%f %f %f %f %f %f %f", ¤t_position.x, ¤t_position.y, ¤t_position.z, ¤t_orient.axis.x, ¤t_orient.axis.y, ¤t_orient.axis.z, ¤t_orient.angle);
Point3F target_position;
AngAxisF target_orient;
dSscanf(argv[2], "%f %f %f %f %f %f %f", &target_position.x, &target_position.y, &target_position.z, &target_orient.axis.x, &target_orient.axis.y, &target_orient.axis.z, &target_orient.angle );
F32 alpha = dAtof(argv[3]);
Point3F final_position;
QuatF current_quat(current_orient);
QuatF target_quat(target_orient);
QuatF final_quat;
final_position.interpolate(current_position, target_position, alpha);
final_quat.interpolate(current_quat, target_quat, alpha);
AngAxisF final_orient(final_quat);
char *buf = Con::getReturnBuffer(256);
dSprintf(buf, 256, "%f %f %f %f %f %f %f", final_position.x, final_position.y, final_position.z, final_orient.axis.x, final_orient.axis.y, final_orient.axis.z, final_orient.angle );
return buf;
}
Then I loop this process using the schedule() method in torquescript, and just move the target with my gui to change the view:
$target = "3.554 -2.468 1.731 0.104 0.050 -0.993 0.902";
function updateCam() {
%cam = LocalClientConnection.camera;
%cam.setTransform(updateTransform(%cam.getTransform(),$target,0.001));
schedule(1, 0, "updateCam");
}
But the refresh rate is HORRIBLE. All the characters in the scene are updating normally, I just get this choppy motion with the camera only updating every five or six frames (not 1ms, as I was lead to believe). If I reduce the schedule time to 0 ms, it just freezes up.
So what's a better method for repeatedly calling a function every frame, since schedule was obviouslt not meant for that kind of continuous update?
About the author
#2
First of all the General forums are supposed to be for non-Torque specific topics. Second, you posted source code which belongs only in the private forums.
06/20/2006 (7:25 am)
@WilliamFirst of all the General forums are supposed to be for non-Torque specific topics. Second, you posted source code which belongs only in the private forums.
Torque Owner Alberto Ganesh Barbati
Default Studio Name