setVelocityTransformation: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "{{Command " to "{{RV|type=command ")
mNo edit summary
 
(115 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{RV|type=command
{{RV|type=command


| arma2oa
|game1= arma2oa
|version1= 1.50
 
|game2= tkoh
|version2= 1.00
 
|game3= arma3
|version3= 0.50


|1.51
|eff= global
|eff= global
|arg= local
|arg= local
Line 9: Line 15:
|gr1= Object Manipulation
|gr1= Object Manipulation


| Interpolates and applies [[PositionASL]], [[velocity]], [[vectorDir]] and [[vectorUp]] to the given object based on the interval value. <br>
|descr= [[File:setVelocityTransformation.jpg|thumb|right]]
When interval is 0 the "fromXXX" values are used for the beginning of the interpolation. When interval is 1, the "toXXX" values are used for the end of interpolation. When interval value is in between, interpolated values are used (see diagram below). The interpolation is linear and along straight line between "from" and "to" positions. If curve is needed, then it should be constructed from multiple straight sections or by dynamically changing value of position params during the interpolation cycle, similar to [https://en.wikipedia.org/wiki/B%C3%A9zier_curve#Quadratic_curves Quadratic Curve animation] (see Example 3).
Interpolates and applies [[Position#PositionASL|PositionASL]], [[velocity]], [[vectorDir]] and [[vectorUp]] to the given object based on the interval value.<br>
<br>The [[velocity]] param doesn't do much in SP, but in MP, provided the velocity component is set correctly, it helps the engine to figure out what the next position of the moving object should be on other clients.
 
<br><br>
When interval is 0 the "fromXXX" values are used for the beginning of the interpolation. When interval is 1, the "toXXX" values are used for the end of interpolation.
When interval value is in between, interpolated values are used (see diagram below). The interpolation is linear and along straight line between "from" and "to" positions.
If curve is needed, then it should be constructed from multiple straight sections or by dynamically changing value of position params during the interpolation cycle, similar to {{Link|https://en.wikipedia.org/wiki/B%C3%A9zier_curve#Quadratic_curves|Quadratic Curve animation}} (see {{Link|#Example 3}}).<br>
 
The [[velocity]] param does not do much in SP, but in MP, provided the velocity component is set correctly, it helps the engine to figure out what the next position of the moving object should be on other clients.<br><br>
The actual approximate interpolation formula for this command is:
The actual approximate interpolation formula for this command is:
<code>_vecCurrent <nowiki>=</nowiki> _vecFrom [[vectorAdd]] (_vecTo [[vectorDiff]] _vecFrom [[vectorMultiply]] _interval);</code><br><br>
<sqf>_vecCurrent = _vecFrom vectorAdd (_vecTo vectorDiff _vecFrom vectorMultiply _interval);</sqf>
[[Image:setVelocityTransformation.jpg|800px]]
 
<br><br>
{{Feature|informative|
{{Informative | For continuous movement this command should be executed each frame while changing interval value. For example to apply interpolation for 10 seconds one could use the following command to translate 10 seconds into 0...1 interval:
For continuous movement this command should be executed each frame while changing the interval value.
<code>t1 <nowiki>=</nowiki> [[time]];  
For example to apply interpolation for 10 seconds one could use the following command to translate 10 seconds into 0..1 interval:
t2 <nowiki>=</nowiki> [[time]] + 10;</code>  
<sqf>
t1 = time;
t2 = time + 10;
</sqf>
Later inside some on frame event...
Later inside some on frame event...
<code>_interval <nowiki>=</nowiki> [[linearConversion]] [t1, t2, [[time]], 0, 1];</code> }}<br>
<sqf>_interval = linearConversion [t1, t2, time, 0, 1];</sqf>
{{Important | In multiplayer, this command should be applied where object is [[local]]}} <br><br>
}}


| object '''setVelocityTransformation''' [fromPosASL, toPosASL, fromVelocity, toVelocity, fromVectorDir, toVectorDir, fromVectorUp, toVectorUp, interval]
|s1= object [[setVelocityTransformation]] [fromPosASL, toPosASL, fromVelocity, toVelocity, fromVectorDir, toVectorDir, fromVectorUp, toVectorUp, interval, customCenter]


|p1= object: [[Object]] - object to be interpolated
|p1= object: [[Object]] - object to be interpolated
|p2= [fromPosASL, toPosASL, fromVelocity, toVelocity, fromVectorDir, toVectorDir, fromVectorUp, toVectorUp, interval] : [[Array]]
|p3= fromPosASL: [[PositionASL]] - starting [[getPosASL]] of the object
|p4= toPosASL: [[PositionASL]] - ending [[getPosASL]] of the object
|p5= fromVelocity: [[Array]] - starting [[velocity]] of the object
|p6= toVelocity: [[Array]] - ending [[velocity]]  of the object
|p7= fromVectorDir: [[Array]] - starting [[vectorDir]]  of the object
|p8= toVectorDir: [[Array]] - ending [[vectorDir]]  of the object
|p9= fromVectorUp: [[Array]] - starting [[vectorUp]]  of the object
|p10= toVectorUp: [[Array]] - ending [[vectorUp]]  of the object
|p11= interval: [[Number]] - interpolation interval (variable value, normally between 0 and 1)
| [[Nothing]]


|x1= <code>_tracker [[setVelocityTransformation]]
|p2= fromPosASL: [[Array]] format [[Position#PositionASL|PositionASL]] - starting [[getPosASL]] of the object
 
|p3= toPosASL: [[Array]] format [[Position#PositionASL|PositionASL]] - ending [[getPosASL]] of the object
 
|p4= fromVelocity: [[Array]] - starting [[velocity]] of the object
 
|p5= toVelocity: [[Array]] - ending [[velocity]] of the object
 
|p6= fromVectorDir: [[Array]] - starting [[vectorDir]] of the object
 
|p7= toVectorDir: [[Array]] - ending [[vectorDir]] of the object
 
|p8= fromVectorUp: [[Array]] - starting [[vectorUp]] of the object
 
|p9= toVectorUp: [[Array]] - ending [[vectorUp]] of the object
 
|p10= interval: [[Number]] - interpolation interval (variable value, normally between 0 and 1)
 
|p11= customCenter: [[Array]] - (Optional, default placing point of the model (see [[getModelInfo]])) custom center [x, y, z] to which transformation would be applied in model coordinates
|p11since= arma3 2.08
 
|r1= [[Nothing]]
 
|x1= <sqf>
_tracker setVelocityTransformation
[
[
_currentPos,
_currentPos,
Line 50: Line 76:
_nextVectorUp,
_nextVectorUp,
_interval
_interval
];</code>
];
</sqf>


|x2= Bob on imaginary stairway to heaven:<code>bob = [[createAgent]] ["C_man_1", [[player]] [[getRelPos]] [5, 0], [], 0, "CAN_COLLIDE"];  
|x2= Bob on imaginary stairway to heaven:
bob [[switchMove]] "ladderciviluploop";
<sqf>
pos1 = [[getPosASL]] bob;
bob = createAgent ["C_man_1", player getRelPos [5, 0], [], 0, "CAN_COLLIDE"];
pos2 = pos1 [[vectorAdd]] [0,0,0.75];
bob switchMove "ladderCivilUpLoop";
bob [[addEventHandler]] ["AnimDone",  
pos1 = getPosASL bob;
pos2 = pos1 vectorAdd [0,0,0.75];
bob addEventHandler ["AnimDone",
{
{
pos1 = pos2;  
pos1 = pos2;
pos2 = pos2 [[vectorAdd]] [0,0,0.75]
pos2 = pos2 vectorAdd [0,0,0.75]
}];
}];
[[onEachFrame]]
 
onEachFrame
{
{
[[if]] (![[alive]] bob) [[then]]
if (!alive bob) then
{
{
[[onEachFrame]] {};  
onEachFrame {};
bob [[switchMove]] "";
bob switchMove "";
bob [[removeAllEventHandlers]] "AnimDone";
bob removeAllEventHandlers "AnimDone";
};
};
bob [[setVelocityTransformation]] [
bob setVelocityTransformation [
pos1,  
pos1,
pos2,  
pos2,
[0,0,0],  
[0,0,0],
[0,0,0],  
[0,0,0],
[0,1,0],  
[0,1,0],
[0,1,0],
[0,1,0],
[0,0,1],  
[0,0,1],
[0,0,1],
[[moveTime]] bob
[0,0,1],
moveTime bob
];
];
};</code>
};
</sqf>


|x3= Advanced trickery with curved movement. The curve is controlled with one control point (controlPointASL), just like quadratic Bézier curve:<code>[[disableSerialization]];
|x3= Advanced trickery with curved movement. The curve is controlled with one control point (controlPointASL), just like quadratic Bézier curve:
[[player]] [[setDir]] 0;
<sqf>
disableSerialization;
player setDir 0;
interval = 0;
interval = 0;
_disp = [[findDisplay]] 46 [[createDisplay]] "RscDisplayEmpty";
_disp = findDisplay 46 createDisplay "RscDisplayEmpty";
_ctrl = _disp [[ctrlCreate]] ["RscSlider", -1];
_ctrl = _disp ctrlCreate ["RscSlider", -1];
_ctrl [[ctrlSetPosition]] [<nowiki/>[[safeZoneX]] + 0.1, 1, [[safeZoneW]] - 0.2, 0.1];
_ctrl ctrlSetPosition [safeZoneX + 0.1, 1, safeZoneW - 0.2, 0.1];
_ctrl [[ctrlSetActiveColor]] [1,0,0,1];
_ctrl ctrlSetActiveColor [1,0,0,1];
_ctrl [[ctrlCommit]] 0;
_ctrl ctrlCommit 0;
_ctrl [[sliderSetPosition]] 0;
_ctrl sliderSetPosition 0;
_ctrl [[sliderSetRange]] [0,1];
_ctrl sliderSetRange [0,1];
_ctrl [[sliderSetSpeed]] [0.1,0.5];
_ctrl sliderSetSpeed [0.1,0.5];
_ctrl [[ctrlAddEventHandler]] ["SliderPosChanged", {interval = [[_this]] [[select]] 1}];
_ctrl ctrlAddEventHandler ["SliderPosChanged", {interval = _this select 1}];
[[ctrlSetFocus]] _ctrl;
ctrlSetFocus _ctrl;
box = "Land_VR_Shape_01_cube_1m_F" [[createVehicle]] [0,0,0];
box = "Land_VR_Shape_01_cube_1m_F" createVehicle [0,0,0];
controlPointASL = [[AGLtoASL]] ([[player]] [[getRelPos]] [70, -30]) [[vectorAdd]] [0, 0, 30];
controlPointASL = AGLToASL (player getRelPos [70, -30]) vectorAdd [0, 0, 30];
fromPosASL = [[AGLtoASL]] ([[player]] [[getRelPos]] [10, -45]);
fromPosASL = AGLToASL (player getRelPos [10, -45]);
toPosASL = [[AGLtoASL]] ([[player]] [[getRelPos]] [10, 45]);
toPosASL = AGLToASL (player getRelPos [10, 45]);
fromControlPointOffset = controlPointASL [[vectorDiff]] fromPosASL;
fromControlPointOffset = controlPointASL vectorDiff fromPosASL;
toControlPointOffset = toPosASL [[vectorDiff]] controlPointASL;
toControlPointOffset = toPosASL vectorDiff controlPointASL;
[[onEachFrame]]
onEachFrame
{
{
[[hintSilent]] [[format]] ["Interval: %1", interval];
hintSilent format ["Interval: %1", interval];
box [[setVelocityTransformation]]
box setVelocityTransformation
[
[
fromPosASL [[vectorAdd]] (fromControlPointOffset [[vectorMultiply]] interval),
fromPosASL vectorAdd (fromControlPointOffset vectorMultiply interval),
controlPointASL [[vectorAdd]] (toControlPointOffset [[vectorMultiply]] interval),
controlPointASL vectorAdd (toControlPointOffset vectorMultiply interval),
[0,0,0],
[0,0,0],
[0,0,0],
[0,0,0],
Line 116: Line 149:
interval
interval
];
];
};</code>
};
</sqf>


| [[velocity]], [[setVelocity]], [[velocityModelSpace]], [[setVelocityModelSpace]], [[speed]], [[moveTime]]
|seealso= [[velocity]] [[setVelocity]] [[velocityModelSpace]] [[setVelocityModelSpace]] [[speed]] [[moveTime]] [[disableBrakes]] [[brakesDisabled]] [[getModelInfo]]
}}
}}


<dl class="command_description">
{{Note
<!-- Note Section BEGIN -->
|user= ffur2007slx2_5
<dd class="notedate">Posted on Aug 4, 2014 – 12:35
|timestamp= 20140804123500
<dt class="note">[[User:ffur2007slx2_5|ffur2007slx2_5]]<dd class="note">
|text= (A3 1.24) Generally speaking [[setVelocityTransformation]] is more likely a combination of [[setPosASL]], [[setVectorDirAndUp]] (or [[BIS_fnc_setPitchBank]]) and time multiplier.
(A3 1.24) Generally speaking [[setVelocityTransformation]] is more likely a combination of [[setPosASL]], [[setVectorDirAndUp]] (or [[BIS_fnc_setPitchBank]]) and time multiplier. It can be used as a position tracker with all necessary information collected, copied and then released within one function. Here’s a simple reproduction on how [[setVelocityTransformation]] works in game:
It can be used as a position tracker with all necessary information collected, copied and then released within one function. Here’s a simple reproduction on how [[setVelocityTransformation]] works in game:
<code>
<sqf>
[[private]] ["_dataOld","_dataNext","_capturedData","_obj","_fps","_startTrackingTime","_stepOld","_stepNext","_tracker","_tempTime"];
private ["_dataOld","_dataNext","_capturedData","_obj","_fps","_startTrackingTime","_stepOld","_stepNext","_tracker","_tempTime"];
_stepOld = 0;
_stepOld = 0;
_tempTime = 0;
_tempTime = 0;
_stepNext = 1;
_stepNext = 1;
[[while]] {[[true]]} [[do]] {
while {true} do
  _capturedData = _capturedData + [[ [[getPosASL]] _obj,[[velocity]] _obj,[[vectorDir]] _obj,[[vectorUp]] _obj]];
{
  [[sleep]] _fps;
_capturedData = _capturedData + [[getPosASL _obj,velocity _obj,vectorDir _obj,vectorUp _obj]];
  _tempTime = _tempTime + _fps;
sleep _fps;
  [[if]] (_tempTime >= _startTrackingTime) [[then]] {
_tempTime = _tempTime + _fps;
        _dataOld = _capturedData [[select]] _stepOld;
if (_tempTime >= _startTrackingTime) then
_dataNext = _capturedData [[select]] _stepNext;
{
_stepOld = _stepOld + 1;
_dataOld = _capturedData select _stepOld;
_stepNext = [[if]] (_stepNext >= ([[count]] _capturedData)) [[then]] [{_stepOld},{_stepNext + 1}];
_dataNext = _capturedData select _stepNext;
_tracker [[setVelocityTransformation]]
_stepOld = _stepOld + 1;
[_dataOld [[select]] 0,_dataNext [[select]] 0,_dataOld [[select]] 1,_dataNext [[select]] 1,
_stepNext = if (_stepNext >= (count _capturedData)) then { _stepOld } else { _stepNext + 1 };
_dataOld [[select]] 2,_dataNext [[select]] 2,_dataOld [[select]] 3,_dataNext [[select]] 3,1];
_tracker setVelocityTransformation [
  };
_dataOld select 0,
};</code>
_dataNext select 0,
_dataOld select 1,
_dataNext select 1,
_dataOld select 2,
_dataNext select 2,
_dataOld select 3,
_dataNext select 3,
1
];
};
};
</sqf>
Tracker starts coping the route and stance from the object when time start counting. TimeDiff determines the distance multiply between the current position and the next position.
Tracker starts coping the route and stance from the object when time start counting. TimeDiff determines the distance multiply between the current position and the next position.
<!-- Note Section END -->
}}
</dl>


 
{{Note
[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]
|user= DrSova
{{GameCategory|arma2|Scripting Commands}}
|timestamp= 20200704081100
{{GameCategory|arma3|Scripting Commands}}
|text= You can't apply this command to the dead body in ragdoll.
{{GameCategory|tkoh|Scripting Commands}}
}}
[[Category:Arma 2: Operation Arrowhead: New Scripting Commands List|{{uc:{{PAGENAME}}}}]]
 
<!-- CONTINUE Notes -->
<dl class="command_description">
<dd class="notedate">Posted on July 4, 2020 - 08:11 (UTC)</dd>
<dt class="note">[[User:DrSova|DrSova]]</dt>
<dd class="note">
You cant apply this command to the dead body in ragdoll
</dd>
</dl>
<!-- DISCONTINUE Notes -->

Latest revision as of 05:59, 27 November 2023

Hover & click on the images for description

Description

Description:
setVelocityTransformation.jpg

Interpolates and applies PositionASL, velocity, vectorDir and vectorUp to the given object based on the interval value.

When interval is 0 the "fromXXX" values are used for the beginning of the interpolation. When interval is 1, the "toXXX" values are used for the end of interpolation. When interval value is in between, interpolated values are used (see diagram below). The interpolation is linear and along straight line between "from" and "to" positions. If curve is needed, then it should be constructed from multiple straight sections or by dynamically changing value of position params during the interpolation cycle, similar to Quadratic Curve animation (see Example 3).

The velocity param does not do much in SP, but in MP, provided the velocity component is set correctly, it helps the engine to figure out what the next position of the moving object should be on other clients.

The actual approximate interpolation formula for this command is:

_vecCurrent = _vecFrom vectorAdd (_vecTo vectorDiff _vecFrom vectorMultiply _interval);

For continuous movement this command should be executed each frame while changing the interval value.

For example to apply interpolation for 10 seconds one could use the following command to translate 10 seconds into 0..1 interval:

t1 = time; t2 = time + 10;
Later inside some on frame event...

_interval = linearConversion [t1, t2, time, 0, 1];
Groups:
Object Manipulation

Syntax

Syntax:
object setVelocityTransformation [fromPosASL, toPosASL, fromVelocity, toVelocity, fromVectorDir, toVectorDir, fromVectorUp, toVectorUp, interval, customCenter]
Parameters:
object: Object - object to be interpolated
fromPosASL: Array format PositionASL - starting getPosASL of the object
toPosASL: Array format PositionASL - ending getPosASL of the object
fromVelocity: Array - starting velocity of the object
toVelocity: Array - ending velocity of the object
fromVectorDir: Array - starting vectorDir of the object
toVectorDir: Array - ending vectorDir of the object
fromVectorUp: Array - starting vectorUp of the object
toVectorUp: Array - ending vectorUp of the object
interval: Number - interpolation interval (variable value, normally between 0 and 1)
since Arma 3 logo black.png2.08
customCenter: Array - (Optional, default placing point of the model (see getModelInfo)) custom center [x, y, z] to which transformation would be applied in model coordinates
Return Value:
Nothing

Examples

Example 1:
_tracker setVelocityTransformation [ _currentPos, _nextPos, _currentVelocity, _nextVelocity, _currentVectorDir, _nextVectorDir, _currentVectorUp, _nextVectorUp, _interval ];
Example 2:
Bob on imaginary stairway to heaven:
bob = createAgent ["C_man_1", player getRelPos [5, 0], [], 0, "CAN_COLLIDE"]; bob switchMove "ladderCivilUpLoop"; pos1 = getPosASL bob; pos2 = pos1 vectorAdd [0,0,0.75]; bob addEventHandler ["AnimDone", { pos1 = pos2; pos2 = pos2 vectorAdd [0,0,0.75] }]; onEachFrame { if (!alive bob) then { onEachFrame {}; bob switchMove ""; bob removeAllEventHandlers "AnimDone"; }; bob setVelocityTransformation [ pos1, pos2, [0,0,0], [0,0,0], [0,1,0], [0,1,0], [0,0,1], [0,0,1], moveTime bob ]; };
Example 3:
Advanced trickery with curved movement. The curve is controlled with one control point (controlPointASL), just like quadratic Bézier curve:
disableSerialization; player setDir 0; interval = 0; _disp = findDisplay 46 createDisplay "RscDisplayEmpty"; _ctrl = _disp ctrlCreate ["RscSlider", -1]; _ctrl ctrlSetPosition [safeZoneX + 0.1, 1, safeZoneW - 0.2, 0.1]; _ctrl ctrlSetActiveColor [1,0,0,1]; _ctrl ctrlCommit 0; _ctrl sliderSetPosition 0; _ctrl sliderSetRange [0,1]; _ctrl sliderSetSpeed [0.1,0.5]; _ctrl ctrlAddEventHandler ["SliderPosChanged", {interval = _this select 1}]; ctrlSetFocus _ctrl; box = "Land_VR_Shape_01_cube_1m_F" createVehicle [0,0,0]; controlPointASL = AGLToASL (player getRelPos [70, -30]) vectorAdd [0, 0, 30]; fromPosASL = AGLToASL (player getRelPos [10, -45]); toPosASL = AGLToASL (player getRelPos [10, 45]); fromControlPointOffset = controlPointASL vectorDiff fromPosASL; toControlPointOffset = toPosASL vectorDiff controlPointASL; onEachFrame { hintSilent format ["Interval: %1", interval]; box setVelocityTransformation [ fromPosASL vectorAdd (fromControlPointOffset vectorMultiply interval), controlPointASL vectorAdd (toControlPointOffset vectorMultiply interval), [0,0,0], [0,0,0], [0,1,0], [1,0,0], [0,0,1], [0,1,0], interval ]; };

Additional Information

See also:
velocity setVelocity velocityModelSpace setVelocityModelSpace speed moveTime disableBrakes brakesDisabled getModelInfo

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note
ffur2007slx2_5 - c
Posted on Aug 04, 2014 - 12:35 (UTC)
(A3 1.24) Generally speaking setVelocityTransformation is more likely a combination of setPosASL, setVectorDirAndUp (or BIS_fnc_setPitchBank) and time multiplier. It can be used as a position tracker with all necessary information collected, copied and then released within one function. Here’s a simple reproduction on how setVelocityTransformation works in game:
private ["_dataOld","_dataNext","_capturedData","_obj","_fps","_startTrackingTime","_stepOld","_stepNext","_tracker","_tempTime"]; _stepOld = 0; _tempTime = 0; _stepNext = 1; while {true} do { _capturedData = _capturedData + [[getPosASL _obj,velocity _obj,vectorDir _obj,vectorUp _obj]]; sleep _fps; _tempTime = _tempTime + _fps; if (_tempTime >= _startTrackingTime) then { _dataOld = _capturedData select _stepOld; _dataNext = _capturedData select _stepNext; _stepOld = _stepOld + 1; _stepNext = if (_stepNext >= (count _capturedData)) then { _stepOld } else { _stepNext + 1 }; _tracker setVelocityTransformation [ _dataOld select 0, _dataNext select 0, _dataOld select 1, _dataNext select 1, _dataOld select 2, _dataNext select 2, _dataOld select 3, _dataNext select 3, 1 ]; }; };
Tracker starts coping the route and stance from the object when time start counting. TimeDiff determines the distance multiply between the current position and the next position.
DrSova - c
Posted on Jul 04, 2020 - 08:11 (UTC)
You can't apply this command to the dead body in ragdoll.