1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Having troubles with BlzSetSpecialEffectOrientation

Discussion in 'Triggers & Scripts' started by Drynwhyl, Aug 17, 2018.

  1. Drynwhyl

    Drynwhyl

    Joined:
    Nov 21, 2016
    Messages:
    18
    Resources:
    0
    Resources:
    0
    Hello everyone! I'm writing a projectile system for my map using new effect natives. And I was testing this BlzSetSpecialEffectOrientation function as well as the others (BlzSetSpecialEffectYaw, etc). And here's the issue: I cannot get the orientation i need. In other projectile systems there were dummy units with facing set by SetUnitFacing and angle of attack set by animations of dummy model. But this effect natives behave weird. Most of the time I need the effect to face a point, or set it orientation using 2 angles: facing (like unit facing) and angle of attack. So I'd like to have a function that takes this values and converts them into corresponding "yaw", "pitch" and "roll". I tried to do it myself for a while but still have not figured out how do i get this conversion. Here is the test map.
     

    Attached Files:

  2. AGD

    AGD

    Joined:
    Mar 29, 2016
    Messages:
    397
    Resources:
    13
    Spells:
    7
    Tutorials:
    1
    JASS:
    5
    Resources:
    13
    Are you aware that yaw, pitch, and roll are rotations about the global axes (x, y, z) and not 'local axes' (which is also dependent on the current orientation) of the unit?
    EDIT: Yaw is rotation about the effect's facing axis, Pitch is rotation about the transverse axis, and Roll is the rotation about the effect's local z-axis.
     
    Last edited: Aug 19, 2018
  3. Drynwhyl

    Drynwhyl

    Joined:
    Nov 21, 2016
    Messages:
    18
    Resources:
    0
    Resources:
    0
    If so, the angles I need are found by formula:
    Code (vJASS):
    set yaw = angleOfAttack * Sin(facing)
    set pitch = angleOfAttack * Cos(facing)
    set roll = facing

    But it gives wrong values.


    Updated:
    So, with this in mind, the real question would be: how do I convert global angles to local ones?
     
    Last edited: Aug 18, 2018
  4. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,163
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
  5. AGD

    AGD

    Joined:
    Mar 29, 2016
    Messages:
    397
    Resources:
    13
    Spells:
    7
    Tutorials:
    1
    JASS:
    5
    Resources:
    13
    Nevermind, this is incorrect. Edited the comment above. They are all rotations about the effect's local axes.
     
  6. AGD

    AGD

    Joined:
    Mar 29, 2016
    Messages:
    397
    Resources:
    13
    Spells:
    7
    Tutorials:
    1
    JASS:
    5
    Resources:
    13
    According to @Wareditor, it uses global axes. That's what I initially thought too according to my tests last night, but after further testing it seems more likely to be using local axes, because some results don't coincide with the expected results if it were using the global axes (and it coincides with the expected results if local axes are used instead). Btw, here are all the things I found out while fiddling with the effect orientation natives last night:
    • Yaw, pitch, and roll values are only updated once per thread execution and the values that are used are the values used in the latest call to the BlzSetSpecialEffect(Yaw/Pitch/Roll/Orientation) functions
    • BlzSetSpecialEffectRoll() rotates the effect about its local z-axis
    • BlzSetSpecialEffectYaw() rotates the effect about its longitudinal axis
    • BlzSetSpecialEffectPitch() rotates the effect about its transverse axis
    • The orientations are updated only after the current thread execution in the following order: yaw -> pitch -> roll
    Ofcourse I could be mistaken, so further test results are welcome.
     
  7. Drynwhyl

    Drynwhyl

    Joined:
    Nov 21, 2016
    Messages:
    18
    Resources:
    0
    Resources:
    0
    This not giving me same effect for all possible facings, It only works right on some (like -180 and 0 degrees). Here is example. When facing is -135 degrees, an unwanted roll effect appears. In this test I use GetCameraEyePosition. I think this happen because of order of Euler angles that SetEffectOrientation uses. It's XYZ, but all we want is a proper euler angles which is ZYZ (Most common is ZXZ but in Warcraft it would be ZYZ).
    [​IMG]
    With this Euler angles sequence the needed rotation require simple and intuitive angles, Z represents facing, Y' - angle of attack and Z'' is roll which most of the time will be equal to 0 (unless you want to flip your effect upside down or whatever).
     

    Attached Files:

    • 03.jpg
      03.jpg
      File size:
      349.9 KB
      Views:
      41
    • 04.jpg
      04.jpg
      File size:
      364 KB
      Views:
      29
  8. Wareditor

    Wareditor

    Joined:
    Jan 16, 2009
    Messages:
    681
    Resources:
    3
    Maps:
    3
    Resources:
    3
    It's working perfectly fine for (though I removed the negation part that @IcemanBo added - it was causing issues). Your problem must be that the camera position coordinates are not what you think they are.
    Here is a map with a sphere made out of peasants.
     

    Attached Files:

  9. Drynwhyl

    Drynwhyl

    Joined:
    Nov 21, 2016
    Messages:
    18
    Resources:
    0
    Resources:
    0
    Yes! The camera position was the issue. Thank you.
     
  10. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,163
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    @Wareditor
    But a same facing can have different axis rotations. Maybe an extra param can be used, not sure. Have a look, at demo, one could expect the pig to turn around differenly (without the visual cut)
    The facing is correct, but yaw/pitch appear not same when dx in this example is smaller or bigger 0. So only with faxing xyz some information of the extra pitch or yaw is missing (?).

    edit: moment

    edit: attached

    btw, a check for 0 divide can be here:

    Code (vJASS):

    set py = (1-(ix/(ix+iy)))

    set px = (1-(iy/(ix+iy)))
     
     

    Attached Files:

  11. Drynwhyl

    Drynwhyl

    Joined:
    Nov 21, 2016
    Messages:
    18
    Resources:
    0
    Resources:
    0
    If you want to set direct angles I wrote this function. What it does is converts ZYX angles to rotation matrix and then back to XYZ. Z is facing and Y is angle of attack, and an extra param "rotation" is X.

    edit: test map added, type angles in degrees to change facing

    Code (vJASS):

        function SetEffectOrientation takes effect e, real z, real y, real x returns nothing
     
            local real c1 = Cos(x)
            local real s1 = Sin(x)
         
            local real c2 = Cos(-y)
            local real s2 = Sin(-y)
         
            local real c3 = Cos(z)
            local real s3 = Sin(z)
                 
            local real sy = SquareRoot(Pow(c2*c3, 2.) + Pow(c1*s3 + c3*s1*s2, 2.))
       
            if not (sy == 0) then // do not change this to !=
         
                set x = Atan2(c3*s1 + c1*s2*s3 , c1*c2)
                set y = Atan2(-s1*s3 + c1*c3*s2, sy)
                set z = Atan2(c1*s3 + c3*s1*s2, c2*c3)
         
            else
         
                set x = Atan2(c2*s1, c1*c3 - s1*s2*s3)
                set y = Atan2(-s1*s3 + c1*c3*s2, sy)
                set z = 0
             
            endif
         
            call BlzSetSpecialEffectOrientation(e, -x, y, z)
                 
        endfunction
     
     

    Attached Files:

    Last edited: Aug 19, 2018
  12. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,163
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    I'm not at home next days, but I surely will look at your map at some time, thanks.

    When you say Y is angleOfAttack, you mean the function takes its yaw, so rotation around its local x-axis, and x is its pitch, so rotation around local y-axis?

    May I ask what does Wareditor's function give you, if you could calculate the respective axis rotations in before?

    I would still be confused I guess how to determine the correct x param, as.. in 2 quandrants 1PI would need to added to make the roll not reset (?), but in which?

    Maybe I'm just also not too much into it, and it should be anyways defined then by user what kind of facing is needed.
     
  13. Drynwhyl

    Drynwhyl

    Joined:
    Nov 21, 2016
    Messages:
    18
    Resources:
    0
    Resources:
    0
    This is Euler angles so the "z" argument is rotation around global Z axis, then "y" argument is rotation around local Y' axis which is formed after the first rotation (Z axis) and therefore affected by it, and finally x is rotation around local X'' axis which affected both by "z" and "y" rotations. Like I said before usually you want the last "x" parameter to be zero unless you want something special, for example passing 90 degrees to this paramereter will turn effect sideways and 180 will flip it upside down.
    I think Wareditor's function is good for facing 3d point for example make projectile face target. You also can do this with function I posted, but you need calculate the angles between effect and facing target. And therefore It will be slower. (I think when you call this kind of function thousands time per seconds speed actually matters)
     
    Last edited: Aug 19, 2018