Gets the Point from an origin to target point with a specific distance offset.
Example Application of Snippet:
Code:
{
gets the point towards another point with a specific offset
Usage: 0AB1: @getpointwithpolaroffset 7 _fromXYZ 0@ 1@ 2@ _offsetdistance 3@ _towardsXYZ 4@ 5@ 6@ _storeXYZ 29@ 30@ 31@
Examples:
0AB1: @getpointwithpolaroffset 7 _fromXYZ 0@ 1@ 2@ _offsetdistance 1.0 _towardsXYZ 4@ 5@ 6@ _storeXYZ 29@ 30@ 31@ // pointA towards to pointB
0AB1: @getpointwithpolaroffset 7 _fromXYZ 0@ 1@ 2@ _offsetdistance -1.0 _towardsXYZ 4@ 5@ 6@ _storeXYZ 29@ 30@ 31@ // pointA away to pointB
}
:getpointwithpolaroffset
// ~~~~~~~~~~~get z-angle towards the target with respect to world z angle
0087: 30@ = 5@ // Y2
0063: 30@ -= 1@ // Y1
0087: 31@ = 4@ // X2
0063: 31@ -= 0@ // X1
// 30@ = atan2(30@,31@)
0AA5: atan2 | 0x4207C0 2 2 | _X 31@ _Y 30@
0AE9: pop_float 30@ // store result from above operation
//
// ~~~~~~~~~~~get x-angle between two points with respect to world x angle
0087: 31@ = 6@ // Z2
0063: 31@ -= 2@ // Z1
0509: 29@ = distance_between_XY 0@ 1@ and_XY 4@ 5@ // adjacent side
// 31@ = atan2(31@,29@)
0AA5: atan2 | 0x4207C0 2 2 | _X 29@ _Y 31@
0AE9: pop_float 31@ // store result from above operation
//
30@ *= 57.295779817106167876798171061675 // radians to degrees
30@ -= 90.0 // gta sa's z-angle lags 90 degrees
31@ *= 57.295779817106167876798171061675 // radians to degrees
0AB1: @get3DXYZInFrontOfTrueNorth 6 _XYZ 0@ 1@ 2@ _ZAngle 30@ _XAngle 31@ _Distance 3@ _ReturnXYZ 29@ 30@ 31@
ret 3 29@ 30@ 31@
:get3DXYZInFrontOfTrueNorth // 0AB1: @get3DXYZInFrontOfTrueNorth 6 _XYZ 0@ 1@ 2@ _ZAngle 3@ _XAngle 4@ _Distance 5@ _ReturnXYZ 0@ 1@ 2@
4@ += 180.0 // WorldXAngle = TrueNorthXAngle + 180.0
3@ += 270.0 // WorldZAngle = (TrueNorthZAngle + 90.0) + 180.0 // we add another 180.0 degrees because we halfy revolve over the World X angle
// Compute X Offset = Cos(Pitch)*Cos(Yaw)*X0
02F7: 31@ = cosine 4@ // (float)
02F7: 30@ = cosine 3@ // (float)
006B: 31@ *= 30@ // (float)
006B: 31@ *= 5@ // (float)
//
// Compute Y Offset = Cos(Pitch)*Sin(Yaw)*X0
02F7: 30@ = cosine 4@ // (float)
02F6: 29@ = sine 3@ // (float)
006B: 30@ *= 29@ // (float)
006B: 30@ *= 5@ // (float)
//
// Compute Z Offset = -Sin(Pitch)*X0
02F6: 29@ = sine 4@ // (float)
006B: 29@ *= 5@ // (float)
29@ *= -1.0
//
005B: 0@ += 31@ // New X
005B: 1@ += 30@ // New Y
005B: 2@ += 29@ // New Z
0AB2: ret 3 0@ 1@ 2@
Example Application of Snippet:
Code:
{$CLEO .cs}
0000: Drag Player by ajom
// CTRL + M ~~~ Drag Player Actor towards to target marker
// CTRL + N ~~~ Drag Player Actor away from target marker
while true
wait 0 // hang avoider
if or
0AB0: key_pressed 77 // M key
0AB0: key_pressed 78 // N key
then
if and
0AB0: key_pressed 17 // ctrl key
0AB6: store_target_marker_coords_to 0@ 1@ 2@ // IF and SET
then
if 0AB0: key_pressed 77 // M key
then 6@ = 1.0 // move towards to marker
else 6@ = -1.0 // move away from marker
end
00A0: store_actor $PLAYER_ACTOR position_to 3@ 4@ 5@
while true
0AB1: @getpointwithpolaroffset 7 _fromXYZ 3@ 4@ 5@ _offsetdistance 6@ _towardsXYZ 0@ 1@ 2@ _storeXYZ 3@ 4@ 5@
09BC: put_actor $PLAYER_ACTOR at 3@ 4@ 5@ no_offset_and_dont_warp_gang
wait 0
if 8AB0: not key_pressed 17 // ctrl key
then break
end
050A: 7@ = distance_between_XYZ 0@ 1@ 2@ and_XYZ 3@ 4@ 5@
if and
7@ >= -1.0
7@ <= 1.0
then break
end
end
while 0AB0: key_pressed 17 // ctrl key
wait 0
end
end
end
end
Last edited: