[SNIPPET] get3DXYZInFrontOf

:get3DXYZInFrontOf{X,Y,Z,ZA,YA,Distance}
{   
    Return:
        PosX-InFrontOf
        PosY-InFrontOf
        PosZ-InFrontOf
       
    Example: 0AB1: call_scm_func @get3DXYZInFrontOf 6 XYZ 1@ 2@ 3@ Z_Angle 4@ Y_Angle 5@  Distance 7.0 Return_XYZ_To 6@ 7@ 8@

}
3@ *= -1.0
02F6: 6@ = sine 3@
006B: 6@ *= 5@
005B: 0@ += 6@
02F7: 6@ = cosine 3@
006B: 6@ *= 5@
005B: 1@ += 6@
02F7: 6@ = cosine 4@
0073: 5@ /= 6@
02F6: 6@ = sine 4@
006B: 5@ *= 6@
005B: 2@ += 5@
0AB2: ret 3 0@ 1@ 2@
 

ajom

Well-known member
Joined
Apr 14, 2020
Messages
389
Solutions
2
Reaction score
270
Location
Pluto
Permission to Post Forum Admin, I always encounter an issue when using this Snippet when "X_Angle" becomes near 90.0/-90.0/270.0/-270.0 Caused by Gimbal Lock.
Code:
...
02F7: 6@ = cosine 4@ // cos(90.0) = cos(270.0) = cos(-90.0) = cos(=270.0) = 0
0073: 5@ /= 6@ // a value gets divided by zero, becomes undefined value towards an infinity value
... // the game crashes
That is why I would like to Update Opcode.eXe's get3DXYZInFrontOf Snippet so that Future Readers will not face the same issue:
Code:
:get3DXYZInFrontOfTrueNorth // 0AB1: @get3DXYZInFrontOfTrueNorth 6 _XYZ 0@ 1@ 2@ _ZAngle 3@ _XAngle 4@  _Distance 5@ _ReturnXYZ 0@ 1@ 2@
    {
        Snippet By AJOM
        Based on Source: http://danceswithcode.net/engineeringnotes/rotations_in_3d/rotations_in_3d_part2.html
        But Using:
            X0 = _Distance = 5@ , Y0 = 0.0 , Z0 = 0.0
            Yaw = _ZAngle = 3@ , Pitch = _XAngle = 4@ , Roll = 0.0
    }
        // Use Opcode.eXe's Coordinate system
    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@
Notice:
  1. The Snippet above replaces Opcode.eXe's get3DXYZInFrontOf Snippet.
  2. Opcode.eXe's Snippet uses the True North Coordinate System of the Game as basis of its rotation angles, and so as this Snippet.



Now this is my Original Version of this Snippet:
Code:
:get3DXYZInFrontOfWorld // 0AB1: @get3DXYZInFrontOfWorld 6 _XYZ 0@ 1@ 2@ _ZAngle 3@ _XAngle 4@  _Distance 5@ _ReturnXYZ 0@ 1@ 2@
    {
        Snippet By AJOM
        Based on Source: http://danceswithcode.net/engineeringnotes/rotations_in_3d/rotations_in_3d_part2.html
        But Using:
            X0 = _Distance = 5@ , Y0 = 0.0 , Z0 = 0.0
            Yaw = _ZAngle = 3@ , Pitch = _XAngle = 4@ , Roll = 0.0
    }
        // 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@
Notice:
  1. The Snippet Above Assumes its rotation angles to respect the Game's World Coordinate System.



There is a difference between Angles of Game's True North and Angles of the Game's World.
  1. Game's True North ZAngle has an additional 90 degrees than Game's World ZAngle
  2. Game's True North XAngle has an additional 180 degrees than Game's World XAngle
Most Opcodes that have connection to angles uses the Game's True North, but there are also some opcodes that bases to the Game's World. So It is up to you which of those snippets I would use... But I will prefer the True North since it is mostly used by most opcodes. Here are some Info:
Code:
// some opcodes that Bases its angles from True North
0172: $TEMPVAR_ANGLE = actor 215@ Z_angle
0173: set_actor $PLAYER_ACTOR Z_angle_to 262.0
0175: set_car 22@ Z_angle_to 315.0
// ... and many more

// some opcodes that Bases its angles from the World
070F: plane 38@ fly_direction 180.0 altitude_between 200.0 and 200.0
// ... and maybe there is something more, But not that much


Application:
Code:
{CLEO}
0000:

while true
    wait 0

    if 0ADC:   test_cheat "fuzzy"
    then
        0619: enable_actor $PLAYER_ACTOR collision_detection false
        0575: set_actor $PLAYER_ACTOR pinned_position 1

        for 8@ = 1 to 10
            wait 100
            0172: 0@ = actor $PLAYER_ACTOR Z_angle
            00A0: store_actor $PLAYER_ACTOR position_to 2@ 3@ 4@
            0AB1: @get3DXYZInFrontOfTrueNorth 6 _XYZ 2@ 3@ 4@ _ZAngle 0@ _XAngle 0.0  _Distance 1.0 _ReturnXYZ 5@ 6@ 7@
            09BC: put_actor $PLAYER_ACTOR at 5@ 6@ 7@ no_offset_and_dont_warp_gang
            0ACD: show_text_highpriority "Moving frontwards" time 300
        end

        for 8@ = 1 to 10
            wait 100
            0172: 0@ = actor $PLAYER_ACTOR Z_angle
            0@ += 180.0 // backwards
            00A0: store_actor $PLAYER_ACTOR position_to 2@ 3@ 4@
            0AB1: @get3DXYZInFrontOfTrueNorth 6 _XYZ 2@ 3@ 4@ _ZAngle 0@ _XAngle 0.0  _Distance 1.0 _ReturnXYZ 5@ 6@ 7@
            09BC: put_actor $PLAYER_ACTOR at 5@ 6@ 7@ no_offset_and_dont_warp_gang
            0ACD: show_text_highpriority "Moving backwards" time 300
        end

        for 1@ = 45.0 to 135.0 step 45.0
            for 8@ = 1 to 10
                wait 100
                0172: 0@ = actor $PLAYER_ACTOR Z_angle
                005B: 0@ += 1@ // extra angle , front to left
                00A0: store_actor $PLAYER_ACTOR position_to 2@ 3@ 4@
                0AB1: @get3DXYZInFrontOfTrueNorth 6 _XYZ 2@ 3@ 4@ _ZAngle 0@ _XAngle 0.0  _Distance 1.0 _ReturnXYZ 5@ 6@ 7@
                09BC: put_actor $PLAYER_ACTOR at 5@ 6@ 7@ no_offset_and_dont_warp_gang
                0AD1: show_formatted_text_highpriority "Moving %f degrees from front to left" time 300 1@
            end
        end

        for 1@ = 45.0 to 135.0 step 45.0
            for 8@ = 1 to 10
                wait 100
                0172: 0@ = actor $PLAYER_ACTOR Z_angle
                0063: 0@ -= 1@ // extra angle , front to right
                00A0: store_actor $PLAYER_ACTOR position_to 2@ 3@ 4@
                0AB1: @get3DXYZInFrontOfTrueNorth 6 _XYZ 2@ 3@ 4@ _ZAngle 0@ _XAngle 0.0  _Distance 1.0 _ReturnXYZ 5@ 6@ 7@
                09BC: put_actor $PLAYER_ACTOR at 5@ 6@ 7@ no_offset_and_dont_warp_gang
                0AD1: show_formatted_text_highpriority "Moving %f degrees from front to right" time 300 1@
            end
        end

        for 8@ = 1 to 10
            wait 100
            0172: 0@ = actor $PLAYER_ACTOR Z_angle
            00A0: store_actor $PLAYER_ACTOR position_to 2@ 3@ 4@
            0AB1: @get3DXYZInFrontOfTrueNorth 6 _XYZ 2@ 3@ 4@ _ZAngle 0@ _XAngle 90.0  _Distance 1.0 _ReturnXYZ 5@ 6@ 7@
            09BC: put_actor $PLAYER_ACTOR at 5@ 6@ 7@ no_offset_and_dont_warp_gang
            0ACD: show_text_highpriority "Moving upwards" time 300
        end

        for 8@ = 1 to 10
            wait 100
            0172: 0@ = actor $PLAYER_ACTOR Z_angle
            00A0: store_actor $PLAYER_ACTOR position_to 2@ 3@ 4@
            0AB1: @get3DXYZInFrontOfTrueNorth 6 _XYZ 2@ 3@ 4@ _ZAngle 0@ _XAngle -90.0  _Distance 1.0 _ReturnXYZ 5@ 6@ 7@
            09BC: put_actor $PLAYER_ACTOR at 5@ 6@ 7@ no_offset_and_dont_warp_gang
            0ACD: show_text_highpriority "Moving downwards" time 300
        end

        for 1@ = -45.0 to 45.0 step 90.0
            for 8@ = 1 to 10
                wait 100
                0172: 0@ = actor $PLAYER_ACTOR Z_angle
                00A0: store_actor $PLAYER_ACTOR position_to 2@ 3@ 4@
                0AB1: @get3DXYZInFrontOfTrueNorth 6 _XYZ 2@ 3@ 4@ _ZAngle 0@ _XAngle 1@  _Distance 1.0 _ReturnXYZ 5@ 6@ 7@
                09BC: put_actor $PLAYER_ACTOR at 5@ 6@ 7@ no_offset_and_dont_warp_gang
                0AD1: show_formatted_text_highpriority "frontward Moving %f degrees from upwards" time 300 1@
            end
        end

        for 1@ = -135.0 to 135.0 step 90.0
            for 8@ = 1 to 10
                wait 100
                0172: 0@ = actor $PLAYER_ACTOR Z_angle
                00A0: store_actor $PLAYER_ACTOR position_to 2@ 3@ 4@
                0AB1: @get3DXYZInFrontOfTrueNorth 6 _XYZ 2@ 3@ 4@ _ZAngle 0@ _XAngle 1@  _Distance 1.0 _ReturnXYZ 5@ 6@ 7@
                09BC: put_actor $PLAYER_ACTOR at 5@ 6@ 7@ no_offset_and_dont_warp_gang
                0AD1: show_formatted_text_highpriority "frontward Moving %f degrees from upwards" time 300 1@
            end
        end

        for 1@ = -135.0 to 135.0 step 90.0
            for 8@ = 1 to 10
                wait 100
                0172: 0@ = actor $PLAYER_ACTOR Z_angle
                0@ += 180.0
                00A0: store_actor $PLAYER_ACTOR position_to 2@ 3@ 4@
                0AB1: @get3DXYZInFrontOfTrueNorth 6 _XYZ 2@ 3@ 4@ _ZAngle 0@ _XAngle 1@  _Distance 1.0 _ReturnXYZ 5@ 6@ 7@
                09BC: put_actor $PLAYER_ACTOR at 5@ 6@ 7@ no_offset_and_dont_warp_gang
                0AD1: show_formatted_text_highpriority "backward Moving %f degrees from upwards" time 300 1@
            end
        end

        0575: set_actor $PLAYER_ACTOR pinned_position 0
        0619: enable_actor $PLAYER_ACTOR collision_detection true
    end
end
 

SamThapa

Active member
Joined
Jan 22, 2018
Messages
82
Reaction score
2
Hey there

i was trying this

getting coordinates from player using this opcode setting offset to get little higher than player position as you can see i use z 0.5
04C4: store_coords_to 10@ 11@ 12@ from_actor $PLAYER_ACTOR with_offset 0.2 0.3 0.5


i need that gives me coordinates to offset value
example using same opcode ok but
04C4: store_coords_to 10@ 11@ 12@ from_actor $PLAYER_ACTOR with_offset 0.2 0.3 0.5
your calculation then some magic happen
0087: 13@ = 10@ // (float)
0087: 14@ = 11@ // (float)
0087: 15@ = 12@ // (float)

0ad1: "Offsets %.2f %.2f %.2f" 2000 13@ 14@ 15@ must give that value 0.2 0.3 0.5

how to do that i try i got nothing :(
 
Top