[Closed] Acceleration
is it possible to find the acceleration produced when an object is dragged in the view port. For example if i have a point helper at the origin [0,0,0] and i drag it to [10,0,0] (using the mouse or keyboard) the output must be “+” for positive acceleration and when i drag the same point helper back to [8,0,0] the output must be “-” for negative acceleration.
note: without using key frames, the output must be interactive
any help is appreciated … Thanks
You are talking about the sing of the velocity vector. The negative acceleration is deceleration.
However the using of script position controller is a step in the right direction.
lot of experimentation later i found a partial solution to the problem . 🙁 … Heres what i did
i created a point helper and placed it at the origin next i created 2 text objects and then added a float script controller to the x_position of the helper heres the code:
i added 3 nodes to the scripted control :
- me = $point01 – my point helper
- temp = $Text01 – the first text object and set it to 0.0
- accel = $Text02 – the second text object this will contain the output
value = (me.pos.x - (temp.text as float))
if value > 0 then
accel.text = "+"
else
accel.text = "-"
temp.text = (me.pos.x) as string
temp.text as float
now when i drag the helper object it shows “+” if i move in the positive X direction and if i drag backwards it shows “-” pretty cool… but when i release the mouse and try to drag the object the second time it first resets its position to the origin and then calculates the motion (confusing!)
note: i tried to use float list then add the script controller but that gives a weird fluctuation of + and –
i also tried to add the script to size property of the point helper and monitor the position of the helper but that to gives weird “+” “-” fluctuations…
attached : the .max file (2010)
any help is appreciated once again … thanks
@ Denis:
yep i was talking about the velocity vector, however i had to give up working on the scripted controller as it was not yielding the complete solution to the problem, so instead i used the timer control in a script call it a “cheat” but i had no choice i setup the timer to 50 ms so that after every 50 ms i can sample the change in position of the point helper and if the change is positive i output “+” else “-” in case of deceleration here’s the code:
my scene consists of 1 point helper $point01 and 1 text object $accel
(
local prevlength = 0
rollout velocityVector "VelocityVector" --creates an empty rollout with a title velocity vector
(
timer mytimer active:true interval:50 -- after every 50ms the timer ticks
on mytimer tick do -- the code is called after every 50ms or the timer interval defined above
(
pointVel = ($point01.pos.x) - prevlength -- calculate the change in x position
/* if its a positive change the text property of the textobject in my case accel changes to "+"
otherwise "-" or "=" depending on the change pretty self explainatory*/
if pointVel>0 then
$accel.text ="+"
else if pointVel<0 then
$accel.text = "-"
else if pointVel==0 then
$accel.text = "="
prevlength = $point01.pos.x --now save the x position for the next tick
)
)
createdialog velocityVector width:10 -- creates the rollout
)
note: i have used the x position in code feel free to try out the length function (which returns the magnitude of the position vector from the origin in simpler terms the position of the object from the origin) … i know this way of scripting is a bit awkward if you have better idea please share thank you!
once again thanks for the reply!
using of the timer is not a “cheat”. it’s only one way to figure your task out. to avoid the timer’s all the time ticking you can use when transform <> change[s] construct (see MXS for details and samples)
thanks for the suggestion, i looked it up in the help file and used it with the timer control … saved a lot of clock cycles