fferro2
07-03-2008, 06:09 PM
I need to know the speed of a moving object; I did it by editing the text of a label inside a rollout.
To update it in real time, I added a registerTimeCallback at the end of the script.
The problem is that when I change the framerate by a spinner in the same rollout, the formula doesn’t use the real distance traveled by the object,continuing with the previous value.
I have just read this part of the help file:
“Note that it is the function value that is being registered, not the function name or global variable. This means that redefining the same-named function after registering it does not change the callback. You either need to unregister, re-define the function and then register it again, or make the registered function an intermediary which calls another function,
For Example:
fn time_cb = print currentTime
fn tcb = time_cb()
registerTimeCallback tcb
In this case, the registered callback function, tcb, calls the real call back, time_cb, (by referencing the global variable it is defined in), meaning you can redefine time_cb() as often as you need and the callback will always invoke the latest definition. This is a useful technique to employ while you are developing and debugging a callback."
But even with this "intermediate calling" step the problem persist:
)
local ctdMaster = getNodeByName "CTDmaster"
global callSpeedRealTimed, speedRealTime
...
function speedRealTime obj = (
if obj != undefined do (
speedM = (distance (at time (currenttime + 0.5f) obj.pos) (at time (currenttime - 0.5f) obj.pos)) * frameRate
ctdSceneConfiguration.speedMtsS.text = speedM as string
...
)
)
function callSpeedRealTimed = speedRealTime ctdMaster
rollout ctdSceneConfiguration "Scene:Configuration" (
label speedMtsS "00.0" width:26 height:16 across:4 align:#left offset:[6,0]
...
spinner animationFrameRate "FPS: " range:[0,1000,frameRate] type:#integer fieldWidth:40 align:#right
)
...
unregisterTimeCallback callSpeedRealTimed
registerTimeCallback callSpeedRealTimed
)
To update it in real time, I added a registerTimeCallback at the end of the script.
The problem is that when I change the framerate by a spinner in the same rollout, the formula doesn’t use the real distance traveled by the object,continuing with the previous value.
I have just read this part of the help file:
“Note that it is the function value that is being registered, not the function name or global variable. This means that redefining the same-named function after registering it does not change the callback. You either need to unregister, re-define the function and then register it again, or make the registered function an intermediary which calls another function,
For Example:
fn time_cb = print currentTime
fn tcb = time_cb()
registerTimeCallback tcb
In this case, the registered callback function, tcb, calls the real call back, time_cb, (by referencing the global variable it is defined in), meaning you can redefine time_cb() as often as you need and the callback will always invoke the latest definition. This is a useful technique to employ while you are developing and debugging a callback."
But even with this "intermediate calling" step the problem persist:
)
local ctdMaster = getNodeByName "CTDmaster"
global callSpeedRealTimed, speedRealTime
...
function speedRealTime obj = (
if obj != undefined do (
speedM = (distance (at time (currenttime + 0.5f) obj.pos) (at time (currenttime - 0.5f) obj.pos)) * frameRate
ctdSceneConfiguration.speedMtsS.text = speedM as string
...
)
)
function callSpeedRealTimed = speedRealTime ctdMaster
rollout ctdSceneConfiguration "Scene:Configuration" (
label speedMtsS "00.0" width:26 height:16 across:4 align:#left offset:[6,0]
...
spinner animationFrameRate "FPS: " range:[0,1000,frameRate] type:#integer fieldWidth:40 align:#right
)
...
unregisterTimeCallback callSpeedRealTimed
registerTimeCallback callSpeedRealTimed
)
